Mercurial > hg > toybox
comparison scripts/install.sh @ 266:2ba3b8dce3ef
Add an install script, with --long --symlink --force and --uninstall options.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 24 Feb 2008 01:34:01 -0600 |
parents | |
children | 150a6d81bd02 |
comparison
equal
deleted
inserted
replaced
265:c7645fab8d73 | 266:2ba3b8dce3ef |
---|---|
1 #!/bin/bash | |
2 | |
3 # Grab default values for $CFLAGS and such. | |
4 | |
5 source ./configure | |
6 | |
7 # Parse command line arguments. | |
8 | |
9 [ -z "$PREFIX" ] && PREFIX="." | |
10 | |
11 LONG_PATH="" | |
12 while [ ! -z "$1" ] | |
13 do | |
14 # Create symlinks instead of hardlinks? | |
15 | |
16 [ "$1" == "--symlink" ] && LINK_TYPE="-s" | |
17 | |
18 # Uninstall? | |
19 | |
20 [ "$1" == "--uninstall" ] && UNINSTALL=1 | |
21 | |
22 # Delete destination command if it exists? | |
23 | |
24 [ "$1" == "--force" ] && DO_FORCE="-f" | |
25 | |
26 # Use {,usr}/{bin,sbin} paths instead of all files in one directory? | |
27 | |
28 if [ "$1" == "--long" ] | |
29 then | |
30 LONG_PATH="bin/" | |
31 fi | |
32 | |
33 shift | |
34 done | |
35 | |
36 echo "Compile instlist..." | |
37 | |
38 $DEBUG $HOSTCC $CCFLAGS -I . scripts/install.c -o instlist || exit 1 | |
39 COMMANDS="$(./instlist $LONG_PATH)" | |
40 | |
41 echo "Install commands..." | |
42 | |
43 # Copy toybox itself | |
44 | |
45 if [ -z "$UNINSTALL" ] | |
46 then | |
47 mkdir -p ${PREFIX}/${LONG_PATH} || exit 1 | |
48 cp toybox ${PREFIX}/${LONG_PATH} || exit 1 | |
49 else | |
50 rm "${PREFIX}/${LONG_PATH}/toybox" 2>/dev/null | |
51 rmdir "${PREFIX}/${LONG_PATH}" 2>/dev/null | |
52 fi | |
53 cd "${PREFIX}" | |
54 | |
55 # Make links to toybox | |
56 | |
57 for i in $COMMANDS | |
58 do | |
59 # Figure out target of link | |
60 | |
61 if [ -z "$LONG_PATH" ] | |
62 then | |
63 DOTPATH="" | |
64 else | |
65 # Create subdirectory for command to go in (if necessary) | |
66 | |
67 DOTPATH="$(echo $i | sed 's@\(.*/\).*@\1@')" | |
68 if [ -z "$UNINSTALL" ] | |
69 then | |
70 mkdir -p "$DOTPATH" || exit 1 | |
71 else | |
72 rmdir "$DOTPATH" 2>/dev/null | |
73 fi | |
74 | |
75 if [ -z "$LINK_TYPE" ] | |
76 then | |
77 dotpath="bin/" | |
78 else | |
79 if [ "$DOTPATH" != "$LONG_PATH" ] | |
80 then | |
81 DOTPATH="$(echo $DOTPATH | sed -e 's@[^/]*/@../@g')"$LONG_PATH | |
82 else | |
83 DOTPATH="" | |
84 fi | |
85 fi | |
86 fi | |
87 | |
88 # Create link | |
89 [ -z "$UNINSTALL" ] && | |
90 ln $DO_FORCE $LINK_TYPE ${DOTPATH}toybox $i || | |
91 rm $i 2>/dev/null | |
92 done |