125
125
if [ x"$src" = x ]
127
echo "install: no input file specified"
127
echo "$0: no input file specified" >&2
133
133
if [ x"$dir_arg" != x ]; then
137
if [ -d "$dst" ]; then
145
145
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
146
# might cause directories to be created, which would be especially bad
146
# might cause directories to be created, which would be especially bad
147
147
# if $src (and thus $dsttmp) contains '*'.
149
if [ -f $src -o -d $src ]
149
if [ -f "$src" ] || [ -d "$src" ]
153
echo "install: $src does not exist"
153
echo "$0: $src does not exist" >&2
157
157
if [ x"$dst" = x ]
159
echo "install: no destination specified"
159
echo "$0: no destination specified" >&2
165
165
# If destination is a directory, append the input filename; if your system
166
166
# does not like double slashes in filenames, you may need to add some logic
170
dst="$dst"/`basename $src`
170
dst=$dst/`basename "$src"`
176
176
## this sed command emulates the dirname command
177
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
177
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
179
179
# Make sure that the destination directory exists.
180
180
# this part is taken from Noah Friedman's mkinstalldirs script
182
182
# Skip lots of stat calls in the usual case.
183
183
if [ ! -d "$dstdir" ]; then
186
IFS="${IFS-${defaultIFS}}"
186
IFS="${IFS-$defaultIFS}"
189
189
# Some sh's can't handle IFS=/ for some reason.
191
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
191
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
196
196
while [ $# -ne 0 ] ; do
197
pathcomp="${pathcomp}${1}"
200
if [ ! -d "${pathcomp}" ] ;
200
if [ ! -d "$pathcomp" ] ;
202
$mkdirprog "${pathcomp}"
202
$mkdirprog "$pathcomp"
207
pathcomp="${pathcomp}/"
211
211
if [ x"$dir_arg" != x ]
213
$doit $instcmd $dst &&
213
$doit $instcmd "$dst" &&
215
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
216
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
217
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
218
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
215
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
216
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
217
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
218
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
221
221
# If we're going to rename the final executable, determine the name now.
223
if [ x"$transformarg" = x ]
223
if [ x"$transformarg" = x ]
225
dstfile=`basename $dst`
225
dstfile=`basename "$dst"`
227
dstfile=`basename $dst $transformbasename |
227
dstfile=`basename "$dst" $transformbasename |
228
228
sed $transformarg`$transformbasename
231
231
# don't allow the sed command to completely eliminate the filename
233
if [ x"$dstfile" = x ]
233
if [ x"$dstfile" = x ]
235
dstfile=`basename $dst`
235
dstfile=`basename "$dst"`
240
# Make a temp file name in the proper directory.
242
dsttmp=$dstdir/#inst.$$#
240
# Make a couple of temp file names in the proper directory.
242
dsttmp=$dstdir/_inst.$$_
243
rmtmp=$dstdir/_rm.$$_
245
# Trap to clean up temp files at exit.
247
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
248
trap '(exit $?); exit' 1 2 13 15
244
250
# Move or copy the file name to the temp name
246
$doit $instcmd $src $dsttmp &&
248
trap "rm -f ${dsttmp}" 0 &&
252
$doit $instcmd "$src" "$dsttmp" &&
250
254
# and set any options; do chmod last to preserve setuid bits
253
257
# ignore errors from any of these, just make sure not to ignore
254
258
# errors from the above "$doit $instcmd $src $dsttmp" command.
256
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
257
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
258
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
259
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
260
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
261
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
262
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
263
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
265
# Now remove or move aside any old file at destination location. We try this
266
# two ways since rm can't unlink itself on some systems and the destination
267
# file might be busy for other reasons. In this case, the final cleanup
268
# might fail but the new file should still install successfully.
271
if [ -f "$dstdir/$dstfile" ]
273
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
274
$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
276
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
261
284
# Now rename the file to the real destination.
263
$doit $rmcmd -f $dstdir/$dstfile &&
264
$doit $mvcmd $dsttmp $dstdir/$dstfile
286
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
290
# The final little trick to "correctly" pass the exit status to the exit trap.