1 | #!/bin/sh
|
---|
2 |
|
---|
3 | export LC_ALL=POSIX
|
---|
4 | export LC_CTYPE=POSIX
|
---|
5 |
|
---|
6 | prefix=$1
|
---|
7 | if [ -z "$prefix" ]; then
|
---|
8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
---|
9 | exit 1
|
---|
10 | fi
|
---|
11 |
|
---|
12 | # Source the configuration
|
---|
13 | . ./.config
|
---|
14 |
|
---|
15 | h=`sort busybox.links | uniq`
|
---|
16 |
|
---|
17 | sharedlib_dir="0_lib"
|
---|
18 |
|
---|
19 | linkopts=""
|
---|
20 | scriptwrapper="n"
|
---|
21 | binaries="n"
|
---|
22 | cleanup="0"
|
---|
23 | noclobber="0"
|
---|
24 | case "$2" in
|
---|
25 | --hardlinks) linkopts="-f";;
|
---|
26 | --symlinks) linkopts="-fs";;
|
---|
27 | --binaries) binaries="y";;
|
---|
28 | --scriptwrapper) scriptwrapper="y";swrapall="y";;
|
---|
29 | --sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
---|
30 | --sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
---|
31 | --cleanup) cleanup="1";;
|
---|
32 | --noclobber) noclobber="1";;
|
---|
33 | "") h="";;
|
---|
34 | *) echo "Unknown install option: $2"; exit 1;;
|
---|
35 | esac
|
---|
36 |
|
---|
37 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
---|
38 | # get the target dir for the libs
|
---|
39 | # assume it starts with lib
|
---|
40 | libdir=$($CC -print-file-name=libc.so | \
|
---|
41 | sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
|
---|
42 | if test -z "$libdir"; then
|
---|
43 | libdir=/lib
|
---|
44 | fi
|
---|
45 |
|
---|
46 | mkdir -p "$prefix/$libdir" || exit 1
|
---|
47 | for i in $DO_INSTALL_LIBS; do
|
---|
48 | rm -f "$prefix/$libdir/$i" || exit 1
|
---|
49 | if [ -f "$i" ]; then
|
---|
50 | echo " Installing $i to the target at $prefix/$libdir/"
|
---|
51 | cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
---|
52 | chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
---|
53 | fi
|
---|
54 | done
|
---|
55 | fi
|
---|
56 |
|
---|
57 | if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
---|
58 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
---|
59 | sub_shell_it=`
|
---|
60 | cd "$prefix"
|
---|
61 | for d in usr/sbin usr/bin sbin bin; do
|
---|
62 | pd=$PWD
|
---|
63 | if [ -d "$d" ]; then
|
---|
64 | cd "$d"
|
---|
65 | ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
|
---|
66 | fi
|
---|
67 | cd "$pd"
|
---|
68 | done
|
---|
69 | `
|
---|
70 | exit 0
|
---|
71 | fi
|
---|
72 |
|
---|
73 | rm -f "$prefix/bin/busybox" || exit 1
|
---|
74 | mkdir -p "$prefix/bin" || exit 1
|
---|
75 | install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
---|
76 |
|
---|
77 | for i in $h; do
|
---|
78 | appdir=`dirname "$i"`
|
---|
79 | app=`basename "$i"`
|
---|
80 | mkdir -p "$prefix/$appdir" || exit 1
|
---|
81 | if [ "$scriptwrapper" = "y" ]; then
|
---|
82 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
---|
83 | ln $linkopts busybox "$prefix/$i" || exit 1
|
---|
84 | else
|
---|
85 | rm -f "$prefix/$i"
|
---|
86 | echo "#!/bin/busybox" >"$prefix/$i"
|
---|
87 | chmod +x "$prefix/$i"
|
---|
88 | fi
|
---|
89 | echo " $prefix/$i"
|
---|
90 | elif [ "$binaries" = "y" ]; then
|
---|
91 | # Copy the binary over rather
|
---|
92 | if [ -e $sharedlib_dir/$app ]; then
|
---|
93 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
---|
94 | echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
---|
95 | cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
|
---|
96 | else
|
---|
97 | echo " $prefix/$i already exists"
|
---|
98 | fi
|
---|
99 | else
|
---|
100 | echo "Error: Could not find $sharedlib_dir/$app"
|
---|
101 | exit 1
|
---|
102 | fi
|
---|
103 | else
|
---|
104 | if [ "$2" = "--hardlinks" ]; then
|
---|
105 | bb_path="$prefix/bin/busybox"
|
---|
106 | else
|
---|
107 | case "$appdir" in
|
---|
108 | /)
|
---|
109 | bb_path="bin/busybox"
|
---|
110 | ;;
|
---|
111 | /bin)
|
---|
112 | bb_path="busybox"
|
---|
113 | ;;
|
---|
114 | /sbin)
|
---|
115 | bb_path="../bin/busybox"
|
---|
116 | ;;
|
---|
117 | /usr/bin | /usr/sbin)
|
---|
118 | bb_path="../../bin/busybox"
|
---|
119 | ;;
|
---|
120 | *)
|
---|
121 | echo "Unknown installation directory: $appdir"
|
---|
122 | exit 1
|
---|
123 | ;;
|
---|
124 | esac
|
---|
125 | fi
|
---|
126 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
---|
127 | echo " $prefix/$i -> $bb_path"
|
---|
128 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
---|
129 | else
|
---|
130 | echo " $prefix/$i already exists"
|
---|
131 | fi
|
---|
132 | fi
|
---|
133 | done
|
---|
134 |
|
---|
135 | exit 0
|
---|