blob: e94b2b98ec6342a76dc57fdc0e22ba6e750d15eb [file] [log] [blame]
Eric Anderseneded54b1999-11-12 08:03:23 +00001#!/bin/sh
2
Eric Andersen39eea892001-03-08 21:42:11 +00003export LC_ALL=POSIX
4export LC_CTYPE=POSIX
5
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +00006prefix=${1}
7if [ -z "$prefix" ]; then
Denis Vlasenko737d1312007-08-25 18:25:24 +00008 echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
Mike Frysinger55b12102006-06-07 17:24:29 +00009 exit 1;
Eric Anderseneded54b1999-11-12 08:03:23 +000010fi
Eric Andersena9c95ea1999-11-15 17:33:30 +000011h=`sort busybox.links | uniq`
Denis Vlasenko737d1312007-08-25 18:25:24 +000012scriptwrapper="n"
Mike Frysinger81514ec2006-06-07 18:08:25 +000013cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000014noclobber="0"
Rob Landleye0c418e2005-12-15 07:25:54 +000015case "$2" in
Denis Vlasenko737d1312007-08-25 18:25:24 +000016 --hardlinks) linkopts="-f";;
17 --symlinks) linkopts="-fs";;
18 --scriptwrapper) scriptwrapper="y";swrapall="y";;
19 --sw-sh-hard) scriptwrapper="y";linkopts="-f";;
20 --sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
21 --cleanup) cleanup="1";;
22 --noclobber) noclobber="1";;
23 "") h="";;
24 *) echo "Unknown install option: $2"; exit 1;;
Rob Landleye0c418e2005-12-15 07:25:54 +000025esac
Eric Anderseneded54b1999-11-12 08:03:23 +000026
Mike Frysinger74b29a12006-06-07 17:27:46 +000027if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000028 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000029 # assume it starts with lib
30 libdir=$($CC -print-file-name=libc.so | \
31 sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
32 if test -z "$libdir"; then
33 libdir=/lib
34 fi
Eric Andersen51154ba2000-07-20 21:57:11 +000035
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000036 mkdir -p $prefix/$libdir || exit 1
37 for i in $DO_INSTALL_LIBS; do
38 rm -f $prefix/$libdir/$i || exit 1
39 if [ -f $i ]; then
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000040 cp -a $i $prefix/$libdir/ || exit 1
41 chmod 0644 $prefix/$libdir/$i || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000042 fi
43 done
44fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000045
46if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
47 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
48 sub_shell_it=`
49 cd "$prefix"
Denis Vlasenkob71c6682007-07-21 15:08:09 +000050 for d in usr/sbin usr/bin sbin bin; do
Mike Frysinger81514ec2006-06-07 18:08:25 +000051 pd=$PWD
52 if [ -d "$d" ]; then
53 cd $d
54 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
55 fi
56 cd "$pd"
57 done
58 `
Denis Vlasenko737d1312007-08-25 18:25:24 +000059 exit 0
Mike Frysinger81514ec2006-06-07 18:08:25 +000060fi
61
Pavel Roskin259972e2000-07-28 19:34:02 +000062rm -f $prefix/bin/busybox || exit 1
63mkdir -p $prefix/bin || exit 1
64install -m 755 busybox $prefix/bin/busybox || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000065
Denis Vlasenkob71c6682007-07-21 15:08:09 +000066for i in $h; do
Eric Andersen51154ba2000-07-20 21:57:11 +000067 appdir=`dirname $i`
Pavel Roskin259972e2000-07-28 19:34:02 +000068 mkdir -p $prefix/$appdir || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000069 if [ "$scriptwrapper" = "y" ]; then
70 if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
71 ln $linkopts busybox $prefix$i || exit 1
72 else
73 rm -f $prefix$i
74 echo "#!/bin/busybox" > $prefix$i
75 chmod +x $prefix/$i
76 fi
77 echo " $prefix$i"
Eric Andersen51154ba2000-07-20 21:57:11 +000078 else
Denis Vlasenko737d1312007-08-25 18:25:24 +000079 if [ "$2" = "--hardlinks" ]; then
80 bb_path="$prefix/bin/busybox"
81 else
82 case "$appdir" in
83 /)
84 bb_path="bin/busybox"
85 ;;
86 /bin)
87 bb_path="busybox"
88 ;;
89 /sbin)
90 bb_path="../bin/busybox"
91 ;;
92 /usr/bin|/usr/sbin)
93 bb_path="../../bin/busybox"
94 ;;
95 *)
96 echo "Unknown installation directory: $appdir"
97 exit 1
98 ;;
99 esac
100 fi
101 if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
102 echo " $prefix$i -> $bb_path"
103 ln $linkopts $bb_path $prefix$i || exit 1
104 else
105 echo " $prefix$i already exists"
106 fi
Mike Frysingere3fdf242006-06-07 18:12:27 +0000107 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000108done
109
Eric Andersencb41c2e1999-11-22 07:41:00 +0000110exit 0