107
107
if [ x"$src" = x ]
109
echo "install: no input file specified"
109
echo "$0: no input file specified" >&2
115
115
if [ x"$dir_arg" != x ]; then
119
if [ -d "$dst" ]; then
127
127
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
128
# might cause directories to be created, which would be especially bad
128
# might cause directories to be created, which would be especially bad
129
129
# if $src (and thus $dsttmp) contains '*'.
131
if [ -f $src -o -d $src ]
131
if [ -f "$src" ] || [ -d "$src" ]
135
echo "install: $src does not exist"
135
echo "$0: $src does not exist" >&2
139
139
if [ x"$dst" = x ]
141
echo "install: no destination specified"
141
echo "$0: no destination specified" >&2
147
147
# If destination is a directory, append the input filename; if your system
148
148
# does not like double slashes in filenames, you may need to add some logic
152
dst="$dst"/`basename $src`
152
dst=$dst/`basename "$src"`
158
158
## this sed command emulates the dirname command
159
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
159
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
161
161
# Make sure that the destination directory exists.
162
162
# this part is taken from Noah Friedman's mkinstalldirs script
164
164
# Skip lots of stat calls in the usual case.
165
165
if [ ! -d "$dstdir" ]; then
168
IFS="${IFS-${defaultIFS}}"
168
IFS="${IFS-$defaultIFS}"
171
171
# Some sh's can't handle IFS=/ for some reason.
173
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
173
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
178
178
while [ $# -ne 0 ] ; do
179
pathcomp="${pathcomp}${1}"
182
if [ ! -d "${pathcomp}" ] ;
182
if [ ! -d "$pathcomp" ] ;
184
$mkdirprog "${pathcomp}"
184
$mkdirprog "$pathcomp"
189
pathcomp="${pathcomp}/"
193
193
if [ x"$dir_arg" != x ]
195
$doit $instcmd $dst &&
195
$doit $instcmd "$dst" &&
197
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
198
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
199
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
200
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
197
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
198
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
199
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
200
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
203
203
# If we're going to rename the final executable, determine the name now.
205
if [ x"$transformarg" = x ]
205
if [ x"$transformarg" = x ]
207
dstfile=`basename $dst`
207
dstfile=`basename "$dst"`
209
dstfile=`basename $dst $transformbasename |
209
dstfile=`basename "$dst" $transformbasename |
210
210
sed $transformarg`$transformbasename
213
213
# don't allow the sed command to completely eliminate the filename
215
if [ x"$dstfile" = x ]
215
if [ x"$dstfile" = x ]
217
dstfile=`basename $dst`
217
dstfile=`basename "$dst"`
222
# Make a temp file name in the proper directory.
222
# Make a couple of temp file names in the proper directory.
224
224
dsttmp=$dstdir/#inst.$$#
225
rmtmp=$dstdir/#rm.$$#
227
# Trap to clean up temp files at exit.
229
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
230
trap '(exit $?); exit' 1 2 13 15
226
232
# Move or copy the file name to the temp name
228
$doit $instcmd $src $dsttmp &&
230
trap "rm -f ${dsttmp}" 0 &&
234
$doit $instcmd "$src" "$dsttmp" &&
232
236
# and set any options; do chmod last to preserve setuid bits
235
239
# ignore errors from any of these, just make sure not to ignore
236
240
# errors from the above "$doit $instcmd $src $dsttmp" command.
238
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
239
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
240
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
241
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
242
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
243
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
244
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
245
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
247
# Now remove or move aside any old file at destination location. We try this
248
# two ways since rm can't unlink itself on some systems and the destination
249
# file might be busy for other reasons. In this case, the final cleanup
250
# might fail but the new file should still install successfully.
253
if [ -f "$dstdir/$dstfile" ]
255
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
256
$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
258
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
243
266
# Now rename the file to the real destination.
245
$doit $rmcmd -f $dstdir/$dstfile &&
246
$doit $mvcmd $dsttmp $dstdir/$dstfile
268
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
272
# The final little trick to "correctly" pass the exit status to the exit trap.