]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | #!/bin/sh |
2 | # | |
3 | # IRC - Internet Relay Chat, tools/mkchroot | |
4 | # Copyright (C) 2001 Kevin L. Mitchell <klmitch@mit.edu> | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 1, or (at your option) | |
9 | # any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | # | |
20 | # $Id: mkchroot,v 1.1 2001/06/21 15:48:16 kev Exp $ | |
21 | ||
22 | if test $# -lt 2; then | |
23 | echo "Usage: $0 <destdir> <executable> [<executable> [...]]" >&2 | |
24 | exit 2 | |
25 | fi | |
26 | ||
27 | destdir=$1 | |
28 | shift | |
29 | ||
30 | # Use ldd to formulate a newline-separated list of libraries | |
31 | liblist= | |
32 | for arg | |
33 | do | |
34 | # Interpret ldd output | |
35 | libs=`ldd $arg | sed -e 's/ / /g' -e 's/ */ /g' -e 's/^ //g' | \ | |
36 | awk 'BEGIN { RS = " "; } { print; }' | grep '^/'` | |
37 | ||
38 | # add it to the list so far | |
39 | if test x"$liblist" = x; then | |
40 | liblist=$libs | |
41 | else | |
42 | liblist="$liblist | |
43 | $libs" | |
44 | fi | |
45 | done | |
46 | # Sort the list and remove duplicates | |
47 | liblist=`echo "$liblist" | sort -u` | |
48 | ||
49 | # Now figure out all the subdirectories we're interested in | |
50 | # Must create the top level, if need be | |
51 | dirlist=/ | |
52 | # Break down the library list into directories and remove duplicates | |
53 | dirs=`echo "$liblist" | sed -e 's@/[^/]*$@@' | sort -u` | |
54 | # Go through each directory to break it down into its components | |
55 | for headdir in $dirs; do | |
56 | tIFS=$IFS | |
57 | IFS=/$IFS | |
58 | # Start at the top level | |
59 | dir= | |
60 | for subdir in $headdir; do | |
61 | # update dir so we know where we are | |
62 | if test x"$dir" = x; then | |
63 | dir=$subdir | |
64 | else | |
65 | dir=$dir/$subdir | |
66 | fi | |
67 | ||
68 | # add (absolute) entry to directory list | |
69 | dirlist="$dirlist | |
70 | /$dir" | |
71 | done | |
72 | IFS=$tIFS | |
73 | done | |
74 | # Sort for ordering and remove duplicates | |
75 | dirlist=`echo "$dirlist" | sort -u` | |
76 | ||
77 | # Create the directories | |
78 | echo "Creating directories:" | |
79 | for dir in $dirlist; do | |
80 | # add destination directory name, remove trailing /, if any, for test | |
81 | dir=`echo "$destdir$dir" | sed -e 's@//*$@@'` | |
82 | echo " $dir" | |
83 | # sanity-check directory... | |
84 | if test -f "$dir" -o -h "$dir"; then | |
85 | echo "ERROR: A non-directory \"$dir\" already exists; bailing out" >&2 | |
86 | exit 2 | |
87 | elif test ! -d "$dir"; then | |
88 | # Create the directory world-readable | |
89 | mkdir -m 755 $dir | |
90 | fi | |
91 | done | |
92 | ||
93 | # Now copy over the libraries | |
94 | echo "Copying libraries:" | |
95 | for lib in $liblist; do | |
96 | echo " $lib -> $destdir$lib" | |
97 | # Preserve permissions | |
98 | cp -p $lib $destdir$lib | |
99 | done |