install-sh revision 6b526288
141b2f0bdSmrg#!/bin/sh 241b2f0bdSmrg# install - install a program, script, or datafile 341b2f0bdSmrg 46b526288Smrgscriptversion=2016-01-11.22; # UTC 541b2f0bdSmrg 641b2f0bdSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 741b2f0bdSmrg# later released in X11R6 (xc/config/util/install.sh) with the 841b2f0bdSmrg# following copyright and license. 941b2f0bdSmrg# 1041b2f0bdSmrg# Copyright (C) 1994 X Consortium 1141b2f0bdSmrg# 1241b2f0bdSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1341b2f0bdSmrg# of this software and associated documentation files (the "Software"), to 1441b2f0bdSmrg# deal in the Software without restriction, including without limitation the 1541b2f0bdSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1641b2f0bdSmrg# sell copies of the Software, and to permit persons to whom the Software is 1741b2f0bdSmrg# furnished to do so, subject to the following conditions: 1841b2f0bdSmrg# 1941b2f0bdSmrg# The above copyright notice and this permission notice shall be included in 2041b2f0bdSmrg# all copies or substantial portions of the Software. 2141b2f0bdSmrg# 2241b2f0bdSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2341b2f0bdSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2441b2f0bdSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2541b2f0bdSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2641b2f0bdSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2741b2f0bdSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2841b2f0bdSmrg# 2941b2f0bdSmrg# Except as contained in this notice, the name of the X Consortium shall not 3041b2f0bdSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 3141b2f0bdSmrg# ings in this Software without prior written authorization from the X Consor- 3241b2f0bdSmrg# tium. 3341b2f0bdSmrg# 3441b2f0bdSmrg# 3541b2f0bdSmrg# FSF changes to this file are in the public domain. 3641b2f0bdSmrg# 3741b2f0bdSmrg# Calling this script install-sh is preferred over install.sh, to prevent 386b526288Smrg# 'make' implicit rules from creating a file called install from it 3941b2f0bdSmrg# when there is no Makefile. 4041b2f0bdSmrg# 4141b2f0bdSmrg# This script is compatible with the BSD install script, but was written 4211245024Smrg# from scratch. 4311245024Smrg 446b526288Smrgtab=' ' 4511245024Smrgnl=' 4611245024Smrg' 476b526288SmrgIFS=" $tab$nl" 4841b2f0bdSmrg 496b526288Smrg# Set DOITPROG to "echo" to test this script. 5041b2f0bdSmrg 5111245024Smrgdoit=${DOITPROG-} 526b526288Smrgdoit_exec=${doit:-exec} 5341b2f0bdSmrg 5411245024Smrg# Put in absolute file names if you don't have them in your path; 5511245024Smrg# or use environment vars. 5611245024Smrg 5711245024Smrgchgrpprog=${CHGRPPROG-chgrp} 5811245024Smrgchmodprog=${CHMODPROG-chmod} 5911245024Smrgchownprog=${CHOWNPROG-chown} 6011245024Smrgcmpprog=${CMPPROG-cmp} 6111245024Smrgcpprog=${CPPROG-cp} 6211245024Smrgmkdirprog=${MKDIRPROG-mkdir} 6311245024Smrgmvprog=${MVPROG-mv} 6411245024Smrgrmprog=${RMPROG-rm} 6511245024Smrgstripprog=${STRIPPROG-strip} 6611245024Smrg 6711245024Smrgposix_mkdir= 6811245024Smrg 6911245024Smrg# Desired mode of installed file. 7011245024Smrgmode=0755 7141b2f0bdSmrg 7241b2f0bdSmrgchgrpcmd= 7311245024Smrgchmodcmd=$chmodprog 7411245024Smrgchowncmd= 7511245024Smrgmvcmd=$mvprog 7641b2f0bdSmrgrmcmd="$rmprog -f" 7711245024Smrgstripcmd= 7811245024Smrg 7941b2f0bdSmrgsrc= 8041b2f0bdSmrgdst= 8141b2f0bdSmrgdir_arg= 8211245024Smrgdst_arg= 8311245024Smrg 8411245024Smrgcopy_on_change=false 856b526288Smrgis_target_a_directory=possibly 8641b2f0bdSmrg 8711245024Smrgusage="\ 8811245024SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 8941b2f0bdSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 9041b2f0bdSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 9141b2f0bdSmrg or: $0 [OPTION]... -d DIRECTORIES... 9241b2f0bdSmrg 9341b2f0bdSmrgIn the 1st form, copy SRCFILE to DSTFILE. 9441b2f0bdSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 9541b2f0bdSmrgIn the 4th, create DIRECTORIES. 9641b2f0bdSmrg 9741b2f0bdSmrgOptions: 9811245024Smrg --help display this help and exit. 9911245024Smrg --version display version info and exit. 10011245024Smrg 10111245024Smrg -c (ignored) 10211245024Smrg -C install only if different (preserve the last data modification time) 10311245024Smrg -d create directories instead of installing files. 10411245024Smrg -g GROUP $chgrpprog installed files to GROUP. 10511245024Smrg -m MODE $chmodprog installed files to MODE. 10611245024Smrg -o USER $chownprog installed files to USER. 10711245024Smrg -s $stripprog installed files. 10811245024Smrg -t DIRECTORY install into DIRECTORY. 10911245024Smrg -T report an error if DSTFILE is a directory. 11041b2f0bdSmrg 11141b2f0bdSmrgEnvironment variables override the default commands: 11211245024Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 11311245024Smrg RMPROG STRIPPROG 11441b2f0bdSmrg" 11541b2f0bdSmrg 11611245024Smrgwhile test $# -ne 0; do 11741b2f0bdSmrg case $1 in 11811245024Smrg -c) ;; 11911245024Smrg 12011245024Smrg -C) copy_on_change=true;; 12141b2f0bdSmrg 12211245024Smrg -d) dir_arg=true;; 12341b2f0bdSmrg 12441b2f0bdSmrg -g) chgrpcmd="$chgrpprog $2" 1256b526288Smrg shift;; 12641b2f0bdSmrg 12741b2f0bdSmrg --help) echo "$usage"; exit $?;; 12841b2f0bdSmrg 12911245024Smrg -m) mode=$2 1306b526288Smrg case $mode in 1316b526288Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1326b526288Smrg echo "$0: invalid mode: $mode" >&2 1336b526288Smrg exit 1;; 1346b526288Smrg esac 1356b526288Smrg shift;; 13641b2f0bdSmrg 13741b2f0bdSmrg -o) chowncmd="$chownprog $2" 1386b526288Smrg shift;; 13941b2f0bdSmrg 14011245024Smrg -s) stripcmd=$stripprog;; 14141b2f0bdSmrg 1426b526288Smrg -t) 1436b526288Smrg is_target_a_directory=always 1446b526288Smrg dst_arg=$2 1456b526288Smrg # Protect names problematic for 'test' and other utilities. 1466b526288Smrg case $dst_arg in 1476b526288Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1486b526288Smrg esac 1496b526288Smrg shift;; 15041b2f0bdSmrg 1516b526288Smrg -T) is_target_a_directory=never;; 15241b2f0bdSmrg 15341b2f0bdSmrg --version) echo "$0 $scriptversion"; exit $?;; 15441b2f0bdSmrg 1556b526288Smrg --) shift 1566b526288Smrg break;; 15711245024Smrg 1586b526288Smrg -*) echo "$0: invalid option: $1" >&2 1596b526288Smrg exit 1;; 16011245024Smrg 16111245024Smrg *) break;; 16241b2f0bdSmrg esac 16311245024Smrg shift 16441b2f0bdSmrgdone 16541b2f0bdSmrg 1666b526288Smrg# We allow the use of options -d and -T together, by making -d 1676b526288Smrg# take the precedence; this is for compatibility with GNU install. 1686b526288Smrg 1696b526288Smrgif test -n "$dir_arg"; then 1706b526288Smrg if test -n "$dst_arg"; then 1716b526288Smrg echo "$0: target directory not allowed when installing a directory." >&2 1726b526288Smrg exit 1 1736b526288Smrg fi 1746b526288Smrgfi 1756b526288Smrg 17611245024Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17711245024Smrg # When -d is used, all remaining arguments are directories to create. 17811245024Smrg # When -t is used, the destination is already specified. 17911245024Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18011245024Smrg for arg 18111245024Smrg do 18211245024Smrg if test -n "$dst_arg"; then 18311245024Smrg # $@ is not empty: it contains at least $arg. 18411245024Smrg set fnord "$@" "$dst_arg" 18511245024Smrg shift # fnord 18611245024Smrg fi 18711245024Smrg shift # arg 18811245024Smrg dst_arg=$arg 1896b526288Smrg # Protect names problematic for 'test' and other utilities. 1906b526288Smrg case $dst_arg in 1916b526288Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1926b526288Smrg esac 19311245024Smrg done 19411245024Smrgfi 19511245024Smrg 19611245024Smrgif test $# -eq 0; then 19741b2f0bdSmrg if test -z "$dir_arg"; then 19841b2f0bdSmrg echo "$0: no input file specified." >&2 19941b2f0bdSmrg exit 1 20041b2f0bdSmrg fi 2016b526288Smrg # It's OK to call 'install-sh -d' without argument. 20241b2f0bdSmrg # This can happen when creating conditional directories. 20341b2f0bdSmrg exit 0 20441b2f0bdSmrgfi 20541b2f0bdSmrg 20611245024Smrgif test -z "$dir_arg"; then 2076b526288Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2086b526288Smrg if test ! -d "$dst_arg"; then 2096b526288Smrg echo "$0: $dst_arg: Is not a directory." >&2 2106b526288Smrg exit 1 2116b526288Smrg fi 2126b526288Smrg fi 2136b526288Smrgfi 2146b526288Smrg 2156b526288Smrgif test -z "$dir_arg"; then 2166b526288Smrg do_exit='(exit $ret); exit $ret' 2176b526288Smrg trap "ret=129; $do_exit" 1 2186b526288Smrg trap "ret=130; $do_exit" 2 2196b526288Smrg trap "ret=141; $do_exit" 13 2206b526288Smrg trap "ret=143; $do_exit" 15 22111245024Smrg 22211245024Smrg # Set umask so as not to create temps with too-generous modes. 22311245024Smrg # However, 'strip' requires both read and write access to temps. 22411245024Smrg case $mode in 22511245024Smrg # Optimize common cases. 22611245024Smrg *644) cp_umask=133;; 22711245024Smrg *755) cp_umask=22;; 22811245024Smrg 22911245024Smrg *[0-7]) 23011245024Smrg if test -z "$stripcmd"; then 2316b526288Smrg u_plus_rw= 23211245024Smrg else 2336b526288Smrg u_plus_rw='% 200' 23411245024Smrg fi 23511245024Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23611245024Smrg *) 23711245024Smrg if test -z "$stripcmd"; then 2386b526288Smrg u_plus_rw= 23911245024Smrg else 2406b526288Smrg u_plus_rw=,u+rw 24111245024Smrg fi 24211245024Smrg cp_umask=$mode$u_plus_rw;; 24311245024Smrg esac 24411245024Smrgfi 24511245024Smrg 24641b2f0bdSmrgfor src 24741b2f0bdSmrgdo 2486b526288Smrg # Protect names problematic for 'test' and other utilities. 24941b2f0bdSmrg case $src in 2506b526288Smrg -* | [=\(\)!]) src=./$src;; 25141b2f0bdSmrg esac 25241b2f0bdSmrg 25341b2f0bdSmrg if test -n "$dir_arg"; then 25441b2f0bdSmrg dst=$src 25511245024Smrg dstdir=$dst 25611245024Smrg test -d "$dstdir" 25711245024Smrg dstdir_status=$? 25841b2f0bdSmrg else 25911245024Smrg 26041b2f0bdSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 26141b2f0bdSmrg # might cause directories to be created, which would be especially bad 26241b2f0bdSmrg # if $src (and thus $dsttmp) contains '*'. 26341b2f0bdSmrg if test ! -f "$src" && test ! -d "$src"; then 26441b2f0bdSmrg echo "$0: $src does not exist." >&2 26541b2f0bdSmrg exit 1 26641b2f0bdSmrg fi 26741b2f0bdSmrg 26811245024Smrg if test -z "$dst_arg"; then 26941b2f0bdSmrg echo "$0: no destination specified." >&2 27041b2f0bdSmrg exit 1 27141b2f0bdSmrg fi 27211245024Smrg dst=$dst_arg 27341b2f0bdSmrg 27441b2f0bdSmrg # If destination is a directory, append the input filename; won't work 27541b2f0bdSmrg # if double slashes aren't ignored. 27641b2f0bdSmrg if test -d "$dst"; then 2776b526288Smrg if test "$is_target_a_directory" = never; then 2786b526288Smrg echo "$0: $dst_arg: Is a directory" >&2 2796b526288Smrg exit 1 28041b2f0bdSmrg fi 28111245024Smrg dstdir=$dst 28211245024Smrg dst=$dstdir/`basename "$src"` 28311245024Smrg dstdir_status=0 28411245024Smrg else 2856b526288Smrg dstdir=`dirname "$dst"` 28611245024Smrg test -d "$dstdir" 28711245024Smrg dstdir_status=$? 28841b2f0bdSmrg fi 28941b2f0bdSmrg fi 29041b2f0bdSmrg 29111245024Smrg obsolete_mkdir_used=false 29211245024Smrg 29311245024Smrg if test $dstdir_status != 0; then 29411245024Smrg case $posix_mkdir in 29511245024Smrg '') 2966b526288Smrg # Create intermediate dirs using mode 755 as modified by the umask. 2976b526288Smrg # This is like FreeBSD 'install' as of 1997-10-28. 2986b526288Smrg umask=`umask` 2996b526288Smrg case $stripcmd.$umask in 3006b526288Smrg # Optimize common cases. 3016b526288Smrg *[2367][2367]) mkdir_umask=$umask;; 3026b526288Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3036b526288Smrg 3046b526288Smrg *[0-7]) 3056b526288Smrg mkdir_umask=`expr $umask + 22 \ 3066b526288Smrg - $umask % 100 % 40 + $umask % 20 \ 3076b526288Smrg - $umask % 10 % 4 + $umask % 2 3086b526288Smrg `;; 3096b526288Smrg *) mkdir_umask=$umask,go-w;; 3106b526288Smrg esac 3116b526288Smrg 3126b526288Smrg # With -d, create the new directory with the user-specified mode. 3136b526288Smrg # Otherwise, rely on $mkdir_umask. 3146b526288Smrg if test -n "$dir_arg"; then 3156b526288Smrg mkdir_mode=-m$mode 3166b526288Smrg else 3176b526288Smrg mkdir_mode= 3186b526288Smrg fi 3196b526288Smrg 3206b526288Smrg posix_mkdir=false 3216b526288Smrg case $umask in 3226b526288Smrg *[123567][0-7][0-7]) 3236b526288Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3246b526288Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3256b526288Smrg ;; 3266b526288Smrg *) 3276b526288Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3286b526288Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3296b526288Smrg 3306b526288Smrg if (umask $mkdir_umask && 3316b526288Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3326b526288Smrg then 3336b526288Smrg if test -z "$dir_arg" || { 3346b526288Smrg # Check for POSIX incompatibilities with -m. 3356b526288Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3366b526288Smrg # other-writable bit of parent directory when it shouldn't. 3376b526288Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3386b526288Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3396b526288Smrg case $ls_ld_tmpdir in 3406b526288Smrg d????-?r-*) different_mode=700;; 3416b526288Smrg d????-?--*) different_mode=755;; 3426b526288Smrg *) false;; 3436b526288Smrg esac && 3446b526288Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3456b526288Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3466b526288Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3476b526288Smrg } 3486b526288Smrg } 3496b526288Smrg then posix_mkdir=: 3506b526288Smrg fi 3516b526288Smrg rmdir "$tmpdir/d" "$tmpdir" 3526b526288Smrg else 3536b526288Smrg # Remove any dirs left behind by ancient mkdir implementations. 3546b526288Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3556b526288Smrg fi 3566b526288Smrg trap '' 0;; 3576b526288Smrg esac;; 35811245024Smrg esac 35941b2f0bdSmrg 36011245024Smrg if 36111245024Smrg $posix_mkdir && ( 3626b526288Smrg umask $mkdir_umask && 3636b526288Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 36411245024Smrg ) 36511245024Smrg then : 36611245024Smrg else 36741b2f0bdSmrg 36811245024Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 36911245024Smrg # or it failed possibly due to a race condition. Create the 37011245024Smrg # directory the slow way, step by step, checking for races as we go. 37141b2f0bdSmrg 37211245024Smrg case $dstdir in 3736b526288Smrg /*) prefix='/';; 3746b526288Smrg [-=\(\)!]*) prefix='./';; 3756b526288Smrg *) prefix='';; 37611245024Smrg esac 37741b2f0bdSmrg 37811245024Smrg oIFS=$IFS 37911245024Smrg IFS=/ 3806b526288Smrg set -f 38111245024Smrg set fnord $dstdir 38241b2f0bdSmrg shift 3836b526288Smrg set +f 38411245024Smrg IFS=$oIFS 38511245024Smrg 38611245024Smrg prefixes= 38711245024Smrg 38811245024Smrg for d 38911245024Smrg do 3906b526288Smrg test X"$d" = X && continue 3916b526288Smrg 3926b526288Smrg prefix=$prefix$d 3936b526288Smrg if test -d "$prefix"; then 3946b526288Smrg prefixes= 3956b526288Smrg else 3966b526288Smrg if $posix_mkdir; then 3976b526288Smrg (umask=$mkdir_umask && 3986b526288Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 3996b526288Smrg # Don't fail if two instances are running concurrently. 4006b526288Smrg test -d "$prefix" || exit 1 4016b526288Smrg else 4026b526288Smrg case $prefix in 4036b526288Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4046b526288Smrg *) qprefix=$prefix;; 4056b526288Smrg esac 4066b526288Smrg prefixes="$prefixes '$qprefix'" 4076b526288Smrg fi 4086b526288Smrg fi 4096b526288Smrg prefix=$prefix/ 41011245024Smrg done 41111245024Smrg 41211245024Smrg if test -n "$prefixes"; then 4136b526288Smrg # Don't fail if two instances are running concurrently. 4146b526288Smrg (umask $mkdir_umask && 4156b526288Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4166b526288Smrg test -d "$dstdir" || exit 1 4176b526288Smrg obsolete_mkdir_used=true 41841b2f0bdSmrg fi 41911245024Smrg fi 42041b2f0bdSmrg fi 42141b2f0bdSmrg 42241b2f0bdSmrg if test -n "$dir_arg"; then 42311245024Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 42411245024Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 42511245024Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 42611245024Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 42741b2f0bdSmrg else 42841b2f0bdSmrg 42941b2f0bdSmrg # Make a couple of temp file names in the proper directory. 43041b2f0bdSmrg dsttmp=$dstdir/_inst.$$_ 43141b2f0bdSmrg rmtmp=$dstdir/_rm.$$_ 43241b2f0bdSmrg 43341b2f0bdSmrg # Trap to clean up those temp files at exit. 43441b2f0bdSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 43541b2f0bdSmrg 43641b2f0bdSmrg # Copy the file name to the temp name. 43711245024Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 43841b2f0bdSmrg 43941b2f0bdSmrg # and set any options; do chmod last to preserve setuid bits. 44041b2f0bdSmrg # 44141b2f0bdSmrg # If any of these fail, we abort the whole thing. If we want to 44241b2f0bdSmrg # ignore errors from any of these, just make sure not to ignore 44341b2f0bdSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 44441b2f0bdSmrg # 44511245024Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 44611245024Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 44711245024Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 44811245024Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 44911245024Smrg 45011245024Smrg # If -C, don't bother to copy if it wouldn't change the file. 45111245024Smrg if $copy_on_change && 4526b526288Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4536b526288Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4546b526288Smrg set -f && 45511245024Smrg set X $old && old=:$2:$4:$5:$6 && 45611245024Smrg set X $new && new=:$2:$4:$5:$6 && 4576b526288Smrg set +f && 45811245024Smrg test "$old" = "$new" && 45911245024Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 46011245024Smrg then 46111245024Smrg rm -f "$dsttmp" 46211245024Smrg else 46311245024Smrg # Rename the file to the real destination. 46411245024Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 46511245024Smrg 46611245024Smrg # The rename failed, perhaps because mv can't rename something else 46711245024Smrg # to itself, or perhaps because mv is so ancient that it does not 46811245024Smrg # support -f. 46911245024Smrg { 4706b526288Smrg # Now remove or move aside any old file at destination location. 4716b526288Smrg # We try this two ways since rm can't unlink itself on some 4726b526288Smrg # systems and the destination file might be busy for other 4736b526288Smrg # reasons. In this case, the final cleanup might fail but the new 4746b526288Smrg # file should still install successfully. 4756b526288Smrg { 4766b526288Smrg test ! -f "$dst" || 4776b526288Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4786b526288Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4796b526288Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4806b526288Smrg } || 4816b526288Smrg { echo "$0: cannot unlink or rename $dst" >&2 4826b526288Smrg (exit 1); exit 1 4836b526288Smrg } 4846b526288Smrg } && 4856b526288Smrg 4866b526288Smrg # Now rename the file to the real destination. 4876b526288Smrg $doit $mvcmd "$dsttmp" "$dst" 48811245024Smrg } 48911245024Smrg fi || exit 1 49011245024Smrg 49111245024Smrg trap '' 0 49211245024Smrg fi 49341b2f0bdSmrgdone 49441b2f0bdSmrg 49541b2f0bdSmrg# Local variables: 49641b2f0bdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 49741b2f0bdSmrg# time-stamp-start: "scriptversion=" 49841b2f0bdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 4996b526288Smrg# time-stamp-time-zone: "UTC0" 50011245024Smrg# time-stamp-end: "; # UTC" 50141b2f0bdSmrg# End: 502