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 |
Yann E. MORIN | 296381f | 2018-04-15 10:55:30 +0200 | [diff] [blame] | 8 | echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]" |
| 9 | echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none" |
| 10 | echo " OPTS is one or more of: --cleanup --noclobber" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 11 | exit 1 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 12 | fi |
Yann E. MORIN | 952d5a6 | 2017-12-28 23:49:48 +0100 | [diff] [blame] | 13 | shift # Keep only remaining options |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 14 | |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 15 | # Source the configuration |
| 16 | . ./.config |
| 17 | |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 18 | h=`sort busybox.links | uniq` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 19 | |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 20 | sharedlib_dir="0_lib" |
| 21 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 22 | linkopts="" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 23 | scriptwrapper="n" |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 24 | binaries="n" |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 25 | cleanup="0" |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 26 | noclobber="0" |
Yann E. MORIN | 952d5a6 | 2017-12-28 23:49:48 +0100 | [diff] [blame] | 27 | while [ ${#} -gt 0 ]; do |
| 28 | case "$1" in |
| 29 | --hardlinks) linkopts="-f";; |
| 30 | --symlinks) linkopts="-fs";; |
| 31 | --binaries) binaries="y";; |
| 32 | --scriptwrapper) scriptwrapper="y"; swrapall="y";; |
| 33 | --sw-sh-hard) scriptwrapper="y"; linkopts="-f";; |
| 34 | --sw-sh-sym) scriptwrapper="y"; linkopts="-fs";; |
| 35 | --cleanup) cleanup="1";; |
| 36 | --noclobber) noclobber="1";; |
Yann E. MORIN | 296381f | 2018-04-15 10:55:30 +0200 | [diff] [blame] | 37 | --none) h="";; |
Yann E. MORIN | 952d5a6 | 2017-12-28 23:49:48 +0100 | [diff] [blame] | 38 | *) echo "Unknown install option: $1"; exit 1;; |
| 39 | esac |
| 40 | shift |
| 41 | done |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 42 | |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 43 | if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 44 | # get the target dir for the libs |
Rob Landley | d196867 | 2006-03-24 02:42:58 +0000 | [diff] [blame] | 45 | # assume it starts with lib |
| 46 | libdir=$($CC -print-file-name=libc.so | \ |
| 47 | sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p') |
| 48 | if test -z "$libdir"; then |
| 49 | libdir=/lib |
| 50 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 51 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 52 | mkdir -p "$prefix/$libdir" || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 53 | for i in $DO_INSTALL_LIBS; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 54 | rm -f "$prefix/$libdir/$i" || exit 1 |
| 55 | if [ -f "$i" ]; then |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 56 | echo " Installing $i to the target at $prefix/$libdir/" |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 57 | cp -pPR "$i" "$prefix/$libdir/" || exit 1 |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 58 | chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1 |
Bernhard Reutner-Fischer | 7ca61b6 | 2006-01-15 14:04:57 +0000 | [diff] [blame] | 59 | fi |
| 60 | done |
| 61 | fi |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 62 | |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 63 | if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 64 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'` |
| 65 | sub_shell_it=` |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 66 | cd "$prefix" |
| 67 | for d in usr/sbin usr/bin sbin bin; do |
| 68 | pd=$PWD |
| 69 | if [ -d "$d" ]; then |
| 70 | cd "$d" |
| 71 | ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f |
| 72 | fi |
| 73 | cd "$pd" |
| 74 | done |
| 75 | ` |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 76 | exit 0 |
Mike Frysinger | 81514ec | 2006-06-07 18:08:25 +0000 | [diff] [blame] | 77 | fi |
| 78 | |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 79 | rm -f "$prefix/bin/busybox" || exit 1 |
| 80 | mkdir -p "$prefix/bin" || exit 1 |
| 81 | install -m 755 busybox "$prefix/bin/busybox" || exit 1 |
Eric Andersen | eded54b | 1999-11-12 08:03:23 +0000 | [diff] [blame] | 82 | |
Denis Vlasenko | b71c668 | 2007-07-21 15:08:09 +0000 | [diff] [blame] | 83 | for i in $h; do |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 84 | appdir=`dirname "$i"` |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 85 | app=`basename "$i"` |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 86 | if [ x"$noclobber" = x"1" ] && [ -e "$prefix/$i" ]; then |
Yann E. MORIN | 84be5ce | 2017-12-28 23:49:47 +0100 | [diff] [blame] | 87 | echo " $prefix/$i already exists" |
| 88 | continue |
| 89 | fi |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 90 | mkdir -p "$prefix/$appdir" || exit 1 |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 91 | if [ x"$scriptwrapper" = x"y" ]; then |
| 92 | if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 93 | ln $linkopts busybox "$prefix/$i" || exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 94 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 95 | rm -f "$prefix/$i" |
| 96 | echo "#!/bin/busybox" >"$prefix/$i" |
| 97 | chmod +x "$prefix/$i" |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 98 | fi |
Denys Vlasenko | 12140e6 | 2011-04-04 03:53:23 +0200 | [diff] [blame] | 99 | echo " $prefix/$i" |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 100 | elif [ x"$binaries" = x"y" ]; then |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 101 | # Copy the binary over rather |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 102 | if [ -e "$sharedlib_dir/$app" ]; then |
Yann E. MORIN | 84be5ce | 2017-12-28 23:49:47 +0100 | [diff] [blame] | 103 | echo " Copying $sharedlib_dir/$app to $prefix/$i" |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 104 | cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1 |
Clayton Shotwell | b7ee7e1 | 2015-05-21 14:48:35 -0500 | [diff] [blame] | 105 | else |
| 106 | echo "Error: Could not find $sharedlib_dir/$app" |
| 107 | exit 1 |
| 108 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 109 | else |
Denys Vlasenko | bf39d97 | 2018-02-23 16:29:26 +0100 | [diff] [blame] | 110 | if [ x"$linkopts" = x"-f" ]; then |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 111 | bb_path="$prefix/bin/busybox" |
| 112 | else |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 113 | case "$appdir" in |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 114 | /) |
| 115 | bb_path="bin/busybox" |
| 116 | ;; |
| 117 | /bin) |
| 118 | bb_path="busybox" |
| 119 | ;; |
| 120 | /sbin) |
| 121 | bb_path="../bin/busybox" |
| 122 | ;; |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 123 | /usr/bin | /usr/sbin) |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 124 | bb_path="../../bin/busybox" |
| 125 | ;; |
| 126 | *) |
Denys Vlasenko | c0644ca | 2011-04-05 02:37:15 +0200 | [diff] [blame] | 127 | echo "Unknown installation directory: $appdir" |
| 128 | exit 1 |
Denis Vlasenko | 737d131 | 2007-08-25 18:25:24 +0000 | [diff] [blame] | 129 | ;; |
| 130 | esac |
| 131 | fi |
Yann E. MORIN | 84be5ce | 2017-12-28 23:49:47 +0100 | [diff] [blame] | 132 | echo " $prefix/$i -> $bb_path" |
| 133 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1 |
Mike Frysinger | e3fdf24 | 2006-06-07 18:12:27 +0000 | [diff] [blame] | 134 | fi |
Eric Andersen | 51154ba | 2000-07-20 21:57:11 +0000 | [diff] [blame] | 135 | done |
| 136 | |
Eric Andersen | cb41c2e | 1999-11-22 07:41:00 +0000 | [diff] [blame] | 137 | exit 0 |