blob: 95b4719d4b6f09982917a0cce345756daec0242c [file] [log] [blame]
Eric Anderseneded54b1999-11-12 08:03:23 +00001#!/bin/sh
2
Eric Andersen39eea892001-03-08 21:42:11 +00003export LC_ALL=POSIX
4export LC_CTYPE=POSIX
5
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +02006prefix=$1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +00007if [ -z "$prefix" ]; then
Denis Vlasenko737d1312007-08-25 18:25:24 +00008 echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +02009 exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000010fi
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020011
Eric Andersena9c95ea1999-11-15 17:33:30 +000012h=`sort busybox.links | uniq`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020013
14linkopts=""
Denis Vlasenko737d1312007-08-25 18:25:24 +000015scriptwrapper="n"
Mike Frysinger81514ec2006-06-07 18:08:25 +000016cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000017noclobber="0"
Rob Landleye0c418e2005-12-15 07:25:54 +000018case "$2" in
Denis Vlasenko737d1312007-08-25 18:25:24 +000019 --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;;
Rob Landleye0c418e2005-12-15 07:25:54 +000028esac
Eric Anderseneded54b1999-11-12 08:03:23 +000029
Mike Frysinger74b29a12006-06-07 17:27:46 +000030if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000031 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000032 # 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
Eric Andersen51154ba2000-07-20 21:57:11 +000038
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020039 mkdir -p "$prefix/$libdir" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000040 for i in $DO_INSTALL_LIBS; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020041 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
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000045 fi
46 done
47fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000048
49if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
50 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
51 sub_shell_it=`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020052 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 `
Denis Vlasenko737d1312007-08-25 18:25:24 +000062 exit 0
Mike Frysinger81514ec2006-06-07 18:08:25 +000063fi
64
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020065rm -f "$prefix/bin/busybox" || exit 1
66mkdir -p "$prefix/bin" || exit 1
67install -m 755 busybox "$prefix/bin/busybox" || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000068
Denis Vlasenkob71c6682007-07-21 15:08:09 +000069for i in $h; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020070 appdir=`dirname "$i"`
71 mkdir -p "$prefix/$appdir" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000072 if [ "$scriptwrapper" = "y" ]; then
73 if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020074 ln $linkopts busybox "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000075 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020076 rm -f "$prefix/$i"
77 echo "#!/bin/busybox" >"$prefix/$i"
78 chmod +x "$prefix/$i"
Denis Vlasenko737d1312007-08-25 18:25:24 +000079 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +020080 echo " $prefix/$i"
Eric Andersen51154ba2000-07-20 21:57:11 +000081 else
Denis Vlasenko737d1312007-08-25 18:25:24 +000082 if [ "$2" = "--hardlinks" ]; then
83 bb_path="$prefix/bin/busybox"
84 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020085 case "$appdir" in
Denis Vlasenko737d1312007-08-25 18:25:24 +000086 /)
87 bb_path="bin/busybox"
88 ;;
89 /bin)
90 bb_path="busybox"
91 ;;
92 /sbin)
93 bb_path="../bin/busybox"
94 ;;
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020095 /usr/bin | /usr/sbin)
Denis Vlasenko737d1312007-08-25 18:25:24 +000096 bb_path="../../bin/busybox"
97 ;;
98 *)
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020099 echo "Unknown installation directory: $appdir"
100 exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000101 ;;
102 esac
103 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +0200104 if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
105 echo " $prefix/$i -> $bb_path"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200106 ln $linkopts "$bb_path" "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000107 else
Denys Vlasenko12140e62011-04-04 03:53:23 +0200108 echo " $prefix/$i already exists"
Denis Vlasenko737d1312007-08-25 18:25:24 +0000109 fi
Mike Frysingere3fdf242006-06-07 18:12:27 +0000110 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000111done
112
Eric Andersencb41c2e1999-11-22 07:41:00 +0000113exit 0