annotate install-sh @ 1781:25824a0e8bf1

Change propagation of source value to textarea
author Adam Chlipala <adam@chlipala.net>
date Fri, 13 Jul 2012 09:01:01 -0400
parents 27d68ccb2c9e
children 6a621a625b04
rev   line source
adamc@1133 1 #!/bin/sh
adamc@1133 2 # install - install a program, script, or datafile
adamc@1133 3
adam@1693 4 scriptversion=2011-01-19.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
adam@1693 159 # Protect names problematic for `test' and other utilities.
adam@1693 160 case $dst_arg in
adam@1693 161 -* | [=\(\)!]) dst_arg=./$dst_arg;;
adam@1693 162 esac
adamc@1133 163 shift;;
adamc@1133 164
adamc@1133 165 -T) no_target_directory=true;;
adamc@1133 166
adamc@1133 167 --version) echo "$0 $scriptversion"; exit $?;;
adamc@1133 168
adamc@1133 169 --) shift
adamc@1133 170 break;;
adamc@1133 171
adamc@1133 172 -*) echo "$0: invalid option: $1" >&2
adamc@1133 173 exit 1;;
adamc@1133 174
adamc@1133 175 *) break;;
adamc@1133 176 esac
adamc@1133 177 shift
adamc@1133 178 done
adamc@1133 179
adamc@1133 180 if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
adamc@1133 181 # When -d is used, all remaining arguments are directories to create.
adamc@1133 182 # When -t is used, the destination is already specified.
adamc@1133 183 # Otherwise, the last argument is the destination. Remove it from $@.
adamc@1133 184 for arg
adamc@1133 185 do
adamc@1133 186 if test -n "$dst_arg"; then
adamc@1133 187 # $@ is not empty: it contains at least $arg.
adamc@1133 188 set fnord "$@" "$dst_arg"
adamc@1133 189 shift # fnord
adamc@1133 190 fi
adamc@1133 191 shift # arg
adamc@1133 192 dst_arg=$arg
adam@1693 193 # Protect names problematic for `test' and other utilities.
adam@1693 194 case $dst_arg in
adam@1693 195 -* | [=\(\)!]) dst_arg=./$dst_arg;;
adam@1693 196 esac
adamc@1133 197 done
adamc@1133 198 fi
adamc@1133 199
adamc@1133 200 if test $# -eq 0; then
adamc@1133 201 if test -z "$dir_arg"; then
adamc@1133 202 echo "$0: no input file specified." >&2
adamc@1133 203 exit 1
adamc@1133 204 fi
adamc@1133 205 # It's OK to call `install-sh -d' without argument.
adamc@1133 206 # This can happen when creating conditional directories.
adamc@1133 207 exit 0
adamc@1133 208 fi
adamc@1133 209
adamc@1133 210 if test -z "$dir_arg"; then
adam@1693 211 do_exit='(exit $ret); exit $ret'
adam@1693 212 trap "ret=129; $do_exit" 1
adam@1693 213 trap "ret=130; $do_exit" 2
adam@1693 214 trap "ret=141; $do_exit" 13
adam@1693 215 trap "ret=143; $do_exit" 15
adamc@1133 216
adamc@1133 217 # Set umask so as not to create temps with too-generous modes.
adamc@1133 218 # However, 'strip' requires both read and write access to temps.
adamc@1133 219 case $mode in
adamc@1133 220 # Optimize common cases.
adamc@1133 221 *644) cp_umask=133;;
adamc@1133 222 *755) cp_umask=22;;
adamc@1133 223
adamc@1133 224 *[0-7])
adamc@1133 225 if test -z "$stripcmd"; then
adamc@1133 226 u_plus_rw=
adamc@1133 227 else
adamc@1133 228 u_plus_rw='% 200'
adamc@1133 229 fi
adamc@1133 230 cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
adamc@1133 231 *)
adamc@1133 232 if test -z "$stripcmd"; then
adamc@1133 233 u_plus_rw=
adamc@1133 234 else
adamc@1133 235 u_plus_rw=,u+rw
adamc@1133 236 fi
adamc@1133 237 cp_umask=$mode$u_plus_rw;;
adamc@1133 238 esac
adamc@1133 239 fi
adamc@1133 240
adamc@1133 241 for src
adamc@1133 242 do
adam@1693 243 # Protect names problematic for `test' and other utilities.
adamc@1133 244 case $src in
adam@1693 245 -* | [=\(\)!]) src=./$src;;
adamc@1133 246 esac
adamc@1133 247
adamc@1133 248 if test -n "$dir_arg"; then
adamc@1133 249 dst=$src
adamc@1133 250 dstdir=$dst
adamc@1133 251 test -d "$dstdir"
adamc@1133 252 dstdir_status=$?
adamc@1133 253 else
adamc@1133 254
adamc@1133 255 # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
adamc@1133 256 # might cause directories to be created, which would be especially bad
adamc@1133 257 # if $src (and thus $dsttmp) contains '*'.
adamc@1133 258 if test ! -f "$src" && test ! -d "$src"; then
adamc@1133 259 echo "$0: $src does not exist." >&2
adamc@1133 260 exit 1
adamc@1133 261 fi
adamc@1133 262
adamc@1133 263 if test -z "$dst_arg"; then
adamc@1133 264 echo "$0: no destination specified." >&2
adamc@1133 265 exit 1
adamc@1133 266 fi
adamc@1133 267 dst=$dst_arg
adamc@1133 268
adamc@1133 269 # If destination is a directory, append the input filename; won't work
adamc@1133 270 # if double slashes aren't ignored.
adamc@1133 271 if test -d "$dst"; then
adamc@1133 272 if test -n "$no_target_directory"; then
adamc@1133 273 echo "$0: $dst_arg: Is a directory" >&2
adamc@1133 274 exit 1
adamc@1133 275 fi
adamc@1133 276 dstdir=$dst
adamc@1133 277 dst=$dstdir/`basename "$src"`
adamc@1133 278 dstdir_status=0
adamc@1133 279 else
adamc@1133 280 # Prefer dirname, but fall back on a substitute if dirname fails.
adamc@1133 281 dstdir=`
adamc@1133 282 (dirname "$dst") 2>/dev/null ||
adamc@1133 283 expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
adamc@1133 284 X"$dst" : 'X\(//\)[^/]' \| \
adamc@1133 285 X"$dst" : 'X\(//\)$' \| \
adamc@1133 286 X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
adamc@1133 287 echo X"$dst" |
adamc@1133 288 sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
adamc@1133 289 s//\1/
adamc@1133 290 q
adamc@1133 291 }
adamc@1133 292 /^X\(\/\/\)[^/].*/{
adamc@1133 293 s//\1/
adamc@1133 294 q
adamc@1133 295 }
adamc@1133 296 /^X\(\/\/\)$/{
adamc@1133 297 s//\1/
adamc@1133 298 q
adamc@1133 299 }
adamc@1133 300 /^X\(\/\).*/{
adamc@1133 301 s//\1/
adamc@1133 302 q
adamc@1133 303 }
adamc@1133 304 s/.*/./; q'
adamc@1133 305 `
adamc@1133 306
adamc@1133 307 test -d "$dstdir"
adamc@1133 308 dstdir_status=$?
adamc@1133 309 fi
adamc@1133 310 fi
adamc@1133 311
adamc@1133 312 obsolete_mkdir_used=false
adamc@1133 313
adamc@1133 314 if test $dstdir_status != 0; then
adamc@1133 315 case $posix_mkdir in
adamc@1133 316 '')
adamc@1133 317 # Create intermediate dirs using mode 755 as modified by the umask.
adamc@1133 318 # This is like FreeBSD 'install' as of 1997-10-28.
adamc@1133 319 umask=`umask`
adamc@1133 320 case $stripcmd.$umask in
adamc@1133 321 # Optimize common cases.
adamc@1133 322 *[2367][2367]) mkdir_umask=$umask;;
adamc@1133 323 .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
adamc@1133 324
adamc@1133 325 *[0-7])
adamc@1133 326 mkdir_umask=`expr $umask + 22 \
adamc@1133 327 - $umask % 100 % 40 + $umask % 20 \
adamc@1133 328 - $umask % 10 % 4 + $umask % 2
adamc@1133 329 `;;
adamc@1133 330 *) mkdir_umask=$umask,go-w;;
adamc@1133 331 esac
adamc@1133 332
adamc@1133 333 # With -d, create the new directory with the user-specified mode.
adamc@1133 334 # Otherwise, rely on $mkdir_umask.
adamc@1133 335 if test -n "$dir_arg"; then
adamc@1133 336 mkdir_mode=-m$mode
adamc@1133 337 else
adamc@1133 338 mkdir_mode=
adamc@1133 339 fi
adamc@1133 340
adamc@1133 341 posix_mkdir=false
adamc@1133 342 case $umask in
adamc@1133 343 *[123567][0-7][0-7])
adamc@1133 344 # POSIX mkdir -p sets u+wx bits regardless of umask, which
adamc@1133 345 # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
adamc@1133 346 ;;
adamc@1133 347 *)
adamc@1133 348 tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
adamc@1133 349 trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
adamc@1133 350
adamc@1133 351 if (umask $mkdir_umask &&
adamc@1133 352 exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
adamc@1133 353 then
adamc@1133 354 if test -z "$dir_arg" || {
adamc@1133 355 # Check for POSIX incompatibilities with -m.
adamc@1133 356 # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
adamc@1133 357 # other-writeable bit of parent directory when it shouldn't.
adamc@1133 358 # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
adamc@1133 359 ls_ld_tmpdir=`ls -ld "$tmpdir"`
adamc@1133 360 case $ls_ld_tmpdir in
adamc@1133 361 d????-?r-*) different_mode=700;;
adamc@1133 362 d????-?--*) different_mode=755;;
adamc@1133 363 *) false;;
adamc@1133 364 esac &&
adamc@1133 365 $mkdirprog -m$different_mode -p -- "$tmpdir" && {
adamc@1133 366 ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
adamc@1133 367 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
adamc@1133 368 }
adamc@1133 369 }
adamc@1133 370 then posix_mkdir=:
adamc@1133 371 fi
adamc@1133 372 rmdir "$tmpdir/d" "$tmpdir"
adamc@1133 373 else
adamc@1133 374 # Remove any dirs left behind by ancient mkdir implementations.
adamc@1133 375 rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
adamc@1133 376 fi
adamc@1133 377 trap '' 0;;
adamc@1133 378 esac;;
adamc@1133 379 esac
adamc@1133 380
adamc@1133 381 if
adamc@1133 382 $posix_mkdir && (
adamc@1133 383 umask $mkdir_umask &&
adamc@1133 384 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
adamc@1133 385 )
adamc@1133 386 then :
adamc@1133 387 else
adamc@1133 388
adamc@1133 389 # The umask is ridiculous, or mkdir does not conform to POSIX,
adamc@1133 390 # or it failed possibly due to a race condition. Create the
adamc@1133 391 # directory the slow way, step by step, checking for races as we go.
adamc@1133 392
adamc@1133 393 case $dstdir in
adamc@1133 394 /*) prefix='/';;
adam@1693 395 [-=\(\)!]*) prefix='./';;
adamc@1133 396 *) prefix='';;
adamc@1133 397 esac
adamc@1133 398
adamc@1133 399 eval "$initialize_posix_glob"
adamc@1133 400
adamc@1133 401 oIFS=$IFS
adamc@1133 402 IFS=/
adamc@1133 403 $posix_glob set -f
adamc@1133 404 set fnord $dstdir
adamc@1133 405 shift
adamc@1133 406 $posix_glob set +f
adamc@1133 407 IFS=$oIFS
adamc@1133 408
adamc@1133 409 prefixes=
adamc@1133 410
adamc@1133 411 for d
adamc@1133 412 do
adam@1693 413 test X"$d" = X && continue
adamc@1133 414
adamc@1133 415 prefix=$prefix$d
adamc@1133 416 if test -d "$prefix"; then
adamc@1133 417 prefixes=
adamc@1133 418 else
adamc@1133 419 if $posix_mkdir; then
adamc@1133 420 (umask=$mkdir_umask &&
adamc@1133 421 $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
adamc@1133 422 # Don't fail if two instances are running concurrently.
adamc@1133 423 test -d "$prefix" || exit 1
adamc@1133 424 else
adamc@1133 425 case $prefix in
adamc@1133 426 *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
adamc@1133 427 *) qprefix=$prefix;;
adamc@1133 428 esac
adamc@1133 429 prefixes="$prefixes '$qprefix'"
adamc@1133 430 fi
adamc@1133 431 fi
adamc@1133 432 prefix=$prefix/
adamc@1133 433 done
adamc@1133 434
adamc@1133 435 if test -n "$prefixes"; then
adamc@1133 436 # Don't fail if two instances are running concurrently.
adamc@1133 437 (umask $mkdir_umask &&
adamc@1133 438 eval "\$doit_exec \$mkdirprog $prefixes") ||
adamc@1133 439 test -d "$dstdir" || exit 1
adamc@1133 440 obsolete_mkdir_used=true
adamc@1133 441 fi
adamc@1133 442 fi
adamc@1133 443 fi
adamc@1133 444
adamc@1133 445 if test -n "$dir_arg"; then
adamc@1133 446 { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
adamc@1133 447 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
adamc@1133 448 { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
adamc@1133 449 test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
adamc@1133 450 else
adamc@1133 451
adamc@1133 452 # Make a couple of temp file names in the proper directory.
adamc@1133 453 dsttmp=$dstdir/_inst.$$_
adamc@1133 454 rmtmp=$dstdir/_rm.$$_
adamc@1133 455
adamc@1133 456 # Trap to clean up those temp files at exit.
adamc@1133 457 trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
adamc@1133 458
adamc@1133 459 # Copy the file name to the temp name.
adamc@1133 460 (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
adamc@1133 461
adamc@1133 462 # and set any options; do chmod last to preserve setuid bits.
adamc@1133 463 #
adamc@1133 464 # If any of these fail, we abort the whole thing. If we want to
adamc@1133 465 # ignore errors from any of these, just make sure not to ignore
adamc@1133 466 # errors from the above "$doit $cpprog $src $dsttmp" command.
adamc@1133 467 #
adamc@1133 468 { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
adamc@1133 469 { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
adamc@1133 470 { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
adamc@1133 471 { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
adamc@1133 472
adamc@1133 473 # If -C, don't bother to copy if it wouldn't change the file.
adamc@1133 474 if $copy_on_change &&
adamc@1133 475 old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
adamc@1133 476 new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
adamc@1133 477
adamc@1133 478 eval "$initialize_posix_glob" &&
adamc@1133 479 $posix_glob set -f &&
adamc@1133 480 set X $old && old=:$2:$4:$5:$6 &&
adamc@1133 481 set X $new && new=:$2:$4:$5:$6 &&
adamc@1133 482 $posix_glob set +f &&
adamc@1133 483
adamc@1133 484 test "$old" = "$new" &&
adamc@1133 485 $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
adamc@1133 486 then
adamc@1133 487 rm -f "$dsttmp"
adamc@1133 488 else
adamc@1133 489 # Rename the file to the real destination.
adamc@1133 490 $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
adamc@1133 491
adamc@1133 492 # The rename failed, perhaps because mv can't rename something else
adamc@1133 493 # to itself, or perhaps because mv is so ancient that it does not
adamc@1133 494 # support -f.
adamc@1133 495 {
adamc@1133 496 # Now remove or move aside any old file at destination location.
adamc@1133 497 # We try this two ways since rm can't unlink itself on some
adamc@1133 498 # systems and the destination file might be busy for other
adamc@1133 499 # reasons. In this case, the final cleanup might fail but the new
adamc@1133 500 # file should still install successfully.
adamc@1133 501 {
adamc@1133 502 test ! -f "$dst" ||
adamc@1133 503 $doit $rmcmd -f "$dst" 2>/dev/null ||
adamc@1133 504 { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
adamc@1133 505 { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
adamc@1133 506 } ||
adamc@1133 507 { echo "$0: cannot unlink or rename $dst" >&2
adamc@1133 508 (exit 1); exit 1
adamc@1133 509 }
adamc@1133 510 } &&
adamc@1133 511
adamc@1133 512 # Now rename the file to the real destination.
adamc@1133 513 $doit $mvcmd "$dsttmp" "$dst"
adamc@1133 514 }
adamc@1133 515 fi || exit 1
adamc@1133 516
adamc@1133 517 trap '' 0
adamc@1133 518 fi
adamc@1133 519 done
adamc@1133 520
adamc@1133 521 # Local variables:
adamc@1133 522 # eval: (add-hook 'write-file-hooks 'time-stamp)
adamc@1133 523 # time-stamp-start: "scriptversion="
adamc@1133 524 # time-stamp-format: "%:y-%02m-%02d.%02H"
adamc@1133 525 # time-stamp-time-zone: "UTC"
adamc@1133 526 # time-stamp-end: "; # UTC"
adamc@1133 527 # End: