Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / applets / install.sh
blob95b4719d4b6f09982917a0cce345756daec0242c
1 #!/bin/sh
3 export LC_ALL=POSIX
4 export LC_CTYPE=POSIX
6 prefix=$1
7 if [ -z "$prefix" ]; then
8 echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
9 exit 1
12 h=`sort busybox.links | uniq`
14 linkopts=""
15 scriptwrapper="n"
16 cleanup="0"
17 noclobber="0"
18 case "$2" in
19 --hardlinks) linkopts="-f";;
20 --symlinks) linkopts="-fs";;
21 --scriptwrapper) scriptwrapper="y";swrapall="y";;
22 --sw-sh-hard) scriptwrapper="y";linkopts="-f";;
23 --sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
24 --cleanup) cleanup="1";;
25 --noclobber) noclobber="1";;
26 "") h="";;
27 *) echo "Unknown install option: $2"; exit 1;;
28 esac
30 if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
31 # get the target dir for the libs
32 # assume it starts with lib
33 libdir=$($CC -print-file-name=libc.so | \
34 sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
35 if test -z "$libdir"; then
36 libdir=/lib
39 mkdir -p "$prefix/$libdir" || exit 1
40 for i in $DO_INSTALL_LIBS; do
41 rm -f "$prefix/$libdir/$i" || exit 1
42 if [ -f "$i" ]; then
43 cp -pPR "$i" "$prefix/$libdir/" || exit 1
44 chmod 0644 "$prefix/$libdir/$i" || exit 1
46 done
49 if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
50 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
51 sub_shell_it=`
52 cd "$prefix"
53 for d in usr/sbin usr/bin sbin bin; do
54 pd=$PWD
55 if [ -d "$d" ]; then
56 cd "$d"
57 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
59 cd "$pd"
60 done
62 exit 0
65 rm -f "$prefix/bin/busybox" || exit 1
66 mkdir -p "$prefix/bin" || exit 1
67 install -m 755 busybox "$prefix/bin/busybox" || exit 1
69 for i in $h; do
70 appdir=`dirname "$i"`
71 mkdir -p "$prefix/$appdir" || exit 1
72 if [ "$scriptwrapper" = "y" ]; then
73 if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
74 ln $linkopts busybox "$prefix/$i" || exit 1
75 else
76 rm -f "$prefix/$i"
77 echo "#!/bin/busybox" >"$prefix/$i"
78 chmod +x "$prefix/$i"
80 echo " $prefix/$i"
81 else
82 if [ "$2" = "--hardlinks" ]; then
83 bb_path="$prefix/bin/busybox"
84 else
85 case "$appdir" in
87 bb_path="bin/busybox"
89 /bin)
90 bb_path="busybox"
92 /sbin)
93 bb_path="../bin/busybox"
95 /usr/bin | /usr/sbin)
96 bb_path="../../bin/busybox"
99 echo "Unknown installation directory: $appdir"
100 exit 1
102 esac
104 if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
105 echo " $prefix/$i -> $bb_path"
106 ln $linkopts "$bb_path" "$prefix/$i" || exit 1
107 else
108 echo " $prefix/$i already exists"
111 done
113 exit 0