install-sh revision 8831d3fb
1100ae103Smrg#!/bin/sh 2100ae103Smrg# install - install a program, script, or datafile 3100ae103Smrg 48831d3fbSmrgscriptversion=2011-01-19.21; # UTC 5100ae103Smrg 6100ae103Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7100ae103Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8100ae103Smrg# following copyright and license. 9100ae103Smrg# 10100ae103Smrg# Copyright (C) 1994 X Consortium 11100ae103Smrg# 12100ae103Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13100ae103Smrg# of this software and associated documentation files (the "Software"), to 14100ae103Smrg# deal in the Software without restriction, including without limitation the 15100ae103Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16100ae103Smrg# sell copies of the Software, and to permit persons to whom the Software is 17100ae103Smrg# furnished to do so, subject to the following conditions: 18100ae103Smrg# 19100ae103Smrg# The above copyright notice and this permission notice shall be included in 20100ae103Smrg# all copies or substantial portions of the Software. 21100ae103Smrg# 22100ae103Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23100ae103Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24100ae103Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25100ae103Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26100ae103Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27100ae103Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28100ae103Smrg# 29100ae103Smrg# Except as contained in this notice, the name of the X Consortium shall not 30100ae103Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31100ae103Smrg# ings in this Software without prior written authorization from the X Consor- 32100ae103Smrg# tium. 33100ae103Smrg# 34100ae103Smrg# 35100ae103Smrg# FSF changes to this file are in the public domain. 36100ae103Smrg# 37100ae103Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38100ae103Smrg# `make' implicit rules from creating a file called install from it 39100ae103Smrg# when there is no Makefile. 40100ae103Smrg# 41100ae103Smrg# This script is compatible with the BSD install script, but was written 42165cb819Smrg# from scratch. 43165cb819Smrg 44165cb819Smrgnl=' 45165cb819Smrg' 46165cb819SmrgIFS=" "" $nl" 47100ae103Smrg 48100ae103Smrg# set DOITPROG to echo to test this script 49100ae103Smrg 50100ae103Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51165cb819Smrgdoit=${DOITPROG-} 52165cb819Smrgif test -z "$doit"; then 53165cb819Smrg doit_exec=exec 54165cb819Smrgelse 55165cb819Smrg doit_exec=$doit 56165cb819Smrgfi 57100ae103Smrg 58165cb819Smrg# Put in absolute file names if you don't have them in your path; 59165cb819Smrg# or use environment vars. 60165cb819Smrg 61165cb819Smrgchgrpprog=${CHGRPPROG-chgrp} 62165cb819Smrgchmodprog=${CHMODPROG-chmod} 63165cb819Smrgchownprog=${CHOWNPROG-chown} 64165cb819Smrgcmpprog=${CMPPROG-cmp} 65165cb819Smrgcpprog=${CPPROG-cp} 66165cb819Smrgmkdirprog=${MKDIRPROG-mkdir} 67165cb819Smrgmvprog=${MVPROG-mv} 68165cb819Smrgrmprog=${RMPROG-rm} 69165cb819Smrgstripprog=${STRIPPROG-strip} 70165cb819Smrg 71165cb819Smrgposix_glob='?' 72165cb819Smrginitialize_posix_glob=' 73165cb819Smrg test "$posix_glob" != "?" || { 74165cb819Smrg if (set -f) 2>/dev/null; then 75165cb819Smrg posix_glob= 76165cb819Smrg else 77165cb819Smrg posix_glob=: 78165cb819Smrg fi 79165cb819Smrg } 80165cb819Smrg' 81100ae103Smrg 82165cb819Smrgposix_mkdir= 83165cb819Smrg 84165cb819Smrg# Desired mode of installed file. 85165cb819Smrgmode=0755 86100ae103Smrg 87100ae103Smrgchgrpcmd= 88165cb819Smrgchmodcmd=$chmodprog 89165cb819Smrgchowncmd= 90165cb819Smrgmvcmd=$mvprog 91100ae103Smrgrmcmd="$rmprog -f" 92165cb819Smrgstripcmd= 93165cb819Smrg 94100ae103Smrgsrc= 95100ae103Smrgdst= 96100ae103Smrgdir_arg= 97165cb819Smrgdst_arg= 98165cb819Smrg 99165cb819Smrgcopy_on_change=false 100100ae103Smrgno_target_directory= 101100ae103Smrg 102165cb819Smrgusage="\ 103165cb819SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104100ae103Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105100ae103Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106100ae103Smrg or: $0 [OPTION]... -d DIRECTORIES... 107100ae103Smrg 108100ae103SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109100ae103SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110100ae103SmrgIn the 4th, create DIRECTORIES. 111100ae103Smrg 112100ae103SmrgOptions: 113165cb819Smrg --help display this help and exit. 114165cb819Smrg --version display version info and exit. 115165cb819Smrg 116165cb819Smrg -c (ignored) 117165cb819Smrg -C install only if different (preserve the last data modification time) 118165cb819Smrg -d create directories instead of installing files. 119165cb819Smrg -g GROUP $chgrpprog installed files to GROUP. 120165cb819Smrg -m MODE $chmodprog installed files to MODE. 121165cb819Smrg -o USER $chownprog installed files to USER. 122165cb819Smrg -s $stripprog installed files. 123165cb819Smrg -t DIRECTORY install into DIRECTORY. 124165cb819Smrg -T report an error if DSTFILE is a directory. 125100ae103Smrg 126100ae103SmrgEnvironment variables override the default commands: 127165cb819Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128165cb819Smrg RMPROG STRIPPROG 129100ae103Smrg" 130100ae103Smrg 131165cb819Smrgwhile test $# -ne 0; do 132100ae103Smrg case $1 in 133165cb819Smrg -c) ;; 134165cb819Smrg 135165cb819Smrg -C) copy_on_change=true;; 136100ae103Smrg 137165cb819Smrg -d) dir_arg=true;; 138100ae103Smrg 139100ae103Smrg -g) chgrpcmd="$chgrpprog $2" 140165cb819Smrg shift;; 141100ae103Smrg 142100ae103Smrg --help) echo "$usage"; exit $?;; 143100ae103Smrg 144165cb819Smrg -m) mode=$2 145165cb819Smrg case $mode in 146165cb819Smrg *' '* | *' '* | *' 147165cb819Smrg'* | *'*'* | *'?'* | *'['*) 148165cb819Smrg echo "$0: invalid mode: $mode" >&2 149165cb819Smrg exit 1;; 150165cb819Smrg esac 151165cb819Smrg shift;; 152100ae103Smrg 153100ae103Smrg -o) chowncmd="$chownprog $2" 154165cb819Smrg shift;; 155100ae103Smrg 156165cb819Smrg -s) stripcmd=$stripprog;; 157100ae103Smrg 158165cb819Smrg -t) dst_arg=$2 1598831d3fbSmrg # Protect names problematic for `test' and other utilities. 1608831d3fbSmrg case $dst_arg in 1618831d3fbSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1628831d3fbSmrg esac 163165cb819Smrg shift;; 164100ae103Smrg 165165cb819Smrg -T) no_target_directory=true;; 166100ae103Smrg 167100ae103Smrg --version) echo "$0 $scriptversion"; exit $?;; 168100ae103Smrg 169165cb819Smrg --) shift 170100ae103Smrg break;; 171165cb819Smrg 172165cb819Smrg -*) echo "$0: invalid option: $1" >&2 173165cb819Smrg exit 1;; 174165cb819Smrg 175165cb819Smrg *) break;; 176100ae103Smrg esac 177165cb819Smrg shift 178100ae103Smrgdone 179100ae103Smrg 180165cb819Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181165cb819Smrg # When -d is used, all remaining arguments are directories to create. 182165cb819Smrg # When -t is used, the destination is already specified. 183165cb819Smrg # Otherwise, the last argument is the destination. Remove it from $@. 184165cb819Smrg for arg 185165cb819Smrg do 186165cb819Smrg if test -n "$dst_arg"; then 187165cb819Smrg # $@ is not empty: it contains at least $arg. 188165cb819Smrg set fnord "$@" "$dst_arg" 189165cb819Smrg shift # fnord 190165cb819Smrg fi 191165cb819Smrg shift # arg 192165cb819Smrg dst_arg=$arg 1938831d3fbSmrg # Protect names problematic for `test' and other utilities. 1948831d3fbSmrg case $dst_arg in 1958831d3fbSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1968831d3fbSmrg esac 197165cb819Smrg done 198165cb819Smrgfi 199165cb819Smrg 200165cb819Smrgif test $# -eq 0; then 201100ae103Smrg if test -z "$dir_arg"; then 202100ae103Smrg echo "$0: no input file specified." >&2 203100ae103Smrg exit 1 204100ae103Smrg fi 205100ae103Smrg # It's OK to call `install-sh -d' without argument. 206100ae103Smrg # This can happen when creating conditional directories. 207100ae103Smrg exit 0 208100ae103Smrgfi 209100ae103Smrg 210165cb819Smrgif test -z "$dir_arg"; then 2118831d3fbSmrg do_exit='(exit $ret); exit $ret' 2128831d3fbSmrg trap "ret=129; $do_exit" 1 2138831d3fbSmrg trap "ret=130; $do_exit" 2 2148831d3fbSmrg trap "ret=141; $do_exit" 13 2158831d3fbSmrg trap "ret=143; $do_exit" 15 216165cb819Smrg 217165cb819Smrg # Set umask so as not to create temps with too-generous modes. 218165cb819Smrg # However, 'strip' requires both read and write access to temps. 219165cb819Smrg case $mode in 220165cb819Smrg # Optimize common cases. 221165cb819Smrg *644) cp_umask=133;; 222165cb819Smrg *755) cp_umask=22;; 223165cb819Smrg 224165cb819Smrg *[0-7]) 225165cb819Smrg if test -z "$stripcmd"; then 226165cb819Smrg u_plus_rw= 227165cb819Smrg else 228165cb819Smrg u_plus_rw='% 200' 229165cb819Smrg fi 230165cb819Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231165cb819Smrg *) 232165cb819Smrg if test -z "$stripcmd"; then 233165cb819Smrg u_plus_rw= 234165cb819Smrg else 235165cb819Smrg u_plus_rw=,u+rw 236165cb819Smrg fi 237165cb819Smrg cp_umask=$mode$u_plus_rw;; 238165cb819Smrg esac 239165cb819Smrgfi 240165cb819Smrg 241100ae103Smrgfor src 242100ae103Smrgdo 2438831d3fbSmrg # Protect names problematic for `test' and other utilities. 244100ae103Smrg case $src in 2458831d3fbSmrg -* | [=\(\)!]) src=./$src;; 246100ae103Smrg esac 247100ae103Smrg 248100ae103Smrg if test -n "$dir_arg"; then 249100ae103Smrg dst=$src 250165cb819Smrg dstdir=$dst 251165cb819Smrg test -d "$dstdir" 252165cb819Smrg dstdir_status=$? 253100ae103Smrg else 254165cb819Smrg 255100ae103Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256100ae103Smrg # might cause directories to be created, which would be especially bad 257100ae103Smrg # if $src (and thus $dsttmp) contains '*'. 258100ae103Smrg if test ! -f "$src" && test ! -d "$src"; then 259100ae103Smrg echo "$0: $src does not exist." >&2 260100ae103Smrg exit 1 261100ae103Smrg fi 262100ae103Smrg 263165cb819Smrg if test -z "$dst_arg"; then 264100ae103Smrg echo "$0: no destination specified." >&2 265100ae103Smrg exit 1 266100ae103Smrg fi 267165cb819Smrg dst=$dst_arg 268100ae103Smrg 269100ae103Smrg # If destination is a directory, append the input filename; won't work 270100ae103Smrg # if double slashes aren't ignored. 271100ae103Smrg if test -d "$dst"; then 272100ae103Smrg if test -n "$no_target_directory"; then 273165cb819Smrg echo "$0: $dst_arg: Is a directory" >&2 274100ae103Smrg exit 1 275100ae103Smrg fi 276165cb819Smrg dstdir=$dst 277165cb819Smrg dst=$dstdir/`basename "$src"` 278165cb819Smrg dstdir_status=0 279165cb819Smrg else 280165cb819Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 281165cb819Smrg dstdir=` 282165cb819Smrg (dirname "$dst") 2>/dev/null || 283165cb819Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284165cb819Smrg X"$dst" : 'X\(//\)[^/]' \| \ 285165cb819Smrg X"$dst" : 'X\(//\)$' \| \ 286165cb819Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287165cb819Smrg echo X"$dst" | 288165cb819Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289165cb819Smrg s//\1/ 290165cb819Smrg q 291165cb819Smrg } 292165cb819Smrg /^X\(\/\/\)[^/].*/{ 293165cb819Smrg s//\1/ 294165cb819Smrg q 295165cb819Smrg } 296165cb819Smrg /^X\(\/\/\)$/{ 297165cb819Smrg s//\1/ 298165cb819Smrg q 299165cb819Smrg } 300165cb819Smrg /^X\(\/\).*/{ 301165cb819Smrg s//\1/ 302165cb819Smrg q 303165cb819Smrg } 304165cb819Smrg s/.*/./; q' 305165cb819Smrg ` 306165cb819Smrg 307165cb819Smrg test -d "$dstdir" 308165cb819Smrg dstdir_status=$? 309100ae103Smrg fi 310100ae103Smrg fi 311100ae103Smrg 312165cb819Smrg obsolete_mkdir_used=false 313165cb819Smrg 314165cb819Smrg if test $dstdir_status != 0; then 315165cb819Smrg case $posix_mkdir in 316165cb819Smrg '') 317165cb819Smrg # Create intermediate dirs using mode 755 as modified by the umask. 318165cb819Smrg # This is like FreeBSD 'install' as of 1997-10-28. 319165cb819Smrg umask=`umask` 320165cb819Smrg case $stripcmd.$umask in 321165cb819Smrg # Optimize common cases. 322165cb819Smrg *[2367][2367]) mkdir_umask=$umask;; 323165cb819Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324165cb819Smrg 325165cb819Smrg *[0-7]) 326165cb819Smrg mkdir_umask=`expr $umask + 22 \ 327165cb819Smrg - $umask % 100 % 40 + $umask % 20 \ 328165cb819Smrg - $umask % 10 % 4 + $umask % 2 329165cb819Smrg `;; 330165cb819Smrg *) mkdir_umask=$umask,go-w;; 331165cb819Smrg esac 332165cb819Smrg 333165cb819Smrg # With -d, create the new directory with the user-specified mode. 334165cb819Smrg # Otherwise, rely on $mkdir_umask. 335165cb819Smrg if test -n "$dir_arg"; then 336165cb819Smrg mkdir_mode=-m$mode 337165cb819Smrg else 338165cb819Smrg mkdir_mode= 339165cb819Smrg fi 340165cb819Smrg 341165cb819Smrg posix_mkdir=false 342165cb819Smrg case $umask in 343165cb819Smrg *[123567][0-7][0-7]) 344165cb819Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345165cb819Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346165cb819Smrg ;; 347165cb819Smrg *) 348165cb819Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349165cb819Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350165cb819Smrg 351165cb819Smrg if (umask $mkdir_umask && 352165cb819Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353165cb819Smrg then 354165cb819Smrg if test -z "$dir_arg" || { 355165cb819Smrg # Check for POSIX incompatibilities with -m. 356165cb819Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357165cb819Smrg # other-writeable bit of parent directory when it shouldn't. 358165cb819Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359165cb819Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360165cb819Smrg case $ls_ld_tmpdir in 361165cb819Smrg d????-?r-*) different_mode=700;; 362165cb819Smrg d????-?--*) different_mode=755;; 363165cb819Smrg *) false;; 364165cb819Smrg esac && 365165cb819Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366165cb819Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367165cb819Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368165cb819Smrg } 369165cb819Smrg } 370165cb819Smrg then posix_mkdir=: 371165cb819Smrg fi 372165cb819Smrg rmdir "$tmpdir/d" "$tmpdir" 373165cb819Smrg else 374165cb819Smrg # Remove any dirs left behind by ancient mkdir implementations. 375165cb819Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376165cb819Smrg fi 377165cb819Smrg trap '' 0;; 378165cb819Smrg esac;; 379165cb819Smrg esac 380100ae103Smrg 381165cb819Smrg if 382165cb819Smrg $posix_mkdir && ( 383165cb819Smrg umask $mkdir_umask && 384165cb819Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385165cb819Smrg ) 386165cb819Smrg then : 387165cb819Smrg else 388100ae103Smrg 389165cb819Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390165cb819Smrg # or it failed possibly due to a race condition. Create the 391165cb819Smrg # directory the slow way, step by step, checking for races as we go. 392100ae103Smrg 393165cb819Smrg case $dstdir in 394165cb819Smrg /*) prefix='/';; 3958831d3fbSmrg [-=\(\)!]*) prefix='./';; 396165cb819Smrg *) prefix='';; 397165cb819Smrg esac 398100ae103Smrg 399165cb819Smrg eval "$initialize_posix_glob" 400100ae103Smrg 401165cb819Smrg oIFS=$IFS 402165cb819Smrg IFS=/ 403165cb819Smrg $posix_glob set -f 404165cb819Smrg set fnord $dstdir 405100ae103Smrg shift 406165cb819Smrg $posix_glob set +f 407165cb819Smrg IFS=$oIFS 408165cb819Smrg 409165cb819Smrg prefixes= 410165cb819Smrg 411165cb819Smrg for d 412165cb819Smrg do 4138831d3fbSmrg test X"$d" = X && continue 414165cb819Smrg 415165cb819Smrg prefix=$prefix$d 416165cb819Smrg if test -d "$prefix"; then 417165cb819Smrg prefixes= 418165cb819Smrg else 419165cb819Smrg if $posix_mkdir; then 420165cb819Smrg (umask=$mkdir_umask && 421165cb819Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422165cb819Smrg # Don't fail if two instances are running concurrently. 423165cb819Smrg test -d "$prefix" || exit 1 424165cb819Smrg else 425165cb819Smrg case $prefix in 426165cb819Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427165cb819Smrg *) qprefix=$prefix;; 428165cb819Smrg esac 429165cb819Smrg prefixes="$prefixes '$qprefix'" 430165cb819Smrg fi 431165cb819Smrg fi 432165cb819Smrg prefix=$prefix/ 433165cb819Smrg done 434165cb819Smrg 435165cb819Smrg if test -n "$prefixes"; then 436165cb819Smrg # Don't fail if two instances are running concurrently. 437165cb819Smrg (umask $mkdir_umask && 438165cb819Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 439165cb819Smrg test -d "$dstdir" || exit 1 440165cb819Smrg obsolete_mkdir_used=true 441100ae103Smrg fi 442165cb819Smrg fi 443100ae103Smrg fi 444100ae103Smrg 445100ae103Smrg if test -n "$dir_arg"; then 446165cb819Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447165cb819Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448165cb819Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449165cb819Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450100ae103Smrg else 451100ae103Smrg 452100ae103Smrg # Make a couple of temp file names in the proper directory. 453100ae103Smrg dsttmp=$dstdir/_inst.$$_ 454100ae103Smrg rmtmp=$dstdir/_rm.$$_ 455100ae103Smrg 456100ae103Smrg # Trap to clean up those temp files at exit. 457100ae103Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458100ae103Smrg 459100ae103Smrg # Copy the file name to the temp name. 460165cb819Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461100ae103Smrg 462100ae103Smrg # and set any options; do chmod last to preserve setuid bits. 463100ae103Smrg # 464100ae103Smrg # If any of these fail, we abort the whole thing. If we want to 465100ae103Smrg # ignore errors from any of these, just make sure not to ignore 466100ae103Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 467100ae103Smrg # 468165cb819Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469165cb819Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470165cb819Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471165cb819Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472165cb819Smrg 473165cb819Smrg # If -C, don't bother to copy if it wouldn't change the file. 474165cb819Smrg if $copy_on_change && 475165cb819Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476165cb819Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477165cb819Smrg 478165cb819Smrg eval "$initialize_posix_glob" && 479165cb819Smrg $posix_glob set -f && 480165cb819Smrg set X $old && old=:$2:$4:$5:$6 && 481165cb819Smrg set X $new && new=:$2:$4:$5:$6 && 482165cb819Smrg $posix_glob set +f && 483165cb819Smrg 484165cb819Smrg test "$old" = "$new" && 485165cb819Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486165cb819Smrg then 487165cb819Smrg rm -f "$dsttmp" 488165cb819Smrg else 489165cb819Smrg # Rename the file to the real destination. 490165cb819Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491165cb819Smrg 492165cb819Smrg # The rename failed, perhaps because mv can't rename something else 493165cb819Smrg # to itself, or perhaps because mv is so ancient that it does not 494165cb819Smrg # support -f. 495165cb819Smrg { 496165cb819Smrg # Now remove or move aside any old file at destination location. 497165cb819Smrg # We try this two ways since rm can't unlink itself on some 498165cb819Smrg # systems and the destination file might be busy for other 499165cb819Smrg # reasons. In this case, the final cleanup might fail but the new 500165cb819Smrg # file should still install successfully. 501165cb819Smrg { 502165cb819Smrg test ! -f "$dst" || 503165cb819Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 504165cb819Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505165cb819Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506165cb819Smrg } || 507165cb819Smrg { echo "$0: cannot unlink or rename $dst" >&2 508165cb819Smrg (exit 1); exit 1 509165cb819Smrg } 510165cb819Smrg } && 511165cb819Smrg 512165cb819Smrg # Now rename the file to the real destination. 513165cb819Smrg $doit $mvcmd "$dsttmp" "$dst" 514165cb819Smrg } 515165cb819Smrg fi || exit 1 516165cb819Smrg 517165cb819Smrg trap '' 0 518165cb819Smrg fi 519100ae103Smrgdone 520100ae103Smrg 521100ae103Smrg# Local variables: 522100ae103Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 523100ae103Smrg# time-stamp-start: "scriptversion=" 524100ae103Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525165cb819Smrg# time-stamp-time-zone: "UTC" 526165cb819Smrg# time-stamp-end: "; # UTC" 527100ae103Smrg# End: 528