install-sh revision 6a45684f
1e6232409Smrg#!/bin/sh 2e6232409Smrg# install - install a program, script, or datafile 3e6232409Smrg 46a45684fSmrgscriptversion=2013-12-25.23; # UTC 5e6232409Smrg 6e6232409Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7e6232409Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8e6232409Smrg# following copyright and license. 9e6232409Smrg# 10e6232409Smrg# Copyright (C) 1994 X Consortium 11e6232409Smrg# 12e6232409Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13e6232409Smrg# of this software and associated documentation files (the "Software"), to 14e6232409Smrg# deal in the Software without restriction, including without limitation the 15e6232409Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16e6232409Smrg# sell copies of the Software, and to permit persons to whom the Software is 17e6232409Smrg# furnished to do so, subject to the following conditions: 18e6232409Smrg# 19e6232409Smrg# The above copyright notice and this permission notice shall be included in 20e6232409Smrg# all copies or substantial portions of the Software. 21e6232409Smrg# 22e6232409Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23e6232409Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24e6232409Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25e6232409Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26e6232409Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27e6232409Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28e6232409Smrg# 29e6232409Smrg# Except as contained in this notice, the name of the X Consortium shall not 30e6232409Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31e6232409Smrg# ings in this Software without prior written authorization from the X Consor- 32e6232409Smrg# tium. 33e6232409Smrg# 34e6232409Smrg# 35e6232409Smrg# FSF changes to this file are in the public domain. 36e6232409Smrg# 37e6232409Smrg# Calling this script install-sh is preferred over install.sh, to prevent 386a45684fSmrg# 'make' implicit rules from creating a file called install from it 39e6232409Smrg# when there is no Makefile. 40e6232409Smrg# 41e6232409Smrg# This script is compatible with the BSD install script, but was written 428fff3f40Smrg# from scratch. 438fff3f40Smrg 446a45684fSmrgtab=' ' 458fff3f40Smrgnl=' 468fff3f40Smrg' 476a45684fSmrgIFS=" $tab$nl" 48e6232409Smrg 496a45684fSmrg# Set DOITPROG to "echo" to test this script. 50e6232409Smrg 518fff3f40Smrgdoit=${DOITPROG-} 526a45684fSmrgdoit_exec=${doit:-exec} 53e6232409Smrg 548fff3f40Smrg# Put in absolute file names if you don't have them in your path; 558fff3f40Smrg# or use environment vars. 568fff3f40Smrg 578fff3f40Smrgchgrpprog=${CHGRPPROG-chgrp} 588fff3f40Smrgchmodprog=${CHMODPROG-chmod} 598fff3f40Smrgchownprog=${CHOWNPROG-chown} 608fff3f40Smrgcmpprog=${CMPPROG-cmp} 618fff3f40Smrgcpprog=${CPPROG-cp} 628fff3f40Smrgmkdirprog=${MKDIRPROG-mkdir} 638fff3f40Smrgmvprog=${MVPROG-mv} 648fff3f40Smrgrmprog=${RMPROG-rm} 658fff3f40Smrgstripprog=${STRIPPROG-strip} 668fff3f40Smrg 678fff3f40Smrgposix_mkdir= 688fff3f40Smrg 698fff3f40Smrg# Desired mode of installed file. 708fff3f40Smrgmode=0755 71e6232409Smrg 72e6232409Smrgchgrpcmd= 738fff3f40Smrgchmodcmd=$chmodprog 748fff3f40Smrgchowncmd= 758fff3f40Smrgmvcmd=$mvprog 76e6232409Smrgrmcmd="$rmprog -f" 778fff3f40Smrgstripcmd= 788fff3f40Smrg 79e6232409Smrgsrc= 80e6232409Smrgdst= 81e6232409Smrgdir_arg= 828fff3f40Smrgdst_arg= 838fff3f40Smrg 848fff3f40Smrgcopy_on_change=false 856a45684fSmrgis_target_a_directory=possibly 86e6232409Smrg 878fff3f40Smrgusage="\ 888fff3f40SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 89e6232409Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 90e6232409Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 91e6232409Smrg or: $0 [OPTION]... -d DIRECTORIES... 92e6232409Smrg 93e6232409SmrgIn the 1st form, copy SRCFILE to DSTFILE. 94e6232409SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 95e6232409SmrgIn the 4th, create DIRECTORIES. 96e6232409Smrg 97e6232409SmrgOptions: 988fff3f40Smrg --help display this help and exit. 998fff3f40Smrg --version display version info and exit. 1008fff3f40Smrg 1018fff3f40Smrg -c (ignored) 1028fff3f40Smrg -C install only if different (preserve the last data modification time) 1038fff3f40Smrg -d create directories instead of installing files. 1048fff3f40Smrg -g GROUP $chgrpprog installed files to GROUP. 1058fff3f40Smrg -m MODE $chmodprog installed files to MODE. 1068fff3f40Smrg -o USER $chownprog installed files to USER. 1078fff3f40Smrg -s $stripprog installed files. 1088fff3f40Smrg -t DIRECTORY install into DIRECTORY. 1098fff3f40Smrg -T report an error if DSTFILE is a directory. 110e6232409Smrg 111e6232409SmrgEnvironment variables override the default commands: 1128fff3f40Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1138fff3f40Smrg RMPROG STRIPPROG 114e6232409Smrg" 115e6232409Smrg 1168fff3f40Smrgwhile test $# -ne 0; do 117e6232409Smrg case $1 in 1188fff3f40Smrg -c) ;; 1198fff3f40Smrg 1208fff3f40Smrg -C) copy_on_change=true;; 121e6232409Smrg 1228fff3f40Smrg -d) dir_arg=true;; 123e6232409Smrg 124e6232409Smrg -g) chgrpcmd="$chgrpprog $2" 1256a45684fSmrg shift;; 126e6232409Smrg 127e6232409Smrg --help) echo "$usage"; exit $?;; 128e6232409Smrg 1298fff3f40Smrg -m) mode=$2 1306a45684fSmrg case $mode in 1316a45684fSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1326a45684fSmrg echo "$0: invalid mode: $mode" >&2 1336a45684fSmrg exit 1;; 1346a45684fSmrg esac 1356a45684fSmrg shift;; 136e6232409Smrg 137e6232409Smrg -o) chowncmd="$chownprog $2" 1386a45684fSmrg shift;; 139e6232409Smrg 1408fff3f40Smrg -s) stripcmd=$stripprog;; 141e6232409Smrg 1426a45684fSmrg -t) 1436a45684fSmrg is_target_a_directory=always 1446a45684fSmrg dst_arg=$2 1456a45684fSmrg # Protect names problematic for 'test' and other utilities. 1466a45684fSmrg case $dst_arg in 1476a45684fSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1486a45684fSmrg esac 1496a45684fSmrg shift;; 150e6232409Smrg 1516a45684fSmrg -T) is_target_a_directory=never;; 152e6232409Smrg 153e6232409Smrg --version) echo "$0 $scriptversion"; exit $?;; 154e6232409Smrg 1556a45684fSmrg --) shift 1566a45684fSmrg break;; 1578fff3f40Smrg 1586a45684fSmrg -*) echo "$0: invalid option: $1" >&2 1596a45684fSmrg exit 1;; 1608fff3f40Smrg 1618fff3f40Smrg *) break;; 162e6232409Smrg esac 1638fff3f40Smrg shift 164e6232409Smrgdone 165e6232409Smrg 1666a45684fSmrg# We allow the use of options -d and -T together, by making -d 1676a45684fSmrg# take the precedence; this is for compatibility with GNU install. 1686a45684fSmrg 1696a45684fSmrgif test -n "$dir_arg"; then 1706a45684fSmrg if test -n "$dst_arg"; then 1716a45684fSmrg echo "$0: target directory not allowed when installing a directory." >&2 1726a45684fSmrg exit 1 1736a45684fSmrg fi 1746a45684fSmrgfi 1756a45684fSmrg 1768fff3f40Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1778fff3f40Smrg # When -d is used, all remaining arguments are directories to create. 1788fff3f40Smrg # When -t is used, the destination is already specified. 1798fff3f40Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1808fff3f40Smrg for arg 1818fff3f40Smrg do 1828fff3f40Smrg if test -n "$dst_arg"; then 1838fff3f40Smrg # $@ is not empty: it contains at least $arg. 1848fff3f40Smrg set fnord "$@" "$dst_arg" 1858fff3f40Smrg shift # fnord 1868fff3f40Smrg fi 1878fff3f40Smrg shift # arg 1888fff3f40Smrg dst_arg=$arg 1896a45684fSmrg # Protect names problematic for 'test' and other utilities. 19094a251fdSmrg case $dst_arg in 19194a251fdSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19294a251fdSmrg esac 1938fff3f40Smrg done 1948fff3f40Smrgfi 1958fff3f40Smrg 1968fff3f40Smrgif test $# -eq 0; then 197e6232409Smrg if test -z "$dir_arg"; then 198e6232409Smrg echo "$0: no input file specified." >&2 199e6232409Smrg exit 1 200e6232409Smrg fi 2016a45684fSmrg # It's OK to call 'install-sh -d' without argument. 202e6232409Smrg # This can happen when creating conditional directories. 203e6232409Smrg exit 0 204e6232409Smrgfi 205e6232409Smrg 2066a45684fSmrgif test -z "$dir_arg"; then 2076a45684fSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2086a45684fSmrg if test ! -d "$dst_arg"; then 2096a45684fSmrg echo "$0: $dst_arg: Is not a directory." >&2 2106a45684fSmrg exit 1 2116a45684fSmrg fi 2126a45684fSmrg fi 2136a45684fSmrgfi 2146a45684fSmrg 2158fff3f40Smrgif test -z "$dir_arg"; then 21694a251fdSmrg do_exit='(exit $ret); exit $ret' 21794a251fdSmrg trap "ret=129; $do_exit" 1 21894a251fdSmrg trap "ret=130; $do_exit" 2 21994a251fdSmrg trap "ret=141; $do_exit" 13 22094a251fdSmrg trap "ret=143; $do_exit" 15 2218fff3f40Smrg 2228fff3f40Smrg # Set umask so as not to create temps with too-generous modes. 2238fff3f40Smrg # However, 'strip' requires both read and write access to temps. 2248fff3f40Smrg case $mode in 2258fff3f40Smrg # Optimize common cases. 2268fff3f40Smrg *644) cp_umask=133;; 2278fff3f40Smrg *755) cp_umask=22;; 2288fff3f40Smrg 2298fff3f40Smrg *[0-7]) 2308fff3f40Smrg if test -z "$stripcmd"; then 2316a45684fSmrg u_plus_rw= 2328fff3f40Smrg else 2336a45684fSmrg u_plus_rw='% 200' 2348fff3f40Smrg fi 2358fff3f40Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2368fff3f40Smrg *) 2378fff3f40Smrg if test -z "$stripcmd"; then 2386a45684fSmrg u_plus_rw= 2398fff3f40Smrg else 2406a45684fSmrg u_plus_rw=,u+rw 2418fff3f40Smrg fi 2428fff3f40Smrg cp_umask=$mode$u_plus_rw;; 2438fff3f40Smrg esac 2448fff3f40Smrgfi 2458fff3f40Smrg 246e6232409Smrgfor src 247e6232409Smrgdo 2486a45684fSmrg # Protect names problematic for 'test' and other utilities. 249e6232409Smrg case $src in 25094a251fdSmrg -* | [=\(\)!]) src=./$src;; 251e6232409Smrg esac 252e6232409Smrg 253e6232409Smrg if test -n "$dir_arg"; then 254e6232409Smrg dst=$src 2558fff3f40Smrg dstdir=$dst 2568fff3f40Smrg test -d "$dstdir" 2578fff3f40Smrg dstdir_status=$? 258e6232409Smrg else 2598fff3f40Smrg 260e6232409Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 261e6232409Smrg # might cause directories to be created, which would be especially bad 262e6232409Smrg # if $src (and thus $dsttmp) contains '*'. 263e6232409Smrg if test ! -f "$src" && test ! -d "$src"; then 264e6232409Smrg echo "$0: $src does not exist." >&2 265e6232409Smrg exit 1 266e6232409Smrg fi 267e6232409Smrg 2688fff3f40Smrg if test -z "$dst_arg"; then 269e6232409Smrg echo "$0: no destination specified." >&2 270e6232409Smrg exit 1 271e6232409Smrg fi 2728fff3f40Smrg dst=$dst_arg 273e6232409Smrg 274e6232409Smrg # If destination is a directory, append the input filename; won't work 275e6232409Smrg # if double slashes aren't ignored. 276e6232409Smrg if test -d "$dst"; then 2776a45684fSmrg if test "$is_target_a_directory" = never; then 2786a45684fSmrg echo "$0: $dst_arg: Is a directory" >&2 2796a45684fSmrg exit 1 280e6232409Smrg fi 2818fff3f40Smrg dstdir=$dst 2828fff3f40Smrg dst=$dstdir/`basename "$src"` 2838fff3f40Smrg dstdir_status=0 2848fff3f40Smrg else 2856a45684fSmrg dstdir=`dirname "$dst"` 2868fff3f40Smrg test -d "$dstdir" 2878fff3f40Smrg dstdir_status=$? 288e6232409Smrg fi 289e6232409Smrg fi 290e6232409Smrg 2918fff3f40Smrg obsolete_mkdir_used=false 2928fff3f40Smrg 2938fff3f40Smrg if test $dstdir_status != 0; then 2948fff3f40Smrg case $posix_mkdir in 2958fff3f40Smrg '') 2966a45684fSmrg # Create intermediate dirs using mode 755 as modified by the umask. 2976a45684fSmrg # This is like FreeBSD 'install' as of 1997-10-28. 2986a45684fSmrg umask=`umask` 2996a45684fSmrg case $stripcmd.$umask in 3006a45684fSmrg # Optimize common cases. 3016a45684fSmrg *[2367][2367]) mkdir_umask=$umask;; 3026a45684fSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3036a45684fSmrg 3046a45684fSmrg *[0-7]) 3056a45684fSmrg mkdir_umask=`expr $umask + 22 \ 3066a45684fSmrg - $umask % 100 % 40 + $umask % 20 \ 3076a45684fSmrg - $umask % 10 % 4 + $umask % 2 3086a45684fSmrg `;; 3096a45684fSmrg *) mkdir_umask=$umask,go-w;; 3106a45684fSmrg esac 3116a45684fSmrg 3126a45684fSmrg # With -d, create the new directory with the user-specified mode. 3136a45684fSmrg # Otherwise, rely on $mkdir_umask. 3146a45684fSmrg if test -n "$dir_arg"; then 3156a45684fSmrg mkdir_mode=-m$mode 3166a45684fSmrg else 3176a45684fSmrg mkdir_mode= 3186a45684fSmrg fi 3196a45684fSmrg 3206a45684fSmrg posix_mkdir=false 3216a45684fSmrg case $umask in 3226a45684fSmrg *[123567][0-7][0-7]) 3236a45684fSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3246a45684fSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3256a45684fSmrg ;; 3266a45684fSmrg *) 3276a45684fSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3286a45684fSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3296a45684fSmrg 3306a45684fSmrg if (umask $mkdir_umask && 3316a45684fSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3326a45684fSmrg then 3336a45684fSmrg if test -z "$dir_arg" || { 3346a45684fSmrg # Check for POSIX incompatibilities with -m. 3356a45684fSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3366a45684fSmrg # other-writable bit of parent directory when it shouldn't. 3376a45684fSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3386a45684fSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3396a45684fSmrg case $ls_ld_tmpdir in 3406a45684fSmrg d????-?r-*) different_mode=700;; 3416a45684fSmrg d????-?--*) different_mode=755;; 3426a45684fSmrg *) false;; 3436a45684fSmrg esac && 3446a45684fSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3456a45684fSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3466a45684fSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3476a45684fSmrg } 3486a45684fSmrg } 3496a45684fSmrg then posix_mkdir=: 3506a45684fSmrg fi 3516a45684fSmrg rmdir "$tmpdir/d" "$tmpdir" 3526a45684fSmrg else 3536a45684fSmrg # Remove any dirs left behind by ancient mkdir implementations. 3546a45684fSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3556a45684fSmrg fi 3566a45684fSmrg trap '' 0;; 3576a45684fSmrg esac;; 3588fff3f40Smrg esac 359e6232409Smrg 3608fff3f40Smrg if 3618fff3f40Smrg $posix_mkdir && ( 3626a45684fSmrg umask $mkdir_umask && 3636a45684fSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3648fff3f40Smrg ) 3658fff3f40Smrg then : 3668fff3f40Smrg else 367e6232409Smrg 3688fff3f40Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3698fff3f40Smrg # or it failed possibly due to a race condition. Create the 3708fff3f40Smrg # directory the slow way, step by step, checking for races as we go. 371e6232409Smrg 3728fff3f40Smrg case $dstdir in 3736a45684fSmrg /*) prefix='/';; 3746a45684fSmrg [-=\(\)!]*) prefix='./';; 3756a45684fSmrg *) prefix='';; 3768fff3f40Smrg esac 377e6232409Smrg 3788fff3f40Smrg oIFS=$IFS 3798fff3f40Smrg IFS=/ 3806a45684fSmrg set -f 3818fff3f40Smrg set fnord $dstdir 382e6232409Smrg shift 3836a45684fSmrg set +f 3848fff3f40Smrg IFS=$oIFS 3858fff3f40Smrg 3868fff3f40Smrg prefixes= 3878fff3f40Smrg 3888fff3f40Smrg for d 3898fff3f40Smrg do 3906a45684fSmrg test X"$d" = X && continue 3916a45684fSmrg 3926a45684fSmrg prefix=$prefix$d 3936a45684fSmrg if test -d "$prefix"; then 3946a45684fSmrg prefixes= 3956a45684fSmrg else 3966a45684fSmrg if $posix_mkdir; then 3976a45684fSmrg (umask=$mkdir_umask && 3986a45684fSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 3996a45684fSmrg # Don't fail if two instances are running concurrently. 4006a45684fSmrg test -d "$prefix" || exit 1 4016a45684fSmrg else 4026a45684fSmrg case $prefix in 4036a45684fSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4046a45684fSmrg *) qprefix=$prefix;; 4056a45684fSmrg esac 4066a45684fSmrg prefixes="$prefixes '$qprefix'" 4076a45684fSmrg fi 4086a45684fSmrg fi 4096a45684fSmrg prefix=$prefix/ 4108fff3f40Smrg done 4118fff3f40Smrg 4128fff3f40Smrg if test -n "$prefixes"; then 4136a45684fSmrg # Don't fail if two instances are running concurrently. 4146a45684fSmrg (umask $mkdir_umask && 4156a45684fSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4166a45684fSmrg test -d "$dstdir" || exit 1 4176a45684fSmrg obsolete_mkdir_used=true 418e6232409Smrg fi 4198fff3f40Smrg fi 420e6232409Smrg fi 421e6232409Smrg 422e6232409Smrg if test -n "$dir_arg"; then 4238fff3f40Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4248fff3f40Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4258fff3f40Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4268fff3f40Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 427e6232409Smrg else 428e6232409Smrg 429e6232409Smrg # Make a couple of temp file names in the proper directory. 430e6232409Smrg dsttmp=$dstdir/_inst.$$_ 431e6232409Smrg rmtmp=$dstdir/_rm.$$_ 432e6232409Smrg 433e6232409Smrg # Trap to clean up those temp files at exit. 434e6232409Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 435e6232409Smrg 436e6232409Smrg # Copy the file name to the temp name. 4378fff3f40Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 438e6232409Smrg 439e6232409Smrg # and set any options; do chmod last to preserve setuid bits. 440e6232409Smrg # 441e6232409Smrg # If any of these fail, we abort the whole thing. If we want to 442e6232409Smrg # ignore errors from any of these, just make sure not to ignore 443e6232409Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 444e6232409Smrg # 4458fff3f40Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4468fff3f40Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4478fff3f40Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4488fff3f40Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4498fff3f40Smrg 4508fff3f40Smrg # If -C, don't bother to copy if it wouldn't change the file. 4518fff3f40Smrg if $copy_on_change && 4526a45684fSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4536a45684fSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4546a45684fSmrg set -f && 4558fff3f40Smrg set X $old && old=:$2:$4:$5:$6 && 4568fff3f40Smrg set X $new && new=:$2:$4:$5:$6 && 4576a45684fSmrg set +f && 4588fff3f40Smrg test "$old" = "$new" && 4598fff3f40Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4608fff3f40Smrg then 4618fff3f40Smrg rm -f "$dsttmp" 4628fff3f40Smrg else 4638fff3f40Smrg # Rename the file to the real destination. 4648fff3f40Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4658fff3f40Smrg 4668fff3f40Smrg # The rename failed, perhaps because mv can't rename something else 4678fff3f40Smrg # to itself, or perhaps because mv is so ancient that it does not 4688fff3f40Smrg # support -f. 4698fff3f40Smrg { 4706a45684fSmrg # Now remove or move aside any old file at destination location. 4716a45684fSmrg # We try this two ways since rm can't unlink itself on some 4726a45684fSmrg # systems and the destination file might be busy for other 4736a45684fSmrg # reasons. In this case, the final cleanup might fail but the new 4746a45684fSmrg # file should still install successfully. 4756a45684fSmrg { 4766a45684fSmrg test ! -f "$dst" || 4776a45684fSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 4786a45684fSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4796a45684fSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4806a45684fSmrg } || 4816a45684fSmrg { echo "$0: cannot unlink or rename $dst" >&2 4826a45684fSmrg (exit 1); exit 1 4836a45684fSmrg } 4846a45684fSmrg } && 4856a45684fSmrg 4866a45684fSmrg # Now rename the file to the real destination. 4876a45684fSmrg $doit $mvcmd "$dsttmp" "$dst" 4888fff3f40Smrg } 4898fff3f40Smrg fi || exit 1 4908fff3f40Smrg 4918fff3f40Smrg trap '' 0 4928fff3f40Smrg fi 493e6232409Smrgdone 494e6232409Smrg 495e6232409Smrg# Local variables: 496e6232409Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 497e6232409Smrg# time-stamp-start: "scriptversion=" 498e6232409Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 4998fff3f40Smrg# time-stamp-time-zone: "UTC" 5008fff3f40Smrg# time-stamp-end: "; # UTC" 501e6232409Smrg# End: 502