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 |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--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 | |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 12 | # Source the configuration |
| 13 | . ./.config |
| 14 | |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 15 | h=`sort busybox.links | uniq` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 16 | |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 17 | sharedlib_dir="0_lib" |
| 18 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 19 | linkopts="" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 20 | scriptwrapper="n" |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 21 | binaries="n" |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 22 | cleanup="0" |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 23 | noclobber="0" |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 24 | case "$2" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 25 | --hardlinks) linkopts="-f";; |
| 26 | --symlinks) linkopts="-fs";; |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 27 | --binaries) binaries="y";; |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 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;; |
Rob Landley | e0c418e | 2005-12-15 07:25:54 +0000 | [diff] [blame] | 35 | esac |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 36 | |
Mike Frysinger | 74b29a1 | 2006-06-07 17:27:46 +0000 | [diff] [blame] | 37 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 38 | # get the target dir for the libs |
Rob Landley | d196867 | 2006-03-24 02:42:58 +0000 | [diff] [blame] | 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 |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 45 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 46 | mkdir -p "$prefix/$libdir" || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 47 | for i in $DO_INSTALL_LIBS; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 48 | rm -f "$prefix/$libdir/$i" || exit 1 |
| 49 | if [ -f "$i" ]; then |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 50 | echo " Installing $i to the target at $prefix/$libdir/" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 51 | cp -pPR "$i" "$prefix/$libdir/" || exit 1 |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 52 | chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 53 | fi |
| 54 | done |
| 55 | fi |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 56 | |
| 57 | if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then |
| 58 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'` |
| 59 | sub_shell_it=` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 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 | ` |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 70 | exit 0 |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 71 | fi |
| 72 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 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 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 76 | |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 77 | for i in $h; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 78 | appdir=`dirname "$i"` |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 79 | app=`basename "$i"` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 80 | mkdir -p "$prefix/$appdir" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 81 | if [ "$scriptwrapper" = "y" ]; then |
| 82 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 83 | ln $linkopts busybox "$prefix/$i" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 84 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 85 | rm -f "$prefix/$i" |
| 86 | echo "#!/bin/busybox" >"$prefix/$i" |
| 87 | chmod +x "$prefix/$i" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 88 | fi |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 89 | echo " $prefix/$i" |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 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 |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 103 | else |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 104 | if [ "$2" = "--hardlinks" ]; then |
| 105 | bb_path="$prefix/bin/busybox" |
| 106 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 107 | case "$appdir" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 108 | /) |
| 109 | bb_path="bin/busybox" |
| 110 | ;; |
| 111 | /bin) |
| 112 | bb_path="busybox" |
| 113 | ;; |
| 114 | /sbin) |
| 115 | bb_path="../bin/busybox" |
| 116 | ;; |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 117 | /usr/bin | /usr/sbin) |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 118 | bb_path="../../bin/busybox" |
| 119 | ;; |
| 120 | *) |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 121 | echo "Unknown installation directory: $appdir" |
| 122 | exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 123 | ;; |
| 124 | esac |
| 125 | fi |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 126 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then |
| 127 | echo " $prefix/$i -> $bb_path" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 128 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 129 | else |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 130 | echo " $prefix/$i already exists" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 131 | fi |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 132 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 133 | done |
| 134 | |
Eric Andersen | cb41c2e | 1999-11-22 07:41:00 +0000 | [diff] [blame] | 135 | exit 0 |