blob: 1cd97bba32db395f67dd1ae62adde5c038162882 [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"
Rob Landleye0c418e2005-12-15 07:25:54 +000013case "$2" in
Mike Frysinger55b12102006-06-07 17:24:29 +000014 --hardlinks) linkopts="-f";;
15 --symlinks) linkopts="-fs";;
Mike Frysinger81514ec2006-06-07 18:08:25 +000016 --cleanup) cleanup="1";;
Mike Frysinger55b12102006-06-07 17:24:29 +000017 "") h="";;
18 *) echo "Unknown install option: $2"; exit 1;;
Rob Landleye0c418e2005-12-15 07:25:54 +000019esac
Eric Anderseneded54b1999-11-12 08:03:23 +000020
Mike Frysinger74b29a12006-06-07 17:27:46 +000021if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000022 # get the target dir for the libs
Rob Landleyd1968672006-03-24 02:42:58 +000023 # assume it starts with lib
24 libdir=$($CC -print-file-name=libc.so | \
25 sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
26 if test -z "$libdir"; then
27 libdir=/lib
28 fi
Eric Andersen51154ba2000-07-20 21:57:11 +000029
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000030 mkdir -p $prefix/$libdir || exit 1
31 for i in $DO_INSTALL_LIBS; do
32 rm -f $prefix/$libdir/$i || exit 1
33 if [ -f $i ]; then
Bernhard Reutner-Fischer5d261262006-03-01 22:54:48 +000034 cp -a $i $prefix/$libdir/ || exit 1
35 chmod 0644 $prefix/$libdir/$i || exit 1
Bernhard Reutner-Fischer7ca61b62006-01-15 14:04:57 +000036 fi
37 done
38fi
Mike Frysinger81514ec2006-06-07 18:08:25 +000039
40if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
41 inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
42 sub_shell_it=`
43 cd "$prefix"
44 for d in usr/sbin usr/bin sbin bin ; do
45 pd=$PWD
46 if [ -d "$d" ]; then
47 cd $d
48 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
49 fi
50 cd "$pd"
51 done
52 `
53fi
54
Pavel Roskin259972e2000-07-28 19:34:02 +000055rm -f $prefix/bin/busybox || exit 1
56mkdir -p $prefix/bin || exit 1
57install -m 755 busybox $prefix/bin/busybox || exit 1
Eric Anderseneded54b1999-11-12 08:03:23 +000058
Eric Andersen51154ba2000-07-20 21:57:11 +000059for i in $h ; do
60 appdir=`dirname $i`
Pavel Roskin259972e2000-07-28 19:34:02 +000061 mkdir -p $prefix/$appdir || exit 1
Eric Andersen51154ba2000-07-20 21:57:11 +000062 if [ "$2" = "--hardlinks" ]; then
Mike Frysinger55b12102006-06-07 17:24:29 +000063 bb_path="$prefix/bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000064 else
Mike Frysinger55b12102006-06-07 17:24:29 +000065 case "$appdir" in
Eric Andersen51154ba2000-07-20 21:57:11 +000066 /)
Mike Frysinger55b12102006-06-07 17:24:29 +000067 bb_path="bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000068 ;;
69 /bin)
Mike Frysinger55b12102006-06-07 17:24:29 +000070 bb_path="busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000071 ;;
72 /sbin)
Mike Frysinger55b12102006-06-07 17:24:29 +000073 bb_path="../bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000074 ;;
75 /usr/bin|/usr/sbin)
Mike Frysinger55b12102006-06-07 17:24:29 +000076 bb_path="../../bin/busybox"
Eric Andersen51154ba2000-07-20 21:57:11 +000077 ;;
78 *)
79 echo "Unknown installation directory: $appdir"
80 exit 1
81 ;;
Mike Frysinger55b12102006-06-07 17:24:29 +000082 esac
Eric Andersen51154ba2000-07-20 21:57:11 +000083 fi
Pavel Roskin259972e2000-07-28 19:34:02 +000084 echo " $prefix$i -> $bb_path"
85 ln $linkopts $bb_path $prefix$i || exit 1
Eric Andersen51154ba2000-07-20 21:57:11 +000086done
87
Eric Andersencb41c2e1999-11-22 07:41:00 +000088exit 0