Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Eric Andersen | 39eea89 | 2001-03-08 21:42:11 +0000 | [diff] [blame] | 3 | export LC_ALL=POSIX |
| 4 | export LC_CTYPE=POSIX |
| 5 | |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 6 | prefix=${1} |
| 7 | if [ -z "$prefix" ]; then |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]" |
Mike Frysinger | 55b1210 | 2006-06-07 17:24:29 +0000 | [diff] [blame] | 9 | exit 1; |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 10 | fi |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 11 | h=`sort busybox.links | uniq` |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 12 | scriptwrapper="n" |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 13 | cleanup="0" |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 14 | noclobber="0" |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 15 | case "$2" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 16 | --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 Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 25 | esac |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 26 | |
Mike Frysinger | 74b29a1 | 2006-06-07 17:27:46 +0000 | [diff] [blame] | 27 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 28 | # get the target dir for the libs |
Rob Landley | d196867 | 2006-03-24 02:42:58 +0000 | [diff] [blame] | 29 | # 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 Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 35 | |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 36 | 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 |
Denis Vlasenko | c0431ed | 2008-04-27 22:06:24 +0000 | [diff] [blame] | 40 | cp -pPR $i $prefix/$libdir/ || exit 1 |
Bernhard Reutner-Fischer | 5d26126 | 2006-03-01 22:54:48 +0000 | [diff] [blame] | 41 | chmod 0644 $prefix/$libdir/$i || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 42 | fi |
| 43 | done |
| 44 | fi |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 45 | |
| 46 | if [ "$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 Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 50 | for d in usr/sbin usr/bin sbin bin; do |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 51 | 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 Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 59 | exit 0 |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 60 | fi |
| 61 | |
Pavel Roskin | 259972e | 2000-07-28 19:34:02 +0000 | [diff] [blame] | 62 | rm -f $prefix/bin/busybox || exit 1 |
| 63 | mkdir -p $prefix/bin || exit 1 |
| 64 | install -m 755 busybox $prefix/bin/busybox || exit 1 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 65 | |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 66 | for i in $h; do |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 67 | appdir=`dirname $i` |
Pavel Roskin | 259972e | 2000-07-28 19:34:02 +0000 | [diff] [blame] | 68 | mkdir -p $prefix/$appdir || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 69 | 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 Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 78 | else |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 79 | 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 Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 107 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 108 | done |
| 109 | |
Eric Andersen | cb41c2e | 1999-11-22 07:41:00 +0000 | [diff] [blame] | 110 | exit 0 |