blob: c75a78e9d12d8131b925f881341885c7da3e9393 [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
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -05008 echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +02009 exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000010fi
Yann E. MORIN952d5a62017-12-28 23:49:48 +010011shift # Keep only remaining options
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020012
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050013# Source the configuration
14. ./.config
15
Eric Andersena9c95ea1999-11-15 17:33:30 +000016h=`sort busybox.links | uniq`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020017
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050018sharedlib_dir="0_lib"
19
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020020linkopts=""
Denis Vlasenko737d1312007-08-25 18:25:24 +000021scriptwrapper="n"
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050022binaries="n"
Mike Frysinger81514ec2006-06-07 18:08:25 +000023cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000024noclobber="0"
Yann E. MORIN952d5a62017-12-28 23:49:48 +010025while [ ${#} -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
39done
Eric Anderseneded54b1999-11-12 08:03:23 +000040
Denys Vlasenkobf39d972018-02-23 16:29:26 +010041if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000042 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000043 # 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 Andersen51154ba2000-07-20 21:57:11 +000049
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020050 mkdir -p "$prefix/$libdir" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000051 for i in $DO_INSTALL_LIBS; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020052 rm -f "$prefix/$libdir/$i" || exit 1
53 if [ -f "$i" ]; then
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050054 echo " Installing $i to the target at $prefix/$libdir/"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020055 cp -pPR "$i" "$prefix/$libdir/" || exit 1
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050056 chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000057 fi
58 done
59fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000060
Denys Vlasenkobf39d972018-02-23 16:29:26 +010061if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then
Mike Frysinger81514ec2006-06-07 18:08:25 +000062 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
63 sub_shell_it=`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020064 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 Vlasenko737d1312007-08-25 18:25:24 +000074 exit 0
Mike Frysinger81514ec2006-06-07 18:08:25 +000075fi
76
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020077rm -f "$prefix/bin/busybox" || exit 1
78mkdir -p "$prefix/bin" || exit 1
79install -m 755 busybox "$prefix/bin/busybox" || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000080
Denis Vlasenkob71c6682007-07-21 15:08:09 +000081for i in $h; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020082 appdir=`dirname "$i"`
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050083 app=`basename "$i"`
Denys Vlasenkobf39d972018-02-23 16:29:26 +010084 if [ x"$noclobber" = x"1" ] && [ -e "$prefix/$i" ]; then
Yann E. MORIN84be5ce2017-12-28 23:49:47 +010085 echo " $prefix/$i already exists"
86 continue
87 fi
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020088 mkdir -p "$prefix/$appdir" || exit 1
Denys Vlasenkobf39d972018-02-23 16:29:26 +010089 if [ x"$scriptwrapper" = x"y" ]; then
90 if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020091 ln $linkopts busybox "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000092 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020093 rm -f "$prefix/$i"
94 echo "#!/bin/busybox" >"$prefix/$i"
95 chmod +x "$prefix/$i"
Denis Vlasenko737d1312007-08-25 18:25:24 +000096 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +020097 echo " $prefix/$i"
Denys Vlasenkobf39d972018-02-23 16:29:26 +010098 elif [ x"$binaries" = x"y" ]; then
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050099 # Copy the binary over rather
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100100 if [ -e "$sharedlib_dir/$app" ]; then
Yann E. MORIN84be5ce2017-12-28 23:49:47 +0100101 echo " Copying $sharedlib_dir/$app to $prefix/$i"
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100102 cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -0500103 else
104 echo "Error: Could not find $sharedlib_dir/$app"
105 exit 1
106 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000107 else
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100108 if [ x"$linkopts" = x"-f" ]; then
Denis Vlasenko737d1312007-08-25 18:25:24 +0000109 bb_path="$prefix/bin/busybox"
110 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200111 case "$appdir" in
Denis Vlasenko737d1312007-08-25 18:25:24 +0000112 /)
113 bb_path="bin/busybox"
114 ;;
115 /bin)
116 bb_path="busybox"
117 ;;
118 /sbin)
119 bb_path="../bin/busybox"
120 ;;
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200121 /usr/bin | /usr/sbin)
Denis Vlasenko737d1312007-08-25 18:25:24 +0000122 bb_path="../../bin/busybox"
123 ;;
124 *)
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200125 echo "Unknown installation directory: $appdir"
126 exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000127 ;;
128 esac
129 fi
Yann E. MORIN84be5ce2017-12-28 23:49:47 +0100130 echo " $prefix/$i -> $bb_path"
131 ln $linkopts "$bb_path" "$prefix/$i" || exit 1
Mike Frysingere3fdf242006-06-07 18:12:27 +0000132 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000133done
134
Eric Andersencb41c2e1999-11-22 07:41:00 +0000135exit 0