install-sh revision 50539131
1ded1caa4Smrg#!/bin/sh 2ded1caa4Smrg# install - install a program, script, or datafile 350539131Smrg 450539131Smrgscriptversion=2009-04-28.21; # UTC 550539131Smrg 6ded1caa4Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7ded1caa4Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8ded1caa4Smrg# following copyright and license. 9ded1caa4Smrg# 10ded1caa4Smrg# Copyright (C) 1994 X Consortium 11ded1caa4Smrg# 12ded1caa4Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13ded1caa4Smrg# of this software and associated documentation files (the "Software"), to 14ded1caa4Smrg# deal in the Software without restriction, including without limitation the 15ded1caa4Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16ded1caa4Smrg# sell copies of the Software, and to permit persons to whom the Software is 17ded1caa4Smrg# furnished to do so, subject to the following conditions: 18ded1caa4Smrg# 19ded1caa4Smrg# The above copyright notice and this permission notice shall be included in 20ded1caa4Smrg# all copies or substantial portions of the Software. 21ded1caa4Smrg# 22ded1caa4Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23ded1caa4Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24ded1caa4Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25ded1caa4Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26ded1caa4Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27ded1caa4Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28ded1caa4Smrg# 29ded1caa4Smrg# Except as contained in this notice, the name of the X Consortium shall not 30ded1caa4Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31ded1caa4Smrg# ings in this Software without prior written authorization from the X Consor- 32ded1caa4Smrg# tium. 33ded1caa4Smrg# 34ded1caa4Smrg# 35ded1caa4Smrg# FSF changes to this file are in the public domain. 36ded1caa4Smrg# 37ded1caa4Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38ded1caa4Smrg# `make' implicit rules from creating a file called install from it 39ded1caa4Smrg# when there is no Makefile. 40ded1caa4Smrg# 41ded1caa4Smrg# This script is compatible with the BSD install script, but was written 4250539131Smrg# from scratch. 43ded1caa4Smrg 4450539131Smrgnl=' 4550539131Smrg' 4650539131SmrgIFS=" "" $nl" 47ded1caa4Smrg 48ded1caa4Smrg# set DOITPROG to echo to test this script 49ded1caa4Smrg 50ded1caa4Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5150539131Smrgdoit=${DOITPROG-} 5250539131Smrgif test -z "$doit"; then 5350539131Smrg doit_exec=exec 54ded1caa4Smrgelse 5550539131Smrg doit_exec=$doit 56ded1caa4Smrgfi 57ded1caa4Smrg 5850539131Smrg# Put in absolute file names if you don't have them in your path; 5950539131Smrg# or use environment vars. 6050539131Smrg 6150539131Smrgchgrpprog=${CHGRPPROG-chgrp} 6250539131Smrgchmodprog=${CHMODPROG-chmod} 6350539131Smrgchownprog=${CHOWNPROG-chown} 6450539131Smrgcmpprog=${CMPPROG-cmp} 6550539131Smrgcpprog=${CPPROG-cp} 6650539131Smrgmkdirprog=${MKDIRPROG-mkdir} 6750539131Smrgmvprog=${MVPROG-mv} 6850539131Smrgrmprog=${RMPROG-rm} 6950539131Smrgstripprog=${STRIPPROG-strip} 7050539131Smrg 7150539131Smrgposix_glob='?' 7250539131Smrginitialize_posix_glob=' 7350539131Smrg test "$posix_glob" != "?" || { 7450539131Smrg if (set -f) 2>/dev/null; then 7550539131Smrg posix_glob= 7650539131Smrg else 7750539131Smrg posix_glob=: 7850539131Smrg fi 7950539131Smrg } 8050539131Smrg' 8150539131Smrg 8250539131Smrgposix_mkdir= 8350539131Smrg 8450539131Smrg# Desired mode of installed file. 8550539131Smrgmode=0755 8650539131Smrg 8750539131Smrgchgrpcmd= 8850539131Smrgchmodcmd=$chmodprog 8950539131Smrgchowncmd= 9050539131Smrgmvcmd=$mvprog 9150539131Smrgrmcmd="$rmprog -f" 9250539131Smrgstripcmd= 93ded1caa4Smrg 9450539131Smrgsrc= 9550539131Smrgdst= 9650539131Smrgdir_arg= 9750539131Smrgdst_arg= 98ded1caa4Smrg 9950539131Smrgcopy_on_change=false 10050539131Smrgno_target_directory= 101ded1caa4Smrg 10250539131Smrgusage="\ 10350539131SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10450539131Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10550539131Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10650539131Smrg or: $0 [OPTION]... -d DIRECTORIES... 107ded1caa4Smrg 10850539131SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10950539131SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11050539131SmrgIn the 4th, create DIRECTORIES. 111ded1caa4Smrg 11250539131SmrgOptions: 11350539131Smrg --help display this help and exit. 11450539131Smrg --version display version info and exit. 115ded1caa4Smrg 11650539131Smrg -c (ignored) 11750539131Smrg -C install only if different (preserve the last data modification time) 11850539131Smrg -d create directories instead of installing files. 11950539131Smrg -g GROUP $chgrpprog installed files to GROUP. 12050539131Smrg -m MODE $chmodprog installed files to MODE. 12150539131Smrg -o USER $chownprog installed files to USER. 12250539131Smrg -s $stripprog installed files. 12350539131Smrg -t DIRECTORY install into DIRECTORY. 12450539131Smrg -T report an error if DSTFILE is a directory. 125ded1caa4Smrg 12650539131SmrgEnvironment variables override the default commands: 12750539131Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12850539131Smrg RMPROG STRIPPROG 12950539131Smrg" 130ded1caa4Smrg 13150539131Smrgwhile test $# -ne 0; do 13250539131Smrg case $1 in 13350539131Smrg -c) ;; 134ded1caa4Smrg 13550539131Smrg -C) copy_on_change=true;; 136ded1caa4Smrg 13750539131Smrg -d) dir_arg=true;; 138ded1caa4Smrg 13950539131Smrg -g) chgrpcmd="$chgrpprog $2" 14050539131Smrg shift;; 141ded1caa4Smrg 14250539131Smrg --help) echo "$usage"; exit $?;; 143ded1caa4Smrg 14450539131Smrg -m) mode=$2 14550539131Smrg case $mode in 14650539131Smrg *' '* | *' '* | *' 14750539131Smrg'* | *'*'* | *'?'* | *'['*) 14850539131Smrg echo "$0: invalid mode: $mode" >&2 14950539131Smrg exit 1;; 15050539131Smrg esac 15150539131Smrg shift;; 152ded1caa4Smrg 15350539131Smrg -o) chowncmd="$chownprog $2" 15450539131Smrg shift;; 155ded1caa4Smrg 15650539131Smrg -s) stripcmd=$stripprog;; 157ded1caa4Smrg 15850539131Smrg -t) dst_arg=$2 15950539131Smrg shift;; 160ded1caa4Smrg 16150539131Smrg -T) no_target_directory=true;; 162ded1caa4Smrg 16350539131Smrg --version) echo "$0 $scriptversion"; exit $?;; 164ded1caa4Smrg 16550539131Smrg --) shift 16650539131Smrg break;; 167ded1caa4Smrg 16850539131Smrg -*) echo "$0: invalid option: $1" >&2 16950539131Smrg exit 1;; 170ded1caa4Smrg 17150539131Smrg *) break;; 17250539131Smrg esac 17350539131Smrg shift 17450539131Smrgdone 175ded1caa4Smrg 17650539131Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17750539131Smrg # When -d is used, all remaining arguments are directories to create. 17850539131Smrg # When -t is used, the destination is already specified. 17950539131Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18050539131Smrg for arg 18150539131Smrg do 18250539131Smrg if test -n "$dst_arg"; then 18350539131Smrg # $@ is not empty: it contains at least $arg. 18450539131Smrg set fnord "$@" "$dst_arg" 18550539131Smrg shift # fnord 18650539131Smrg fi 18750539131Smrg shift # arg 18850539131Smrg dst_arg=$arg 18950539131Smrg done 19050539131Smrgfi 191ded1caa4Smrg 19250539131Smrgif test $# -eq 0; then 19350539131Smrg if test -z "$dir_arg"; then 19450539131Smrg echo "$0: no input file specified." >&2 19550539131Smrg exit 1 19650539131Smrg fi 19750539131Smrg # It's OK to call `install-sh -d' without argument. 19850539131Smrg # This can happen when creating conditional directories. 19950539131Smrg exit 0 20050539131Smrgfi 201ded1caa4Smrg 20250539131Smrgif test -z "$dir_arg"; then 20350539131Smrg trap '(exit $?); exit' 1 2 13 15 20450539131Smrg 20550539131Smrg # Set umask so as not to create temps with too-generous modes. 20650539131Smrg # However, 'strip' requires both read and write access to temps. 20750539131Smrg case $mode in 20850539131Smrg # Optimize common cases. 20950539131Smrg *644) cp_umask=133;; 21050539131Smrg *755) cp_umask=22;; 21150539131Smrg 21250539131Smrg *[0-7]) 21350539131Smrg if test -z "$stripcmd"; then 21450539131Smrg u_plus_rw= 21550539131Smrg else 21650539131Smrg u_plus_rw='% 200' 21750539131Smrg fi 21850539131Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21950539131Smrg *) 22050539131Smrg if test -z "$stripcmd"; then 22150539131Smrg u_plus_rw= 22250539131Smrg else 22350539131Smrg u_plus_rw=,u+rw 22450539131Smrg fi 22550539131Smrg cp_umask=$mode$u_plus_rw;; 22650539131Smrg esac 22750539131Smrgfi 228ded1caa4Smrg 22950539131Smrgfor src 23050539131Smrgdo 23150539131Smrg # Protect names starting with `-'. 23250539131Smrg case $src in 23350539131Smrg -*) src=./$src;; 23450539131Smrg esac 23550539131Smrg 23650539131Smrg if test -n "$dir_arg"; then 23750539131Smrg dst=$src 23850539131Smrg dstdir=$dst 23950539131Smrg test -d "$dstdir" 24050539131Smrg dstdir_status=$? 24150539131Smrg else 24250539131Smrg 24350539131Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24450539131Smrg # might cause directories to be created, which would be especially bad 24550539131Smrg # if $src (and thus $dsttmp) contains '*'. 24650539131Smrg if test ! -f "$src" && test ! -d "$src"; then 24750539131Smrg echo "$0: $src does not exist." >&2 24850539131Smrg exit 1 24950539131Smrg fi 25050539131Smrg 25150539131Smrg if test -z "$dst_arg"; then 25250539131Smrg echo "$0: no destination specified." >&2 25350539131Smrg exit 1 25450539131Smrg fi 25550539131Smrg 25650539131Smrg dst=$dst_arg 25750539131Smrg # Protect names starting with `-'. 25850539131Smrg case $dst in 25950539131Smrg -*) dst=./$dst;; 26050539131Smrg esac 261ded1caa4Smrg 26250539131Smrg # If destination is a directory, append the input filename; won't work 26350539131Smrg # if double slashes aren't ignored. 26450539131Smrg if test -d "$dst"; then 26550539131Smrg if test -n "$no_target_directory"; then 26650539131Smrg echo "$0: $dst_arg: Is a directory" >&2 26750539131Smrg exit 1 26850539131Smrg fi 26950539131Smrg dstdir=$dst 27050539131Smrg dst=$dstdir/`basename "$src"` 27150539131Smrg dstdir_status=0 27250539131Smrg else 27350539131Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 27450539131Smrg dstdir=` 27550539131Smrg (dirname "$dst") 2>/dev/null || 27650539131Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27750539131Smrg X"$dst" : 'X\(//\)[^/]' \| \ 27850539131Smrg X"$dst" : 'X\(//\)$' \| \ 27950539131Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28050539131Smrg echo X"$dst" | 28150539131Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28250539131Smrg s//\1/ 28350539131Smrg q 28450539131Smrg } 28550539131Smrg /^X\(\/\/\)[^/].*/{ 28650539131Smrg s//\1/ 28750539131Smrg q 28850539131Smrg } 28950539131Smrg /^X\(\/\/\)$/{ 29050539131Smrg s//\1/ 29150539131Smrg q 29250539131Smrg } 29350539131Smrg /^X\(\/\).*/{ 29450539131Smrg s//\1/ 29550539131Smrg q 29650539131Smrg } 29750539131Smrg s/.*/./; q' 29850539131Smrg ` 29950539131Smrg 30050539131Smrg test -d "$dstdir" 30150539131Smrg dstdir_status=$? 30250539131Smrg fi 30350539131Smrg fi 30450539131Smrg 30550539131Smrg obsolete_mkdir_used=false 30650539131Smrg 30750539131Smrg if test $dstdir_status != 0; then 30850539131Smrg case $posix_mkdir in 30950539131Smrg '') 31050539131Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31150539131Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31250539131Smrg umask=`umask` 31350539131Smrg case $stripcmd.$umask in 31450539131Smrg # Optimize common cases. 31550539131Smrg *[2367][2367]) mkdir_umask=$umask;; 31650539131Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31750539131Smrg 31850539131Smrg *[0-7]) 31950539131Smrg mkdir_umask=`expr $umask + 22 \ 32050539131Smrg - $umask % 100 % 40 + $umask % 20 \ 32150539131Smrg - $umask % 10 % 4 + $umask % 2 32250539131Smrg `;; 32350539131Smrg *) mkdir_umask=$umask,go-w;; 32450539131Smrg esac 32550539131Smrg 32650539131Smrg # With -d, create the new directory with the user-specified mode. 32750539131Smrg # Otherwise, rely on $mkdir_umask. 32850539131Smrg if test -n "$dir_arg"; then 32950539131Smrg mkdir_mode=-m$mode 330ded1caa4Smrg else 33150539131Smrg mkdir_mode= 332ded1caa4Smrg fi 333ded1caa4Smrg 33450539131Smrg posix_mkdir=false 33550539131Smrg case $umask in 33650539131Smrg *[123567][0-7][0-7]) 33750539131Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33850539131Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33950539131Smrg ;; 34050539131Smrg *) 34150539131Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34250539131Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34350539131Smrg 34450539131Smrg if (umask $mkdir_umask && 34550539131Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34650539131Smrg then 34750539131Smrg if test -z "$dir_arg" || { 34850539131Smrg # Check for POSIX incompatibilities with -m. 34950539131Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35050539131Smrg # other-writeable bit of parent directory when it shouldn't. 35150539131Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35250539131Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 35350539131Smrg case $ls_ld_tmpdir in 35450539131Smrg d????-?r-*) different_mode=700;; 35550539131Smrg d????-?--*) different_mode=755;; 35650539131Smrg *) false;; 35750539131Smrg esac && 35850539131Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35950539131Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36050539131Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36150539131Smrg } 36250539131Smrg } 36350539131Smrg then posix_mkdir=: 36450539131Smrg fi 36550539131Smrg rmdir "$tmpdir/d" "$tmpdir" 36650539131Smrg else 36750539131Smrg # Remove any dirs left behind by ancient mkdir implementations. 36850539131Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36950539131Smrg fi 37050539131Smrg trap '' 0;; 37150539131Smrg esac;; 37250539131Smrg esac 373ded1caa4Smrg 37450539131Smrg if 37550539131Smrg $posix_mkdir && ( 37650539131Smrg umask $mkdir_umask && 37750539131Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37850539131Smrg ) 37950539131Smrg then : 38050539131Smrg else 38150539131Smrg 38250539131Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38350539131Smrg # or it failed possibly due to a race condition. Create the 38450539131Smrg # directory the slow way, step by step, checking for races as we go. 38550539131Smrg 38650539131Smrg case $dstdir in 38750539131Smrg /*) prefix='/';; 38850539131Smrg -*) prefix='./';; 38950539131Smrg *) prefix='';; 39050539131Smrg esac 39150539131Smrg 39250539131Smrg eval "$initialize_posix_glob" 39350539131Smrg 39450539131Smrg oIFS=$IFS 39550539131Smrg IFS=/ 39650539131Smrg $posix_glob set -f 39750539131Smrg set fnord $dstdir 39850539131Smrg shift 39950539131Smrg $posix_glob set +f 40050539131Smrg IFS=$oIFS 40150539131Smrg 40250539131Smrg prefixes= 40350539131Smrg 40450539131Smrg for d 40550539131Smrg do 40650539131Smrg test -z "$d" && continue 40750539131Smrg 40850539131Smrg prefix=$prefix$d 40950539131Smrg if test -d "$prefix"; then 41050539131Smrg prefixes= 41150539131Smrg else 41250539131Smrg if $posix_mkdir; then 41350539131Smrg (umask=$mkdir_umask && 41450539131Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41550539131Smrg # Don't fail if two instances are running concurrently. 41650539131Smrg test -d "$prefix" || exit 1 41750539131Smrg else 41850539131Smrg case $prefix in 41950539131Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42050539131Smrg *) qprefix=$prefix;; 42150539131Smrg esac 42250539131Smrg prefixes="$prefixes '$qprefix'" 42350539131Smrg fi 42450539131Smrg fi 42550539131Smrg prefix=$prefix/ 42650539131Smrg done 42750539131Smrg 42850539131Smrg if test -n "$prefixes"; then 42950539131Smrg # Don't fail if two instances are running concurrently. 43050539131Smrg (umask $mkdir_umask && 43150539131Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43250539131Smrg test -d "$dstdir" || exit 1 43350539131Smrg obsolete_mkdir_used=true 43450539131Smrg fi 43550539131Smrg fi 43650539131Smrg fi 43750539131Smrg 43850539131Smrg if test -n "$dir_arg"; then 43950539131Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44050539131Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44150539131Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44250539131Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44350539131Smrg else 44450539131Smrg 44550539131Smrg # Make a couple of temp file names in the proper directory. 44650539131Smrg dsttmp=$dstdir/_inst.$$_ 44750539131Smrg rmtmp=$dstdir/_rm.$$_ 44850539131Smrg 44950539131Smrg # Trap to clean up those temp files at exit. 45050539131Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45150539131Smrg 45250539131Smrg # Copy the file name to the temp name. 45350539131Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45450539131Smrg 45550539131Smrg # and set any options; do chmod last to preserve setuid bits. 45650539131Smrg # 45750539131Smrg # If any of these fail, we abort the whole thing. If we want to 45850539131Smrg # ignore errors from any of these, just make sure not to ignore 45950539131Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46050539131Smrg # 46150539131Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46250539131Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46350539131Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46450539131Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46550539131Smrg 46650539131Smrg # If -C, don't bother to copy if it wouldn't change the file. 46750539131Smrg if $copy_on_change && 46850539131Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46950539131Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47050539131Smrg 47150539131Smrg eval "$initialize_posix_glob" && 47250539131Smrg $posix_glob set -f && 47350539131Smrg set X $old && old=:$2:$4:$5:$6 && 47450539131Smrg set X $new && new=:$2:$4:$5:$6 && 47550539131Smrg $posix_glob set +f && 47650539131Smrg 47750539131Smrg test "$old" = "$new" && 47850539131Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47950539131Smrg then 48050539131Smrg rm -f "$dsttmp" 48150539131Smrg else 48250539131Smrg # Rename the file to the real destination. 48350539131Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48450539131Smrg 48550539131Smrg # The rename failed, perhaps because mv can't rename something else 48650539131Smrg # to itself, or perhaps because mv is so ancient that it does not 48750539131Smrg # support -f. 48850539131Smrg { 48950539131Smrg # Now remove or move aside any old file at destination location. 49050539131Smrg # We try this two ways since rm can't unlink itself on some 49150539131Smrg # systems and the destination file might be busy for other 49250539131Smrg # reasons. In this case, the final cleanup might fail but the new 49350539131Smrg # file should still install successfully. 49450539131Smrg { 49550539131Smrg test ! -f "$dst" || 49650539131Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 49750539131Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49850539131Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49950539131Smrg } || 50050539131Smrg { echo "$0: cannot unlink or rename $dst" >&2 50150539131Smrg (exit 1); exit 1 50250539131Smrg } 50350539131Smrg } && 50450539131Smrg 50550539131Smrg # Now rename the file to the real destination. 50650539131Smrg $doit $mvcmd "$dsttmp" "$dst" 50750539131Smrg } 50850539131Smrg fi || exit 1 50950539131Smrg 51050539131Smrg trap '' 0 51150539131Smrg fi 51250539131Smrgdone 513ded1caa4Smrg 51450539131Smrg# Local variables: 51550539131Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 51650539131Smrg# time-stamp-start: "scriptversion=" 51750539131Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 51850539131Smrg# time-stamp-time-zone: "UTC" 51950539131Smrg# time-stamp-end: "; # UTC" 52050539131Smrg# End: 521