install-sh revision ba85709e
11d54945dSmrg#!/bin/sh 21d54945dSmrg# install - install a program, script, or datafile 31d54945dSmrg 4ba85709eSmrgscriptversion=2006-10-14.15 51d54945dSmrg 61d54945dSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71d54945dSmrg# later released in X11R6 (xc/config/util/install.sh) with the 81d54945dSmrg# following copyright and license. 91d54945dSmrg# 101d54945dSmrg# Copyright (C) 1994 X Consortium 111d54945dSmrg# 121d54945dSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131d54945dSmrg# of this software and associated documentation files (the "Software"), to 141d54945dSmrg# deal in the Software without restriction, including without limitation the 151d54945dSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161d54945dSmrg# sell copies of the Software, and to permit persons to whom the Software is 171d54945dSmrg# furnished to do so, subject to the following conditions: 181d54945dSmrg# 191d54945dSmrg# The above copyright notice and this permission notice shall be included in 201d54945dSmrg# all copies or substantial portions of the Software. 211d54945dSmrg# 221d54945dSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231d54945dSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241d54945dSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251d54945dSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261d54945dSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271d54945dSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281d54945dSmrg# 291d54945dSmrg# Except as contained in this notice, the name of the X Consortium shall not 301d54945dSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 311d54945dSmrg# ings in this Software without prior written authorization from the X Consor- 321d54945dSmrg# tium. 331d54945dSmrg# 341d54945dSmrg# 351d54945dSmrg# FSF changes to this file are in the public domain. 361d54945dSmrg# 371d54945dSmrg# Calling this script install-sh is preferred over install.sh, to prevent 381d54945dSmrg# `make' implicit rules from creating a file called install from it 391d54945dSmrg# when there is no Makefile. 401d54945dSmrg# 411d54945dSmrg# This script is compatible with the BSD install script, but was written 42ba85709eSmrg# from scratch. 43ba85709eSmrg 44ba85709eSmrgnl=' 45ba85709eSmrg' 46ba85709eSmrgIFS=" "" $nl" 471d54945dSmrg 481d54945dSmrg# set DOITPROG to echo to test this script 491d54945dSmrg 501d54945dSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 511d54945dSmrgdoit="${DOITPROG-}" 52ba85709eSmrgif test -z "$doit"; then 53ba85709eSmrg doit_exec=exec 54ba85709eSmrgelse 55ba85709eSmrg doit_exec=$doit 56ba85709eSmrgfi 571d54945dSmrg 58ba85709eSmrg# Put in absolute file names if you don't have them in your path; 59ba85709eSmrg# or use environment vars. 601d54945dSmrg 611d54945dSmrgmvprog="${MVPROG-mv}" 621d54945dSmrgcpprog="${CPPROG-cp}" 631d54945dSmrgchmodprog="${CHMODPROG-chmod}" 641d54945dSmrgchownprog="${CHOWNPROG-chown}" 651d54945dSmrgchgrpprog="${CHGRPPROG-chgrp}" 661d54945dSmrgstripprog="${STRIPPROG-strip}" 671d54945dSmrgrmprog="${RMPROG-rm}" 681d54945dSmrgmkdirprog="${MKDIRPROG-mkdir}" 691d54945dSmrg 70ba85709eSmrgposix_glob= 71ba85709eSmrgposix_mkdir= 72ba85709eSmrg 73ba85709eSmrg# Desired mode of installed file. 74ba85709eSmrgmode=0755 75ba85709eSmrg 76ba85709eSmrgchmodcmd=$chmodprog 771d54945dSmrgchowncmd= 781d54945dSmrgchgrpcmd= 791d54945dSmrgstripcmd= 801d54945dSmrgrmcmd="$rmprog -f" 811d54945dSmrgmvcmd="$mvprog" 821d54945dSmrgsrc= 831d54945dSmrgdst= 841d54945dSmrgdir_arg= 851d54945dSmrgdstarg= 861d54945dSmrgno_target_directory= 871d54945dSmrg 881d54945dSmrgusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 891d54945dSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 901d54945dSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 911d54945dSmrg or: $0 [OPTION]... -d DIRECTORIES... 921d54945dSmrg 931d54945dSmrgIn the 1st form, copy SRCFILE to DSTFILE. 941d54945dSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 951d54945dSmrgIn the 4th, create DIRECTORIES. 961d54945dSmrg 971d54945dSmrgOptions: 981d54945dSmrg-c (ignored) 991d54945dSmrg-d create directories instead of installing files. 1001d54945dSmrg-g GROUP $chgrpprog installed files to GROUP. 1011d54945dSmrg-m MODE $chmodprog installed files to MODE. 1021d54945dSmrg-o USER $chownprog installed files to USER. 1031d54945dSmrg-s $stripprog installed files. 1041d54945dSmrg-t DIRECTORY install into DIRECTORY. 1051d54945dSmrg-T report an error if DSTFILE is a directory. 1061d54945dSmrg--help display this help and exit. 1071d54945dSmrg--version display version info and exit. 1081d54945dSmrg 1091d54945dSmrgEnvironment variables override the default commands: 1101d54945dSmrg CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 1111d54945dSmrg" 1121d54945dSmrg 113ba85709eSmrgwhile test $# -ne 0; do 1141d54945dSmrg case $1 in 1151d54945dSmrg -c) shift 1161d54945dSmrg continue;; 1171d54945dSmrg 1181d54945dSmrg -d) dir_arg=true 1191d54945dSmrg shift 1201d54945dSmrg continue;; 1211d54945dSmrg 1221d54945dSmrg -g) chgrpcmd="$chgrpprog $2" 1231d54945dSmrg shift 1241d54945dSmrg shift 1251d54945dSmrg continue;; 1261d54945dSmrg 1271d54945dSmrg --help) echo "$usage"; exit $?;; 1281d54945dSmrg 129ba85709eSmrg -m) mode=$2 1301d54945dSmrg shift 1311d54945dSmrg shift 132ba85709eSmrg case $mode in 133ba85709eSmrg *' '* | *' '* | *' 134ba85709eSmrg'* | *'*'* | *'?'* | *'['*) 135ba85709eSmrg echo "$0: invalid mode: $mode" >&2 136ba85709eSmrg exit 1;; 137ba85709eSmrg esac 1381d54945dSmrg continue;; 1391d54945dSmrg 1401d54945dSmrg -o) chowncmd="$chownprog $2" 1411d54945dSmrg shift 1421d54945dSmrg shift 1431d54945dSmrg continue;; 1441d54945dSmrg 1451d54945dSmrg -s) stripcmd=$stripprog 1461d54945dSmrg shift 1471d54945dSmrg continue;; 1481d54945dSmrg 1491d54945dSmrg -t) dstarg=$2 1501d54945dSmrg shift 1511d54945dSmrg shift 1521d54945dSmrg continue;; 1531d54945dSmrg 1541d54945dSmrg -T) no_target_directory=true 1551d54945dSmrg shift 1561d54945dSmrg continue;; 1571d54945dSmrg 1581d54945dSmrg --version) echo "$0 $scriptversion"; exit $?;; 1591d54945dSmrg 160ba85709eSmrg --) shift 1611d54945dSmrg break;; 162ba85709eSmrg 163ba85709eSmrg -*) echo "$0: invalid option: $1" >&2 164ba85709eSmrg exit 1;; 165ba85709eSmrg 166ba85709eSmrg *) break;; 1671d54945dSmrg esac 1681d54945dSmrgdone 1691d54945dSmrg 170ba85709eSmrgif test $# -ne 0 && test -z "$dir_arg$dstarg"; then 171ba85709eSmrg # When -d is used, all remaining arguments are directories to create. 172ba85709eSmrg # When -t is used, the destination is already specified. 173ba85709eSmrg # Otherwise, the last argument is the destination. Remove it from $@. 174ba85709eSmrg for arg 175ba85709eSmrg do 176ba85709eSmrg if test -n "$dstarg"; then 177ba85709eSmrg # $@ is not empty: it contains at least $arg. 178ba85709eSmrg set fnord "$@" "$dstarg" 179ba85709eSmrg shift # fnord 180ba85709eSmrg fi 181ba85709eSmrg shift # arg 182ba85709eSmrg dstarg=$arg 183ba85709eSmrg done 184ba85709eSmrgfi 185ba85709eSmrg 186ba85709eSmrgif test $# -eq 0; then 1871d54945dSmrg if test -z "$dir_arg"; then 1881d54945dSmrg echo "$0: no input file specified." >&2 1891d54945dSmrg exit 1 1901d54945dSmrg fi 1911d54945dSmrg # It's OK to call `install-sh -d' without argument. 1921d54945dSmrg # This can happen when creating conditional directories. 1931d54945dSmrg exit 0 1941d54945dSmrgfi 1951d54945dSmrg 196ba85709eSmrgif test -z "$dir_arg"; then 197ba85709eSmrg trap '(exit $?); exit' 1 2 13 15 198ba85709eSmrg 199ba85709eSmrg # Set umask so as not to create temps with too-generous modes. 200ba85709eSmrg # However, 'strip' requires both read and write access to temps. 201ba85709eSmrg case $mode in 202ba85709eSmrg # Optimize common cases. 203ba85709eSmrg *644) cp_umask=133;; 204ba85709eSmrg *755) cp_umask=22;; 205ba85709eSmrg 206ba85709eSmrg *[0-7]) 207ba85709eSmrg if test -z "$stripcmd"; then 208ba85709eSmrg u_plus_rw= 209ba85709eSmrg else 210ba85709eSmrg u_plus_rw='% 200' 211ba85709eSmrg fi 212ba85709eSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 213ba85709eSmrg *) 214ba85709eSmrg if test -z "$stripcmd"; then 215ba85709eSmrg u_plus_rw= 216ba85709eSmrg else 217ba85709eSmrg u_plus_rw=,u+rw 218ba85709eSmrg fi 219ba85709eSmrg cp_umask=$mode$u_plus_rw;; 220ba85709eSmrg esac 221ba85709eSmrgfi 222ba85709eSmrg 2231d54945dSmrgfor src 2241d54945dSmrgdo 2251d54945dSmrg # Protect names starting with `-'. 2261d54945dSmrg case $src in 2271d54945dSmrg -*) src=./$src ;; 2281d54945dSmrg esac 2291d54945dSmrg 2301d54945dSmrg if test -n "$dir_arg"; then 2311d54945dSmrg dst=$src 232ba85709eSmrg dstdir=$dst 233ba85709eSmrg test -d "$dstdir" 234ba85709eSmrg dstdir_status=$? 2351d54945dSmrg else 236ba85709eSmrg 2371d54945dSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2381d54945dSmrg # might cause directories to be created, which would be especially bad 2391d54945dSmrg # if $src (and thus $dsttmp) contains '*'. 2401d54945dSmrg if test ! -f "$src" && test ! -d "$src"; then 2411d54945dSmrg echo "$0: $src does not exist." >&2 2421d54945dSmrg exit 1 2431d54945dSmrg fi 2441d54945dSmrg 2451d54945dSmrg if test -z "$dstarg"; then 2461d54945dSmrg echo "$0: no destination specified." >&2 2471d54945dSmrg exit 1 2481d54945dSmrg fi 2491d54945dSmrg 2501d54945dSmrg dst=$dstarg 2511d54945dSmrg # Protect names starting with `-'. 2521d54945dSmrg case $dst in 2531d54945dSmrg -*) dst=./$dst ;; 2541d54945dSmrg esac 2551d54945dSmrg 2561d54945dSmrg # If destination is a directory, append the input filename; won't work 2571d54945dSmrg # if double slashes aren't ignored. 2581d54945dSmrg if test -d "$dst"; then 2591d54945dSmrg if test -n "$no_target_directory"; then 2601d54945dSmrg echo "$0: $dstarg: Is a directory" >&2 2611d54945dSmrg exit 1 2621d54945dSmrg fi 263ba85709eSmrg dstdir=$dst 264ba85709eSmrg dst=$dstdir/`basename "$src"` 265ba85709eSmrg dstdir_status=0 266ba85709eSmrg else 267ba85709eSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 268ba85709eSmrg dstdir=` 269ba85709eSmrg (dirname "$dst") 2>/dev/null || 270ba85709eSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 271ba85709eSmrg X"$dst" : 'X\(//\)[^/]' \| \ 272ba85709eSmrg X"$dst" : 'X\(//\)$' \| \ 273ba85709eSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 274ba85709eSmrg echo X"$dst" | 275ba85709eSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 276ba85709eSmrg s//\1/ 277ba85709eSmrg q 278ba85709eSmrg } 279ba85709eSmrg /^X\(\/\/\)[^/].*/{ 280ba85709eSmrg s//\1/ 281ba85709eSmrg q 282ba85709eSmrg } 283ba85709eSmrg /^X\(\/\/\)$/{ 284ba85709eSmrg s//\1/ 285ba85709eSmrg q 286ba85709eSmrg } 287ba85709eSmrg /^X\(\/\).*/{ 288ba85709eSmrg s//\1/ 289ba85709eSmrg q 290ba85709eSmrg } 291ba85709eSmrg s/.*/./; q' 292ba85709eSmrg ` 293ba85709eSmrg 294ba85709eSmrg test -d "$dstdir" 295ba85709eSmrg dstdir_status=$? 2961d54945dSmrg fi 2971d54945dSmrg fi 2981d54945dSmrg 299ba85709eSmrg obsolete_mkdir_used=false 300ba85709eSmrg 301ba85709eSmrg if test $dstdir_status != 0; then 302ba85709eSmrg case $posix_mkdir in 303ba85709eSmrg '') 304ba85709eSmrg # Create intermediate dirs using mode 755 as modified by the umask. 305ba85709eSmrg # This is like FreeBSD 'install' as of 1997-10-28. 306ba85709eSmrg umask=`umask` 307ba85709eSmrg case $stripcmd.$umask in 308ba85709eSmrg # Optimize common cases. 309ba85709eSmrg *[2367][2367]) mkdir_umask=$umask;; 310ba85709eSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 311ba85709eSmrg 312ba85709eSmrg *[0-7]) 313ba85709eSmrg mkdir_umask=`expr $umask + 22 \ 314ba85709eSmrg - $umask % 100 % 40 + $umask % 20 \ 315ba85709eSmrg - $umask % 10 % 4 + $umask % 2 316ba85709eSmrg `;; 317ba85709eSmrg *) mkdir_umask=$umask,go-w;; 318ba85709eSmrg esac 319ba85709eSmrg 320ba85709eSmrg # With -d, create the new directory with the user-specified mode. 321ba85709eSmrg # Otherwise, rely on $mkdir_umask. 322ba85709eSmrg if test -n "$dir_arg"; then 323ba85709eSmrg mkdir_mode=-m$mode 324ba85709eSmrg else 325ba85709eSmrg mkdir_mode= 326ba85709eSmrg fi 327ba85709eSmrg 328ba85709eSmrg posix_mkdir=false 329ba85709eSmrg case $umask in 330ba85709eSmrg *[123567][0-7][0-7]) 331ba85709eSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 332ba85709eSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 333ba85709eSmrg ;; 334ba85709eSmrg *) 335ba85709eSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 336ba85709eSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 337ba85709eSmrg 338ba85709eSmrg if (umask $mkdir_umask && 339ba85709eSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 340ba85709eSmrg then 341ba85709eSmrg if test -z "$dir_arg" || { 342ba85709eSmrg # Check for POSIX incompatibilities with -m. 343ba85709eSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 344ba85709eSmrg # other-writeable bit of parent directory when it shouldn't. 345ba85709eSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 346ba85709eSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 347ba85709eSmrg case $ls_ld_tmpdir in 348ba85709eSmrg d????-?r-*) different_mode=700;; 349ba85709eSmrg d????-?--*) different_mode=755;; 350ba85709eSmrg *) false;; 351ba85709eSmrg esac && 352ba85709eSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 353ba85709eSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 354ba85709eSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 355ba85709eSmrg } 356ba85709eSmrg } 357ba85709eSmrg then posix_mkdir=: 358ba85709eSmrg fi 359ba85709eSmrg rmdir "$tmpdir/d" "$tmpdir" 360ba85709eSmrg else 361ba85709eSmrg # Remove any dirs left behind by ancient mkdir implementations. 362ba85709eSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 363ba85709eSmrg fi 364ba85709eSmrg trap '' 0;; 365ba85709eSmrg esac;; 366ba85709eSmrg esac 3671d54945dSmrg 368ba85709eSmrg if 369ba85709eSmrg $posix_mkdir && ( 370ba85709eSmrg umask $mkdir_umask && 371ba85709eSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 372ba85709eSmrg ) 373ba85709eSmrg then : 374ba85709eSmrg else 3751d54945dSmrg 376ba85709eSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 377ba85709eSmrg # or it failed possibly due to a race condition. Create the 378ba85709eSmrg # directory the slow way, step by step, checking for races as we go. 379ba85709eSmrg 380ba85709eSmrg case $dstdir in 381ba85709eSmrg /*) prefix=/ ;; 382ba85709eSmrg -*) prefix=./ ;; 383ba85709eSmrg *) prefix= ;; 384ba85709eSmrg esac 385ba85709eSmrg 386ba85709eSmrg case $posix_glob in 387ba85709eSmrg '') 388ba85709eSmrg if (set -f) 2>/dev/null; then 389ba85709eSmrg posix_glob=true 390ba85709eSmrg else 391ba85709eSmrg posix_glob=false 392ba85709eSmrg fi ;; 393ba85709eSmrg esac 394ba85709eSmrg 395ba85709eSmrg oIFS=$IFS 396ba85709eSmrg IFS=/ 397ba85709eSmrg $posix_glob && set -f 398ba85709eSmrg set fnord $dstdir 3991d54945dSmrg shift 400ba85709eSmrg $posix_glob && set +f 401ba85709eSmrg IFS=$oIFS 402ba85709eSmrg 403ba85709eSmrg prefixes= 404ba85709eSmrg 405ba85709eSmrg for d 406ba85709eSmrg do 407ba85709eSmrg test -z "$d" && continue 408ba85709eSmrg 409ba85709eSmrg prefix=$prefix$d 410ba85709eSmrg if test -d "$prefix"; then 411ba85709eSmrg prefixes= 412ba85709eSmrg else 413ba85709eSmrg if $posix_mkdir; then 414ba85709eSmrg (umask=$mkdir_umask && 415ba85709eSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 416ba85709eSmrg # Don't fail if two instances are running concurrently. 417ba85709eSmrg test -d "$prefix" || exit 1 418ba85709eSmrg else 419ba85709eSmrg case $prefix in 420ba85709eSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 421ba85709eSmrg *) qprefix=$prefix;; 422ba85709eSmrg esac 423ba85709eSmrg prefixes="$prefixes '$qprefix'" 424ba85709eSmrg fi 425ba85709eSmrg fi 426ba85709eSmrg prefix=$prefix/ 427ba85709eSmrg done 428ba85709eSmrg 429ba85709eSmrg if test -n "$prefixes"; then 430ba85709eSmrg # Don't fail if two instances are running concurrently. 431ba85709eSmrg (umask $mkdir_umask && 432ba85709eSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 433ba85709eSmrg test -d "$dstdir" || exit 1 434ba85709eSmrg obsolete_mkdir_used=true 4351d54945dSmrg fi 436ba85709eSmrg fi 4371d54945dSmrg fi 4381d54945dSmrg 4391d54945dSmrg if test -n "$dir_arg"; then 440ba85709eSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 441ba85709eSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 442ba85709eSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 443ba85709eSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4441d54945dSmrg else 4451d54945dSmrg 4461d54945dSmrg # Make a couple of temp file names in the proper directory. 4471d54945dSmrg dsttmp=$dstdir/_inst.$$_ 4481d54945dSmrg rmtmp=$dstdir/_rm.$$_ 4491d54945dSmrg 4501d54945dSmrg # Trap to clean up those temp files at exit. 4511d54945dSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4521d54945dSmrg 4531d54945dSmrg # Copy the file name to the temp name. 454ba85709eSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4551d54945dSmrg 4561d54945dSmrg # and set any options; do chmod last to preserve setuid bits. 4571d54945dSmrg # 4581d54945dSmrg # If any of these fail, we abort the whole thing. If we want to 4591d54945dSmrg # ignore errors from any of these, just make sure not to ignore 4601d54945dSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4611d54945dSmrg # 4621d54945dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 4631d54945dSmrg && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 4641d54945dSmrg && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ 465ba85709eSmrg && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4661d54945dSmrg 4671d54945dSmrg # Now rename the file to the real destination. 468ba85709eSmrg { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \ 4691d54945dSmrg || { 4701d54945dSmrg # The rename failed, perhaps because mv can't rename something else 4711d54945dSmrg # to itself, or perhaps because mv is so ancient that it does not 4721d54945dSmrg # support -f. 4731d54945dSmrg 4741d54945dSmrg # Now remove or move aside any old file at destination location. 4751d54945dSmrg # We try this two ways since rm can't unlink itself on some 4761d54945dSmrg # systems and the destination file might be busy for other 4771d54945dSmrg # reasons. In this case, the final cleanup might fail but the new 4781d54945dSmrg # file should still install successfully. 4791d54945dSmrg { 480ba85709eSmrg if test -f "$dst"; then 481ba85709eSmrg $doit $rmcmd -f "$dst" 2>/dev/null \ 482ba85709eSmrg || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \ 483ba85709eSmrg && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\ 4841d54945dSmrg || { 485ba85709eSmrg echo "$0: cannot unlink or rename $dst" >&2 4861d54945dSmrg (exit 1); exit 1 4871d54945dSmrg } 4881d54945dSmrg else 4891d54945dSmrg : 4901d54945dSmrg fi 4911d54945dSmrg } && 4921d54945dSmrg 4931d54945dSmrg # Now rename the file to the real destination. 494ba85709eSmrg $doit $mvcmd "$dsttmp" "$dst" 4951d54945dSmrg } 496ba85709eSmrg } || exit 1 4971d54945dSmrg 498ba85709eSmrg trap '' 0 499ba85709eSmrg fi 500ba85709eSmrgdone 5011d54945dSmrg 5021d54945dSmrg# Local variables: 5031d54945dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5041d54945dSmrg# time-stamp-start: "scriptversion=" 5051d54945dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5061d54945dSmrg# time-stamp-end: "$" 5071d54945dSmrg# End: 508