blob: f6c097e57e9b1527eee68bef96b7ec1a723932c4 [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
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020011
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050012# Source the configuration
13. ./.config
14
Eric Andersena9c95ea1999-11-15 17:33:30 +000015h=`sort busybox.links | uniq`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020016
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050017sharedlib_dir="0_lib"
18
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020019linkopts=""
Denis Vlasenko737d1312007-08-25 18:25:24 +000020scriptwrapper="n"
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050021binaries="n"
Mike Frysinger81514ec2006-06-07 18:08:25 +000022cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000023noclobber="0"
Rob Landleye0c418e2005-12-15 07:25:54 +000024case "$2" in
Denis Vlasenko737d1312007-08-25 18:25:24 +000025 --hardlinks) linkopts="-f";;
26 --symlinks) linkopts="-fs";;
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050027 --binaries) binaries="y";;
Denis Vlasenko737d1312007-08-25 18:25:24 +000028 --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;;
Rob Landleye0c418e2005-12-15 07:25:54 +000035esac
Eric Anderseneded54b1999-11-12 08:03:23 +000036
Mike Frysinger74b29a12006-06-07 17:27:46 +000037if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000038 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000039 # 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
Eric Andersen51154ba2000-07-20 21:57:11 +000045
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020046 mkdir -p "$prefix/$libdir" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000047 for i in $DO_INSTALL_LIBS; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020048 rm -f "$prefix/$libdir/$i" || exit 1
49 if [ -f "$i" ]; then
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050050 echo " Installing $i to the target at $prefix/$libdir/"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020051 cp -pPR "$i" "$prefix/$libdir/" || exit 1
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050052 chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000053 fi
54 done
55fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000056
57if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
58 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
59 sub_shell_it=`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020060 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 `
Denis Vlasenko737d1312007-08-25 18:25:24 +000070 exit 0
Mike Frysinger81514ec2006-06-07 18:08:25 +000071fi
72
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020073rm -f "$prefix/bin/busybox" || exit 1
74mkdir -p "$prefix/bin" || exit 1
75install -m 755 busybox "$prefix/bin/busybox" || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000076
Denis Vlasenkob71c6682007-07-21 15:08:09 +000077for i in $h; do
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020078 appdir=`dirname "$i"`
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050079 app=`basename "$i"`
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020080 mkdir -p "$prefix/$appdir" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000081 if [ "$scriptwrapper" = "y" ]; then
82 if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020083 ln $linkopts busybox "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +000084 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +020085 rm -f "$prefix/$i"
86 echo "#!/bin/busybox" >"$prefix/$i"
87 chmod +x "$prefix/$i"
Denis Vlasenko737d1312007-08-25 18:25:24 +000088 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +020089 echo " $prefix/$i"
Clayton Shotwellb7ee7e12015-05-21 14:48:35 -050090 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
Eric Andersen51154ba2000-07-20 21:57:11 +0000103 else
Denis Vlasenko737d1312007-08-25 18:25:24 +0000104 if [ "$2" = "--hardlinks" ]; then
105 bb_path="$prefix/bin/busybox"
106 else
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200107 case "$appdir" in
Denis Vlasenko737d1312007-08-25 18:25:24 +0000108 /)
109 bb_path="bin/busybox"
110 ;;
111 /bin)
112 bb_path="busybox"
113 ;;
114 /sbin)
115 bb_path="../bin/busybox"
116 ;;
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200117 /usr/bin | /usr/sbin)
Denis Vlasenko737d1312007-08-25 18:25:24 +0000118 bb_path="../../bin/busybox"
119 ;;
120 *)
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200121 echo "Unknown installation directory: $appdir"
122 exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000123 ;;
124 esac
125 fi
Denys Vlasenko12140e62011-04-04 03:53:23 +0200126 if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
127 echo " $prefix/$i -> $bb_path"
Denys Vlasenkoc0644ca2011-04-05 02:37:15 +0200128 ln $linkopts "$bb_path" "$prefix/$i" || exit 1
Denis Vlasenko737d1312007-08-25 18:25:24 +0000129 else
Denys Vlasenko12140e62011-04-04 03:53:23 +0200130 echo " $prefix/$i already exists"
Denis Vlasenko737d1312007-08-25 18:25:24 +0000131 fi
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