install-sh revision 245c37e9
11016ad83Smrg#!/bin/sh 21016ad83Smrg# install - install a program, script, or datafile 31016ad83Smrg 4245c37e9Smrgscriptversion=2016-01-11.22; # UTC 51016ad83Smrg 61016ad83Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71016ad83Smrg# later released in X11R6 (xc/config/util/install.sh) with the 81016ad83Smrg# following copyright and license. 91016ad83Smrg# 101016ad83Smrg# Copyright (C) 1994 X Consortium 111016ad83Smrg# 121016ad83Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131016ad83Smrg# of this software and associated documentation files (the "Software"), to 141016ad83Smrg# deal in the Software without restriction, including without limitation the 151016ad83Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161016ad83Smrg# sell copies of the Software, and to permit persons to whom the Software is 171016ad83Smrg# furnished to do so, subject to the following conditions: 181016ad83Smrg# 191016ad83Smrg# The above copyright notice and this permission notice shall be included in 201016ad83Smrg# all copies or substantial portions of the Software. 211016ad83Smrg# 221016ad83Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231016ad83Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241016ad83Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251016ad83Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261016ad83Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271016ad83Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281016ad83Smrg# 291016ad83Smrg# Except as contained in this notice, the name of the X Consortium shall not 301016ad83Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 311016ad83Smrg# ings in this Software without prior written authorization from the X Consor- 321016ad83Smrg# tium. 331016ad83Smrg# 341016ad83Smrg# 351016ad83Smrg# FSF changes to this file are in the public domain. 361016ad83Smrg# 371016ad83Smrg# Calling this script install-sh is preferred over install.sh, to prevent 381016ad83Smrg# 'make' implicit rules from creating a file called install from it 391016ad83Smrg# when there is no Makefile. 401016ad83Smrg# 411016ad83Smrg# This script is compatible with the BSD install script, but was written 421016ad83Smrg# from scratch. 431016ad83Smrg 44709d36bbSmrgtab=' ' 451016ad83Smrgnl=' 461016ad83Smrg' 47709d36bbSmrgIFS=" $tab$nl" 481016ad83Smrg 49709d36bbSmrg# Set DOITPROG to "echo" to test this script. 501016ad83Smrg 511016ad83Smrgdoit=${DOITPROG-} 52709d36bbSmrgdoit_exec=${doit:-exec} 531016ad83Smrg 541016ad83Smrg# Put in absolute file names if you don't have them in your path; 551016ad83Smrg# or use environment vars. 561016ad83Smrg 571016ad83Smrgchgrpprog=${CHGRPPROG-chgrp} 581016ad83Smrgchmodprog=${CHMODPROG-chmod} 591016ad83Smrgchownprog=${CHOWNPROG-chown} 601016ad83Smrgcmpprog=${CMPPROG-cmp} 611016ad83Smrgcpprog=${CPPROG-cp} 621016ad83Smrgmkdirprog=${MKDIRPROG-mkdir} 631016ad83Smrgmvprog=${MVPROG-mv} 641016ad83Smrgrmprog=${RMPROG-rm} 651016ad83Smrgstripprog=${STRIPPROG-strip} 661016ad83Smrg 671016ad83Smrgposix_mkdir= 681016ad83Smrg 691016ad83Smrg# Desired mode of installed file. 701016ad83Smrgmode=0755 711016ad83Smrg 721016ad83Smrgchgrpcmd= 731016ad83Smrgchmodcmd=$chmodprog 741016ad83Smrgchowncmd= 751016ad83Smrgmvcmd=$mvprog 761016ad83Smrgrmcmd="$rmprog -f" 771016ad83Smrgstripcmd= 781016ad83Smrg 791016ad83Smrgsrc= 801016ad83Smrgdst= 811016ad83Smrgdir_arg= 821016ad83Smrgdst_arg= 831016ad83Smrg 841016ad83Smrgcopy_on_change=false 85709d36bbSmrgis_target_a_directory=possibly 861016ad83Smrg 871016ad83Smrgusage="\ 881016ad83SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 891016ad83Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 901016ad83Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 911016ad83Smrg or: $0 [OPTION]... -d DIRECTORIES... 921016ad83Smrg 931016ad83SmrgIn the 1st form, copy SRCFILE to DSTFILE. 941016ad83SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 951016ad83SmrgIn the 4th, create DIRECTORIES. 961016ad83Smrg 971016ad83SmrgOptions: 981016ad83Smrg --help display this help and exit. 991016ad83Smrg --version display version info and exit. 1001016ad83Smrg 1011016ad83Smrg -c (ignored) 1021016ad83Smrg -C install only if different (preserve the last data modification time) 1031016ad83Smrg -d create directories instead of installing files. 1041016ad83Smrg -g GROUP $chgrpprog installed files to GROUP. 1051016ad83Smrg -m MODE $chmodprog installed files to MODE. 1061016ad83Smrg -o USER $chownprog installed files to USER. 1071016ad83Smrg -s $stripprog installed files. 1081016ad83Smrg -t DIRECTORY install into DIRECTORY. 1091016ad83Smrg -T report an error if DSTFILE is a directory. 1101016ad83Smrg 1111016ad83SmrgEnvironment variables override the default commands: 1121016ad83Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1131016ad83Smrg RMPROG STRIPPROG 1141016ad83Smrg" 1151016ad83Smrg 1161016ad83Smrgwhile test $# -ne 0; do 1171016ad83Smrg case $1 in 1181016ad83Smrg -c) ;; 1191016ad83Smrg 1201016ad83Smrg -C) copy_on_change=true;; 1211016ad83Smrg 1221016ad83Smrg -d) dir_arg=true;; 1231016ad83Smrg 1241016ad83Smrg -g) chgrpcmd="$chgrpprog $2" 125709d36bbSmrg shift;; 1261016ad83Smrg 1271016ad83Smrg --help) echo "$usage"; exit $?;; 1281016ad83Smrg 1291016ad83Smrg -m) mode=$2 130709d36bbSmrg case $mode in 131709d36bbSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132709d36bbSmrg echo "$0: invalid mode: $mode" >&2 133709d36bbSmrg exit 1;; 134709d36bbSmrg esac 135709d36bbSmrg shift;; 1361016ad83Smrg 1371016ad83Smrg -o) chowncmd="$chownprog $2" 138709d36bbSmrg shift;; 1391016ad83Smrg 1401016ad83Smrg -s) stripcmd=$stripprog;; 1411016ad83Smrg 142709d36bbSmrg -t) 143709d36bbSmrg is_target_a_directory=always 144709d36bbSmrg dst_arg=$2 145709d36bbSmrg # Protect names problematic for 'test' and other utilities. 146709d36bbSmrg case $dst_arg in 147709d36bbSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 148709d36bbSmrg esac 149709d36bbSmrg shift;; 1501016ad83Smrg 151709d36bbSmrg -T) is_target_a_directory=never;; 1521016ad83Smrg 1531016ad83Smrg --version) echo "$0 $scriptversion"; exit $?;; 1541016ad83Smrg 155709d36bbSmrg --) shift 156709d36bbSmrg break;; 1571016ad83Smrg 158709d36bbSmrg -*) echo "$0: invalid option: $1" >&2 159709d36bbSmrg exit 1;; 1601016ad83Smrg 1611016ad83Smrg *) break;; 1621016ad83Smrg esac 1631016ad83Smrg shift 1641016ad83Smrgdone 1651016ad83Smrg 166709d36bbSmrg# We allow the use of options -d and -T together, by making -d 167709d36bbSmrg# take the precedence; this is for compatibility with GNU install. 168709d36bbSmrg 169709d36bbSmrgif test -n "$dir_arg"; then 170709d36bbSmrg if test -n "$dst_arg"; then 171709d36bbSmrg echo "$0: target directory not allowed when installing a directory." >&2 172709d36bbSmrg exit 1 173709d36bbSmrg fi 174709d36bbSmrgfi 175709d36bbSmrg 1761016ad83Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1771016ad83Smrg # When -d is used, all remaining arguments are directories to create. 1781016ad83Smrg # When -t is used, the destination is already specified. 1791016ad83Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1801016ad83Smrg for arg 1811016ad83Smrg do 1821016ad83Smrg if test -n "$dst_arg"; then 1831016ad83Smrg # $@ is not empty: it contains at least $arg. 1841016ad83Smrg set fnord "$@" "$dst_arg" 1851016ad83Smrg shift # fnord 1861016ad83Smrg fi 1871016ad83Smrg shift # arg 1881016ad83Smrg dst_arg=$arg 1891016ad83Smrg # Protect names problematic for 'test' and other utilities. 1901016ad83Smrg case $dst_arg in 1911016ad83Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1921016ad83Smrg esac 1931016ad83Smrg done 1941016ad83Smrgfi 1951016ad83Smrg 1961016ad83Smrgif test $# -eq 0; then 1971016ad83Smrg if test -z "$dir_arg"; then 1981016ad83Smrg echo "$0: no input file specified." >&2 1991016ad83Smrg exit 1 2001016ad83Smrg fi 2011016ad83Smrg # It's OK to call 'install-sh -d' without argument. 2021016ad83Smrg # This can happen when creating conditional directories. 2031016ad83Smrg exit 0 2041016ad83Smrgfi 2051016ad83Smrg 206709d36bbSmrgif test -z "$dir_arg"; then 207709d36bbSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 208709d36bbSmrg if test ! -d "$dst_arg"; then 209709d36bbSmrg echo "$0: $dst_arg: Is not a directory." >&2 210709d36bbSmrg exit 1 211709d36bbSmrg fi 212709d36bbSmrg fi 213709d36bbSmrgfi 214709d36bbSmrg 2151016ad83Smrgif test -z "$dir_arg"; then 2161016ad83Smrg do_exit='(exit $ret); exit $ret' 2171016ad83Smrg trap "ret=129; $do_exit" 1 2181016ad83Smrg trap "ret=130; $do_exit" 2 2191016ad83Smrg trap "ret=141; $do_exit" 13 2201016ad83Smrg trap "ret=143; $do_exit" 15 2211016ad83Smrg 2221016ad83Smrg # Set umask so as not to create temps with too-generous modes. 2231016ad83Smrg # However, 'strip' requires both read and write access to temps. 2241016ad83Smrg case $mode in 2251016ad83Smrg # Optimize common cases. 2261016ad83Smrg *644) cp_umask=133;; 2271016ad83Smrg *755) cp_umask=22;; 2281016ad83Smrg 2291016ad83Smrg *[0-7]) 2301016ad83Smrg if test -z "$stripcmd"; then 231709d36bbSmrg u_plus_rw= 2321016ad83Smrg else 233709d36bbSmrg u_plus_rw='% 200' 2341016ad83Smrg fi 2351016ad83Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2361016ad83Smrg *) 2371016ad83Smrg if test -z "$stripcmd"; then 238709d36bbSmrg u_plus_rw= 2391016ad83Smrg else 240709d36bbSmrg u_plus_rw=,u+rw 2411016ad83Smrg fi 2421016ad83Smrg cp_umask=$mode$u_plus_rw;; 2431016ad83Smrg esac 2441016ad83Smrgfi 2451016ad83Smrg 2461016ad83Smrgfor src 2471016ad83Smrgdo 2481016ad83Smrg # Protect names problematic for 'test' and other utilities. 2491016ad83Smrg case $src in 2501016ad83Smrg -* | [=\(\)!]) src=./$src;; 2511016ad83Smrg esac 2521016ad83Smrg 2531016ad83Smrg if test -n "$dir_arg"; then 2541016ad83Smrg dst=$src 2551016ad83Smrg dstdir=$dst 2561016ad83Smrg test -d "$dstdir" 2571016ad83Smrg dstdir_status=$? 2581016ad83Smrg else 2591016ad83Smrg 2601016ad83Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2611016ad83Smrg # might cause directories to be created, which would be especially bad 2621016ad83Smrg # if $src (and thus $dsttmp) contains '*'. 2631016ad83Smrg if test ! -f "$src" && test ! -d "$src"; then 2641016ad83Smrg echo "$0: $src does not exist." >&2 2651016ad83Smrg exit 1 2661016ad83Smrg fi 2671016ad83Smrg 2681016ad83Smrg if test -z "$dst_arg"; then 2691016ad83Smrg echo "$0: no destination specified." >&2 2701016ad83Smrg exit 1 2711016ad83Smrg fi 2721016ad83Smrg dst=$dst_arg 2731016ad83Smrg 2741016ad83Smrg # If destination is a directory, append the input filename; won't work 2751016ad83Smrg # if double slashes aren't ignored. 2761016ad83Smrg if test -d "$dst"; then 277709d36bbSmrg if test "$is_target_a_directory" = never; then 278709d36bbSmrg echo "$0: $dst_arg: Is a directory" >&2 279709d36bbSmrg exit 1 2801016ad83Smrg fi 2811016ad83Smrg dstdir=$dst 2821016ad83Smrg dst=$dstdir/`basename "$src"` 2831016ad83Smrg dstdir_status=0 2841016ad83Smrg else 285709d36bbSmrg dstdir=`dirname "$dst"` 2861016ad83Smrg test -d "$dstdir" 2871016ad83Smrg dstdir_status=$? 2881016ad83Smrg fi 2891016ad83Smrg fi 2901016ad83Smrg 2911016ad83Smrg obsolete_mkdir_used=false 2921016ad83Smrg 2931016ad83Smrg if test $dstdir_status != 0; then 2941016ad83Smrg case $posix_mkdir in 2951016ad83Smrg '') 296709d36bbSmrg # Create intermediate dirs using mode 755 as modified by the umask. 297709d36bbSmrg # This is like FreeBSD 'install' as of 1997-10-28. 298709d36bbSmrg umask=`umask` 299709d36bbSmrg case $stripcmd.$umask in 300709d36bbSmrg # Optimize common cases. 301709d36bbSmrg *[2367][2367]) mkdir_umask=$umask;; 302709d36bbSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 303709d36bbSmrg 304709d36bbSmrg *[0-7]) 305709d36bbSmrg mkdir_umask=`expr $umask + 22 \ 306709d36bbSmrg - $umask % 100 % 40 + $umask % 20 \ 307709d36bbSmrg - $umask % 10 % 4 + $umask % 2 308709d36bbSmrg `;; 309709d36bbSmrg *) mkdir_umask=$umask,go-w;; 310709d36bbSmrg esac 311709d36bbSmrg 312709d36bbSmrg # With -d, create the new directory with the user-specified mode. 313709d36bbSmrg # Otherwise, rely on $mkdir_umask. 314709d36bbSmrg if test -n "$dir_arg"; then 315709d36bbSmrg mkdir_mode=-m$mode 316709d36bbSmrg else 317709d36bbSmrg mkdir_mode= 318709d36bbSmrg fi 319709d36bbSmrg 320709d36bbSmrg posix_mkdir=false 321709d36bbSmrg case $umask in 322709d36bbSmrg *[123567][0-7][0-7]) 323709d36bbSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 324709d36bbSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 325709d36bbSmrg ;; 326709d36bbSmrg *) 327709d36bbSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 328245c37e9Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 329709d36bbSmrg 330709d36bbSmrg if (umask $mkdir_umask && 331245c37e9Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 332709d36bbSmrg then 333709d36bbSmrg if test -z "$dir_arg" || { 334709d36bbSmrg # Check for POSIX incompatibilities with -m. 335709d36bbSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336709d36bbSmrg # other-writable bit of parent directory when it shouldn't. 337709d36bbSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 338245c37e9Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 339709d36bbSmrg case $ls_ld_tmpdir in 340709d36bbSmrg d????-?r-*) different_mode=700;; 341709d36bbSmrg d????-?--*) different_mode=755;; 342709d36bbSmrg *) false;; 343709d36bbSmrg esac && 344245c37e9Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 345245c37e9Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 346709d36bbSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 347709d36bbSmrg } 348709d36bbSmrg } 349709d36bbSmrg then posix_mkdir=: 350709d36bbSmrg fi 351245c37e9Smrg rmdir "$tmpdir/d" "$tmpdir" 352709d36bbSmrg else 353709d36bbSmrg # Remove any dirs left behind by ancient mkdir implementations. 354245c37e9Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 355709d36bbSmrg fi 356709d36bbSmrg trap '' 0;; 357709d36bbSmrg esac;; 3581016ad83Smrg esac 3591016ad83Smrg 3601016ad83Smrg if 3611016ad83Smrg $posix_mkdir && ( 362709d36bbSmrg umask $mkdir_umask && 363709d36bbSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3641016ad83Smrg ) 3651016ad83Smrg then : 3661016ad83Smrg else 3671016ad83Smrg 3681016ad83Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3691016ad83Smrg # or it failed possibly due to a race condition. Create the 3701016ad83Smrg # directory the slow way, step by step, checking for races as we go. 3711016ad83Smrg 3721016ad83Smrg case $dstdir in 373709d36bbSmrg /*) prefix='/';; 374709d36bbSmrg [-=\(\)!]*) prefix='./';; 375709d36bbSmrg *) prefix='';; 3761016ad83Smrg esac 3771016ad83Smrg 3781016ad83Smrg oIFS=$IFS 3791016ad83Smrg IFS=/ 380709d36bbSmrg set -f 3811016ad83Smrg set fnord $dstdir 3821016ad83Smrg shift 383709d36bbSmrg set +f 3841016ad83Smrg IFS=$oIFS 3851016ad83Smrg 3861016ad83Smrg prefixes= 3871016ad83Smrg 3881016ad83Smrg for d 3891016ad83Smrg do 390709d36bbSmrg test X"$d" = X && continue 391709d36bbSmrg 392709d36bbSmrg prefix=$prefix$d 393709d36bbSmrg if test -d "$prefix"; then 394709d36bbSmrg prefixes= 395709d36bbSmrg else 396709d36bbSmrg if $posix_mkdir; then 397709d36bbSmrg (umask=$mkdir_umask && 398709d36bbSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 399709d36bbSmrg # Don't fail if two instances are running concurrently. 400709d36bbSmrg test -d "$prefix" || exit 1 401709d36bbSmrg else 402709d36bbSmrg case $prefix in 403709d36bbSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 404709d36bbSmrg *) qprefix=$prefix;; 405709d36bbSmrg esac 406709d36bbSmrg prefixes="$prefixes '$qprefix'" 407709d36bbSmrg fi 408709d36bbSmrg fi 409709d36bbSmrg prefix=$prefix/ 4101016ad83Smrg done 4111016ad83Smrg 4121016ad83Smrg if test -n "$prefixes"; then 413709d36bbSmrg # Don't fail if two instances are running concurrently. 414709d36bbSmrg (umask $mkdir_umask && 415709d36bbSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 416709d36bbSmrg test -d "$dstdir" || exit 1 417709d36bbSmrg obsolete_mkdir_used=true 4181016ad83Smrg fi 4191016ad83Smrg fi 4201016ad83Smrg fi 4211016ad83Smrg 4221016ad83Smrg if test -n "$dir_arg"; then 4231016ad83Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4241016ad83Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4251016ad83Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4261016ad83Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4271016ad83Smrg else 4281016ad83Smrg 4291016ad83Smrg # Make a couple of temp file names in the proper directory. 4301016ad83Smrg dsttmp=$dstdir/_inst.$$_ 4311016ad83Smrg rmtmp=$dstdir/_rm.$$_ 4321016ad83Smrg 4331016ad83Smrg # Trap to clean up those temp files at exit. 4341016ad83Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4351016ad83Smrg 4361016ad83Smrg # Copy the file name to the temp name. 4371016ad83Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4381016ad83Smrg 4391016ad83Smrg # and set any options; do chmod last to preserve setuid bits. 4401016ad83Smrg # 4411016ad83Smrg # If any of these fail, we abort the whole thing. If we want to 4421016ad83Smrg # ignore errors from any of these, just make sure not to ignore 4431016ad83Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4441016ad83Smrg # 4451016ad83Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4461016ad83Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4471016ad83Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4481016ad83Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4491016ad83Smrg 4501016ad83Smrg # If -C, don't bother to copy if it wouldn't change the file. 4511016ad83Smrg if $copy_on_change && 452709d36bbSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 453709d36bbSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454709d36bbSmrg set -f && 4551016ad83Smrg set X $old && old=:$2:$4:$5:$6 && 4561016ad83Smrg set X $new && new=:$2:$4:$5:$6 && 457709d36bbSmrg set +f && 4581016ad83Smrg test "$old" = "$new" && 4591016ad83Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4601016ad83Smrg then 4611016ad83Smrg rm -f "$dsttmp" 4621016ad83Smrg else 4631016ad83Smrg # Rename the file to the real destination. 4641016ad83Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4651016ad83Smrg 4661016ad83Smrg # The rename failed, perhaps because mv can't rename something else 4671016ad83Smrg # to itself, or perhaps because mv is so ancient that it does not 4681016ad83Smrg # support -f. 4691016ad83Smrg { 470709d36bbSmrg # Now remove or move aside any old file at destination location. 471709d36bbSmrg # We try this two ways since rm can't unlink itself on some 472709d36bbSmrg # systems and the destination file might be busy for other 473709d36bbSmrg # reasons. In this case, the final cleanup might fail but the new 474709d36bbSmrg # file should still install successfully. 475709d36bbSmrg { 476709d36bbSmrg test ! -f "$dst" || 477709d36bbSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 478709d36bbSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 479709d36bbSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 480709d36bbSmrg } || 481709d36bbSmrg { echo "$0: cannot unlink or rename $dst" >&2 482709d36bbSmrg (exit 1); exit 1 483709d36bbSmrg } 484709d36bbSmrg } && 485709d36bbSmrg 486709d36bbSmrg # Now rename the file to the real destination. 487709d36bbSmrg $doit $mvcmd "$dsttmp" "$dst" 4881016ad83Smrg } 4891016ad83Smrg fi || exit 1 4901016ad83Smrg 4911016ad83Smrg trap '' 0 4921016ad83Smrg fi 4931016ad83Smrgdone 4941016ad83Smrg 4951016ad83Smrg# Local variables: 4961016ad83Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 4971016ad83Smrg# time-stamp-start: "scriptversion=" 4981016ad83Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 499245c37e9Smrg# time-stamp-time-zone: "UTC0" 5001016ad83Smrg# time-stamp-end: "; # UTC" 5011016ad83Smrg# End: 502