blob: 9aede0f530e277f7abe3e646f45bb31623361bf7 [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
Yann E. MORIN296381f2018-04-15 10:55:30 +02008 echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]"
9 echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none"
10 echo " OPTS is one or more of: --cleanup --noclobber"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020011 exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000012fi
Yann E. MORIN952d5a62017-12-28 23:49:48 +010013shift # Keep only remaining options
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020014
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050015# Source the configuration
16. ./.config
17
Eric Andersena9c95ea1999-11-15 17:33:30 +000018h=`sort busybox.links | uniq`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020019
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050020sharedlib_dir="0_lib"
21
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020022linkopts=""
Denis Vlasenko737d1312007-08-25 18:25:24 +000023scriptwrapper="n"
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050024binaries="n"
Mike Frysinger81514ec2006-06-07 18:08:25 +000025cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000026noclobber="0"
Yann E. MORIN952d5a62017-12-28 23:49:48 +010027while [ ${#} -gt 0 ]; do
28 case "$1" in
29 --hardlinks) linkopts="-f";;
30 --symlinks) linkopts="-fs";;
31 --binaries) binaries="y";;
32 --scriptwrapper) scriptwrapper="y"; swrapall="y";;
33 --sw-sh-hard) scriptwrapper="y"; linkopts="-f";;
34 --sw-sh-sym) scriptwrapper="y"; linkopts="-fs";;
35 --cleanup) cleanup="1";;
36 --noclobber) noclobber="1";;
Yann E. MORIN296381f2018-04-15 10:55:30 +020037 --none) h="";;
Yann E. MORIN952d5a62017-12-28 23:49:48 +010038 *) echo "Unknown install option: $1"; exit 1;;
39 esac
40 shift
41done
Eric Anderseneded54b1999-11-12 08:03:23 +000042
Denys Vlasenkobf39d972018-02-23 16:29:26 +010043if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000044 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000045 # assume it starts with lib
46 libdir=$($CC -print-file-name=libc.so | \
47 sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
48 if test -z "$libdir"; then
49 libdir=/lib
50 fi
Eric Andersen51154ba2000-07-20 21:57:11 +000051
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020052 mkdir -p "$prefix/$libdir" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000053 for i in $DO_INSTALL_LIBS; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020054 rm -f "$prefix/$libdir/$i" || exit 1
55 if [ -f "$i" ]; then
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050056 echo " Installing $i to the target at $prefix/$libdir/"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020057 cp -pPR "$i" "$prefix/$libdir/" || exit 1
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050058 chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000059 fi
60 done
61fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000062
Denys Vlasenkobf39d972018-02-23 16:29:26 +010063if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then
Mike Frysinger81514ec2006-06-07 18:08:25 +000064 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
65 sub_shell_it=`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020066 cd "$prefix"
67 for d in usr/sbin usr/bin sbin bin; do
68 pd=$PWD
69 if [ -d "$d" ]; then
70 cd "$d"
71 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
72 fi
73 cd "$pd"
74 done
75 `
Denis Vlasenko737d1312007-08-25 18:25:24 +000076 exit 0
Mike Frysinger81514ec2006-06-07 18:08:25 +000077fi
78
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020079rm -f "$prefix/bin/busybox" || exit 1
80mkdir -p "$prefix/bin" || exit 1
81install -m 755 busybox "$prefix/bin/busybox" || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000082
Denis Vlasenkob71c6682007-07-21 15:08:09 +000083for i in $h; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020084 appdir=`dirname "$i"`
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050085 app=`basename "$i"`
Denys Vlasenkobf39d972018-02-23 16:29:26 +010086 if [ x"$noclobber" = x"1" ] && [ -e "$prefix/$i" ]; then
Yann E. MORIN84be5ce2017-12-28 23:49:47 +010087 echo " $prefix/$i already exists"
88 continue
89 fi
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020090 mkdir -p "$prefix/$appdir" || exit 1
Denys Vlasenkobf39d972018-02-23 16:29:26 +010091 if [ x"$scriptwrapper" = x"y" ]; then
92 if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020093 ln $linkopts busybox "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000094 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020095 rm -f "$prefix/$i"
96 echo "#!/bin/busybox" >"$prefix/$i"
97 chmod +x "$prefix/$i"
Denis Vlasenko737d1312007-08-25 18:25:24 +000098 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +020099 echo " $prefix/$i"
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100100 elif [ x"$binaries" = x"y" ]; then
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -0500101 # Copy the binary over rather
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100102 if [ -e "$sharedlib_dir/$app" ]; then
Yann E. MORIN84be5ce2017-12-28 23:49:47 +0100103 echo " Copying $sharedlib_dir/$app to $prefix/$i"
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100104 cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -0500105 else
106 echo "Error: Could not find $sharedlib_dir/$app"
107 exit 1
108 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000109 else
Denys Vlasenkobf39d972018-02-23 16:29:26 +0100110 if [ x"$linkopts" = x"-f" ]; then
Denis Vlasenko737d1312007-08-25 18:25:24 +0000111 bb_path="$prefix/bin/busybox"
112 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200113 case "$appdir" in
Denis Vlasenko737d1312007-08-25 18:25:24 +0000114 /)
115 bb_path="bin/busybox"
116 ;;
117 /bin)
118 bb_path="busybox"
119 ;;
120 /sbin)
121 bb_path="../bin/busybox"
122 ;;
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200123 /usr/bin | /usr/sbin)
Denis Vlasenko737d1312007-08-25 18:25:24 +0000124 bb_path="../../bin/busybox"
125 ;;
126 *)
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200127 echo "Unknown installation directory: $appdir"
128 exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000129 ;;
130 esac
131 fi
Yann E. MORIN84be5ce2017-12-28 23:49:47 +0100132 echo " $prefix/$i -> $bb_path"
133 ln $linkopts "$bb_path" "$prefix/$i" || exit 1
Mike Frysingere3fdf242006-06-07 18:12:27 +0000134 fi
Eric Andersen51154ba2000-07-20 21:57:11 +0000135done
136
Eric Andersencb41c2e1999-11-22 07:41:00 +0000137exit 0