cc6c1fa497591b59489f6be5e9a1b05ab4dd2fa4
[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 [ -z "$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 if [ "$DO_INSTALL_LIBS" != "n" ]; then
20         # get the target dir for the libs
21         # This is an incomplete/incorrect list for now
22         case $(uname -m) in
23         x86_64|ppc64*|sparc64*|ia64*|hppa*64*) libdir=/lib64 ;;
24         *) libdir=/lib ;;
25         esac
26
27         mkdir -p $prefix/$libdir || exit 1
28         for i in $DO_INSTALL_LIBS; do
29                 rm -f $prefix/$libdir/$i || exit 1
30                 if [ -f $i ]; then
31                         install -m 644 $i $prefix/$libdir/ || exit 1
32                 fi
33         done
34 fi
35 rm -f $prefix/bin/busybox || exit 1
36 mkdir -p $prefix/bin || exit 1
37 install -m 755 busybox $prefix/bin/busybox || exit 1
38
39 for i in $h ; do
40         appdir=`dirname $i`
41         mkdir -p $prefix/$appdir || exit 1
42         if [ "$2" = "--hardlinks" ]; then
43             bb_path="$prefix/bin/busybox"
44         else
45             case "$appdir" in
46                 /)
47                     bb_path="bin/busybox"
48                 ;;
49                 /bin)
50                     bb_path="busybox"
51                 ;;
52                 /sbin)
53                     bb_path="../bin/busybox"
54                 ;;
55                 /usr/bin|/usr/sbin)
56                     bb_path="../../bin/busybox"
57                 ;;
58                 *)
59                 echo "Unknown installation directory: $appdir"
60                 exit 1
61                 ;;
62             esac
63         fi
64         echo "  $prefix$i -> $bb_path"
65         ln $linkopts $bb_path $prefix$i || exit 1
66 done
67
68 exit 0