install-sh revision a4f78def
1a4f78defSmrg#!/bin/sh 2a4f78defSmrg# install - install a program, script, or datafile 3a4f78defSmrg 4a4f78defSmrgscriptversion=2013-12-25.23; # UTC 5a4f78defSmrg 6a4f78defSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7a4f78defSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8a4f78defSmrg# following copyright and license. 9a4f78defSmrg# 10a4f78defSmrg# Copyright (C) 1994 X Consortium 11a4f78defSmrg# 12a4f78defSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13a4f78defSmrg# of this software and associated documentation files (the "Software"), to 14a4f78defSmrg# deal in the Software without restriction, including without limitation the 15a4f78defSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16a4f78defSmrg# sell copies of the Software, and to permit persons to whom the Software is 17a4f78defSmrg# furnished to do so, subject to the following conditions: 18a4f78defSmrg# 19a4f78defSmrg# The above copyright notice and this permission notice shall be included in 20a4f78defSmrg# all copies or substantial portions of the Software. 21a4f78defSmrg# 22a4f78defSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23a4f78defSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24a4f78defSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25a4f78defSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26a4f78defSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27a4f78defSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28a4f78defSmrg# 29a4f78defSmrg# Except as contained in this notice, the name of the X Consortium shall not 30a4f78defSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31a4f78defSmrg# ings in this Software without prior written authorization from the X Consor- 32a4f78defSmrg# tium. 33a4f78defSmrg# 34a4f78defSmrg# 35a4f78defSmrg# FSF changes to this file are in the public domain. 36a4f78defSmrg# 37a4f78defSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38a4f78defSmrg# 'make' implicit rules from creating a file called install from it 39a4f78defSmrg# when there is no Makefile. 40a4f78defSmrg# 41a4f78defSmrg# This script is compatible with the BSD install script, but was written 42a4f78defSmrg# from scratch. 43a4f78defSmrg 44a4f78defSmrgtab=' ' 45a4f78defSmrgnl=' 46a4f78defSmrg' 47a4f78defSmrgIFS=" $tab$nl" 48a4f78defSmrg 49a4f78defSmrg# Set DOITPROG to "echo" to test this script. 50a4f78defSmrg 51a4f78defSmrgdoit=${DOITPROG-} 52a4f78defSmrgdoit_exec=${doit:-exec} 53a4f78defSmrg 54a4f78defSmrg# Put in absolute file names if you don't have them in your path; 55a4f78defSmrg# or use environment vars. 56a4f78defSmrg 57a4f78defSmrgchgrpprog=${CHGRPPROG-chgrp} 58a4f78defSmrgchmodprog=${CHMODPROG-chmod} 59a4f78defSmrgchownprog=${CHOWNPROG-chown} 60a4f78defSmrgcmpprog=${CMPPROG-cmp} 61a4f78defSmrgcpprog=${CPPROG-cp} 62a4f78defSmrgmkdirprog=${MKDIRPROG-mkdir} 63a4f78defSmrgmvprog=${MVPROG-mv} 64a4f78defSmrgrmprog=${RMPROG-rm} 65a4f78defSmrgstripprog=${STRIPPROG-strip} 66a4f78defSmrg 67a4f78defSmrgposix_mkdir= 68a4f78defSmrg 69a4f78defSmrg# Desired mode of installed file. 70a4f78defSmrgmode=0755 71a4f78defSmrg 72a4f78defSmrgchgrpcmd= 73a4f78defSmrgchmodcmd=$chmodprog 74a4f78defSmrgchowncmd= 75a4f78defSmrgmvcmd=$mvprog 76a4f78defSmrgrmcmd="$rmprog -f" 77a4f78defSmrgstripcmd= 78a4f78defSmrg 79a4f78defSmrgsrc= 80a4f78defSmrgdst= 81a4f78defSmrgdir_arg= 82a4f78defSmrgdst_arg= 83a4f78defSmrg 84a4f78defSmrgcopy_on_change=false 85a4f78defSmrgis_target_a_directory=possibly 86a4f78defSmrg 87a4f78defSmrgusage="\ 88a4f78defSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 89a4f78defSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 90a4f78defSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 91a4f78defSmrg or: $0 [OPTION]... -d DIRECTORIES... 92a4f78defSmrg 93a4f78defSmrgIn the 1st form, copy SRCFILE to DSTFILE. 94a4f78defSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 95a4f78defSmrgIn the 4th, create DIRECTORIES. 96a4f78defSmrg 97a4f78defSmrgOptions: 98a4f78defSmrg --help display this help and exit. 99a4f78defSmrg --version display version info and exit. 100a4f78defSmrg 101a4f78defSmrg -c (ignored) 102a4f78defSmrg -C install only if different (preserve the last data modification time) 103a4f78defSmrg -d create directories instead of installing files. 104a4f78defSmrg -g GROUP $chgrpprog installed files to GROUP. 105a4f78defSmrg -m MODE $chmodprog installed files to MODE. 106a4f78defSmrg -o USER $chownprog installed files to USER. 107a4f78defSmrg -s $stripprog installed files. 108a4f78defSmrg -t DIRECTORY install into DIRECTORY. 109a4f78defSmrg -T report an error if DSTFILE is a directory. 110a4f78defSmrg 111a4f78defSmrgEnvironment variables override the default commands: 112a4f78defSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 113a4f78defSmrg RMPROG STRIPPROG 114a4f78defSmrg" 115a4f78defSmrg 116a4f78defSmrgwhile test $# -ne 0; do 117a4f78defSmrg case $1 in 118a4f78defSmrg -c) ;; 119a4f78defSmrg 120a4f78defSmrg -C) copy_on_change=true;; 121a4f78defSmrg 122a4f78defSmrg -d) dir_arg=true;; 123a4f78defSmrg 124a4f78defSmrg -g) chgrpcmd="$chgrpprog $2" 125a4f78defSmrg shift;; 126a4f78defSmrg 127a4f78defSmrg --help) echo "$usage"; exit $?;; 128a4f78defSmrg 129a4f78defSmrg -m) mode=$2 130a4f78defSmrg case $mode in 131a4f78defSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132a4f78defSmrg echo "$0: invalid mode: $mode" >&2 133a4f78defSmrg exit 1;; 134a4f78defSmrg esac 135a4f78defSmrg shift;; 136a4f78defSmrg 137a4f78defSmrg -o) chowncmd="$chownprog $2" 138a4f78defSmrg shift;; 139a4f78defSmrg 140a4f78defSmrg -s) stripcmd=$stripprog;; 141a4f78defSmrg 142a4f78defSmrg -t) 143a4f78defSmrg is_target_a_directory=always 144a4f78defSmrg dst_arg=$2 145a4f78defSmrg # Protect names problematic for 'test' and other utilities. 146a4f78defSmrg case $dst_arg in 147a4f78defSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 148a4f78defSmrg esac 149a4f78defSmrg shift;; 150a4f78defSmrg 151a4f78defSmrg -T) is_target_a_directory=never;; 152a4f78defSmrg 153a4f78defSmrg --version) echo "$0 $scriptversion"; exit $?;; 154a4f78defSmrg 155a4f78defSmrg --) shift 156a4f78defSmrg break;; 157a4f78defSmrg 158a4f78defSmrg -*) echo "$0: invalid option: $1" >&2 159a4f78defSmrg exit 1;; 160a4f78defSmrg 161a4f78defSmrg *) break;; 162a4f78defSmrg esac 163a4f78defSmrg shift 164a4f78defSmrgdone 165a4f78defSmrg 166a4f78defSmrg# We allow the use of options -d and -T together, by making -d 167a4f78defSmrg# take the precedence; this is for compatibility with GNU install. 168a4f78defSmrg 169a4f78defSmrgif test -n "$dir_arg"; then 170a4f78defSmrg if test -n "$dst_arg"; then 171a4f78defSmrg echo "$0: target directory not allowed when installing a directory." >&2 172a4f78defSmrg exit 1 173a4f78defSmrg fi 174a4f78defSmrgfi 175a4f78defSmrg 176a4f78defSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 177a4f78defSmrg # When -d is used, all remaining arguments are directories to create. 178a4f78defSmrg # When -t is used, the destination is already specified. 179a4f78defSmrg # Otherwise, the last argument is the destination. Remove it from $@. 180a4f78defSmrg for arg 181a4f78defSmrg do 182a4f78defSmrg if test -n "$dst_arg"; then 183a4f78defSmrg # $@ is not empty: it contains at least $arg. 184a4f78defSmrg set fnord "$@" "$dst_arg" 185a4f78defSmrg shift # fnord 186a4f78defSmrg fi 187a4f78defSmrg shift # arg 188a4f78defSmrg dst_arg=$arg 189a4f78defSmrg # Protect names problematic for 'test' and other utilities. 190a4f78defSmrg case $dst_arg in 191a4f78defSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 192a4f78defSmrg esac 193a4f78defSmrg done 194a4f78defSmrgfi 195a4f78defSmrg 196a4f78defSmrgif test $# -eq 0; then 197a4f78defSmrg if test -z "$dir_arg"; then 198a4f78defSmrg echo "$0: no input file specified." >&2 199a4f78defSmrg exit 1 200a4f78defSmrg fi 201a4f78defSmrg # It's OK to call 'install-sh -d' without argument. 202a4f78defSmrg # This can happen when creating conditional directories. 203a4f78defSmrg exit 0 204a4f78defSmrgfi 205a4f78defSmrg 206a4f78defSmrgif test -z "$dir_arg"; then 207a4f78defSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 208a4f78defSmrg if test ! -d "$dst_arg"; then 209a4f78defSmrg echo "$0: $dst_arg: Is not a directory." >&2 210a4f78defSmrg exit 1 211a4f78defSmrg fi 212a4f78defSmrg fi 213a4f78defSmrgfi 214a4f78defSmrg 215a4f78defSmrgif test -z "$dir_arg"; then 216a4f78defSmrg do_exit='(exit $ret); exit $ret' 217a4f78defSmrg trap "ret=129; $do_exit" 1 218a4f78defSmrg trap "ret=130; $do_exit" 2 219a4f78defSmrg trap "ret=141; $do_exit" 13 220a4f78defSmrg trap "ret=143; $do_exit" 15 221a4f78defSmrg 222a4f78defSmrg # Set umask so as not to create temps with too-generous modes. 223a4f78defSmrg # However, 'strip' requires both read and write access to temps. 224a4f78defSmrg case $mode in 225a4f78defSmrg # Optimize common cases. 226a4f78defSmrg *644) cp_umask=133;; 227a4f78defSmrg *755) cp_umask=22;; 228a4f78defSmrg 229a4f78defSmrg *[0-7]) 230a4f78defSmrg if test -z "$stripcmd"; then 231a4f78defSmrg u_plus_rw= 232a4f78defSmrg else 233a4f78defSmrg u_plus_rw='% 200' 234a4f78defSmrg fi 235a4f78defSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 236a4f78defSmrg *) 237a4f78defSmrg if test -z "$stripcmd"; then 238a4f78defSmrg u_plus_rw= 239a4f78defSmrg else 240a4f78defSmrg u_plus_rw=,u+rw 241a4f78defSmrg fi 242a4f78defSmrg cp_umask=$mode$u_plus_rw;; 243a4f78defSmrg esac 244a4f78defSmrgfi 245a4f78defSmrg 246a4f78defSmrgfor src 247a4f78defSmrgdo 248a4f78defSmrg # Protect names problematic for 'test' and other utilities. 249a4f78defSmrg case $src in 250a4f78defSmrg -* | [=\(\)!]) src=./$src;; 251a4f78defSmrg esac 252a4f78defSmrg 253a4f78defSmrg if test -n "$dir_arg"; then 254a4f78defSmrg dst=$src 255a4f78defSmrg dstdir=$dst 256a4f78defSmrg test -d "$dstdir" 257a4f78defSmrg dstdir_status=$? 258a4f78defSmrg else 259a4f78defSmrg 260a4f78defSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 261a4f78defSmrg # might cause directories to be created, which would be especially bad 262a4f78defSmrg # if $src (and thus $dsttmp) contains '*'. 263a4f78defSmrg if test ! -f "$src" && test ! -d "$src"; then 264a4f78defSmrg echo "$0: $src does not exist." >&2 265a4f78defSmrg exit 1 266a4f78defSmrg fi 267a4f78defSmrg 268a4f78defSmrg if test -z "$dst_arg"; then 269a4f78defSmrg echo "$0: no destination specified." >&2 270a4f78defSmrg exit 1 271a4f78defSmrg fi 272a4f78defSmrg dst=$dst_arg 273a4f78defSmrg 274a4f78defSmrg # If destination is a directory, append the input filename; won't work 275a4f78defSmrg # if double slashes aren't ignored. 276a4f78defSmrg if test -d "$dst"; then 277a4f78defSmrg if test "$is_target_a_directory" = never; then 278a4f78defSmrg echo "$0: $dst_arg: Is a directory" >&2 279a4f78defSmrg exit 1 280a4f78defSmrg fi 281a4f78defSmrg dstdir=$dst 282a4f78defSmrg dst=$dstdir/`basename "$src"` 283a4f78defSmrg dstdir_status=0 284a4f78defSmrg else 285a4f78defSmrg dstdir=`dirname "$dst"` 286a4f78defSmrg test -d "$dstdir" 287a4f78defSmrg dstdir_status=$? 288a4f78defSmrg fi 289a4f78defSmrg fi 290a4f78defSmrg 291a4f78defSmrg obsolete_mkdir_used=false 292a4f78defSmrg 293a4f78defSmrg if test $dstdir_status != 0; then 294a4f78defSmrg case $posix_mkdir in 295a4f78defSmrg '') 296a4f78defSmrg # Create intermediate dirs using mode 755 as modified by the umask. 297a4f78defSmrg # This is like FreeBSD 'install' as of 1997-10-28. 298a4f78defSmrg umask=`umask` 299a4f78defSmrg case $stripcmd.$umask in 300a4f78defSmrg # Optimize common cases. 301a4f78defSmrg *[2367][2367]) mkdir_umask=$umask;; 302a4f78defSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 303a4f78defSmrg 304a4f78defSmrg *[0-7]) 305a4f78defSmrg mkdir_umask=`expr $umask + 22 \ 306a4f78defSmrg - $umask % 100 % 40 + $umask % 20 \ 307a4f78defSmrg - $umask % 10 % 4 + $umask % 2 308a4f78defSmrg `;; 309a4f78defSmrg *) mkdir_umask=$umask,go-w;; 310a4f78defSmrg esac 311a4f78defSmrg 312a4f78defSmrg # With -d, create the new directory with the user-specified mode. 313a4f78defSmrg # Otherwise, rely on $mkdir_umask. 314a4f78defSmrg if test -n "$dir_arg"; then 315a4f78defSmrg mkdir_mode=-m$mode 316a4f78defSmrg else 317a4f78defSmrg mkdir_mode= 318a4f78defSmrg fi 319a4f78defSmrg 320a4f78defSmrg posix_mkdir=false 321a4f78defSmrg case $umask in 322a4f78defSmrg *[123567][0-7][0-7]) 323a4f78defSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 324a4f78defSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 325a4f78defSmrg ;; 326a4f78defSmrg *) 327a4f78defSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 328a4f78defSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 329a4f78defSmrg 330a4f78defSmrg if (umask $mkdir_umask && 331a4f78defSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 332a4f78defSmrg then 333a4f78defSmrg if test -z "$dir_arg" || { 334a4f78defSmrg # Check for POSIX incompatibilities with -m. 335a4f78defSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336a4f78defSmrg # other-writable bit of parent directory when it shouldn't. 337a4f78defSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 338a4f78defSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 339a4f78defSmrg case $ls_ld_tmpdir in 340a4f78defSmrg d????-?r-*) different_mode=700;; 341a4f78defSmrg d????-?--*) different_mode=755;; 342a4f78defSmrg *) false;; 343a4f78defSmrg esac && 344a4f78defSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 345a4f78defSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 346a4f78defSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 347a4f78defSmrg } 348a4f78defSmrg } 349a4f78defSmrg then posix_mkdir=: 350a4f78defSmrg fi 351a4f78defSmrg rmdir "$tmpdir/d" "$tmpdir" 352a4f78defSmrg else 353a4f78defSmrg # Remove any dirs left behind by ancient mkdir implementations. 354a4f78defSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 355a4f78defSmrg fi 356a4f78defSmrg trap '' 0;; 357a4f78defSmrg esac;; 358a4f78defSmrg esac 359a4f78defSmrg 360a4f78defSmrg if 361a4f78defSmrg $posix_mkdir && ( 362a4f78defSmrg umask $mkdir_umask && 363a4f78defSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 364a4f78defSmrg ) 365a4f78defSmrg then : 366a4f78defSmrg else 367a4f78defSmrg 368a4f78defSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 369a4f78defSmrg # or it failed possibly due to a race condition. Create the 370a4f78defSmrg # directory the slow way, step by step, checking for races as we go. 371a4f78defSmrg 372a4f78defSmrg case $dstdir in 373a4f78defSmrg /*) prefix='/';; 374a4f78defSmrg [-=\(\)!]*) prefix='./';; 375a4f78defSmrg *) prefix='';; 376a4f78defSmrg esac 377a4f78defSmrg 378a4f78defSmrg oIFS=$IFS 379a4f78defSmrg IFS=/ 380a4f78defSmrg set -f 381a4f78defSmrg set fnord $dstdir 382a4f78defSmrg shift 383a4f78defSmrg set +f 384a4f78defSmrg IFS=$oIFS 385a4f78defSmrg 386a4f78defSmrg prefixes= 387a4f78defSmrg 388a4f78defSmrg for d 389a4f78defSmrg do 390a4f78defSmrg test X"$d" = X && continue 391a4f78defSmrg 392a4f78defSmrg prefix=$prefix$d 393a4f78defSmrg if test -d "$prefix"; then 394a4f78defSmrg prefixes= 395a4f78defSmrg else 396a4f78defSmrg if $posix_mkdir; then 397a4f78defSmrg (umask=$mkdir_umask && 398a4f78defSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 399a4f78defSmrg # Don't fail if two instances are running concurrently. 400a4f78defSmrg test -d "$prefix" || exit 1 401a4f78defSmrg else 402a4f78defSmrg case $prefix in 403a4f78defSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 404a4f78defSmrg *) qprefix=$prefix;; 405a4f78defSmrg esac 406a4f78defSmrg prefixes="$prefixes '$qprefix'" 407a4f78defSmrg fi 408a4f78defSmrg fi 409a4f78defSmrg prefix=$prefix/ 410a4f78defSmrg done 411a4f78defSmrg 412a4f78defSmrg if test -n "$prefixes"; then 413a4f78defSmrg # Don't fail if two instances are running concurrently. 414a4f78defSmrg (umask $mkdir_umask && 415a4f78defSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 416a4f78defSmrg test -d "$dstdir" || exit 1 417a4f78defSmrg obsolete_mkdir_used=true 418a4f78defSmrg fi 419a4f78defSmrg fi 420a4f78defSmrg fi 421a4f78defSmrg 422a4f78defSmrg if test -n "$dir_arg"; then 423a4f78defSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 424a4f78defSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 425a4f78defSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 426a4f78defSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 427a4f78defSmrg else 428a4f78defSmrg 429a4f78defSmrg # Make a couple of temp file names in the proper directory. 430a4f78defSmrg dsttmp=$dstdir/_inst.$$_ 431a4f78defSmrg rmtmp=$dstdir/_rm.$$_ 432a4f78defSmrg 433a4f78defSmrg # Trap to clean up those temp files at exit. 434a4f78defSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 435a4f78defSmrg 436a4f78defSmrg # Copy the file name to the temp name. 437a4f78defSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 438a4f78defSmrg 439a4f78defSmrg # and set any options; do chmod last to preserve setuid bits. 440a4f78defSmrg # 441a4f78defSmrg # If any of these fail, we abort the whole thing. If we want to 442a4f78defSmrg # ignore errors from any of these, just make sure not to ignore 443a4f78defSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 444a4f78defSmrg # 445a4f78defSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 446a4f78defSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 447a4f78defSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 448a4f78defSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 449a4f78defSmrg 450a4f78defSmrg # If -C, don't bother to copy if it wouldn't change the file. 451a4f78defSmrg if $copy_on_change && 452a4f78defSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 453a4f78defSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454a4f78defSmrg set -f && 455a4f78defSmrg set X $old && old=:$2:$4:$5:$6 && 456a4f78defSmrg set X $new && new=:$2:$4:$5:$6 && 457a4f78defSmrg set +f && 458a4f78defSmrg test "$old" = "$new" && 459a4f78defSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 460a4f78defSmrg then 461a4f78defSmrg rm -f "$dsttmp" 462a4f78defSmrg else 463a4f78defSmrg # Rename the file to the real destination. 464a4f78defSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 465a4f78defSmrg 466a4f78defSmrg # The rename failed, perhaps because mv can't rename something else 467a4f78defSmrg # to itself, or perhaps because mv is so ancient that it does not 468a4f78defSmrg # support -f. 469a4f78defSmrg { 470a4f78defSmrg # Now remove or move aside any old file at destination location. 471a4f78defSmrg # We try this two ways since rm can't unlink itself on some 472a4f78defSmrg # systems and the destination file might be busy for other 473a4f78defSmrg # reasons. In this case, the final cleanup might fail but the new 474a4f78defSmrg # file should still install successfully. 475a4f78defSmrg { 476a4f78defSmrg test ! -f "$dst" || 477a4f78defSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 478a4f78defSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 479a4f78defSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 480a4f78defSmrg } || 481a4f78defSmrg { echo "$0: cannot unlink or rename $dst" >&2 482a4f78defSmrg (exit 1); exit 1 483a4f78defSmrg } 484a4f78defSmrg } && 485a4f78defSmrg 486a4f78defSmrg # Now rename the file to the real destination. 487a4f78defSmrg $doit $mvcmd "$dsttmp" "$dst" 488a4f78defSmrg } 489a4f78defSmrg fi || exit 1 490a4f78defSmrg 491a4f78defSmrg trap '' 0 492a4f78defSmrg fi 493a4f78defSmrgdone 494a4f78defSmrg 495a4f78defSmrg# Local variables: 496a4f78defSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 497a4f78defSmrg# time-stamp-start: "scriptversion=" 498a4f78defSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 499a4f78defSmrg# time-stamp-time-zone: "UTC" 500a4f78defSmrg# time-stamp-end: "; # UTC" 501a4f78defSmrg# End: 502