[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
|
---|
[3621] | 8 | echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
---|
[3232] | 9 | exit 1
|
---|
[821] | 10 | fi
|
---|
[3232] | 11 |
|
---|
[3621] | 12 | # Source the configuration
|
---|
| 13 | . ./.config
|
---|
| 14 |
|
---|
[821] | 15 | h=`sort busybox.links | uniq`
|
---|
[3232] | 16 |
|
---|
[3621] | 17 | sharedlib_dir="0_lib"
|
---|
| 18 |
|
---|
[3232] | 19 | linkopts=""
|
---|
[2725] | 20 | scriptwrapper="n"
|
---|
[3621] | 21 | binaries="n"
|
---|
[821] | 22 | cleanup="0"
|
---|
| 23 | noclobber="0"
|
---|
| 24 | case "$2" in
|
---|
[2725] | 25 | --hardlinks) linkopts="-f";;
|
---|
| 26 | --symlinks) linkopts="-fs";;
|
---|
[3621] | 27 | --binaries) binaries="y";;
|
---|
[2725] | 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;;
|
---|
[821] | 35 | esac
|
---|
| 36 |
|
---|
| 37 | if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
---|
| 38 | # get the target dir for the libs
|
---|
| 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
|
---|
| 45 |
|
---|
[3232] | 46 | mkdir -p "$prefix/$libdir" || exit 1
|
---|
[821] | 47 | for i in $DO_INSTALL_LIBS; do
|
---|
[3232] | 48 | rm -f "$prefix/$libdir/$i" || exit 1
|
---|
| 49 | if [ -f "$i" ]; then
|
---|
[3621] | 50 | echo " Installing $i to the target at $prefix/$libdir/"
|
---|
[3232] | 51 | cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
---|
[3621] | 52 | chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
---|
[821] | 53 | fi
|
---|
| 54 | done
|
---|
| 55 | fi
|
---|
| 56 |
|
---|
| 57 | if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
---|
| 58 | inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
---|
| 59 | sub_shell_it=`
|
---|
[3232] | 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 | `
|
---|
[2725] | 70 | exit 0
|
---|
[821] | 71 | fi
|
---|
| 72 |
|
---|
[3232] | 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
|
---|
[821] | 76 |
|
---|
[1765] | 77 | for i in $h; do
|
---|
[3232] | 78 | appdir=`dirname "$i"`
|
---|
[3621] | 79 | app=`basename "$i"`
|
---|
[3232] | 80 | mkdir -p "$prefix/$appdir" || exit 1
|
---|
[2725] | 81 | if [ "$scriptwrapper" = "y" ]; then
|
---|
| 82 | if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
---|
[3232] | 83 | ln $linkopts busybox "$prefix/$i" || exit 1
|
---|
[2725] | 84 | else
|
---|
[3232] | 85 | rm -f "$prefix/$i"
|
---|
| 86 | echo "#!/bin/busybox" >"$prefix/$i"
|
---|
| 87 | chmod +x "$prefix/$i"
|
---|
[2725] | 88 | fi
|
---|
[3232] | 89 | echo " $prefix/$i"
|
---|
[3621] | 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
|
---|
[821] | 103 | else
|
---|
[2725] | 104 | if [ "$2" = "--hardlinks" ]; then
|
---|
| 105 | bb_path="$prefix/bin/busybox"
|
---|
| 106 | else
|
---|
| 107 | case "$appdir" in
|
---|
| 108 | /)
|
---|
| 109 | bb_path="bin/busybox"
|
---|
| 110 | ;;
|
---|
| 111 | /bin)
|
---|
| 112 | bb_path="busybox"
|
---|
| 113 | ;;
|
---|
| 114 | /sbin)
|
---|
| 115 | bb_path="../bin/busybox"
|
---|
| 116 | ;;
|
---|
[3232] | 117 | /usr/bin | /usr/sbin)
|
---|
[2725] | 118 | bb_path="../../bin/busybox"
|
---|
| 119 | ;;
|
---|
| 120 | *)
|
---|
[3232] | 121 | echo "Unknown installation directory: $appdir"
|
---|
| 122 | exit 1
|
---|
[2725] | 123 | ;;
|
---|
| 124 | esac
|
---|
| 125 | fi
|
---|
[3232] | 126 | if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
---|
| 127 | echo " $prefix/$i -> $bb_path"
|
---|
| 128 | ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
---|
[2725] | 129 | else
|
---|
[3232] | 130 | echo " $prefix/$i already exists"
|
---|
[2725] | 131 | fi
|
---|
[821] | 132 | fi
|
---|
| 133 | done
|
---|
| 134 |
|
---|
| 135 | exit 0
|
---|