install-sh revision 339a7c43
1444c061aSmrg#!/bin/sh 2444c061aSmrg# install - install a program, script, or datafile 3444c061aSmrg 4339a7c43Smrgscriptversion=2013-12-25.23; # UTC 5444c061aSmrg 6444c061aSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7444c061aSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8444c061aSmrg# following copyright and license. 9444c061aSmrg# 10444c061aSmrg# Copyright (C) 1994 X Consortium 11444c061aSmrg# 12444c061aSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13444c061aSmrg# of this software and associated documentation files (the "Software"), to 14444c061aSmrg# deal in the Software without restriction, including without limitation the 15444c061aSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16444c061aSmrg# sell copies of the Software, and to permit persons to whom the Software is 17444c061aSmrg# furnished to do so, subject to the following conditions: 18444c061aSmrg# 19444c061aSmrg# The above copyright notice and this permission notice shall be included in 20444c061aSmrg# all copies or substantial portions of the Software. 21444c061aSmrg# 22444c061aSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23444c061aSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24444c061aSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25444c061aSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26444c061aSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27444c061aSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28444c061aSmrg# 29444c061aSmrg# Except as contained in this notice, the name of the X Consortium shall not 30444c061aSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31444c061aSmrg# ings in this Software without prior written authorization from the X Consor- 32444c061aSmrg# tium. 33444c061aSmrg# 34444c061aSmrg# 35444c061aSmrg# FSF changes to this file are in the public domain. 36444c061aSmrg# 37444c061aSmrg# Calling this script install-sh is preferred over install.sh, to prevent 389e7bcd65Smrg# 'make' implicit rules from creating a file called install from it 39444c061aSmrg# when there is no Makefile. 40444c061aSmrg# 41444c061aSmrg# This script is compatible with the BSD install script, but was written 422265a131Smrg# from scratch. 432265a131Smrg 44339a7c43Smrgtab=' ' 452265a131Smrgnl=' 462265a131Smrg' 47339a7c43SmrgIFS=" $tab$nl" 48444c061aSmrg 49339a7c43Smrg# Set DOITPROG to "echo" to test this script. 50444c061aSmrg 512265a131Smrgdoit=${DOITPROG-} 52339a7c43Smrgdoit_exec=${doit:-exec} 53444c061aSmrg 542265a131Smrg# Put in absolute file names if you don't have them in your path; 552265a131Smrg# or use environment vars. 562265a131Smrg 572265a131Smrgchgrpprog=${CHGRPPROG-chgrp} 582265a131Smrgchmodprog=${CHMODPROG-chmod} 592265a131Smrgchownprog=${CHOWNPROG-chown} 602265a131Smrgcmpprog=${CMPPROG-cmp} 612265a131Smrgcpprog=${CPPROG-cp} 622265a131Smrgmkdirprog=${MKDIRPROG-mkdir} 632265a131Smrgmvprog=${MVPROG-mv} 642265a131Smrgrmprog=${RMPROG-rm} 652265a131Smrgstripprog=${STRIPPROG-strip} 662265a131Smrg 672265a131Smrgposix_mkdir= 682265a131Smrg 692265a131Smrg# Desired mode of installed file. 702265a131Smrgmode=0755 71444c061aSmrg 72444c061aSmrgchgrpcmd= 732265a131Smrgchmodcmd=$chmodprog 742265a131Smrgchowncmd= 752265a131Smrgmvcmd=$mvprog 76444c061aSmrgrmcmd="$rmprog -f" 772265a131Smrgstripcmd= 782265a131Smrg 79444c061aSmrgsrc= 80444c061aSmrgdst= 81444c061aSmrgdir_arg= 822265a131Smrgdst_arg= 832265a131Smrg 842265a131Smrgcopy_on_change=false 85339a7c43Smrgis_target_a_directory=possibly 86444c061aSmrg 872265a131Smrgusage="\ 882265a131SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 89444c061aSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 90444c061aSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 91444c061aSmrg or: $0 [OPTION]... -d DIRECTORIES... 92444c061aSmrg 93444c061aSmrgIn the 1st form, copy SRCFILE to DSTFILE. 94444c061aSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 95444c061aSmrgIn the 4th, create DIRECTORIES. 96444c061aSmrg 97444c061aSmrgOptions: 982265a131Smrg --help display this help and exit. 992265a131Smrg --version display version info and exit. 1002265a131Smrg 1012265a131Smrg -c (ignored) 1022265a131Smrg -C install only if different (preserve the last data modification time) 1032265a131Smrg -d create directories instead of installing files. 1042265a131Smrg -g GROUP $chgrpprog installed files to GROUP. 1052265a131Smrg -m MODE $chmodprog installed files to MODE. 1062265a131Smrg -o USER $chownprog installed files to USER. 1072265a131Smrg -s $stripprog installed files. 1082265a131Smrg -t DIRECTORY install into DIRECTORY. 1092265a131Smrg -T report an error if DSTFILE is a directory. 110444c061aSmrg 111444c061aSmrgEnvironment variables override the default commands: 1122265a131Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1132265a131Smrg RMPROG STRIPPROG 114444c061aSmrg" 115444c061aSmrg 1162265a131Smrgwhile test $# -ne 0; do 117444c061aSmrg case $1 in 1182265a131Smrg -c) ;; 1192265a131Smrg 1202265a131Smrg -C) copy_on_change=true;; 121444c061aSmrg 1222265a131Smrg -d) dir_arg=true;; 123444c061aSmrg 124444c061aSmrg -g) chgrpcmd="$chgrpprog $2" 125339a7c43Smrg shift;; 126444c061aSmrg 127444c061aSmrg --help) echo "$usage"; exit $?;; 128444c061aSmrg 1292265a131Smrg -m) mode=$2 130339a7c43Smrg case $mode in 131339a7c43Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132339a7c43Smrg echo "$0: invalid mode: $mode" >&2 133339a7c43Smrg exit 1;; 134339a7c43Smrg esac 135339a7c43Smrg shift;; 136444c061aSmrg 137444c061aSmrg -o) chowncmd="$chownprog $2" 138339a7c43Smrg shift;; 139444c061aSmrg 1402265a131Smrg -s) stripcmd=$stripprog;; 141444c061aSmrg 142339a7c43Smrg -t) 143339a7c43Smrg is_target_a_directory=always 144339a7c43Smrg dst_arg=$2 145339a7c43Smrg # Protect names problematic for 'test' and other utilities. 146339a7c43Smrg case $dst_arg in 147339a7c43Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 148339a7c43Smrg esac 149339a7c43Smrg shift;; 150444c061aSmrg 151339a7c43Smrg -T) is_target_a_directory=never;; 152444c061aSmrg 153444c061aSmrg --version) echo "$0 $scriptversion"; exit $?;; 154444c061aSmrg 155339a7c43Smrg --) shift 156339a7c43Smrg break;; 1572265a131Smrg 158339a7c43Smrg -*) echo "$0: invalid option: $1" >&2 159339a7c43Smrg exit 1;; 1602265a131Smrg 1612265a131Smrg *) break;; 162444c061aSmrg esac 1632265a131Smrg shift 164444c061aSmrgdone 165444c061aSmrg 166339a7c43Smrg# We allow the use of options -d and -T together, by making -d 167339a7c43Smrg# take the precedence; this is for compatibility with GNU install. 168339a7c43Smrg 169339a7c43Smrgif test -n "$dir_arg"; then 170339a7c43Smrg if test -n "$dst_arg"; then 171339a7c43Smrg echo "$0: target directory not allowed when installing a directory." >&2 172339a7c43Smrg exit 1 173339a7c43Smrg fi 174339a7c43Smrgfi 175339a7c43Smrg 1762265a131Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1772265a131Smrg # When -d is used, all remaining arguments are directories to create. 1782265a131Smrg # When -t is used, the destination is already specified. 1792265a131Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1802265a131Smrg for arg 1812265a131Smrg do 1822265a131Smrg if test -n "$dst_arg"; then 1832265a131Smrg # $@ is not empty: it contains at least $arg. 1842265a131Smrg set fnord "$@" "$dst_arg" 1852265a131Smrg shift # fnord 1862265a131Smrg fi 1872265a131Smrg shift # arg 1882265a131Smrg dst_arg=$arg 1899e7bcd65Smrg # Protect names problematic for 'test' and other utilities. 1909e7bcd65Smrg case $dst_arg in 1919e7bcd65Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1929e7bcd65Smrg esac 1932265a131Smrg done 1942265a131Smrgfi 1952265a131Smrg 1962265a131Smrgif test $# -eq 0; then 197444c061aSmrg if test -z "$dir_arg"; then 198444c061aSmrg echo "$0: no input file specified." >&2 199444c061aSmrg exit 1 200444c061aSmrg fi 2019e7bcd65Smrg # It's OK to call 'install-sh -d' without argument. 202444c061aSmrg # This can happen when creating conditional directories. 203444c061aSmrg exit 0 204444c061aSmrgfi 205444c061aSmrg 206339a7c43Smrgif test -z "$dir_arg"; then 207339a7c43Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 208339a7c43Smrg if test ! -d "$dst_arg"; then 209339a7c43Smrg echo "$0: $dst_arg: Is not a directory." >&2 210339a7c43Smrg exit 1 211339a7c43Smrg fi 212339a7c43Smrg fi 213339a7c43Smrgfi 214339a7c43Smrg 2152265a131Smrgif test -z "$dir_arg"; then 2169e7bcd65Smrg do_exit='(exit $ret); exit $ret' 2179e7bcd65Smrg trap "ret=129; $do_exit" 1 2189e7bcd65Smrg trap "ret=130; $do_exit" 2 2199e7bcd65Smrg trap "ret=141; $do_exit" 13 2209e7bcd65Smrg trap "ret=143; $do_exit" 15 2212265a131Smrg 2222265a131Smrg # Set umask so as not to create temps with too-generous modes. 2232265a131Smrg # However, 'strip' requires both read and write access to temps. 2242265a131Smrg case $mode in 2252265a131Smrg # Optimize common cases. 2262265a131Smrg *644) cp_umask=133;; 2272265a131Smrg *755) cp_umask=22;; 2282265a131Smrg 2292265a131Smrg *[0-7]) 2302265a131Smrg if test -z "$stripcmd"; then 231339a7c43Smrg u_plus_rw= 2322265a131Smrg else 233339a7c43Smrg u_plus_rw='% 200' 2342265a131Smrg fi 2352265a131Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2362265a131Smrg *) 2372265a131Smrg if test -z "$stripcmd"; then 238339a7c43Smrg u_plus_rw= 2392265a131Smrg else 240339a7c43Smrg u_plus_rw=,u+rw 2412265a131Smrg fi 2422265a131Smrg cp_umask=$mode$u_plus_rw;; 2432265a131Smrg esac 2442265a131Smrgfi 2452265a131Smrg 246444c061aSmrgfor src 247444c061aSmrgdo 2489e7bcd65Smrg # Protect names problematic for 'test' and other utilities. 249444c061aSmrg case $src in 2509e7bcd65Smrg -* | [=\(\)!]) src=./$src;; 251444c061aSmrg esac 252444c061aSmrg 253444c061aSmrg if test -n "$dir_arg"; then 254444c061aSmrg dst=$src 2552265a131Smrg dstdir=$dst 2562265a131Smrg test -d "$dstdir" 2572265a131Smrg dstdir_status=$? 258444c061aSmrg else 2592265a131Smrg 260444c061aSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 261444c061aSmrg # might cause directories to be created, which would be especially bad 262444c061aSmrg # if $src (and thus $dsttmp) contains '*'. 263444c061aSmrg if test ! -f "$src" && test ! -d "$src"; then 264444c061aSmrg echo "$0: $src does not exist." >&2 265444c061aSmrg exit 1 266444c061aSmrg fi 267444c061aSmrg 2682265a131Smrg if test -z "$dst_arg"; then 269444c061aSmrg echo "$0: no destination specified." >&2 270444c061aSmrg exit 1 271444c061aSmrg fi 2722265a131Smrg dst=$dst_arg 273444c061aSmrg 274444c061aSmrg # If destination is a directory, append the input filename; won't work 275444c061aSmrg # if double slashes aren't ignored. 276444c061aSmrg if test -d "$dst"; then 277339a7c43Smrg if test "$is_target_a_directory" = never; then 278339a7c43Smrg echo "$0: $dst_arg: Is a directory" >&2 279339a7c43Smrg exit 1 280444c061aSmrg fi 2812265a131Smrg dstdir=$dst 2822265a131Smrg dst=$dstdir/`basename "$src"` 2832265a131Smrg dstdir_status=0 2842265a131Smrg else 285339a7c43Smrg dstdir=`dirname "$dst"` 2862265a131Smrg test -d "$dstdir" 2872265a131Smrg dstdir_status=$? 288444c061aSmrg fi 289444c061aSmrg fi 290444c061aSmrg 2912265a131Smrg obsolete_mkdir_used=false 2922265a131Smrg 2932265a131Smrg if test $dstdir_status != 0; then 2942265a131Smrg case $posix_mkdir in 2952265a131Smrg '') 296339a7c43Smrg # Create intermediate dirs using mode 755 as modified by the umask. 297339a7c43Smrg # This is like FreeBSD 'install' as of 1997-10-28. 298339a7c43Smrg umask=`umask` 299339a7c43Smrg case $stripcmd.$umask in 300339a7c43Smrg # Optimize common cases. 301339a7c43Smrg *[2367][2367]) mkdir_umask=$umask;; 302339a7c43Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 303339a7c43Smrg 304339a7c43Smrg *[0-7]) 305339a7c43Smrg mkdir_umask=`expr $umask + 22 \ 306339a7c43Smrg - $umask % 100 % 40 + $umask % 20 \ 307339a7c43Smrg - $umask % 10 % 4 + $umask % 2 308339a7c43Smrg `;; 309339a7c43Smrg *) mkdir_umask=$umask,go-w;; 310339a7c43Smrg esac 311339a7c43Smrg 312339a7c43Smrg # With -d, create the new directory with the user-specified mode. 313339a7c43Smrg # Otherwise, rely on $mkdir_umask. 314339a7c43Smrg if test -n "$dir_arg"; then 315339a7c43Smrg mkdir_mode=-m$mode 316339a7c43Smrg else 317339a7c43Smrg mkdir_mode= 318339a7c43Smrg fi 319339a7c43Smrg 320339a7c43Smrg posix_mkdir=false 321339a7c43Smrg case $umask in 322339a7c43Smrg *[123567][0-7][0-7]) 323339a7c43Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 324339a7c43Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 325339a7c43Smrg ;; 326339a7c43Smrg *) 327339a7c43Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 328339a7c43Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 329339a7c43Smrg 330339a7c43Smrg if (umask $mkdir_umask && 331339a7c43Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 332339a7c43Smrg then 333339a7c43Smrg if test -z "$dir_arg" || { 334339a7c43Smrg # Check for POSIX incompatibilities with -m. 335339a7c43Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336339a7c43Smrg # other-writable bit of parent directory when it shouldn't. 337339a7c43Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 338339a7c43Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 339339a7c43Smrg case $ls_ld_tmpdir in 340339a7c43Smrg d????-?r-*) different_mode=700;; 341339a7c43Smrg d????-?--*) different_mode=755;; 342339a7c43Smrg *) false;; 343339a7c43Smrg esac && 344339a7c43Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 345339a7c43Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 346339a7c43Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 347339a7c43Smrg } 348339a7c43Smrg } 349339a7c43Smrg then posix_mkdir=: 350339a7c43Smrg fi 351339a7c43Smrg rmdir "$tmpdir/d" "$tmpdir" 352339a7c43Smrg else 353339a7c43Smrg # Remove any dirs left behind by ancient mkdir implementations. 354339a7c43Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 355339a7c43Smrg fi 356339a7c43Smrg trap '' 0;; 357339a7c43Smrg esac;; 3582265a131Smrg esac 359444c061aSmrg 3602265a131Smrg if 3612265a131Smrg $posix_mkdir && ( 362339a7c43Smrg umask $mkdir_umask && 363339a7c43Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3642265a131Smrg ) 3652265a131Smrg then : 3662265a131Smrg else 367444c061aSmrg 3682265a131Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3692265a131Smrg # or it failed possibly due to a race condition. Create the 3702265a131Smrg # directory the slow way, step by step, checking for races as we go. 371444c061aSmrg 3722265a131Smrg case $dstdir in 373339a7c43Smrg /*) prefix='/';; 374339a7c43Smrg [-=\(\)!]*) prefix='./';; 375339a7c43Smrg *) prefix='';; 3762265a131Smrg esac 377444c061aSmrg 3782265a131Smrg oIFS=$IFS 3792265a131Smrg IFS=/ 380339a7c43Smrg set -f 3812265a131Smrg set fnord $dstdir 382444c061aSmrg shift 383339a7c43Smrg set +f 3842265a131Smrg IFS=$oIFS 3852265a131Smrg 3862265a131Smrg prefixes= 3872265a131Smrg 3882265a131Smrg for d 3892265a131Smrg do 390339a7c43Smrg test X"$d" = X && continue 391339a7c43Smrg 392339a7c43Smrg prefix=$prefix$d 393339a7c43Smrg if test -d "$prefix"; then 394339a7c43Smrg prefixes= 395339a7c43Smrg else 396339a7c43Smrg if $posix_mkdir; then 397339a7c43Smrg (umask=$mkdir_umask && 398339a7c43Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 399339a7c43Smrg # Don't fail if two instances are running concurrently. 400339a7c43Smrg test -d "$prefix" || exit 1 401339a7c43Smrg else 402339a7c43Smrg case $prefix in 403339a7c43Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 404339a7c43Smrg *) qprefix=$prefix;; 405339a7c43Smrg esac 406339a7c43Smrg prefixes="$prefixes '$qprefix'" 407339a7c43Smrg fi 408339a7c43Smrg fi 409339a7c43Smrg prefix=$prefix/ 4102265a131Smrg done 4112265a131Smrg 4122265a131Smrg if test -n "$prefixes"; then 413339a7c43Smrg # Don't fail if two instances are running concurrently. 414339a7c43Smrg (umask $mkdir_umask && 415339a7c43Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 416339a7c43Smrg test -d "$dstdir" || exit 1 417339a7c43Smrg obsolete_mkdir_used=true 418444c061aSmrg fi 4192265a131Smrg fi 420444c061aSmrg fi 421444c061aSmrg 422444c061aSmrg if test -n "$dir_arg"; then 4232265a131Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4242265a131Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4252265a131Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4262265a131Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 427444c061aSmrg else 428444c061aSmrg 429444c061aSmrg # Make a couple of temp file names in the proper directory. 430444c061aSmrg dsttmp=$dstdir/_inst.$$_ 431444c061aSmrg rmtmp=$dstdir/_rm.$$_ 432444c061aSmrg 433444c061aSmrg # Trap to clean up those temp files at exit. 434444c061aSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 435444c061aSmrg 436444c061aSmrg # Copy the file name to the temp name. 4372265a131Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 438444c061aSmrg 439444c061aSmrg # and set any options; do chmod last to preserve setuid bits. 440444c061aSmrg # 441444c061aSmrg # If any of these fail, we abort the whole thing. If we want to 442444c061aSmrg # ignore errors from any of these, just make sure not to ignore 443444c061aSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 444444c061aSmrg # 4452265a131Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4462265a131Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4472265a131Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4482265a131Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4492265a131Smrg 4502265a131Smrg # If -C, don't bother to copy if it wouldn't change the file. 4512265a131Smrg if $copy_on_change && 452339a7c43Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 453339a7c43Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454339a7c43Smrg set -f && 4552265a131Smrg set X $old && old=:$2:$4:$5:$6 && 4562265a131Smrg set X $new && new=:$2:$4:$5:$6 && 457339a7c43Smrg set +f && 4582265a131Smrg test "$old" = "$new" && 4592265a131Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4602265a131Smrg then 4612265a131Smrg rm -f "$dsttmp" 4622265a131Smrg else 4632265a131Smrg # Rename the file to the real destination. 4642265a131Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4652265a131Smrg 4662265a131Smrg # The rename failed, perhaps because mv can't rename something else 4672265a131Smrg # to itself, or perhaps because mv is so ancient that it does not 4682265a131Smrg # support -f. 4692265a131Smrg { 470339a7c43Smrg # Now remove or move aside any old file at destination location. 471339a7c43Smrg # We try this two ways since rm can't unlink itself on some 472339a7c43Smrg # systems and the destination file might be busy for other 473339a7c43Smrg # reasons. In this case, the final cleanup might fail but the new 474339a7c43Smrg # file should still install successfully. 475339a7c43Smrg { 476339a7c43Smrg test ! -f "$dst" || 477339a7c43Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 478339a7c43Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 479339a7c43Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 480339a7c43Smrg } || 481339a7c43Smrg { echo "$0: cannot unlink or rename $dst" >&2 482339a7c43Smrg (exit 1); exit 1 483339a7c43Smrg } 484339a7c43Smrg } && 485339a7c43Smrg 486339a7c43Smrg # Now rename the file to the real destination. 487339a7c43Smrg $doit $mvcmd "$dsttmp" "$dst" 4882265a131Smrg } 4892265a131Smrg fi || exit 1 4902265a131Smrg 4912265a131Smrg trap '' 0 4922265a131Smrg fi 493444c061aSmrgdone 494444c061aSmrg 495444c061aSmrg# Local variables: 496444c061aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 497444c061aSmrg# time-stamp-start: "scriptversion=" 498444c061aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 4992ae83157Smrg# time-stamp-time-zone: "UTC" 5002ae83157Smrg# time-stamp-end: "; # UTC" 501444c061aSmrg# End: 502