blob: 4ec96c254a0ea46ca38e811c1542818b4ac4d2d0 [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
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +00006prefix=${1}
7if [ -z "$prefix" ]; then
Mike Frysinger55b12102006-06-07 17:24:29 +00008 echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks]"
9 exit 1;
Eric Anderseneded54b1999-11-12 08:03:23 +000010fi
Eric Andersena9c95ea1999-11-15 17:33:30 +000011h=`sort busybox.links | uniq`
Mike Frysinger81514ec2006-06-07 18:08:25 +000012cleanup="0"
Mike Frysingere3fdf242006-06-07 18:12:27 +000013noclobber="0"
Rob Landleye0c418e2005-12-15 07:25:54 +000014case "$2" in
Mike Frysinger55b12102006-06-07 17:24:29 +000015 --hardlinks) linkopts="-f";;
16 --symlinks) linkopts="-fs";;
Mike Frysinger81514ec2006-06-07 18:08:25 +000017 --cleanup) cleanup="1";;
Mike Frysingere3fdf242006-06-07 18:12:27 +000018 --noclobber) noclobber="1";;
Mike Frysinger55b12102006-06-07 17:24:29 +000019 "") h="";;
20 *) echo "Unknown install option: $2"; exit 1;;
Rob Landleye0c418e2005-12-15 07:25:54 +000021esac
Eric Anderseneded54b1999-11-12 08:03:23 +000022
Mike Frysinger74b29a12006-06-07 17:27:46 +000023if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000024 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000025 # assume it starts with lib
26 libdir=$($CC -print-file-name=libc.so | \
27 sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
28 if test -z "$libdir"; then
29 libdir=/lib
30 fi
Eric Andersen51154ba2000-07-20 21:57:11 +000031
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000032 mkdir -p $prefix/$libdir || exit 1
33 for i in $DO_INSTALL_LIBS; do
34 rm -f $prefix/$libdir/$i || exit 1
35 if [ -f $i ]; then
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000036 cp -a $i $prefix/$libdir/ || exit 1
37 chmod 0644 $prefix/$libdir/$i || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000038 fi
39 done
40fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000041
42if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
43 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
44 sub_shell_it=`
45 cd "$prefix"
46 for d in usr/sbin usr/bin sbin bin ; do
47 pd=$PWD
48 if [ -d "$d" ]; then
49 cd $d
50 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
51 fi
52 cd "$pd"
53 done
54 `
55fi
56
Pavel Roskin259972e2000-07-28 19:34:02 +000057rm -f $prefix/bin/busybox || exit 1
58mkdir -p $prefix/bin || exit 1
59install -m 755 busybox $prefix/bin/busybox || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000060
Eric Andersen51154ba2000-07-20 21:57:11 +000061for i in $h ; do
62 appdir=`dirname $i`
Pavel Roskin259972e2000-07-28 19:34:02 +000063 mkdir -p $prefix/$appdir || exit 1
Eric Andersen51154ba2000-07-20 21:57:11 +000064 if [ "$2" = "--hardlinks" ]; then
Mike Frysinger55b12102006-06-07 17:24:29 +000065 bb_path="$prefix/bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000066 else
Mike Frysinger55b12102006-06-07 17:24:29 +000067 case "$appdir" in
Eric Andersen51154ba2000-07-20 21:57:11 +000068 /)
Mike Frysinger55b12102006-06-07 17:24:29 +000069 bb_path="bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000070 ;;
71 /bin)
Mike Frysinger55b12102006-06-07 17:24:29 +000072 bb_path="busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000073 ;;
74 /sbin)
Mike Frysinger55b12102006-06-07 17:24:29 +000075 bb_path="../bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000076 ;;
77 /usr/bin|/usr/sbin)
Mike Frysinger55b12102006-06-07 17:24:29 +000078 bb_path="../../bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000079 ;;
80 *)
81 echo "Unknown installation directory: $appdir"
82 exit 1
83 ;;
Mike Frysinger55b12102006-06-07 17:24:29 +000084 esac
Eric Andersen51154ba2000-07-20 21:57:11 +000085 fi
Mike Frysingere3fdf242006-06-07 18:12:27 +000086 if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
87 echo " $prefix$i -> $bb_path"
88 ln $linkopts $bb_path $prefix$i || exit 1
89 else
90 echo " $prefix$i already exists"
91 fi
Eric Andersen51154ba2000-07-20 21:57:11 +000092done
93
Eric Andersencb41c2e1999-11-22 07:41:00 +000094exit 0