install-sh revision 079e7944
10eb10989Smrg#!/bin/sh 20eb10989Smrg# install - install a program, script, or datafile 30eb10989Smrg 4079e7944Smrgscriptversion=2011-11-20.07; # 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 38079e7944Smrg# '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 159079e7944Smrg # Protect names problematic for 'test' and other utilities. 160079e7944Smrg case $dst_arg in 161079e7944Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162079e7944Smrg esac 16363165362Smrg shift;; 1640eb10989Smrg 16563165362Smrg -T) no_target_directory=true;; 1660eb10989Smrg 1670eb10989Smrg --version) echo "$0 $scriptversion"; exit $?;; 1680eb10989Smrg 16963165362Smrg --) shift 1700eb10989Smrg break;; 17163165362Smrg 17263165362Smrg -*) echo "$0: invalid option: $1" >&2 17363165362Smrg exit 1;; 17463165362Smrg 17563165362Smrg *) break;; 1760eb10989Smrg esac 17763165362Smrg shift 1780eb10989Smrgdone 1790eb10989Smrg 18063165362Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 18163165362Smrg # When -d is used, all remaining arguments are directories to create. 18263165362Smrg # When -t is used, the destination is already specified. 18363165362Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18463165362Smrg for arg 18563165362Smrg do 18663165362Smrg if test -n "$dst_arg"; then 18763165362Smrg # $@ is not empty: it contains at least $arg. 18863165362Smrg set fnord "$@" "$dst_arg" 18963165362Smrg shift # fnord 19063165362Smrg fi 19163165362Smrg shift # arg 19263165362Smrg dst_arg=$arg 193079e7944Smrg # Protect names problematic for 'test' and other utilities. 194079e7944Smrg case $dst_arg in 195079e7944Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196079e7944Smrg esac 19763165362Smrg done 19863165362Smrgfi 19963165362Smrg 20063165362Smrgif test $# -eq 0; then 2010eb10989Smrg if test -z "$dir_arg"; then 2020eb10989Smrg echo "$0: no input file specified." >&2 2030eb10989Smrg exit 1 2040eb10989Smrg fi 205079e7944Smrg # It's OK to call 'install-sh -d' without argument. 2060eb10989Smrg # This can happen when creating conditional directories. 2070eb10989Smrg exit 0 2080eb10989Smrgfi 2090eb10989Smrg 21063165362Smrgif test -z "$dir_arg"; then 211079e7944Smrg do_exit='(exit $ret); exit $ret' 212079e7944Smrg trap "ret=129; $do_exit" 1 213079e7944Smrg trap "ret=130; $do_exit" 2 214079e7944Smrg trap "ret=141; $do_exit" 13 215079e7944Smrg trap "ret=143; $do_exit" 15 21663165362Smrg 21763165362Smrg # Set umask so as not to create temps with too-generous modes. 21863165362Smrg # However, 'strip' requires both read and write access to temps. 21963165362Smrg case $mode in 22063165362Smrg # Optimize common cases. 22163165362Smrg *644) cp_umask=133;; 22263165362Smrg *755) cp_umask=22;; 22363165362Smrg 22463165362Smrg *[0-7]) 22563165362Smrg if test -z "$stripcmd"; then 22663165362Smrg u_plus_rw= 22763165362Smrg else 22863165362Smrg u_plus_rw='% 200' 22963165362Smrg fi 23063165362Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23163165362Smrg *) 23263165362Smrg if test -z "$stripcmd"; then 23363165362Smrg u_plus_rw= 23463165362Smrg else 23563165362Smrg u_plus_rw=,u+rw 23663165362Smrg fi 23763165362Smrg cp_umask=$mode$u_plus_rw;; 23863165362Smrg esac 23963165362Smrgfi 24063165362Smrg 2410eb10989Smrgfor src 2420eb10989Smrgdo 243079e7944Smrg # Protect names problematic for 'test' and other utilities. 2440eb10989Smrg case $src in 245079e7944Smrg -* | [=\(\)!]) src=./$src;; 2460eb10989Smrg esac 2470eb10989Smrg 2480eb10989Smrg if test -n "$dir_arg"; then 2490eb10989Smrg dst=$src 25063165362Smrg dstdir=$dst 25163165362Smrg test -d "$dstdir" 25263165362Smrg dstdir_status=$? 2530eb10989Smrg else 25463165362Smrg 2550eb10989Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2560eb10989Smrg # might cause directories to be created, which would be especially bad 2570eb10989Smrg # if $src (and thus $dsttmp) contains '*'. 2580eb10989Smrg if test ! -f "$src" && test ! -d "$src"; then 2590eb10989Smrg echo "$0: $src does not exist." >&2 2600eb10989Smrg exit 1 2610eb10989Smrg fi 2620eb10989Smrg 26363165362Smrg if test -z "$dst_arg"; then 2640eb10989Smrg echo "$0: no destination specified." >&2 2650eb10989Smrg exit 1 2660eb10989Smrg fi 26763165362Smrg dst=$dst_arg 2680eb10989Smrg 2690eb10989Smrg # If destination is a directory, append the input filename; won't work 2700eb10989Smrg # if double slashes aren't ignored. 2710eb10989Smrg if test -d "$dst"; then 2720eb10989Smrg if test -n "$no_target_directory"; then 27363165362Smrg echo "$0: $dst_arg: Is a directory" >&2 2740eb10989Smrg exit 1 2750eb10989Smrg fi 27663165362Smrg dstdir=$dst 27763165362Smrg dst=$dstdir/`basename "$src"` 27863165362Smrg dstdir_status=0 27963165362Smrg else 28063165362Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 28163165362Smrg dstdir=` 28263165362Smrg (dirname "$dst") 2>/dev/null || 28363165362Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 28463165362Smrg X"$dst" : 'X\(//\)[^/]' \| \ 28563165362Smrg X"$dst" : 'X\(//\)$' \| \ 28663165362Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28763165362Smrg echo X"$dst" | 28863165362Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28963165362Smrg s//\1/ 29063165362Smrg q 29163165362Smrg } 29263165362Smrg /^X\(\/\/\)[^/].*/{ 29363165362Smrg s//\1/ 29463165362Smrg q 29563165362Smrg } 29663165362Smrg /^X\(\/\/\)$/{ 29763165362Smrg s//\1/ 29863165362Smrg q 29963165362Smrg } 30063165362Smrg /^X\(\/\).*/{ 30163165362Smrg s//\1/ 30263165362Smrg q 30363165362Smrg } 30463165362Smrg s/.*/./; q' 30563165362Smrg ` 30663165362Smrg 30763165362Smrg test -d "$dstdir" 30863165362Smrg dstdir_status=$? 3090eb10989Smrg fi 3100eb10989Smrg fi 3110eb10989Smrg 31263165362Smrg obsolete_mkdir_used=false 31363165362Smrg 31463165362Smrg if test $dstdir_status != 0; then 31563165362Smrg case $posix_mkdir in 31663165362Smrg '') 31763165362Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31863165362Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31963165362Smrg umask=`umask` 32063165362Smrg case $stripcmd.$umask in 32163165362Smrg # Optimize common cases. 32263165362Smrg *[2367][2367]) mkdir_umask=$umask;; 32363165362Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 32463165362Smrg 32563165362Smrg *[0-7]) 32663165362Smrg mkdir_umask=`expr $umask + 22 \ 32763165362Smrg - $umask % 100 % 40 + $umask % 20 \ 32863165362Smrg - $umask % 10 % 4 + $umask % 2 32963165362Smrg `;; 33063165362Smrg *) mkdir_umask=$umask,go-w;; 33163165362Smrg esac 33263165362Smrg 33363165362Smrg # With -d, create the new directory with the user-specified mode. 33463165362Smrg # Otherwise, rely on $mkdir_umask. 33563165362Smrg if test -n "$dir_arg"; then 33663165362Smrg mkdir_mode=-m$mode 33763165362Smrg else 33863165362Smrg mkdir_mode= 33963165362Smrg fi 34063165362Smrg 34163165362Smrg posix_mkdir=false 34263165362Smrg case $umask in 34363165362Smrg *[123567][0-7][0-7]) 34463165362Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 34563165362Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 34663165362Smrg ;; 34763165362Smrg *) 34863165362Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34963165362Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 35063165362Smrg 35163165362Smrg if (umask $mkdir_umask && 35263165362Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 35363165362Smrg then 35463165362Smrg if test -z "$dir_arg" || { 35563165362Smrg # Check for POSIX incompatibilities with -m. 35663165362Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357079e7944Smrg # other-writable bit of parent directory when it shouldn't. 35863165362Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35963165362Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 36063165362Smrg case $ls_ld_tmpdir in 36163165362Smrg d????-?r-*) different_mode=700;; 36263165362Smrg d????-?--*) different_mode=755;; 36363165362Smrg *) false;; 36463165362Smrg esac && 36563165362Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 36663165362Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36763165362Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36863165362Smrg } 36963165362Smrg } 37063165362Smrg then posix_mkdir=: 37163165362Smrg fi 37263165362Smrg rmdir "$tmpdir/d" "$tmpdir" 37363165362Smrg else 37463165362Smrg # Remove any dirs left behind by ancient mkdir implementations. 37563165362Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 37663165362Smrg fi 37763165362Smrg trap '' 0;; 37863165362Smrg esac;; 37963165362Smrg esac 3800eb10989Smrg 38163165362Smrg if 38263165362Smrg $posix_mkdir && ( 38363165362Smrg umask $mkdir_umask && 38463165362Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38563165362Smrg ) 38663165362Smrg then : 38763165362Smrg else 3880eb10989Smrg 38963165362Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 39063165362Smrg # or it failed possibly due to a race condition. Create the 39163165362Smrg # directory the slow way, step by step, checking for races as we go. 3920eb10989Smrg 39363165362Smrg case $dstdir in 39463165362Smrg /*) prefix='/';; 395079e7944Smrg [-=\(\)!]*) prefix='./';; 39663165362Smrg *) prefix='';; 39763165362Smrg esac 3980eb10989Smrg 39963165362Smrg eval "$initialize_posix_glob" 4000eb10989Smrg 40163165362Smrg oIFS=$IFS 40263165362Smrg IFS=/ 40363165362Smrg $posix_glob set -f 40463165362Smrg set fnord $dstdir 4050eb10989Smrg shift 40663165362Smrg $posix_glob set +f 40763165362Smrg IFS=$oIFS 40863165362Smrg 40963165362Smrg prefixes= 41063165362Smrg 41163165362Smrg for d 41263165362Smrg do 413079e7944Smrg test X"$d" = X && continue 41463165362Smrg 41563165362Smrg prefix=$prefix$d 41663165362Smrg if test -d "$prefix"; then 41763165362Smrg prefixes= 41863165362Smrg else 41963165362Smrg if $posix_mkdir; then 42063165362Smrg (umask=$mkdir_umask && 42163165362Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42263165362Smrg # Don't fail if two instances are running concurrently. 42363165362Smrg test -d "$prefix" || exit 1 42463165362Smrg else 42563165362Smrg case $prefix in 42663165362Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42763165362Smrg *) qprefix=$prefix;; 42863165362Smrg esac 42963165362Smrg prefixes="$prefixes '$qprefix'" 43063165362Smrg fi 43163165362Smrg fi 43263165362Smrg prefix=$prefix/ 43363165362Smrg done 43463165362Smrg 43563165362Smrg if test -n "$prefixes"; then 43663165362Smrg # Don't fail if two instances are running concurrently. 43763165362Smrg (umask $mkdir_umask && 43863165362Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43963165362Smrg test -d "$dstdir" || exit 1 44063165362Smrg obsolete_mkdir_used=true 4410eb10989Smrg fi 44263165362Smrg fi 4430eb10989Smrg fi 4440eb10989Smrg 4450eb10989Smrg if test -n "$dir_arg"; then 44663165362Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44763165362Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44863165362Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44963165362Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4500eb10989Smrg else 4510eb10989Smrg 4520eb10989Smrg # Make a couple of temp file names in the proper directory. 4530eb10989Smrg dsttmp=$dstdir/_inst.$$_ 4540eb10989Smrg rmtmp=$dstdir/_rm.$$_ 4550eb10989Smrg 4560eb10989Smrg # Trap to clean up those temp files at exit. 4570eb10989Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4580eb10989Smrg 4590eb10989Smrg # Copy the file name to the temp name. 46063165362Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4610eb10989Smrg 4620eb10989Smrg # and set any options; do chmod last to preserve setuid bits. 4630eb10989Smrg # 4640eb10989Smrg # If any of these fail, we abort the whole thing. If we want to 4650eb10989Smrg # ignore errors from any of these, just make sure not to ignore 4660eb10989Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4670eb10989Smrg # 46863165362Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46963165362Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 47063165362Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 47163165362Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 47263165362Smrg 47363165362Smrg # If -C, don't bother to copy if it wouldn't change the file. 47463165362Smrg if $copy_on_change && 47563165362Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 47663165362Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47763165362Smrg 47863165362Smrg eval "$initialize_posix_glob" && 47963165362Smrg $posix_glob set -f && 48063165362Smrg set X $old && old=:$2:$4:$5:$6 && 48163165362Smrg set X $new && new=:$2:$4:$5:$6 && 48263165362Smrg $posix_glob set +f && 48363165362Smrg 48463165362Smrg test "$old" = "$new" && 48563165362Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 48663165362Smrg then 48763165362Smrg rm -f "$dsttmp" 48863165362Smrg else 48963165362Smrg # Rename the file to the real destination. 49063165362Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 49163165362Smrg 49263165362Smrg # The rename failed, perhaps because mv can't rename something else 49363165362Smrg # to itself, or perhaps because mv is so ancient that it does not 49463165362Smrg # support -f. 49563165362Smrg { 49663165362Smrg # Now remove or move aside any old file at destination location. 49763165362Smrg # We try this two ways since rm can't unlink itself on some 49863165362Smrg # systems and the destination file might be busy for other 49963165362Smrg # reasons. In this case, the final cleanup might fail but the new 50063165362Smrg # file should still install successfully. 50163165362Smrg { 50263165362Smrg test ! -f "$dst" || 50363165362Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 50463165362Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 50563165362Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 50663165362Smrg } || 50763165362Smrg { echo "$0: cannot unlink or rename $dst" >&2 50863165362Smrg (exit 1); exit 1 50963165362Smrg } 51063165362Smrg } && 51163165362Smrg 51263165362Smrg # Now rename the file to the real destination. 51363165362Smrg $doit $mvcmd "$dsttmp" "$dst" 51463165362Smrg } 51563165362Smrg fi || exit 1 51663165362Smrg 51763165362Smrg trap '' 0 51863165362Smrg fi 5190eb10989Smrgdone 5200eb10989Smrg 5210eb10989Smrg# Local variables: 5220eb10989Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5230eb10989Smrg# time-stamp-start: "scriptversion=" 5240eb10989Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52563165362Smrg# time-stamp-time-zone: "UTC" 52663165362Smrg# time-stamp-end: "; # UTC" 5270eb10989Smrg# End: 528