The rest of Yann E. Morin's install revamp.
[oweals/busybox.git] / applets / install.sh
1 #!/bin/sh
2
3 export LC_ALL=POSIX
4 export LC_CTYPE=POSIX
5
6 prefix=$1
7 if [ "$prefix" = "" ]; then
8     echo "No installation directory, aborting."
9     exit 1;
10 fi
11 h=`sort busybox.links | uniq`
12 case "$2" in
13     --hardlinks) linkopts="-f";;
14     --symlinks)  linkopts="-fs";;
15     "")          h="";;
16     *)           echo "Unknown install option: $2"; exit 1;;
17 esac
18
19
20 rm -f $prefix/bin/busybox || exit 1
21 mkdir -p $prefix/bin || exit 1
22 install -m 755 busybox $prefix/bin/busybox || exit 1
23
24 for i in $h ; do
25         appdir=`dirname $i`
26         mkdir -p $prefix/$appdir || exit 1
27         if [ "$2" = "--hardlinks" ]; then
28             bb_path="$prefix/bin/busybox"
29         else
30             case "$appdir" in
31                 /)
32                     bb_path="bin/busybox"
33                 ;;
34                 /bin)
35                     bb_path="busybox"
36                 ;;
37                 /sbin)
38                     bb_path="../bin/busybox"
39                 ;;
40                 /usr/bin|/usr/sbin)
41                     bb_path="../../bin/busybox"
42                 ;;
43                 *)
44                 echo "Unknown installation directory: $appdir"
45                 exit 1
46                 ;;
47             esac
48         fi
49         echo "  $prefix$i -> $bb_path"
50         ln $linkopts $bb_path $prefix$i || exit 1
51 done
52
53 exit 0