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