1 |
#!/bin/sh |
2 |
# |
3 |
# Copyright (c) 2000 Carnegie Mellon University. All rights reserved. |
4 |
# |
5 |
# Redistribution and use in source and binary forms, with or without |
6 |
# modification, are permitted provided that the following conditions |
7 |
# are met: |
8 |
# |
9 |
# 1. Redistributions of source code must retain the above copyright |
10 |
# notice, this list of conditions and the following disclaimer. |
11 |
# |
12 |
# 2. Redistributions in binary form must reproduce the above copyright |
13 |
# notice, this list of conditions and the following disclaimer in |
14 |
# the documentation and/or other materials provided with the |
15 |
# distribution. |
16 |
# |
17 |
# 3. The name "Carnegie Mellon University" must not be used to |
18 |
# endorse or promote products derived from this software without |
19 |
# prior written permission. For permission or any other legal |
20 |
# details, please contact |
21 |
# Office of Technology Transfer |
22 |
# Carnegie Mellon University |
23 |
# 5000 Forbes Avenue |
24 |
# Pittsburgh, PA 15213-3890 |
25 |
# (412) 268-4387, fax: (412) 268-7395 |
26 |
# tech-transfer@andrew.cmu.edu |
27 |
# |
28 |
# 4. Redistributions of any form whatsoever must retain the following |
29 |
# acknowledgment: |
30 |
# "This product includes software developed by Computing Services |
31 |
# at Carnegie Mellon University (http://www.cmu.edu/computing/)." |
32 |
# |
33 |
# CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO |
34 |
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
35 |
# AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE |
36 |
# FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
37 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN |
38 |
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
39 |
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
40 |
# |
41 |
# install - install a program, script, or datafile |
42 |
# This comes from X11R5. |
43 |
# |
44 |
# Calling this script install-sh is preferred over install.sh, to prevent |
45 |
# `make' implicit rules from creating a file called install from it |
46 |
# when there is no Makefile. |
47 |
# |
48 |
# This script is compatible with the BSD install script, but was written |
49 |
# from scratch. |
50 |
# |
51 |
|
52 |
|
53 |
# set DOITPROG to echo to test this script |
54 |
|
55 |
# Don't use :- since 4.3BSD and earlier shells don't like it. |
56 |
doit="${DOITPROG-}" |
57 |
|
58 |
|
59 |
# put in absolute paths if you don't have them in your path; or use env. vars. |
60 |
|
61 |
mvprog="${MVPROG-mv}" |
62 |
cpprog="${CPPROG-cp}" |
63 |
chmodprog="${CHMODPROG-chmod}" |
64 |
chownprog="${CHOWNPROG-chown}" |
65 |
chgrpprog="${CHGRPPROG-chgrp}" |
66 |
stripprog="${STRIPPROG-strip}" |
67 |
rmprog="${RMPROG-rm}" |
68 |
mkdirprog="${MKDIRPROG-mkdir}" |
69 |
|
70 |
tranformbasename="" |
71 |
transform_arg="" |
72 |
instcmd="$mvprog" |
73 |
chmodcmd="$chmodprog 0755" |
74 |
chowncmd="" |
75 |
chgrpcmd="" |
76 |
stripcmd="" |
77 |
rmcmd="$rmprog -f" |
78 |
mvcmd="$mvprog" |
79 |
src="" |
80 |
dst="" |
81 |
dir_arg="" |
82 |
|
83 |
while [ x"$1" != x ]; do |
84 |
case $1 in |
85 |
-c) instcmd="$cpprog" |
86 |
shift |
87 |
continue;; |
88 |
|
89 |
-d) dir_arg=true |
90 |
shift |
91 |
continue;; |
92 |
|
93 |
-m) chmodcmd="$chmodprog $2" |
94 |
shift |
95 |
shift |
96 |
continue;; |
97 |
|
98 |
-o) chowncmd="$chownprog $2" |
99 |
shift |
100 |
shift |
101 |
continue;; |
102 |
|
103 |
-g) chgrpcmd="$chgrpprog $2" |
104 |
shift |
105 |
shift |
106 |
continue;; |
107 |
|
108 |
-s) stripcmd="$stripprog" |
109 |
shift |
110 |
continue;; |
111 |
|
112 |
-t=*) transformarg=`echo $1 | sed 's/-t=//'` |
113 |
shift |
114 |
continue;; |
115 |
|
116 |
-b=*) transformbasename=`echo $1 | sed 's/-b=//'` |
117 |
shift |
118 |
continue;; |
119 |
|
120 |
*) if [ x"$src" = x ] |
121 |
then |
122 |
src=$1 |
123 |
else |
124 |
# this colon is to work around a 386BSD /bin/sh bug |
125 |
: |
126 |
dst=$1 |
127 |
fi |
128 |
shift |
129 |
continue;; |
130 |
esac |
131 |
done |
132 |
|
133 |
if [ x"$src" = x ] |
134 |
then |
135 |
echo "install: no input file specified" |
136 |
exit 1 |
137 |
else |
138 |
true |
139 |
fi |
140 |
|
141 |
if [ x"$dir_arg" != x ]; then |
142 |
dst=$src |
143 |
src="" |
144 |
|
145 |
if [ -d $dst ]; then |
146 |
instcmd=: |
147 |
else |
148 |
instcmd=mkdir |
149 |
fi |
150 |
else |
151 |
|
152 |
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command |
153 |
# might cause directories to be created, which would be especially bad |
154 |
# if $src (and thus $dsttmp) contains '*'. |
155 |
|
156 |
if [ -f $src -o -d $src ] |
157 |
then |
158 |
true |
159 |
else |
160 |
echo "install: $src does not exist" |
161 |
exit 1 |
162 |
fi |
163 |
|
164 |
if [ x"$dst" = x ] |
165 |
then |
166 |
echo "install: no destination specified" |
167 |
exit 1 |
168 |
else |
169 |
true |
170 |
fi |
171 |
|
172 |
# If destination is a directory, append the input filename; if your system |
173 |
# does not like double slashes in filenames, you may need to add some logic |
174 |
|
175 |
if [ -d $dst ] |
176 |
then |
177 |
dst="$dst"/`basename $src` |
178 |
else |
179 |
true |
180 |
fi |
181 |
fi |
182 |
|
183 |
## this sed command emulates the dirname command |
184 |
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` |
185 |
|
186 |
# Make sure that the destination directory exists. |
187 |
# this part is taken from Noah Friedman's mkinstalldirs script |
188 |
|
189 |
# Skip lots of stat calls in the usual case. |
190 |
if [ ! -d "$dstdir" ]; then |
191 |
defaultIFS=' |
192 |
' |
193 |
IFS="${IFS-${defaultIFS}}" |
194 |
|
195 |
oIFS="${IFS}" |
196 |
# Some sh's can't handle IFS=/ for some reason. |
197 |
IFS='%' |
198 |
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` |
199 |
IFS="${oIFS}" |
200 |
|
201 |
pathcomp='' |
202 |
|
203 |
while [ $# -ne 0 ] ; do |
204 |
pathcomp="${pathcomp}${1}" |
205 |
shift |
206 |
|
207 |
if [ ! -d "${pathcomp}" ] ; |
208 |
then |
209 |
$mkdirprog "${pathcomp}" |
210 |
else |
211 |
true |
212 |
fi |
213 |
|
214 |
pathcomp="${pathcomp}/" |
215 |
done |
216 |
fi |
217 |
|
218 |
if [ x"$dir_arg" != x ] |
219 |
then |
220 |
$doit $instcmd $dst && |
221 |
|
222 |
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && |
223 |
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && |
224 |
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && |
225 |
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi |
226 |
else |
227 |
|
228 |
# If we're going to rename the final executable, determine the name now. |
229 |
|
230 |
if [ x"$transformarg" = x ] |
231 |
then |
232 |
dstfile=`basename $dst` |
233 |
else |
234 |
dstfile=`basename $dst $transformbasename | |
235 |
sed $transformarg`$transformbasename |
236 |
fi |
237 |
|
238 |
# don't allow the sed command to completely eliminate the filename |
239 |
|
240 |
if [ x"$dstfile" = x ] |
241 |
then |
242 |
dstfile=`basename $dst` |
243 |
else |
244 |
true |
245 |
fi |
246 |
|
247 |
# Make a temp file name in the proper directory. |
248 |
|
249 |
dsttmp=$dstdir/#inst.$$# |
250 |
|
251 |
# Move or copy the file name to the temp name |
252 |
|
253 |
$doit $instcmd $src $dsttmp && |
254 |
|
255 |
trap "rm -f ${dsttmp}" 0 && |
256 |
|
257 |
# and set any options; do chmod last to preserve setuid bits |
258 |
|
259 |
# If any of these fail, we abort the whole thing. If we want to |
260 |
# ignore errors from any of these, just make sure not to ignore |
261 |
# errors from the above "$doit $instcmd $src $dsttmp" command. |
262 |
|
263 |
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && |
264 |
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && |
265 |
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && |
266 |
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && |
267 |
|
268 |
# Now rename the file to the real destination. |
269 |
|
270 |
$doit $rmcmd -f $dstdir/$dstfile && |
271 |
$doit $mvcmd $dsttmp $dstdir/$dstfile |
272 |
|
273 |
fi && |
274 |
|
275 |
|
276 |
exit 0 |