[821] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 | export LC_ALL=POSIX
|
---|
| 4 | export LC_CTYPE=POSIX
|
---|
| 5 |
|
---|
[3232] | 6 | prefix=$1
|
---|
[821] | 7 | if [ -z "$prefix" ]; then
|
---|
[2725] | 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
---|
[3232] | 9 | exit 1
|
---|
[821] | 10 | fi
|
---|
[3232] | 11 |
|
---|
[821] | 12 | h=`sort busybox.links | uniq`
|
---|
[3232] | 13 |
|
---|
| 14 | linkopts=""
|
---|
[2725] | 15 | scriptwrapper="n"
|
---|
[821] | 16 | cleanup="0"
|
---|
| 17 | noclobber="0"
|
---|
| 18 | case "$2" in
|
---|
[2725] | 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;;
|
---|
[821] | 28 | esac
|
---|
| 29 |
|
---|
| 30 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
---|
| 31 | # get the target dir for the libs
|
---|
| 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
|
---|
| 38 |
|
---|
[3232] | 39 | mkdir -p "$prefix/$libdir" || exit 1
|
---|
[821] | 40 | for i in $DO_INSTALL_LIBS; do
|
---|
[3232] | 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
|
---|
[821] | 45 | fi
|
---|
| 46 | done
|
---|
| 47 | fi
|
---|
| 48 |
|
---|
| 49 | if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
---|
| 50 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
---|
| 51 | sub_shell_it=`
|
---|
[3232] | 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 | `
|
---|
[2725] | 62 | exit 0
|
---|
[821] | 63 | fi
|
---|
| 64 |
|
---|
[3232] | 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
|
---|
[821] | 68 |
|
---|
[1765] | 69 | for i in $h; do
|
---|
[3232] | 70 | appdir=`dirname "$i"`
|
---|
| 71 | mkdir -p "$prefix/$appdir" || exit 1
|
---|
[2725] | 72 | if [ "$scriptwrapper" = "y" ]; then
|
---|
| 73 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
---|
[3232] | 74 | ln $linkopts busybox "$prefix/$i" || exit 1
|
---|
[2725] | 75 | else
|
---|
[3232] | 76 | rm -f "$prefix/$i"
|
---|
| 77 | echo "#!/bin/busybox" >"$prefix/$i"
|
---|
| 78 | chmod +x "$prefix/$i"
|
---|
[2725] | 79 | fi
|
---|
[3232] | 80 | echo " $prefix/$i"
|
---|
[821] | 81 | else
|
---|
[2725] | 82 | if [ "$2" = "--hardlinks" ]; then
|
---|
| 83 | bb_path="$prefix/bin/busybox"
|
---|
| 84 | else
|
---|
| 85 | case "$appdir" in
|
---|
| 86 | /)
|
---|
| 87 | bb_path="bin/busybox"
|
---|
| 88 | ;;
|
---|
| 89 | /bin)
|
---|
| 90 | bb_path="busybox"
|
---|
| 91 | ;;
|
---|
| 92 | /sbin)
|
---|
| 93 | bb_path="../bin/busybox"
|
---|
| 94 | ;;
|
---|
[3232] | 95 | /usr/bin | /usr/sbin)
|
---|
[2725] | 96 | bb_path="../../bin/busybox"
|
---|
| 97 | ;;
|
---|
| 98 | *)
|
---|
[3232] | 99 | echo "Unknown installation directory: $appdir"
|
---|
| 100 | exit 1
|
---|
[2725] | 101 | ;;
|
---|
| 102 | esac
|
---|
| 103 | fi
|
---|
[3232] | 104 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
---|
| 105 | echo " $prefix/$i -> $bb_path"
|
---|
| 106 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
---|
[2725] | 107 | else
|
---|
[3232] | 108 | echo " $prefix/$i already exists"
|
---|
[2725] | 109 | fi
|
---|
[821] | 110 | fi
|
---|
| 111 | done
|
---|
| 112 |
|
---|
| 113 | exit 0
|
---|