leo_sobral@2
|
1 |
#!/bin/sh
|
leo_sobral@2
|
2 |
# install - install a program, script, or datafile
|
leo_sobral@2
|
3 |
|
leo_sobral@2
|
4 |
scriptversion=2004-04-01.17
|
leo_sobral@2
|
5 |
|
leo_sobral@2
|
6 |
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
leo_sobral@2
|
7 |
# later released in X11R6 (xc/config/util/install.sh) with the
|
leo_sobral@2
|
8 |
# following copyright and license.
|
leo_sobral@2
|
9 |
#
|
leo_sobral@2
|
10 |
# Copyright (C) 1994 X Consortium
|
leo_sobral@2
|
11 |
#
|
leo_sobral@2
|
12 |
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
leo_sobral@2
|
13 |
# of this software and associated documentation files (the "Software"), to
|
leo_sobral@2
|
14 |
# deal in the Software without restriction, including without limitation the
|
leo_sobral@2
|
15 |
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
leo_sobral@2
|
16 |
# sell copies of the Software, and to permit persons to whom the Software is
|
leo_sobral@2
|
17 |
# furnished to do so, subject to the following conditions:
|
leo_sobral@2
|
18 |
#
|
leo_sobral@2
|
19 |
# The above copyright notice and this permission notice shall be included in
|
leo_sobral@2
|
20 |
# all copies or substantial portions of the Software.
|
leo_sobral@2
|
21 |
#
|
leo_sobral@2
|
22 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
leo_sobral@2
|
23 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
leo_sobral@2
|
24 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
leo_sobral@2
|
25 |
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
leo_sobral@2
|
26 |
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
leo_sobral@2
|
27 |
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
leo_sobral@2
|
28 |
#
|
leo_sobral@2
|
29 |
# Except as contained in this notice, the name of the X Consortium shall not
|
leo_sobral@2
|
30 |
# be used in advertising or otherwise to promote the sale, use or other deal-
|
leo_sobral@2
|
31 |
# ings in this Software without prior written authorization from the X Consor-
|
leo_sobral@2
|
32 |
# tium.
|
leo_sobral@2
|
33 |
#
|
leo_sobral@2
|
34 |
#
|
leo_sobral@2
|
35 |
# FSF changes to this file are in the public domain.
|
leo_sobral@2
|
36 |
#
|
leo_sobral@2
|
37 |
# Calling this script install-sh is preferred over install.sh, to prevent
|
leo_sobral@2
|
38 |
# `make' implicit rules from creating a file called install from it
|
leo_sobral@2
|
39 |
# when there is no Makefile.
|
leo_sobral@2
|
40 |
#
|
leo_sobral@2
|
41 |
# This script is compatible with the BSD install script, but was written
|
leo_sobral@2
|
42 |
# from scratch. It can only install one file at a time, a restriction
|
leo_sobral@2
|
43 |
# shared with many OS's install programs.
|
leo_sobral@2
|
44 |
|
leo_sobral@2
|
45 |
# set DOITPROG to echo to test this script
|
leo_sobral@2
|
46 |
|
leo_sobral@2
|
47 |
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
leo_sobral@2
|
48 |
doit="${DOITPROG-}"
|
leo_sobral@2
|
49 |
|
leo_sobral@2
|
50 |
# put in absolute paths if you don't have them in your path; or use env. vars.
|
leo_sobral@2
|
51 |
|
leo_sobral@2
|
52 |
mvprog="${MVPROG-mv}"
|
leo_sobral@2
|
53 |
cpprog="${CPPROG-cp}"
|
leo_sobral@2
|
54 |
chmodprog="${CHMODPROG-chmod}"
|
leo_sobral@2
|
55 |
chownprog="${CHOWNPROG-chown}"
|
leo_sobral@2
|
56 |
chgrpprog="${CHGRPPROG-chgrp}"
|
leo_sobral@2
|
57 |
stripprog="${STRIPPROG-strip}"
|
leo_sobral@2
|
58 |
rmprog="${RMPROG-rm}"
|
leo_sobral@2
|
59 |
mkdirprog="${MKDIRPROG-mkdir}"
|
leo_sobral@2
|
60 |
|
leo_sobral@2
|
61 |
transformbasename=
|
leo_sobral@2
|
62 |
transform_arg=
|
leo_sobral@2
|
63 |
instcmd="$mvprog"
|
leo_sobral@2
|
64 |
chmodcmd="$chmodprog 0755"
|
leo_sobral@2
|
65 |
chowncmd=
|
leo_sobral@2
|
66 |
chgrpcmd=
|
leo_sobral@2
|
67 |
stripcmd=
|
leo_sobral@2
|
68 |
rmcmd="$rmprog -f"
|
leo_sobral@2
|
69 |
mvcmd="$mvprog"
|
leo_sobral@2
|
70 |
src=
|
leo_sobral@2
|
71 |
dst=
|
leo_sobral@2
|
72 |
dir_arg=
|
leo_sobral@2
|
73 |
|
leo_sobral@2
|
74 |
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
|
leo_sobral@2
|
75 |
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
leo_sobral@2
|
76 |
or: $0 -d DIRECTORIES...
|
leo_sobral@2
|
77 |
|
leo_sobral@2
|
78 |
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
|
leo_sobral@2
|
79 |
In the second, create the directory path DIR.
|
leo_sobral@2
|
80 |
|
leo_sobral@2
|
81 |
Options:
|
leo_sobral@2
|
82 |
-b=TRANSFORMBASENAME
|
leo_sobral@2
|
83 |
-c copy source (using $cpprog) instead of moving (using $mvprog).
|
leo_sobral@2
|
84 |
-d create directories instead of installing files.
|
leo_sobral@2
|
85 |
-g GROUP $chgrp installed files to GROUP.
|
leo_sobral@2
|
86 |
-m MODE $chmod installed files to MODE.
|
leo_sobral@2
|
87 |
-o USER $chown installed files to USER.
|
leo_sobral@2
|
88 |
-s strip installed files (using $stripprog).
|
leo_sobral@2
|
89 |
-t=TRANSFORM
|
leo_sobral@2
|
90 |
--help display this help and exit.
|
leo_sobral@2
|
91 |
--version display version info and exit.
|
leo_sobral@2
|
92 |
|
leo_sobral@2
|
93 |
Environment variables override the default commands:
|
leo_sobral@2
|
94 |
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
|
leo_sobral@2
|
95 |
"
|
leo_sobral@2
|
96 |
|
leo_sobral@2
|
97 |
while test -n "$1"; do
|
leo_sobral@2
|
98 |
case $1 in
|
leo_sobral@2
|
99 |
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
leo_sobral@2
|
100 |
shift
|
leo_sobral@2
|
101 |
continue;;
|
leo_sobral@2
|
102 |
|
leo_sobral@2
|
103 |
-c) instcmd=$cpprog
|
leo_sobral@2
|
104 |
shift
|
leo_sobral@2
|
105 |
continue;;
|
leo_sobral@2
|
106 |
|
leo_sobral@2
|
107 |
-d) dir_arg=true
|
leo_sobral@2
|
108 |
shift
|
leo_sobral@2
|
109 |
continue;;
|
leo_sobral@2
|
110 |
|
leo_sobral@2
|
111 |
-g) chgrpcmd="$chgrpprog $2"
|
leo_sobral@2
|
112 |
shift
|
leo_sobral@2
|
113 |
shift
|
leo_sobral@2
|
114 |
continue;;
|
leo_sobral@2
|
115 |
|
leo_sobral@2
|
116 |
--help) echo "$usage"; exit 0;;
|
leo_sobral@2
|
117 |
|
leo_sobral@2
|
118 |
-m) chmodcmd="$chmodprog $2"
|
leo_sobral@2
|
119 |
shift
|
leo_sobral@2
|
120 |
shift
|
leo_sobral@2
|
121 |
continue;;
|
leo_sobral@2
|
122 |
|
leo_sobral@2
|
123 |
-o) chowncmd="$chownprog $2"
|
leo_sobral@2
|
124 |
shift
|
leo_sobral@2
|
125 |
shift
|
leo_sobral@2
|
126 |
continue;;
|
leo_sobral@2
|
127 |
|
leo_sobral@2
|
128 |
-s) stripcmd=$stripprog
|
leo_sobral@2
|
129 |
shift
|
leo_sobral@2
|
130 |
continue;;
|
leo_sobral@2
|
131 |
|
leo_sobral@2
|
132 |
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
leo_sobral@2
|
133 |
shift
|
leo_sobral@2
|
134 |
continue;;
|
leo_sobral@2
|
135 |
|
leo_sobral@2
|
136 |
--version) echo "$0 $scriptversion"; exit 0;;
|
leo_sobral@2
|
137 |
|
leo_sobral@2
|
138 |
*) # When -d is used, all remaining arguments are directories to create.
|
leo_sobral@2
|
139 |
test -n "$dir_arg" && break
|
leo_sobral@2
|
140 |
# Otherwise, the last argument is the destination. Remove it from $@.
|
leo_sobral@2
|
141 |
for arg
|
leo_sobral@2
|
142 |
do
|
leo_sobral@2
|
143 |
if test -n "$dstarg"; then
|
leo_sobral@2
|
144 |
# $@ is not empty: it contains at least $arg.
|
leo_sobral@2
|
145 |
set fnord "$@" "$dstarg"
|
leo_sobral@2
|
146 |
shift # fnord
|
leo_sobral@2
|
147 |
fi
|
leo_sobral@2
|
148 |
shift # arg
|
leo_sobral@2
|
149 |
dstarg=$arg
|
leo_sobral@2
|
150 |
done
|
leo_sobral@2
|
151 |
break;;
|
leo_sobral@2
|
152 |
esac
|
leo_sobral@2
|
153 |
done
|
leo_sobral@2
|
154 |
|
leo_sobral@2
|
155 |
if test -z "$1"; then
|
leo_sobral@2
|
156 |
if test -z "$dir_arg"; then
|
leo_sobral@2
|
157 |
echo "$0: no input file specified." >&2
|
leo_sobral@2
|
158 |
exit 1
|
leo_sobral@2
|
159 |
fi
|
leo_sobral@2
|
160 |
# It's OK to call `install-sh -d' without argument.
|
leo_sobral@2
|
161 |
# This can happen when creating conditional directories.
|
leo_sobral@2
|
162 |
exit 0
|
leo_sobral@2
|
163 |
fi
|
leo_sobral@2
|
164 |
|
leo_sobral@2
|
165 |
for src
|
leo_sobral@2
|
166 |
do
|
leo_sobral@2
|
167 |
# Protect names starting with `-'.
|
leo_sobral@2
|
168 |
case $src in
|
leo_sobral@2
|
169 |
-*) src=./$src ;;
|
leo_sobral@2
|
170 |
esac
|
leo_sobral@2
|
171 |
|
leo_sobral@2
|
172 |
if test -n "$dir_arg"; then
|
leo_sobral@2
|
173 |
dst=$src
|
leo_sobral@2
|
174 |
src=
|
leo_sobral@2
|
175 |
|
leo_sobral@2
|
176 |
if test -d "$dst"; then
|
leo_sobral@2
|
177 |
instcmd=:
|
leo_sobral@2
|
178 |
chmodcmd=
|
leo_sobral@2
|
179 |
else
|
leo_sobral@2
|
180 |
instcmd=$mkdirprog
|
leo_sobral@2
|
181 |
fi
|
leo_sobral@2
|
182 |
else
|
leo_sobral@2
|
183 |
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
leo_sobral@2
|
184 |
# might cause directories to be created, which would be especially bad
|
leo_sobral@2
|
185 |
# if $src (and thus $dsttmp) contains '*'.
|
leo_sobral@2
|
186 |
if test ! -f "$src" && test ! -d "$src"; then
|
leo_sobral@2
|
187 |
echo "$0: $src does not exist." >&2
|
leo_sobral@2
|
188 |
exit 1
|
leo_sobral@2
|
189 |
fi
|
leo_sobral@2
|
190 |
|
leo_sobral@2
|
191 |
if test -z "$dstarg"; then
|
leo_sobral@2
|
192 |
echo "$0: no destination specified." >&2
|
leo_sobral@2
|
193 |
exit 1
|
leo_sobral@2
|
194 |
fi
|
leo_sobral@2
|
195 |
|
leo_sobral@2
|
196 |
dst=$dstarg
|
leo_sobral@2
|
197 |
# Protect names starting with `-'.
|
leo_sobral@2
|
198 |
case $dst in
|
leo_sobral@2
|
199 |
-*) dst=./$dst ;;
|
leo_sobral@2
|
200 |
esac
|
leo_sobral@2
|
201 |
|
leo_sobral@2
|
202 |
# If destination is a directory, append the input filename; won't work
|
leo_sobral@2
|
203 |
# if double slashes aren't ignored.
|
leo_sobral@2
|
204 |
if test -d "$dst"; then
|
leo_sobral@2
|
205 |
dst=$dst/`basename "$src"`
|
leo_sobral@2
|
206 |
fi
|
leo_sobral@2
|
207 |
fi
|
leo_sobral@2
|
208 |
|
leo_sobral@2
|
209 |
# This sed command emulates the dirname command.
|
leo_sobral@2
|
210 |
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
leo_sobral@2
|
211 |
|
leo_sobral@2
|
212 |
# Make sure that the destination directory exists.
|
leo_sobral@2
|
213 |
|
leo_sobral@2
|
214 |
# Skip lots of stat calls in the usual case.
|
leo_sobral@2
|
215 |
if test ! -d "$dstdir"; then
|
leo_sobral@2
|
216 |
defaultIFS='
|
leo_sobral@2
|
217 |
'
|
leo_sobral@2
|
218 |
IFS="${IFS-$defaultIFS}"
|
leo_sobral@2
|
219 |
|
leo_sobral@2
|
220 |
oIFS=$IFS
|
leo_sobral@2
|
221 |
# Some sh's can't handle IFS=/ for some reason.
|
leo_sobral@2
|
222 |
IFS='%'
|
leo_sobral@2
|
223 |
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
|
leo_sobral@2
|
224 |
IFS=$oIFS
|
leo_sobral@2
|
225 |
|
leo_sobral@2
|
226 |
pathcomp=
|
leo_sobral@2
|
227 |
|
leo_sobral@2
|
228 |
while test $# -ne 0 ; do
|
leo_sobral@2
|
229 |
pathcomp=$pathcomp$1
|
leo_sobral@2
|
230 |
shift
|
leo_sobral@2
|
231 |
if test ! -d "$pathcomp"; then
|
leo_sobral@2
|
232 |
$mkdirprog "$pathcomp" || lasterr=$?
|
leo_sobral@2
|
233 |
# mkdir can fail with a `File exist' error in case several
|
leo_sobral@2
|
234 |
# install-sh are creating the directory concurrently. This
|
leo_sobral@2
|
235 |
# is OK.
|
leo_sobral@2
|
236 |
test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
|
leo_sobral@2
|
237 |
fi
|
leo_sobral@2
|
238 |
pathcomp=$pathcomp/
|
leo_sobral@2
|
239 |
done
|
leo_sobral@2
|
240 |
fi
|
leo_sobral@2
|
241 |
|
leo_sobral@2
|
242 |
if test -n "$dir_arg"; then
|
leo_sobral@2
|
243 |
$doit $instcmd "$dst" \
|
leo_sobral@2
|
244 |
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
|
leo_sobral@2
|
245 |
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
|
leo_sobral@2
|
246 |
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
|
leo_sobral@2
|
247 |
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
|
leo_sobral@2
|
248 |
|
leo_sobral@2
|
249 |
else
|
leo_sobral@2
|
250 |
# If we're going to rename the final executable, determine the name now.
|
leo_sobral@2
|
251 |
if test -z "$transformarg"; then
|
leo_sobral@2
|
252 |
dstfile=`basename "$dst"`
|
leo_sobral@2
|
253 |
else
|
leo_sobral@2
|
254 |
dstfile=`basename "$dst" $transformbasename \
|
leo_sobral@2
|
255 |
| sed $transformarg`$transformbasename
|
leo_sobral@2
|
256 |
fi
|
leo_sobral@2
|
257 |
|
leo_sobral@2
|
258 |
# don't allow the sed command to completely eliminate the filename.
|
leo_sobral@2
|
259 |
test -z "$dstfile" && dstfile=`basename "$dst"`
|
leo_sobral@2
|
260 |
|
leo_sobral@2
|
261 |
# Make a couple of temp file names in the proper directory.
|
leo_sobral@2
|
262 |
dsttmp=$dstdir/_inst.$$_
|
leo_sobral@2
|
263 |
rmtmp=$dstdir/_rm.$$_
|
leo_sobral@2
|
264 |
|
leo_sobral@2
|
265 |
# Trap to clean up those temp files at exit.
|
leo_sobral@2
|
266 |
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
|
leo_sobral@2
|
267 |
trap '(exit $?); exit' 1 2 13 15
|
leo_sobral@2
|
268 |
|
leo_sobral@2
|
269 |
# Move or copy the file name to the temp name
|
leo_sobral@2
|
270 |
$doit $instcmd "$src" "$dsttmp" &&
|
leo_sobral@2
|
271 |
|
leo_sobral@2
|
272 |
# and set any options; do chmod last to preserve setuid bits.
|
leo_sobral@2
|
273 |
#
|
leo_sobral@2
|
274 |
# If any of these fail, we abort the whole thing. If we want to
|
leo_sobral@2
|
275 |
# ignore errors from any of these, just make sure not to ignore
|
leo_sobral@2
|
276 |
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
leo_sobral@2
|
277 |
#
|
leo_sobral@2
|
278 |
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
|
leo_sobral@2
|
279 |
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
|
leo_sobral@2
|
280 |
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
|
leo_sobral@2
|
281 |
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
|
leo_sobral@2
|
282 |
|
leo_sobral@2
|
283 |
# Now rename the file to the real destination.
|
leo_sobral@2
|
284 |
{ $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
|
leo_sobral@2
|
285 |
|| {
|
leo_sobral@2
|
286 |
# The rename failed, perhaps because mv can't rename something else
|
leo_sobral@2
|
287 |
# to itself, or perhaps because mv is so ancient that it does not
|
leo_sobral@2
|
288 |
# support -f.
|
leo_sobral@2
|
289 |
|
leo_sobral@2
|
290 |
# Now remove or move aside any old file at destination location.
|
leo_sobral@2
|
291 |
# We try this two ways since rm can't unlink itself on some
|
leo_sobral@2
|
292 |
# systems and the destination file might be busy for other
|
leo_sobral@2
|
293 |
# reasons. In this case, the final cleanup might fail but the new
|
leo_sobral@2
|
294 |
# file should still install successfully.
|
leo_sobral@2
|
295 |
{
|
leo_sobral@2
|
296 |
if test -f "$dstdir/$dstfile"; then
|
leo_sobral@2
|
297 |
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
|
leo_sobral@2
|
298 |
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
|
leo_sobral@2
|
299 |
|| {
|
leo_sobral@2
|
300 |
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
|
leo_sobral@2
|
301 |
(exit 1); exit
|
leo_sobral@2
|
302 |
}
|
leo_sobral@2
|
303 |
else
|
leo_sobral@2
|
304 |
:
|
leo_sobral@2
|
305 |
fi
|
leo_sobral@2
|
306 |
} &&
|
leo_sobral@2
|
307 |
|
leo_sobral@2
|
308 |
# Now rename the file to the real destination.
|
leo_sobral@2
|
309 |
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
|
leo_sobral@2
|
310 |
}
|
leo_sobral@2
|
311 |
}
|
leo_sobral@2
|
312 |
fi || { (exit 1); exit; }
|
leo_sobral@2
|
313 |
done
|
leo_sobral@2
|
314 |
|
leo_sobral@2
|
315 |
# The final little trick to "correctly" pass the exit status to the exit trap.
|
leo_sobral@2
|
316 |
{
|
leo_sobral@2
|
317 |
(exit 0); exit
|
leo_sobral@2
|
318 |
}
|
leo_sobral@2
|
319 |
|
leo_sobral@2
|
320 |
# Local variables:
|
leo_sobral@2
|
321 |
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
leo_sobral@2
|
322 |
# time-stamp-start: "scriptversion="
|
leo_sobral@2
|
323 |
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
leo_sobral@2
|
324 |
# time-stamp-end: "$"
|
leo_sobral@2
|
325 |
# End:
|