install-sh revision 1b983734
11a30de1fSmrg#!/bin/sh 21a30de1fSmrg# install - install a program, script, or datafile 31a30de1fSmrg 41b983734Smrgscriptversion=2013-12-25.23; # UTC 51a30de1fSmrg 61a30de1fSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71a30de1fSmrg# later released in X11R6 (xc/config/util/install.sh) with the 81a30de1fSmrg# following copyright and license. 91a30de1fSmrg# 101a30de1fSmrg# Copyright (C) 1994 X Consortium 111a30de1fSmrg# 121a30de1fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131a30de1fSmrg# of this software and associated documentation files (the "Software"), to 141a30de1fSmrg# deal in the Software without restriction, including without limitation the 151a30de1fSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161a30de1fSmrg# sell copies of the Software, and to permit persons to whom the Software is 171a30de1fSmrg# furnished to do so, subject to the following conditions: 181a30de1fSmrg# 191a30de1fSmrg# The above copyright notice and this permission notice shall be included in 201a30de1fSmrg# all copies or substantial portions of the Software. 211a30de1fSmrg# 221a30de1fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231a30de1fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241a30de1fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251a30de1fSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261a30de1fSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271a30de1fSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281a30de1fSmrg# 291a30de1fSmrg# Except as contained in this notice, the name of the X Consortium shall not 301a30de1fSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 311a30de1fSmrg# ings in this Software without prior written authorization from the X Consor- 321a30de1fSmrg# tium. 331a30de1fSmrg# 341a30de1fSmrg# 351a30de1fSmrg# FSF changes to this file are in the public domain. 361a30de1fSmrg# 371a30de1fSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38a733a5bfSmrg# 'make' implicit rules from creating a file called install from it 391a30de1fSmrg# when there is no Makefile. 401a30de1fSmrg# 411a30de1fSmrg# This script is compatible with the BSD install script, but was written 421a30de1fSmrg# from scratch. 431a30de1fSmrg 441b983734Smrgtab=' ' 451a30de1fSmrgnl=' 461a30de1fSmrg' 471b983734SmrgIFS=" $tab$nl" 481a30de1fSmrg 491b983734Smrg# Set DOITPROG to "echo" to test this script. 501a30de1fSmrg 51b7fb5eacSmrgdoit=${DOITPROG-} 521b983734Smrgdoit_exec=${doit:-exec} 531a30de1fSmrg 541a30de1fSmrg# Put in absolute file names if you don't have them in your path; 551a30de1fSmrg# or use environment vars. 561a30de1fSmrg 57b7fb5eacSmrgchgrpprog=${CHGRPPROG-chgrp} 58b7fb5eacSmrgchmodprog=${CHMODPROG-chmod} 59b7fb5eacSmrgchownprog=${CHOWNPROG-chown} 60b7fb5eacSmrgcmpprog=${CMPPROG-cmp} 61b7fb5eacSmrgcpprog=${CPPROG-cp} 62b7fb5eacSmrgmkdirprog=${MKDIRPROG-mkdir} 63b7fb5eacSmrgmvprog=${MVPROG-mv} 64b7fb5eacSmrgrmprog=${RMPROG-rm} 65b7fb5eacSmrgstripprog=${STRIPPROG-strip} 66b7fb5eacSmrg 671a30de1fSmrgposix_mkdir= 681a30de1fSmrg 691a30de1fSmrg# Desired mode of installed file. 701a30de1fSmrgmode=0755 711a30de1fSmrg 72b7fb5eacSmrgchgrpcmd= 731a30de1fSmrgchmodcmd=$chmodprog 741a30de1fSmrgchowncmd= 75b7fb5eacSmrgmvcmd=$mvprog 761a30de1fSmrgrmcmd="$rmprog -f" 77b7fb5eacSmrgstripcmd= 78b7fb5eacSmrg 791a30de1fSmrgsrc= 801a30de1fSmrgdst= 811a30de1fSmrgdir_arg= 82b7fb5eacSmrgdst_arg= 83b7fb5eacSmrg 84b7fb5eacSmrgcopy_on_change=false 851b983734Smrgis_target_a_directory=possibly 861a30de1fSmrg 87b7fb5eacSmrgusage="\ 88b7fb5eacSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 891a30de1fSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 901a30de1fSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 911a30de1fSmrg or: $0 [OPTION]... -d DIRECTORIES... 921a30de1fSmrg 931a30de1fSmrgIn the 1st form, copy SRCFILE to DSTFILE. 941a30de1fSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 951a30de1fSmrgIn the 4th, create DIRECTORIES. 961a30de1fSmrg 971a30de1fSmrgOptions: 98b7fb5eacSmrg --help display this help and exit. 99b7fb5eacSmrg --version display version info and exit. 100b7fb5eacSmrg 101b7fb5eacSmrg -c (ignored) 102b7fb5eacSmrg -C install only if different (preserve the last data modification time) 103b7fb5eacSmrg -d create directories instead of installing files. 104b7fb5eacSmrg -g GROUP $chgrpprog installed files to GROUP. 105b7fb5eacSmrg -m MODE $chmodprog installed files to MODE. 106b7fb5eacSmrg -o USER $chownprog installed files to USER. 107b7fb5eacSmrg -s $stripprog installed files. 108b7fb5eacSmrg -t DIRECTORY install into DIRECTORY. 109b7fb5eacSmrg -T report an error if DSTFILE is a directory. 1101a30de1fSmrg 1111a30de1fSmrgEnvironment variables override the default commands: 112b7fb5eacSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 113b7fb5eacSmrg RMPROG STRIPPROG 1141a30de1fSmrg" 1151a30de1fSmrg 1161a30de1fSmrgwhile test $# -ne 0; do 1171a30de1fSmrg case $1 in 118b7fb5eacSmrg -c) ;; 119b7fb5eacSmrg 120b7fb5eacSmrg -C) copy_on_change=true;; 1211a30de1fSmrg 122b7fb5eacSmrg -d) dir_arg=true;; 1231a30de1fSmrg 1241a30de1fSmrg -g) chgrpcmd="$chgrpprog $2" 1251b983734Smrg shift;; 1261a30de1fSmrg 1271a30de1fSmrg --help) echo "$usage"; exit $?;; 1281a30de1fSmrg 1291a30de1fSmrg -m) mode=$2 1301b983734Smrg case $mode in 1311b983734Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1321b983734Smrg echo "$0: invalid mode: $mode" >&2 1331b983734Smrg exit 1;; 1341b983734Smrg esac 1351b983734Smrg shift;; 1361a30de1fSmrg 1371a30de1fSmrg -o) chowncmd="$chownprog $2" 1381b983734Smrg shift;; 1391a30de1fSmrg 140b7fb5eacSmrg -s) stripcmd=$stripprog;; 1411a30de1fSmrg 1421b983734Smrg -t) 1431b983734Smrg is_target_a_directory=always 1441b983734Smrg dst_arg=$2 1451b983734Smrg # Protect names problematic for 'test' and other utilities. 1461b983734Smrg case $dst_arg in 1471b983734Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1481b983734Smrg esac 1491b983734Smrg shift;; 1501a30de1fSmrg 1511b983734Smrg -T) is_target_a_directory=never;; 1521a30de1fSmrg 1531a30de1fSmrg --version) echo "$0 $scriptversion"; exit $?;; 1541a30de1fSmrg 1551b983734Smrg --) shift 1561b983734Smrg break;; 1571a30de1fSmrg 1581b983734Smrg -*) echo "$0: invalid option: $1" >&2 1591b983734Smrg exit 1;; 1601a30de1fSmrg 1611a30de1fSmrg *) break;; 1621a30de1fSmrg esac 163b7fb5eacSmrg shift 1641a30de1fSmrgdone 1651a30de1fSmrg 1661b983734Smrg# We allow the use of options -d and -T together, by making -d 1671b983734Smrg# take the precedence; this is for compatibility with GNU install. 1681b983734Smrg 1691b983734Smrgif test -n "$dir_arg"; then 1701b983734Smrg if test -n "$dst_arg"; then 1711b983734Smrg echo "$0: target directory not allowed when installing a directory." >&2 1721b983734Smrg exit 1 1731b983734Smrg fi 1741b983734Smrgfi 1751b983734Smrg 176b7fb5eacSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1771a30de1fSmrg # When -d is used, all remaining arguments are directories to create. 1781a30de1fSmrg # When -t is used, the destination is already specified. 1791a30de1fSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1801a30de1fSmrg for arg 1811a30de1fSmrg do 182b7fb5eacSmrg if test -n "$dst_arg"; then 1831a30de1fSmrg # $@ is not empty: it contains at least $arg. 184b7fb5eacSmrg set fnord "$@" "$dst_arg" 1851a30de1fSmrg shift # fnord 1861a30de1fSmrg fi 1871a30de1fSmrg shift # arg 188b7fb5eacSmrg dst_arg=$arg 189a733a5bfSmrg # Protect names problematic for 'test' and other utilities. 190a733a5bfSmrg case $dst_arg in 191a733a5bfSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 192a733a5bfSmrg esac 1931a30de1fSmrg done 1941a30de1fSmrgfi 1951a30de1fSmrg 1961a30de1fSmrgif test $# -eq 0; then 1971a30de1fSmrg if test -z "$dir_arg"; then 1981a30de1fSmrg echo "$0: no input file specified." >&2 1991a30de1fSmrg exit 1 2001a30de1fSmrg fi 201a733a5bfSmrg # It's OK to call 'install-sh -d' without argument. 2021a30de1fSmrg # This can happen when creating conditional directories. 2031a30de1fSmrg exit 0 2041a30de1fSmrgfi 2051a30de1fSmrg 2061b983734Smrgif test -z "$dir_arg"; then 2071b983734Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2081b983734Smrg if test ! -d "$dst_arg"; then 2091b983734Smrg echo "$0: $dst_arg: Is not a directory." >&2 2101b983734Smrg exit 1 2111b983734Smrg fi 2121b983734Smrg fi 2131b983734Smrgfi 2141b983734Smrg 2151a30de1fSmrgif test -z "$dir_arg"; then 216a733a5bfSmrg do_exit='(exit $ret); exit $ret' 217a733a5bfSmrg trap "ret=129; $do_exit" 1 218a733a5bfSmrg trap "ret=130; $do_exit" 2 219a733a5bfSmrg trap "ret=141; $do_exit" 13 220a733a5bfSmrg trap "ret=143; $do_exit" 15 2211a30de1fSmrg 2221a30de1fSmrg # Set umask so as not to create temps with too-generous modes. 2231a30de1fSmrg # However, 'strip' requires both read and write access to temps. 2241a30de1fSmrg case $mode in 2251a30de1fSmrg # Optimize common cases. 2261a30de1fSmrg *644) cp_umask=133;; 2271a30de1fSmrg *755) cp_umask=22;; 2281a30de1fSmrg 2291a30de1fSmrg *[0-7]) 2301a30de1fSmrg if test -z "$stripcmd"; then 2311b983734Smrg u_plus_rw= 2321a30de1fSmrg else 2331b983734Smrg u_plus_rw='% 200' 2341a30de1fSmrg fi 2351a30de1fSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2361a30de1fSmrg *) 2371a30de1fSmrg if test -z "$stripcmd"; then 2381b983734Smrg u_plus_rw= 2391a30de1fSmrg else 2401b983734Smrg u_plus_rw=,u+rw 2411a30de1fSmrg fi 2421a30de1fSmrg cp_umask=$mode$u_plus_rw;; 2431a30de1fSmrg esac 2441a30de1fSmrgfi 2451a30de1fSmrg 2461a30de1fSmrgfor src 2471a30de1fSmrgdo 248a733a5bfSmrg # Protect names problematic for 'test' and other utilities. 2491a30de1fSmrg case $src in 250a733a5bfSmrg -* | [=\(\)!]) src=./$src;; 2511a30de1fSmrg esac 2521a30de1fSmrg 2531a30de1fSmrg if test -n "$dir_arg"; then 2541a30de1fSmrg dst=$src 2551a30de1fSmrg dstdir=$dst 2561a30de1fSmrg test -d "$dstdir" 2571a30de1fSmrg dstdir_status=$? 2581a30de1fSmrg else 2591a30de1fSmrg 2601a30de1fSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2611a30de1fSmrg # might cause directories to be created, which would be especially bad 2621a30de1fSmrg # if $src (and thus $dsttmp) contains '*'. 2631a30de1fSmrg if test ! -f "$src" && test ! -d "$src"; then 2641a30de1fSmrg echo "$0: $src does not exist." >&2 2651a30de1fSmrg exit 1 2661a30de1fSmrg fi 2671a30de1fSmrg 268b7fb5eacSmrg if test -z "$dst_arg"; then 2691a30de1fSmrg echo "$0: no destination specified." >&2 2701a30de1fSmrg exit 1 2711a30de1fSmrg fi 272b7fb5eacSmrg dst=$dst_arg 2731a30de1fSmrg 2741a30de1fSmrg # If destination is a directory, append the input filename; won't work 2751a30de1fSmrg # if double slashes aren't ignored. 2761a30de1fSmrg if test -d "$dst"; then 2771b983734Smrg if test "$is_target_a_directory" = never; then 2781b983734Smrg echo "$0: $dst_arg: Is a directory" >&2 2791b983734Smrg exit 1 2801a30de1fSmrg fi 2811a30de1fSmrg dstdir=$dst 2821a30de1fSmrg dst=$dstdir/`basename "$src"` 2831a30de1fSmrg dstdir_status=0 2841a30de1fSmrg else 2851b983734Smrg dstdir=`dirname "$dst"` 2861a30de1fSmrg test -d "$dstdir" 2871a30de1fSmrg dstdir_status=$? 2881a30de1fSmrg fi 2891a30de1fSmrg fi 2901a30de1fSmrg 2911a30de1fSmrg obsolete_mkdir_used=false 2921a30de1fSmrg 2931a30de1fSmrg if test $dstdir_status != 0; then 2941a30de1fSmrg case $posix_mkdir in 2951a30de1fSmrg '') 2961b983734Smrg # Create intermediate dirs using mode 755 as modified by the umask. 2971b983734Smrg # This is like FreeBSD 'install' as of 1997-10-28. 2981b983734Smrg umask=`umask` 2991b983734Smrg case $stripcmd.$umask in 3001b983734Smrg # Optimize common cases. 3011b983734Smrg *[2367][2367]) mkdir_umask=$umask;; 3021b983734Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3031b983734Smrg 3041b983734Smrg *[0-7]) 3051b983734Smrg mkdir_umask=`expr $umask + 22 \ 3061b983734Smrg - $umask % 100 % 40 + $umask % 20 \ 3071b983734Smrg - $umask % 10 % 4 + $umask % 2 3081b983734Smrg `;; 3091b983734Smrg *) mkdir_umask=$umask,go-w;; 3101b983734Smrg esac 3111b983734Smrg 3121b983734Smrg # With -d, create the new directory with the user-specified mode. 3131b983734Smrg # Otherwise, rely on $mkdir_umask. 3141b983734Smrg if test -n "$dir_arg"; then 3151b983734Smrg mkdir_mode=-m$mode 3161b983734Smrg else 3171b983734Smrg mkdir_mode= 3181b983734Smrg fi 3191b983734Smrg 3201b983734Smrg posix_mkdir=false 3211b983734Smrg case $umask in 3221b983734Smrg *[123567][0-7][0-7]) 3231b983734Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3241b983734Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3251b983734Smrg ;; 3261b983734Smrg *) 3271b983734Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3281b983734Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3291b983734Smrg 3301b983734Smrg if (umask $mkdir_umask && 3311b983734Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3321b983734Smrg then 3331b983734Smrg if test -z "$dir_arg" || { 3341b983734Smrg # Check for POSIX incompatibilities with -m. 3351b983734Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3361b983734Smrg # other-writable bit of parent directory when it shouldn't. 3371b983734Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3381b983734Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3391b983734Smrg case $ls_ld_tmpdir in 3401b983734Smrg d????-?r-*) different_mode=700;; 3411b983734Smrg d????-?--*) different_mode=755;; 3421b983734Smrg *) false;; 3431b983734Smrg esac && 3441b983734Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3451b983734Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3461b983734Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3471b983734Smrg } 3481b983734Smrg } 3491b983734Smrg then posix_mkdir=: 3501b983734Smrg fi 3511b983734Smrg rmdir "$tmpdir/d" "$tmpdir" 3521b983734Smrg else 3531b983734Smrg # Remove any dirs left behind by ancient mkdir implementations. 3541b983734Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3551b983734Smrg fi 3561b983734Smrg trap '' 0;; 3571b983734Smrg esac;; 3581a30de1fSmrg esac 3591a30de1fSmrg 3601a30de1fSmrg if 3611a30de1fSmrg $posix_mkdir && ( 3621b983734Smrg umask $mkdir_umask && 3631b983734Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3641a30de1fSmrg ) 3651a30de1fSmrg then : 3661a30de1fSmrg else 3671a30de1fSmrg 3681a30de1fSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3691a30de1fSmrg # or it failed possibly due to a race condition. Create the 3701a30de1fSmrg # directory the slow way, step by step, checking for races as we go. 3711a30de1fSmrg 3721a30de1fSmrg case $dstdir in 3731b983734Smrg /*) prefix='/';; 3741b983734Smrg [-=\(\)!]*) prefix='./';; 3751b983734Smrg *) prefix='';; 3761a30de1fSmrg esac 3771a30de1fSmrg 3781a30de1fSmrg oIFS=$IFS 3791a30de1fSmrg IFS=/ 3801b983734Smrg set -f 3811a30de1fSmrg set fnord $dstdir 3821a30de1fSmrg shift 3831b983734Smrg set +f 3841a30de1fSmrg IFS=$oIFS 3851a30de1fSmrg 3861a30de1fSmrg prefixes= 3871a30de1fSmrg 3881a30de1fSmrg for d 3891a30de1fSmrg do 3901b983734Smrg test X"$d" = X && continue 3911b983734Smrg 3921b983734Smrg prefix=$prefix$d 3931b983734Smrg if test -d "$prefix"; then 3941b983734Smrg prefixes= 3951b983734Smrg else 3961b983734Smrg if $posix_mkdir; then 3971b983734Smrg (umask=$mkdir_umask && 3981b983734Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 3991b983734Smrg # Don't fail if two instances are running concurrently. 4001b983734Smrg test -d "$prefix" || exit 1 4011b983734Smrg else 4021b983734Smrg case $prefix in 4031b983734Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4041b983734Smrg *) qprefix=$prefix;; 4051b983734Smrg esac 4061b983734Smrg prefixes="$prefixes '$qprefix'" 4071b983734Smrg fi 4081b983734Smrg fi 4091b983734Smrg prefix=$prefix/ 4101a30de1fSmrg done 4111a30de1fSmrg 4121a30de1fSmrg if test -n "$prefixes"; then 4131b983734Smrg # Don't fail if two instances are running concurrently. 4141b983734Smrg (umask $mkdir_umask && 4151b983734Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4161b983734Smrg test -d "$dstdir" || exit 1 4171b983734Smrg obsolete_mkdir_used=true 4181a30de1fSmrg fi 4191a30de1fSmrg fi 4201a30de1fSmrg fi 4211a30de1fSmrg 4221a30de1fSmrg if test -n "$dir_arg"; then 4231a30de1fSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4241a30de1fSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4251a30de1fSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4261a30de1fSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4271a30de1fSmrg else 4281a30de1fSmrg 4291a30de1fSmrg # Make a couple of temp file names in the proper directory. 4301a30de1fSmrg dsttmp=$dstdir/_inst.$$_ 4311a30de1fSmrg rmtmp=$dstdir/_rm.$$_ 4321a30de1fSmrg 4331a30de1fSmrg # Trap to clean up those temp files at exit. 4341a30de1fSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4351a30de1fSmrg 4361a30de1fSmrg # Copy the file name to the temp name. 4371a30de1fSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4381a30de1fSmrg 4391a30de1fSmrg # and set any options; do chmod last to preserve setuid bits. 4401a30de1fSmrg # 4411a30de1fSmrg # If any of these fail, we abort the whole thing. If we want to 4421a30de1fSmrg # ignore errors from any of these, just make sure not to ignore 4431a30de1fSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4441a30de1fSmrg # 445b7fb5eacSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 446b7fb5eacSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 447b7fb5eacSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 448b7fb5eacSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 449b7fb5eacSmrg 450b7fb5eacSmrg # If -C, don't bother to copy if it wouldn't change the file. 451b7fb5eacSmrg if $copy_on_change && 4521b983734Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4531b983734Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4541b983734Smrg set -f && 455b7fb5eacSmrg set X $old && old=:$2:$4:$5:$6 && 456b7fb5eacSmrg set X $new && new=:$2:$4:$5:$6 && 4571b983734Smrg set +f && 458b7fb5eacSmrg test "$old" = "$new" && 459b7fb5eacSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 460b7fb5eacSmrg then 461b7fb5eacSmrg rm -f "$dsttmp" 462b7fb5eacSmrg else 463b7fb5eacSmrg # Rename the file to the real destination. 464b7fb5eacSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 465b7fb5eacSmrg 466b7fb5eacSmrg # The rename failed, perhaps because mv can't rename something else 467b7fb5eacSmrg # to itself, or perhaps because mv is so ancient that it does not 468b7fb5eacSmrg # support -f. 469b7fb5eacSmrg { 4701b983734Smrg # Now remove or move aside any old file at destination location. 4711b983734Smrg # We try this two ways since rm can't unlink itself on some 4721b983734Smrg # systems and the destination file might be busy for other 4731b983734Smrg # reasons. In this case, the final cleanup might fail but the new 4741b983734Smrg # file should still install successfully. 4751b983734Smrg { 4761b983734Smrg test ! -f "$dst" || 4771b983734Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4781b983734Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4791b983734Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4801b983734Smrg } || 4811b983734Smrg { echo "$0: cannot unlink or rename $dst" >&2 4821b983734Smrg (exit 1); exit 1 4831b983734Smrg } 4841b983734Smrg } && 4851b983734Smrg 4861b983734Smrg # Now rename the file to the real destination. 4871b983734Smrg $doit $mvcmd "$dsttmp" "$dst" 488b7fb5eacSmrg } 489b7fb5eacSmrg fi || exit 1 4901a30de1fSmrg 4911a30de1fSmrg trap '' 0 4921a30de1fSmrg fi 4931a30de1fSmrgdone 4941a30de1fSmrg 4951a30de1fSmrg# Local variables: 4961a30de1fSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 4971a30de1fSmrg# time-stamp-start: "scriptversion=" 4981a30de1fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 499b7fb5eacSmrg# time-stamp-time-zone: "UTC" 500b7fb5eacSmrg# time-stamp-end: "; # UTC" 5011a30de1fSmrg# End: 502