install-sh revision a39bb051
1c19de146Smrg#!/bin/sh 2c19de146Smrg# install - install a program, script, or datafile 39ef7378bSmrg 4a39bb051Smrgscriptversion=2013-12-25.23; # UTC 59ef7378bSmrg 6c19de146Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7c19de146Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8c19de146Smrg# following copyright and license. 9c19de146Smrg# 10c19de146Smrg# Copyright (C) 1994 X Consortium 11c19de146Smrg# 12c19de146Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13c19de146Smrg# of this software and associated documentation files (the "Software"), to 14c19de146Smrg# deal in the Software without restriction, including without limitation the 15c19de146Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16c19de146Smrg# sell copies of the Software, and to permit persons to whom the Software is 17c19de146Smrg# furnished to do so, subject to the following conditions: 18c19de146Smrg# 19c19de146Smrg# The above copyright notice and this permission notice shall be included in 20c19de146Smrg# all copies or substantial portions of the Software. 21c19de146Smrg# 22c19de146Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23c19de146Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24c19de146Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25c19de146Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26c19de146Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27c19de146Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28c19de146Smrg# 29c19de146Smrg# Except as contained in this notice, the name of the X Consortium shall not 30c19de146Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31c19de146Smrg# ings in this Software without prior written authorization from the X Consor- 32c19de146Smrg# tium. 33c19de146Smrg# 34c19de146Smrg# 35c19de146Smrg# FSF changes to this file are in the public domain. 36c19de146Smrg# 37c19de146Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38a39bb051Smrg# 'make' implicit rules from creating a file called install from it 39c19de146Smrg# when there is no Makefile. 40c19de146Smrg# 41c19de146Smrg# This script is compatible with the BSD install script, but was written 429ef7378bSmrg# from scratch. 43c19de146Smrg 44a39bb051Smrgtab=' ' 459ef7378bSmrgnl=' 469ef7378bSmrg' 47a39bb051SmrgIFS=" $tab$nl" 48c19de146Smrg 49a39bb051Smrg# Set DOITPROG to "echo" to test this script. 50c19de146Smrg 519ef7378bSmrgdoit=${DOITPROG-} 52a39bb051Smrgdoit_exec=${doit:-exec} 53c19de146Smrg 549ef7378bSmrg# Put in absolute file names if you don't have them in your path; 559ef7378bSmrg# or use environment vars. 569ef7378bSmrg 579ef7378bSmrgchgrpprog=${CHGRPPROG-chgrp} 589ef7378bSmrgchmodprog=${CHMODPROG-chmod} 599ef7378bSmrgchownprog=${CHOWNPROG-chown} 609ef7378bSmrgcmpprog=${CMPPROG-cmp} 619ef7378bSmrgcpprog=${CPPROG-cp} 629ef7378bSmrgmkdirprog=${MKDIRPROG-mkdir} 639ef7378bSmrgmvprog=${MVPROG-mv} 649ef7378bSmrgrmprog=${RMPROG-rm} 659ef7378bSmrgstripprog=${STRIPPROG-strip} 669ef7378bSmrg 679ef7378bSmrgposix_mkdir= 689ef7378bSmrg 699ef7378bSmrg# Desired mode of installed file. 709ef7378bSmrgmode=0755 719ef7378bSmrg 729ef7378bSmrgchgrpcmd= 739ef7378bSmrgchmodcmd=$chmodprog 749ef7378bSmrgchowncmd= 759ef7378bSmrgmvcmd=$mvprog 769ef7378bSmrgrmcmd="$rmprog -f" 779ef7378bSmrgstripcmd= 78c19de146Smrg 799ef7378bSmrgsrc= 809ef7378bSmrgdst= 819ef7378bSmrgdir_arg= 829ef7378bSmrgdst_arg= 83c19de146Smrg 849ef7378bSmrgcopy_on_change=false 85a39bb051Smrgis_target_a_directory=possibly 86c19de146Smrg 879ef7378bSmrgusage="\ 889ef7378bSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 899ef7378bSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 909ef7378bSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 919ef7378bSmrg or: $0 [OPTION]... -d DIRECTORIES... 92c19de146Smrg 939ef7378bSmrgIn the 1st form, copy SRCFILE to DSTFILE. 949ef7378bSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 959ef7378bSmrgIn the 4th, create DIRECTORIES. 96c19de146Smrg 979ef7378bSmrgOptions: 989ef7378bSmrg --help display this help and exit. 999ef7378bSmrg --version display version info and exit. 100c19de146Smrg 1019ef7378bSmrg -c (ignored) 1029ef7378bSmrg -C install only if different (preserve the last data modification time) 1039ef7378bSmrg -d create directories instead of installing files. 1049ef7378bSmrg -g GROUP $chgrpprog installed files to GROUP. 1059ef7378bSmrg -m MODE $chmodprog installed files to MODE. 1069ef7378bSmrg -o USER $chownprog installed files to USER. 1079ef7378bSmrg -s $stripprog installed files. 1089ef7378bSmrg -t DIRECTORY install into DIRECTORY. 1099ef7378bSmrg -T report an error if DSTFILE is a directory. 110c19de146Smrg 1119ef7378bSmrgEnvironment variables override the default commands: 1129ef7378bSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1139ef7378bSmrg RMPROG STRIPPROG 1149ef7378bSmrg" 115c19de146Smrg 1169ef7378bSmrgwhile test $# -ne 0; do 1179ef7378bSmrg case $1 in 1189ef7378bSmrg -c) ;; 119c19de146Smrg 1209ef7378bSmrg -C) copy_on_change=true;; 121c19de146Smrg 1229ef7378bSmrg -d) dir_arg=true;; 123c19de146Smrg 1249ef7378bSmrg -g) chgrpcmd="$chgrpprog $2" 125a39bb051Smrg shift;; 126c19de146Smrg 1279ef7378bSmrg --help) echo "$usage"; exit $?;; 128c19de146Smrg 1299ef7378bSmrg -m) mode=$2 130a39bb051Smrg case $mode in 131a39bb051Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132a39bb051Smrg echo "$0: invalid mode: $mode" >&2 133a39bb051Smrg exit 1;; 134a39bb051Smrg esac 135a39bb051Smrg shift;; 136c19de146Smrg 1379ef7378bSmrg -o) chowncmd="$chownprog $2" 138a39bb051Smrg shift;; 139c19de146Smrg 1409ef7378bSmrg -s) stripcmd=$stripprog;; 141c19de146Smrg 142a39bb051Smrg -t) 143a39bb051Smrg is_target_a_directory=always 144a39bb051Smrg dst_arg=$2 145a39bb051Smrg # Protect names problematic for 'test' and other utilities. 146a39bb051Smrg case $dst_arg in 147a39bb051Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 148a39bb051Smrg esac 149a39bb051Smrg shift;; 150c19de146Smrg 151a39bb051Smrg -T) is_target_a_directory=never;; 152c19de146Smrg 1539ef7378bSmrg --version) echo "$0 $scriptversion"; exit $?;; 154c19de146Smrg 155a39bb051Smrg --) shift 156a39bb051Smrg break;; 157c19de146Smrg 158a39bb051Smrg -*) echo "$0: invalid option: $1" >&2 159a39bb051Smrg exit 1;; 160c19de146Smrg 1619ef7378bSmrg *) break;; 1629ef7378bSmrg esac 1639ef7378bSmrg shift 1649ef7378bSmrgdone 165c19de146Smrg 166a39bb051Smrg# We allow the use of options -d and -T together, by making -d 167a39bb051Smrg# take the precedence; this is for compatibility with GNU install. 168a39bb051Smrg 169a39bb051Smrgif test -n "$dir_arg"; then 170a39bb051Smrg if test -n "$dst_arg"; then 171a39bb051Smrg echo "$0: target directory not allowed when installing a directory." >&2 172a39bb051Smrg exit 1 173a39bb051Smrg fi 174a39bb051Smrgfi 175a39bb051Smrg 1769ef7378bSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1779ef7378bSmrg # When -d is used, all remaining arguments are directories to create. 1789ef7378bSmrg # When -t is used, the destination is already specified. 1799ef7378bSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1809ef7378bSmrg for arg 1819ef7378bSmrg do 1829ef7378bSmrg if test -n "$dst_arg"; then 1839ef7378bSmrg # $@ is not empty: it contains at least $arg. 1849ef7378bSmrg set fnord "$@" "$dst_arg" 1859ef7378bSmrg shift # fnord 1869ef7378bSmrg fi 1879ef7378bSmrg shift # arg 1889ef7378bSmrg dst_arg=$arg 189a39bb051Smrg # Protect names problematic for 'test' and other utilities. 190a39bb051Smrg case $dst_arg in 191a39bb051Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 192a39bb051Smrg esac 1939ef7378bSmrg done 1949ef7378bSmrgfi 195c19de146Smrg 1969ef7378bSmrgif test $# -eq 0; then 1979ef7378bSmrg if test -z "$dir_arg"; then 1989ef7378bSmrg echo "$0: no input file specified." >&2 1999ef7378bSmrg exit 1 2009ef7378bSmrg fi 201a39bb051Smrg # It's OK to call 'install-sh -d' without argument. 2029ef7378bSmrg # This can happen when creating conditional directories. 2039ef7378bSmrg exit 0 2049ef7378bSmrgfi 205c19de146Smrg 2069ef7378bSmrgif test -z "$dir_arg"; then 207a39bb051Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 208a39bb051Smrg if test ! -d "$dst_arg"; then 209a39bb051Smrg echo "$0: $dst_arg: Is not a directory." >&2 210a39bb051Smrg exit 1 211a39bb051Smrg fi 212a39bb051Smrg fi 213a39bb051Smrgfi 214a39bb051Smrg 215a39bb051Smrgif test -z "$dir_arg"; then 216a39bb051Smrg do_exit='(exit $ret); exit $ret' 217a39bb051Smrg trap "ret=129; $do_exit" 1 218a39bb051Smrg trap "ret=130; $do_exit" 2 219a39bb051Smrg trap "ret=141; $do_exit" 13 220a39bb051Smrg trap "ret=143; $do_exit" 15 2219ef7378bSmrg 2229ef7378bSmrg # Set umask so as not to create temps with too-generous modes. 2239ef7378bSmrg # However, 'strip' requires both read and write access to temps. 2249ef7378bSmrg case $mode in 2259ef7378bSmrg # Optimize common cases. 2269ef7378bSmrg *644) cp_umask=133;; 2279ef7378bSmrg *755) cp_umask=22;; 2289ef7378bSmrg 2299ef7378bSmrg *[0-7]) 2309ef7378bSmrg if test -z "$stripcmd"; then 231a39bb051Smrg u_plus_rw= 2329ef7378bSmrg else 233a39bb051Smrg u_plus_rw='% 200' 2349ef7378bSmrg fi 2359ef7378bSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2369ef7378bSmrg *) 2379ef7378bSmrg if test -z "$stripcmd"; then 238a39bb051Smrg u_plus_rw= 2399ef7378bSmrg else 240a39bb051Smrg u_plus_rw=,u+rw 2419ef7378bSmrg fi 2429ef7378bSmrg cp_umask=$mode$u_plus_rw;; 2439ef7378bSmrg esac 2449ef7378bSmrgfi 245c19de146Smrg 2469ef7378bSmrgfor src 2479ef7378bSmrgdo 248a39bb051Smrg # Protect names problematic for 'test' and other utilities. 2499ef7378bSmrg case $src in 250a39bb051Smrg -* | [=\(\)!]) src=./$src;; 2519ef7378bSmrg esac 2529ef7378bSmrg 2539ef7378bSmrg if test -n "$dir_arg"; then 2549ef7378bSmrg dst=$src 2559ef7378bSmrg dstdir=$dst 2569ef7378bSmrg test -d "$dstdir" 2579ef7378bSmrg dstdir_status=$? 2589ef7378bSmrg else 2599ef7378bSmrg 2609ef7378bSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2619ef7378bSmrg # might cause directories to be created, which would be especially bad 2629ef7378bSmrg # if $src (and thus $dsttmp) contains '*'. 2639ef7378bSmrg if test ! -f "$src" && test ! -d "$src"; then 2649ef7378bSmrg echo "$0: $src does not exist." >&2 2659ef7378bSmrg exit 1 2669ef7378bSmrg fi 2679ef7378bSmrg 2689ef7378bSmrg if test -z "$dst_arg"; then 2699ef7378bSmrg echo "$0: no destination specified." >&2 2709ef7378bSmrg exit 1 2719ef7378bSmrg fi 2729ef7378bSmrg dst=$dst_arg 273c19de146Smrg 2749ef7378bSmrg # If destination is a directory, append the input filename; won't work 2759ef7378bSmrg # if double slashes aren't ignored. 2769ef7378bSmrg if test -d "$dst"; then 277a39bb051Smrg if test "$is_target_a_directory" = never; then 278a39bb051Smrg echo "$0: $dst_arg: Is a directory" >&2 279a39bb051Smrg exit 1 2809ef7378bSmrg fi 2819ef7378bSmrg dstdir=$dst 2829ef7378bSmrg dst=$dstdir/`basename "$src"` 2839ef7378bSmrg dstdir_status=0 2849ef7378bSmrg else 285a39bb051Smrg dstdir=`dirname "$dst"` 2869ef7378bSmrg test -d "$dstdir" 2879ef7378bSmrg dstdir_status=$? 2889ef7378bSmrg fi 2899ef7378bSmrg fi 2909ef7378bSmrg 2919ef7378bSmrg obsolete_mkdir_used=false 2929ef7378bSmrg 2939ef7378bSmrg if test $dstdir_status != 0; then 2949ef7378bSmrg case $posix_mkdir in 2959ef7378bSmrg '') 296a39bb051Smrg # Create intermediate dirs using mode 755 as modified by the umask. 297a39bb051Smrg # This is like FreeBSD 'install' as of 1997-10-28. 298a39bb051Smrg umask=`umask` 299a39bb051Smrg case $stripcmd.$umask in 300a39bb051Smrg # Optimize common cases. 301a39bb051Smrg *[2367][2367]) mkdir_umask=$umask;; 302a39bb051Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 303a39bb051Smrg 304a39bb051Smrg *[0-7]) 305a39bb051Smrg mkdir_umask=`expr $umask + 22 \ 306a39bb051Smrg - $umask % 100 % 40 + $umask % 20 \ 307a39bb051Smrg - $umask % 10 % 4 + $umask % 2 308a39bb051Smrg `;; 309a39bb051Smrg *) mkdir_umask=$umask,go-w;; 310a39bb051Smrg esac 311a39bb051Smrg 312a39bb051Smrg # With -d, create the new directory with the user-specified mode. 313a39bb051Smrg # Otherwise, rely on $mkdir_umask. 314a39bb051Smrg if test -n "$dir_arg"; then 315a39bb051Smrg mkdir_mode=-m$mode 316a39bb051Smrg else 317a39bb051Smrg mkdir_mode= 318a39bb051Smrg fi 319a39bb051Smrg 320a39bb051Smrg posix_mkdir=false 321a39bb051Smrg case $umask in 322a39bb051Smrg *[123567][0-7][0-7]) 323a39bb051Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 324a39bb051Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 325a39bb051Smrg ;; 326a39bb051Smrg *) 327a39bb051Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 328a39bb051Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 329a39bb051Smrg 330a39bb051Smrg if (umask $mkdir_umask && 331a39bb051Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 332a39bb051Smrg then 333a39bb051Smrg if test -z "$dir_arg" || { 334a39bb051Smrg # Check for POSIX incompatibilities with -m. 335a39bb051Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336a39bb051Smrg # other-writable bit of parent directory when it shouldn't. 337a39bb051Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 338a39bb051Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 339a39bb051Smrg case $ls_ld_tmpdir in 340a39bb051Smrg d????-?r-*) different_mode=700;; 341a39bb051Smrg d????-?--*) different_mode=755;; 342a39bb051Smrg *) false;; 343a39bb051Smrg esac && 344a39bb051Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 345a39bb051Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 346a39bb051Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 347a39bb051Smrg } 348a39bb051Smrg } 349a39bb051Smrg then posix_mkdir=: 350a39bb051Smrg fi 351a39bb051Smrg rmdir "$tmpdir/d" "$tmpdir" 352a39bb051Smrg else 353a39bb051Smrg # Remove any dirs left behind by ancient mkdir implementations. 354a39bb051Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 355a39bb051Smrg fi 356a39bb051Smrg trap '' 0;; 357a39bb051Smrg esac;; 3589ef7378bSmrg esac 359c19de146Smrg 3609ef7378bSmrg if 3619ef7378bSmrg $posix_mkdir && ( 362a39bb051Smrg umask $mkdir_umask && 363a39bb051Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3649ef7378bSmrg ) 3659ef7378bSmrg then : 3669ef7378bSmrg else 3679ef7378bSmrg 3689ef7378bSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3699ef7378bSmrg # or it failed possibly due to a race condition. Create the 3709ef7378bSmrg # directory the slow way, step by step, checking for races as we go. 3719ef7378bSmrg 3729ef7378bSmrg case $dstdir in 373a39bb051Smrg /*) prefix='/';; 374a39bb051Smrg [-=\(\)!]*) prefix='./';; 375a39bb051Smrg *) prefix='';; 3769ef7378bSmrg esac 3779ef7378bSmrg 3789ef7378bSmrg oIFS=$IFS 3799ef7378bSmrg IFS=/ 380a39bb051Smrg set -f 3819ef7378bSmrg set fnord $dstdir 3829ef7378bSmrg shift 383a39bb051Smrg set +f 3849ef7378bSmrg IFS=$oIFS 3859ef7378bSmrg 3869ef7378bSmrg prefixes= 3879ef7378bSmrg 3889ef7378bSmrg for d 3899ef7378bSmrg do 390a39bb051Smrg test X"$d" = X && continue 391a39bb051Smrg 392a39bb051Smrg prefix=$prefix$d 393a39bb051Smrg if test -d "$prefix"; then 394a39bb051Smrg prefixes= 395a39bb051Smrg else 396a39bb051Smrg if $posix_mkdir; then 397a39bb051Smrg (umask=$mkdir_umask && 398a39bb051Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 399a39bb051Smrg # Don't fail if two instances are running concurrently. 400a39bb051Smrg test -d "$prefix" || exit 1 401a39bb051Smrg else 402a39bb051Smrg case $prefix in 403a39bb051Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 404a39bb051Smrg *) qprefix=$prefix;; 405a39bb051Smrg esac 406a39bb051Smrg prefixes="$prefixes '$qprefix'" 407a39bb051Smrg fi 408a39bb051Smrg fi 409a39bb051Smrg prefix=$prefix/ 4109ef7378bSmrg done 4119ef7378bSmrg 4129ef7378bSmrg if test -n "$prefixes"; then 413a39bb051Smrg # Don't fail if two instances are running concurrently. 414a39bb051Smrg (umask $mkdir_umask && 415a39bb051Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 416a39bb051Smrg test -d "$dstdir" || exit 1 417a39bb051Smrg obsolete_mkdir_used=true 4189ef7378bSmrg fi 4199ef7378bSmrg fi 4209ef7378bSmrg fi 4219ef7378bSmrg 4229ef7378bSmrg if test -n "$dir_arg"; then 4239ef7378bSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4249ef7378bSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4259ef7378bSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4269ef7378bSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4279ef7378bSmrg else 4289ef7378bSmrg 4299ef7378bSmrg # Make a couple of temp file names in the proper directory. 4309ef7378bSmrg dsttmp=$dstdir/_inst.$$_ 4319ef7378bSmrg rmtmp=$dstdir/_rm.$$_ 4329ef7378bSmrg 4339ef7378bSmrg # Trap to clean up those temp files at exit. 4349ef7378bSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4359ef7378bSmrg 4369ef7378bSmrg # Copy the file name to the temp name. 4379ef7378bSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4389ef7378bSmrg 4399ef7378bSmrg # and set any options; do chmod last to preserve setuid bits. 4409ef7378bSmrg # 4419ef7378bSmrg # If any of these fail, we abort the whole thing. If we want to 4429ef7378bSmrg # ignore errors from any of these, just make sure not to ignore 4439ef7378bSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4449ef7378bSmrg # 4459ef7378bSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4469ef7378bSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4479ef7378bSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4489ef7378bSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4499ef7378bSmrg 4509ef7378bSmrg # If -C, don't bother to copy if it wouldn't change the file. 4519ef7378bSmrg if $copy_on_change && 452a39bb051Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 453a39bb051Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454a39bb051Smrg set -f && 4559ef7378bSmrg set X $old && old=:$2:$4:$5:$6 && 4569ef7378bSmrg set X $new && new=:$2:$4:$5:$6 && 457a39bb051Smrg set +f && 4589ef7378bSmrg test "$old" = "$new" && 4599ef7378bSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4609ef7378bSmrg then 4619ef7378bSmrg rm -f "$dsttmp" 4629ef7378bSmrg else 4639ef7378bSmrg # Rename the file to the real destination. 4649ef7378bSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4659ef7378bSmrg 4669ef7378bSmrg # The rename failed, perhaps because mv can't rename something else 4679ef7378bSmrg # to itself, or perhaps because mv is so ancient that it does not 4689ef7378bSmrg # support -f. 4699ef7378bSmrg { 470a39bb051Smrg # Now remove or move aside any old file at destination location. 471a39bb051Smrg # We try this two ways since rm can't unlink itself on some 472a39bb051Smrg # systems and the destination file might be busy for other 473a39bb051Smrg # reasons. In this case, the final cleanup might fail but the new 474a39bb051Smrg # file should still install successfully. 475a39bb051Smrg { 476a39bb051Smrg test ! -f "$dst" || 477a39bb051Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 478a39bb051Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 479a39bb051Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 480a39bb051Smrg } || 481a39bb051Smrg { echo "$0: cannot unlink or rename $dst" >&2 482a39bb051Smrg (exit 1); exit 1 483a39bb051Smrg } 484a39bb051Smrg } && 485a39bb051Smrg 486a39bb051Smrg # Now rename the file to the real destination. 487a39bb051Smrg $doit $mvcmd "$dsttmp" "$dst" 4889ef7378bSmrg } 4899ef7378bSmrg fi || exit 1 4909ef7378bSmrg 4919ef7378bSmrg trap '' 0 4929ef7378bSmrg fi 4939ef7378bSmrgdone 494c19de146Smrg 4959ef7378bSmrg# Local variables: 4969ef7378bSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 4979ef7378bSmrg# time-stamp-start: "scriptversion=" 4989ef7378bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 4999ef7378bSmrg# time-stamp-time-zone: "UTC" 5009ef7378bSmrg# time-stamp-end: "; # UTC" 5019ef7378bSmrg# End: 502