]>
Commit | Line | Data |
---|---|---|
bf168768 DZ |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
4 | # | |
5 | # install - install a program, script, or datafile | |
6 | # This comes from X11R5; it is not part of GNU. | |
7 | # | |
8 | # $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $ | |
9 | # | |
10 | # This script is compatible with the BSD install script, but was written | |
11 | # from scratch. | |
12 | # | |
13 | ||
14 | ||
15 | # set DOITPROG to echo to test this script | |
16 | ||
17 | # Don't use :- since 4.3BSD and earlier shells don't like it. | |
18 | doit="${DOITPROG-}" | |
19 | ||
20 | ||
21 | # put in absolute paths if you don't have them in your path; or use env. vars. | |
22 | ||
23 | mvprog="${MVPROG-mv}" | |
24 | cpprog="${CPPROG-cp}" | |
25 | chmodprog="${CHMODPROG-chmod}" | |
26 | chownprog="${CHOWNPROG-chown}" | |
27 | chgrpprog="${CHGRPPROG-chgrp}" | |
28 | stripprog="${STRIPPROG-strip}" | |
29 | rmprog="${RMPROG-rm}" | |
30 | mkdirprog="${MKDIRPROG-mkdir}" | |
31 | ||
32 | tranformbasename="" | |
33 | transform_arg="" | |
34 | instcmd="$mvprog" | |
35 | chmodcmd="" | |
36 | chowncmd="" | |
37 | chgrpcmd="" | |
38 | stripcmd="" | |
39 | rmcmd="$rmprog -f" | |
40 | mvcmd="$mvprog" | |
41 | src="" | |
42 | dst="" | |
43 | ||
44 | while [ x"$1" != x ]; do | |
45 | case $1 in | |
46 | -c) instcmd="$cpprog" | |
47 | shift | |
48 | continue;; | |
49 | ||
50 | -m) chmodcmd="$chmodprog $2" | |
51 | shift | |
52 | shift | |
53 | continue;; | |
54 | ||
55 | -o) chowncmd="$chownprog $2" | |
56 | shift | |
57 | shift | |
58 | continue;; | |
59 | ||
60 | -g) chgrpcmd="$chgrpprog $2" | |
61 | shift | |
62 | shift | |
63 | continue;; | |
64 | ||
65 | -s) stripcmd="$stripprog" | |
66 | shift | |
67 | continue;; | |
68 | ||
69 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` | |
70 | shift | |
71 | continue;; | |
72 | ||
73 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` | |
74 | shift | |
75 | continue;; | |
76 | ||
77 | *) if [ x"$src" = x ] | |
78 | then | |
79 | src=$1 | |
80 | else | |
f0d7cc29 DZ |
81 | # this colon is to work around a 386BSD /bin/sh bug |
82 | : | |
bf168768 DZ |
83 | dst=$1 |
84 | fi | |
85 | shift | |
86 | continue;; | |
87 | esac | |
88 | done | |
89 | ||
90 | if [ x"$src" = x ] | |
91 | then | |
92 | echo "install: no input file specified" | |
93 | exit 1 | |
94 | else | |
95 | true | |
96 | fi | |
97 | ||
98 | if [ x"$dst" = x ] | |
99 | then | |
100 | echo "install: no destination specified" | |
101 | exit 1 | |
102 | else | |
103 | true | |
104 | fi | |
105 | ||
106 | # If destination is a directory, append the input filename; if your system | |
107 | # does not like double slashes in filenames, you may need to add some logic | |
108 | ||
109 | if [ -d $dst ] | |
110 | then | |
111 | dst="$dst"/`basename $src` | |
112 | else | |
113 | true | |
114 | fi | |
115 | ||
116 | ||
117 | # Make a temp file name in the proper directory. | |
118 | ||
af864713 DZ |
119 | ## this sed command emulates the dirname command |
120 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` | |
bf168768 DZ |
121 | dsttmp=$dstdir/#inst.$$# |
122 | ||
123 | # Make sure that the destination directory exists. | |
124 | # this part is taken from Noah Friedman's mkinstalldirs script | |
125 | ||
126 | defaultIFS=' | |
127 | ' | |
128 | IFS="${IFS-${defaultIFS}}" | |
129 | ||
130 | oIFS="${IFS}" | |
131 | # Some sh's can't handle IFS=/ for some reason. | |
132 | IFS='%' | |
133 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` | |
134 | IFS="${oIFS}" | |
135 | ||
136 | pathcomp='' | |
137 | ||
138 | while [ $# -ne 0 ] ; do | |
139 | pathcomp="${pathcomp}${1}" | |
140 | shift | |
141 | ||
142 | if [ ! -d "${pathcomp}" ] ; | |
143 | then | |
144 | $mkdirprog "${pathcomp}" | |
145 | else | |
146 | true | |
147 | fi | |
148 | ||
149 | pathcomp="${pathcomp}/" | |
150 | done | |
151 | ||
152 | # If we're going to rename the final executable, determine the name now. | |
153 | ||
154 | if [ x"$transformarg" = x ] | |
155 | then | |
156 | dstfile=`basename $dst` | |
157 | else | |
1a4874f7 | 158 | dstfile=`basename $dst $transformbasename | sed $transformarg`$transformbasename |
bf168768 DZ |
159 | fi |
160 | ||
161 | # don't allow the sed command to completely eliminate the filename | |
162 | ||
163 | if [ x"$dstfile" = x ] | |
164 | then | |
165 | dstfile=`basename $dst` | |
166 | else | |
167 | true | |
168 | fi | |
169 | ||
170 | # Move or copy the file name to the temp name | |
171 | ||
172 | $doit $instcmd $src $dsttmp | |
173 | ||
174 | # and set any options; do chmod last to preserve setuid bits | |
175 | ||
176 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi | |
177 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi | |
178 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi | |
179 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi | |
180 | ||
181 | # Now rename the file to the real destination. | |
182 | ||
183 | $doit $rmcmd $dstdir/$dstfile | |
184 | $doit $mvcmd $dsttmp $dstdir/$dstfile | |
185 | ||
186 | ||
187 | exit 0 |