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 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 6 | prefix=$1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 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]" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 9 | exit 1 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 10 | fi |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 11 | |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 12 | h=`sort busybox.links | uniq` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 13 | |
| 14 | linkopts="" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 15 | scriptwrapper="n" |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 16 | cleanup="0" |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 17 | noclobber="0" |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 18 | case "$2" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 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;; |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 28 | esac |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 29 | |
Mike Frysinger | 74b29a1 | 2006-06-07 17:27:46 +0000 | [diff] [blame] | 30 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 31 | # get the target dir for the libs |
Rob Landley | d196867 | 2006-03-24 02:42:58 +0000 | [diff] [blame] | 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 |
| 37 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 38 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 39 | mkdir -p "$prefix/$libdir" || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 40 | for i in $DO_INSTALL_LIBS; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 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 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 45 | fi |
| 46 | done |
| 47 | fi |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 48 | |
| 49 | if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then |
| 50 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'` |
| 51 | sub_shell_it=` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 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 |
| 58 | fi |
| 59 | cd "$pd" |
| 60 | done |
| 61 | ` |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 62 | exit 0 |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 63 | fi |
| 64 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 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 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 68 | |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 69 | for i in $h; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 70 | appdir=`dirname "$i"` |
| 71 | mkdir -p "$prefix/$appdir" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 72 | if [ "$scriptwrapper" = "y" ]; then |
| 73 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 74 | ln $linkopts busybox "$prefix/$i" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 75 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 76 | rm -f "$prefix/$i" |
| 77 | echo "#!/bin/busybox" >"$prefix/$i" |
| 78 | chmod +x "$prefix/$i" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 79 | fi |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 80 | echo " $prefix/$i" |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 81 | else |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 82 | if [ "$2" = "--hardlinks" ]; then |
| 83 | bb_path="$prefix/bin/busybox" |
| 84 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 85 | case "$appdir" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 86 | /) |
| 87 | bb_path="bin/busybox" |
| 88 | ;; |
| 89 | /bin) |
| 90 | bb_path="busybox" |
| 91 | ;; |
| 92 | /sbin) |
| 93 | bb_path="../bin/busybox" |
| 94 | ;; |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 95 | /usr/bin | /usr/sbin) |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 96 | bb_path="../../bin/busybox" |
| 97 | ;; |
| 98 | *) |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 99 | echo "Unknown installation directory: $appdir" |
| 100 | exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 101 | ;; |
| 102 | esac |
| 103 | fi |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 104 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then |
| 105 | echo " $prefix/$i -> $bb_path" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 106 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 107 | else |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 108 | echo " $prefix/$i already exists" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 109 | fi |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 110 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 111 | done |
| 112 | |
Eric Andersen | cb41c2e | 1999-11-22 07:41:00 +0000 | [diff] [blame] | 113 | exit 0 |