install-sh revision 63165362
10eb10989Smrg#!/bin/sh 20eb10989Smrg# install - install a program, script, or datafile 30eb10989Smrg 463165362Smrgscriptversion=2009-04-28.21; # UTC 50eb10989Smrg 60eb10989Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 70eb10989Smrg# later released in X11R6 (xc/config/util/install.sh) with the 80eb10989Smrg# following copyright and license. 90eb10989Smrg# 100eb10989Smrg# Copyright (C) 1994 X Consortium 110eb10989Smrg# 120eb10989Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 130eb10989Smrg# of this software and associated documentation files (the "Software"), to 140eb10989Smrg# deal in the Software without restriction, including without limitation the 150eb10989Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 160eb10989Smrg# sell copies of the Software, and to permit persons to whom the Software is 170eb10989Smrg# furnished to do so, subject to the following conditions: 180eb10989Smrg# 190eb10989Smrg# The above copyright notice and this permission notice shall be included in 200eb10989Smrg# all copies or substantial portions of the Software. 210eb10989Smrg# 220eb10989Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 230eb10989Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 240eb10989Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 250eb10989Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 260eb10989Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 270eb10989Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 280eb10989Smrg# 290eb10989Smrg# Except as contained in this notice, the name of the X Consortium shall not 300eb10989Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 310eb10989Smrg# ings in this Software without prior written authorization from the X Consor- 320eb10989Smrg# tium. 330eb10989Smrg# 340eb10989Smrg# 350eb10989Smrg# FSF changes to this file are in the public domain. 360eb10989Smrg# 370eb10989Smrg# Calling this script install-sh is preferred over install.sh, to prevent 380eb10989Smrg# `make' implicit rules from creating a file called install from it 390eb10989Smrg# when there is no Makefile. 400eb10989Smrg# 410eb10989Smrg# This script is compatible with the BSD install script, but was written 4263165362Smrg# from scratch. 4363165362Smrg 4463165362Smrgnl=' 4563165362Smrg' 4663165362SmrgIFS=" "" $nl" 470eb10989Smrg 480eb10989Smrg# set DOITPROG to echo to test this script 490eb10989Smrg 500eb10989Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5163165362Smrgdoit=${DOITPROG-} 5263165362Smrgif test -z "$doit"; then 5363165362Smrg doit_exec=exec 5463165362Smrgelse 5563165362Smrg doit_exec=$doit 5663165362Smrgfi 570eb10989Smrg 5863165362Smrg# Put in absolute file names if you don't have them in your path; 5963165362Smrg# or use environment vars. 6063165362Smrg 6163165362Smrgchgrpprog=${CHGRPPROG-chgrp} 6263165362Smrgchmodprog=${CHMODPROG-chmod} 6363165362Smrgchownprog=${CHOWNPROG-chown} 6463165362Smrgcmpprog=${CMPPROG-cmp} 6563165362Smrgcpprog=${CPPROG-cp} 6663165362Smrgmkdirprog=${MKDIRPROG-mkdir} 6763165362Smrgmvprog=${MVPROG-mv} 6863165362Smrgrmprog=${RMPROG-rm} 6963165362Smrgstripprog=${STRIPPROG-strip} 7063165362Smrg 7163165362Smrgposix_glob='?' 7263165362Smrginitialize_posix_glob=' 7363165362Smrg test "$posix_glob" != "?" || { 7463165362Smrg if (set -f) 2>/dev/null; then 7563165362Smrg posix_glob= 7663165362Smrg else 7763165362Smrg posix_glob=: 7863165362Smrg fi 7963165362Smrg } 8063165362Smrg' 810eb10989Smrg 8263165362Smrgposix_mkdir= 8363165362Smrg 8463165362Smrg# Desired mode of installed file. 8563165362Smrgmode=0755 860eb10989Smrg 870eb10989Smrgchgrpcmd= 8863165362Smrgchmodcmd=$chmodprog 8963165362Smrgchowncmd= 9063165362Smrgmvcmd=$mvprog 910eb10989Smrgrmcmd="$rmprog -f" 9263165362Smrgstripcmd= 9363165362Smrg 940eb10989Smrgsrc= 950eb10989Smrgdst= 960eb10989Smrgdir_arg= 9763165362Smrgdst_arg= 9863165362Smrg 9963165362Smrgcopy_on_change=false 1000eb10989Smrgno_target_directory= 1010eb10989Smrg 10263165362Smrgusage="\ 10363165362SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1040eb10989Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1050eb10989Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1060eb10989Smrg or: $0 [OPTION]... -d DIRECTORIES... 1070eb10989Smrg 1080eb10989SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1090eb10989SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1100eb10989SmrgIn the 4th, create DIRECTORIES. 1110eb10989Smrg 1120eb10989SmrgOptions: 11363165362Smrg --help display this help and exit. 11463165362Smrg --version display version info and exit. 11563165362Smrg 11663165362Smrg -c (ignored) 11763165362Smrg -C install only if different (preserve the last data modification time) 11863165362Smrg -d create directories instead of installing files. 11963165362Smrg -g GROUP $chgrpprog installed files to GROUP. 12063165362Smrg -m MODE $chmodprog installed files to MODE. 12163165362Smrg -o USER $chownprog installed files to USER. 12263165362Smrg -s $stripprog installed files. 12363165362Smrg -t DIRECTORY install into DIRECTORY. 12463165362Smrg -T report an error if DSTFILE is a directory. 1250eb10989Smrg 1260eb10989SmrgEnvironment variables override the default commands: 12763165362Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12863165362Smrg RMPROG STRIPPROG 1290eb10989Smrg" 1300eb10989Smrg 13163165362Smrgwhile test $# -ne 0; do 1320eb10989Smrg case $1 in 13363165362Smrg -c) ;; 13463165362Smrg 13563165362Smrg -C) copy_on_change=true;; 1360eb10989Smrg 13763165362Smrg -d) dir_arg=true;; 1380eb10989Smrg 1390eb10989Smrg -g) chgrpcmd="$chgrpprog $2" 14063165362Smrg shift;; 1410eb10989Smrg 1420eb10989Smrg --help) echo "$usage"; exit $?;; 1430eb10989Smrg 14463165362Smrg -m) mode=$2 14563165362Smrg case $mode in 14663165362Smrg *' '* | *' '* | *' 14763165362Smrg'* | *'*'* | *'?'* | *'['*) 14863165362Smrg echo "$0: invalid mode: $mode" >&2 14963165362Smrg exit 1;; 15063165362Smrg esac 15163165362Smrg shift;; 1520eb10989Smrg 1530eb10989Smrg -o) chowncmd="$chownprog $2" 15463165362Smrg shift;; 1550eb10989Smrg 15663165362Smrg -s) stripcmd=$stripprog;; 1570eb10989Smrg 15863165362Smrg -t) dst_arg=$2 15963165362Smrg shift;; 1600eb10989Smrg 16163165362Smrg -T) no_target_directory=true;; 1620eb10989Smrg 1630eb10989Smrg --version) echo "$0 $scriptversion"; exit $?;; 1640eb10989Smrg 16563165362Smrg --) shift 1660eb10989Smrg break;; 16763165362Smrg 16863165362Smrg -*) echo "$0: invalid option: $1" >&2 16963165362Smrg exit 1;; 17063165362Smrg 17163165362Smrg *) break;; 1720eb10989Smrg esac 17363165362Smrg shift 1740eb10989Smrgdone 1750eb10989Smrg 17663165362Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17763165362Smrg # When -d is used, all remaining arguments are directories to create. 17863165362Smrg # When -t is used, the destination is already specified. 17963165362Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18063165362Smrg for arg 18163165362Smrg do 18263165362Smrg if test -n "$dst_arg"; then 18363165362Smrg # $@ is not empty: it contains at least $arg. 18463165362Smrg set fnord "$@" "$dst_arg" 18563165362Smrg shift # fnord 18663165362Smrg fi 18763165362Smrg shift # arg 18863165362Smrg dst_arg=$arg 18963165362Smrg done 19063165362Smrgfi 19163165362Smrg 19263165362Smrgif test $# -eq 0; then 1930eb10989Smrg if test -z "$dir_arg"; then 1940eb10989Smrg echo "$0: no input file specified." >&2 1950eb10989Smrg exit 1 1960eb10989Smrg fi 1970eb10989Smrg # It's OK to call `install-sh -d' without argument. 1980eb10989Smrg # This can happen when creating conditional directories. 1990eb10989Smrg exit 0 2000eb10989Smrgfi 2010eb10989Smrg 20263165362Smrgif test -z "$dir_arg"; then 20363165362Smrg trap '(exit $?); exit' 1 2 13 15 20463165362Smrg 20563165362Smrg # Set umask so as not to create temps with too-generous modes. 20663165362Smrg # However, 'strip' requires both read and write access to temps. 20763165362Smrg case $mode in 20863165362Smrg # Optimize common cases. 20963165362Smrg *644) cp_umask=133;; 21063165362Smrg *755) cp_umask=22;; 21163165362Smrg 21263165362Smrg *[0-7]) 21363165362Smrg if test -z "$stripcmd"; then 21463165362Smrg u_plus_rw= 21563165362Smrg else 21663165362Smrg u_plus_rw='% 200' 21763165362Smrg fi 21863165362Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21963165362Smrg *) 22063165362Smrg if test -z "$stripcmd"; then 22163165362Smrg u_plus_rw= 22263165362Smrg else 22363165362Smrg u_plus_rw=,u+rw 22463165362Smrg fi 22563165362Smrg cp_umask=$mode$u_plus_rw;; 22663165362Smrg esac 22763165362Smrgfi 22863165362Smrg 2290eb10989Smrgfor src 2300eb10989Smrgdo 2310eb10989Smrg # Protect names starting with `-'. 2320eb10989Smrg case $src in 23363165362Smrg -*) src=./$src;; 2340eb10989Smrg esac 2350eb10989Smrg 2360eb10989Smrg if test -n "$dir_arg"; then 2370eb10989Smrg dst=$src 23863165362Smrg dstdir=$dst 23963165362Smrg test -d "$dstdir" 24063165362Smrg dstdir_status=$? 2410eb10989Smrg else 24263165362Smrg 2430eb10989Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2440eb10989Smrg # might cause directories to be created, which would be especially bad 2450eb10989Smrg # if $src (and thus $dsttmp) contains '*'. 2460eb10989Smrg if test ! -f "$src" && test ! -d "$src"; then 2470eb10989Smrg echo "$0: $src does not exist." >&2 2480eb10989Smrg exit 1 2490eb10989Smrg fi 2500eb10989Smrg 25163165362Smrg if test -z "$dst_arg"; then 2520eb10989Smrg echo "$0: no destination specified." >&2 2530eb10989Smrg exit 1 2540eb10989Smrg fi 2550eb10989Smrg 25663165362Smrg dst=$dst_arg 2570eb10989Smrg # Protect names starting with `-'. 2580eb10989Smrg case $dst in 25963165362Smrg -*) dst=./$dst;; 2600eb10989Smrg esac 2610eb10989Smrg 2620eb10989Smrg # If destination is a directory, append the input filename; won't work 2630eb10989Smrg # if double slashes aren't ignored. 2640eb10989Smrg if test -d "$dst"; then 2650eb10989Smrg if test -n "$no_target_directory"; then 26663165362Smrg echo "$0: $dst_arg: Is a directory" >&2 2670eb10989Smrg exit 1 2680eb10989Smrg fi 26963165362Smrg dstdir=$dst 27063165362Smrg dst=$dstdir/`basename "$src"` 27163165362Smrg dstdir_status=0 27263165362Smrg else 27363165362Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 27463165362Smrg dstdir=` 27563165362Smrg (dirname "$dst") 2>/dev/null || 27663165362Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27763165362Smrg X"$dst" : 'X\(//\)[^/]' \| \ 27863165362Smrg X"$dst" : 'X\(//\)$' \| \ 27963165362Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28063165362Smrg echo X"$dst" | 28163165362Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28263165362Smrg s//\1/ 28363165362Smrg q 28463165362Smrg } 28563165362Smrg /^X\(\/\/\)[^/].*/{ 28663165362Smrg s//\1/ 28763165362Smrg q 28863165362Smrg } 28963165362Smrg /^X\(\/\/\)$/{ 29063165362Smrg s//\1/ 29163165362Smrg q 29263165362Smrg } 29363165362Smrg /^X\(\/\).*/{ 29463165362Smrg s//\1/ 29563165362Smrg q 29663165362Smrg } 29763165362Smrg s/.*/./; q' 29863165362Smrg ` 29963165362Smrg 30063165362Smrg test -d "$dstdir" 30163165362Smrg dstdir_status=$? 3020eb10989Smrg fi 3030eb10989Smrg fi 3040eb10989Smrg 30563165362Smrg obsolete_mkdir_used=false 30663165362Smrg 30763165362Smrg if test $dstdir_status != 0; then 30863165362Smrg case $posix_mkdir in 30963165362Smrg '') 31063165362Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31163165362Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31263165362Smrg umask=`umask` 31363165362Smrg case $stripcmd.$umask in 31463165362Smrg # Optimize common cases. 31563165362Smrg *[2367][2367]) mkdir_umask=$umask;; 31663165362Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31763165362Smrg 31863165362Smrg *[0-7]) 31963165362Smrg mkdir_umask=`expr $umask + 22 \ 32063165362Smrg - $umask % 100 % 40 + $umask % 20 \ 32163165362Smrg - $umask % 10 % 4 + $umask % 2 32263165362Smrg `;; 32363165362Smrg *) mkdir_umask=$umask,go-w;; 32463165362Smrg esac 32563165362Smrg 32663165362Smrg # With -d, create the new directory with the user-specified mode. 32763165362Smrg # Otherwise, rely on $mkdir_umask. 32863165362Smrg if test -n "$dir_arg"; then 32963165362Smrg mkdir_mode=-m$mode 33063165362Smrg else 33163165362Smrg mkdir_mode= 33263165362Smrg fi 33363165362Smrg 33463165362Smrg posix_mkdir=false 33563165362Smrg case $umask in 33663165362Smrg *[123567][0-7][0-7]) 33763165362Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33863165362Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33963165362Smrg ;; 34063165362Smrg *) 34163165362Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34263165362Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34363165362Smrg 34463165362Smrg if (umask $mkdir_umask && 34563165362Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34663165362Smrg then 34763165362Smrg if test -z "$dir_arg" || { 34863165362Smrg # Check for POSIX incompatibilities with -m. 34963165362Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35063165362Smrg # other-writeable bit of parent directory when it shouldn't. 35163165362Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35263165362Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 35363165362Smrg case $ls_ld_tmpdir in 35463165362Smrg d????-?r-*) different_mode=700;; 35563165362Smrg d????-?--*) different_mode=755;; 35663165362Smrg *) false;; 35763165362Smrg esac && 35863165362Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35963165362Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36063165362Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36163165362Smrg } 36263165362Smrg } 36363165362Smrg then posix_mkdir=: 36463165362Smrg fi 36563165362Smrg rmdir "$tmpdir/d" "$tmpdir" 36663165362Smrg else 36763165362Smrg # Remove any dirs left behind by ancient mkdir implementations. 36863165362Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36963165362Smrg fi 37063165362Smrg trap '' 0;; 37163165362Smrg esac;; 37263165362Smrg esac 3730eb10989Smrg 37463165362Smrg if 37563165362Smrg $posix_mkdir && ( 37663165362Smrg umask $mkdir_umask && 37763165362Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37863165362Smrg ) 37963165362Smrg then : 38063165362Smrg else 3810eb10989Smrg 38263165362Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38363165362Smrg # or it failed possibly due to a race condition. Create the 38463165362Smrg # directory the slow way, step by step, checking for races as we go. 3850eb10989Smrg 38663165362Smrg case $dstdir in 38763165362Smrg /*) prefix='/';; 38863165362Smrg -*) prefix='./';; 38963165362Smrg *) prefix='';; 39063165362Smrg esac 3910eb10989Smrg 39263165362Smrg eval "$initialize_posix_glob" 3930eb10989Smrg 39463165362Smrg oIFS=$IFS 39563165362Smrg IFS=/ 39663165362Smrg $posix_glob set -f 39763165362Smrg set fnord $dstdir 3980eb10989Smrg shift 39963165362Smrg $posix_glob set +f 40063165362Smrg IFS=$oIFS 40163165362Smrg 40263165362Smrg prefixes= 40363165362Smrg 40463165362Smrg for d 40563165362Smrg do 40663165362Smrg test -z "$d" && continue 40763165362Smrg 40863165362Smrg prefix=$prefix$d 40963165362Smrg if test -d "$prefix"; then 41063165362Smrg prefixes= 41163165362Smrg else 41263165362Smrg if $posix_mkdir; then 41363165362Smrg (umask=$mkdir_umask && 41463165362Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41563165362Smrg # Don't fail if two instances are running concurrently. 41663165362Smrg test -d "$prefix" || exit 1 41763165362Smrg else 41863165362Smrg case $prefix in 41963165362Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42063165362Smrg *) qprefix=$prefix;; 42163165362Smrg esac 42263165362Smrg prefixes="$prefixes '$qprefix'" 42363165362Smrg fi 42463165362Smrg fi 42563165362Smrg prefix=$prefix/ 42663165362Smrg done 42763165362Smrg 42863165362Smrg if test -n "$prefixes"; then 42963165362Smrg # Don't fail if two instances are running concurrently. 43063165362Smrg (umask $mkdir_umask && 43163165362Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43263165362Smrg test -d "$dstdir" || exit 1 43363165362Smrg obsolete_mkdir_used=true 4340eb10989Smrg fi 43563165362Smrg fi 4360eb10989Smrg fi 4370eb10989Smrg 4380eb10989Smrg if test -n "$dir_arg"; then 43963165362Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44063165362Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44163165362Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44263165362Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4430eb10989Smrg else 4440eb10989Smrg 4450eb10989Smrg # Make a couple of temp file names in the proper directory. 4460eb10989Smrg dsttmp=$dstdir/_inst.$$_ 4470eb10989Smrg rmtmp=$dstdir/_rm.$$_ 4480eb10989Smrg 4490eb10989Smrg # Trap to clean up those temp files at exit. 4500eb10989Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4510eb10989Smrg 4520eb10989Smrg # Copy the file name to the temp name. 45363165362Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4540eb10989Smrg 4550eb10989Smrg # and set any options; do chmod last to preserve setuid bits. 4560eb10989Smrg # 4570eb10989Smrg # If any of these fail, we abort the whole thing. If we want to 4580eb10989Smrg # ignore errors from any of these, just make sure not to ignore 4590eb10989Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4600eb10989Smrg # 46163165362Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46263165362Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46363165362Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46463165362Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46563165362Smrg 46663165362Smrg # If -C, don't bother to copy if it wouldn't change the file. 46763165362Smrg if $copy_on_change && 46863165362Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46963165362Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47063165362Smrg 47163165362Smrg eval "$initialize_posix_glob" && 47263165362Smrg $posix_glob set -f && 47363165362Smrg set X $old && old=:$2:$4:$5:$6 && 47463165362Smrg set X $new && new=:$2:$4:$5:$6 && 47563165362Smrg $posix_glob set +f && 47663165362Smrg 47763165362Smrg test "$old" = "$new" && 47863165362Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47963165362Smrg then 48063165362Smrg rm -f "$dsttmp" 48163165362Smrg else 48263165362Smrg # Rename the file to the real destination. 48363165362Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48463165362Smrg 48563165362Smrg # The rename failed, perhaps because mv can't rename something else 48663165362Smrg # to itself, or perhaps because mv is so ancient that it does not 48763165362Smrg # support -f. 48863165362Smrg { 48963165362Smrg # Now remove or move aside any old file at destination location. 49063165362Smrg # We try this two ways since rm can't unlink itself on some 49163165362Smrg # systems and the destination file might be busy for other 49263165362Smrg # reasons. In this case, the final cleanup might fail but the new 49363165362Smrg # file should still install successfully. 49463165362Smrg { 49563165362Smrg test ! -f "$dst" || 49663165362Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 49763165362Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49863165362Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49963165362Smrg } || 50063165362Smrg { echo "$0: cannot unlink or rename $dst" >&2 50163165362Smrg (exit 1); exit 1 50263165362Smrg } 50363165362Smrg } && 50463165362Smrg 50563165362Smrg # Now rename the file to the real destination. 50663165362Smrg $doit $mvcmd "$dsttmp" "$dst" 50763165362Smrg } 50863165362Smrg fi || exit 1 50963165362Smrg 51063165362Smrg trap '' 0 51163165362Smrg fi 5120eb10989Smrgdone 5130eb10989Smrg 5140eb10989Smrg# Local variables: 5150eb10989Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5160eb10989Smrg# time-stamp-start: "scriptversion=" 5170eb10989Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 51863165362Smrg# time-stamp-time-zone: "UTC" 51963165362Smrg# time-stamp-end: "; # UTC" 5200eb10989Smrg# End: 521