build system: use od -b instead of od -t x1
[platform/upstream/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 "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
9         exit 1
10 fi
11
12 h=`sort busybox.links | uniq`
13
14 linkopts=""
15 scriptwrapper="n"
16 cleanup="0"
17 noclobber="0"
18 case "$2" in
19         --hardlinks)     linkopts="-f";;
20         --symlinks)      linkopts="-fs";;
21         --scriptwrapper) scriptwrapper="y";swrapall="y";;
22         --sw-sh-hard)    scriptwrapper="y";linkopts="-f";;
23         --sw-sh-sym)     scriptwrapper="y";linkopts="-fs";;
24         --cleanup)       cleanup="1";;
25         --noclobber)     noclobber="1";;
26         "")              h="";;
27         *)               echo "Unknown install option: $2"; exit 1;;
28 esac
29
30 if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
31         # get the target dir for the libs
32         # assume it starts with lib
33         libdir=$($CC -print-file-name=libc.so | \
34                  sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
35         if test -z "$libdir"; then
36                 libdir=/lib
37         fi
38
39         mkdir -p "$prefix/$libdir" || exit 1
40         for i in $DO_INSTALL_LIBS; do
41                 rm -f "$prefix/$libdir/$i" || exit 1
42                 if [ -f "$i" ]; then
43                         cp -pPR "$i" "$prefix/$libdir/" || exit 1
44                         chmod 0644 "$prefix/$libdir/$i" || exit 1
45                 fi
46         done
47 fi
48
49 if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
50         inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
51         sub_shell_it=`
52                 cd "$prefix"
53                 for d in usr/sbin usr/bin sbin bin; do
54                         pd=$PWD
55                         if [ -d "$d" ]; then
56                                 cd "$d"
57                                 ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
58                         fi
59                         cd "$pd"
60                 done
61                 `
62         exit 0
63 fi
64
65 rm -f "$prefix/bin/busybox" || exit 1
66 mkdir -p "$prefix/bin" || exit 1
67 install -m 755 busybox "$prefix/bin/busybox" || exit 1
68
69 for i in $h; do
70         appdir=`dirname "$i"`
71         mkdir -p "$prefix/$appdir" || exit 1
72         if [ "$scriptwrapper" = "y" ]; then
73                 if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
74                         ln $linkopts busybox "$prefix/$i" || exit 1
75                 else
76                         rm -f "$prefix/$i"
77                         echo "#!/bin/busybox" >"$prefix/$i"
78                         chmod +x "$prefix/$i"
79                 fi
80                 echo "  $prefix/$i"
81         else
82                 if [ "$2" = "--hardlinks" ]; then
83                         bb_path="$prefix/bin/busybox"
84                 else
85                         case "$appdir" in
86                         /)
87                                 bb_path="bin/busybox"
88                         ;;
89                         /bin)
90                                 bb_path="busybox"
91                         ;;
92                         /sbin)
93                                 bb_path="../bin/busybox"
94                         ;;
95                         /usr/bin | /usr/sbin)
96                                 bb_path="../../bin/busybox"
97                         ;;
98                         *)
99                                 echo "Unknown installation directory: $appdir"
100                                 exit 1
101                         ;;
102                         esac
103                 fi
104                 if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
105                         echo "  $prefix/$i -> $bb_path"
106                         ln $linkopts "$bb_path" "$prefix/$i" || exit 1
107                 else
108                         echo "  $prefix/$i already exists"
109                 fi
110         fi
111 done
112
113 exit 0