annotate install-sh @ 1442:204ca664b5d6

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