install-sh revision 53354cdb
153354cdbSmrg#!/bin/sh 253354cdbSmrg# install - install a program, script, or datafile 353354cdbSmrg 453354cdbSmrgscriptversion=2006-10-14.15 553354cdbSmrg 653354cdbSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 753354cdbSmrg# later released in X11R6 (xc/config/util/install.sh) with the 853354cdbSmrg# following copyright and license. 953354cdbSmrg# 1053354cdbSmrg# Copyright (C) 1994 X Consortium 1153354cdbSmrg# 1253354cdbSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1353354cdbSmrg# of this software and associated documentation files (the "Software"), to 1453354cdbSmrg# deal in the Software without restriction, including without limitation the 1553354cdbSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1653354cdbSmrg# sell copies of the Software, and to permit persons to whom the Software is 1753354cdbSmrg# furnished to do so, subject to the following conditions: 1853354cdbSmrg# 1953354cdbSmrg# The above copyright notice and this permission notice shall be included in 2053354cdbSmrg# all copies or substantial portions of the Software. 2153354cdbSmrg# 2253354cdbSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2353354cdbSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2453354cdbSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2553354cdbSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2653354cdbSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2753354cdbSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2853354cdbSmrg# 2953354cdbSmrg# Except as contained in this notice, the name of the X Consortium shall not 3053354cdbSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 3153354cdbSmrg# ings in this Software without prior written authorization from the X Consor- 3253354cdbSmrg# tium. 3353354cdbSmrg# 3453354cdbSmrg# 3553354cdbSmrg# FSF changes to this file are in the public domain. 3653354cdbSmrg# 3753354cdbSmrg# Calling this script install-sh is preferred over install.sh, to prevent 3853354cdbSmrg# `make' implicit rules from creating a file called install from it 3953354cdbSmrg# when there is no Makefile. 4053354cdbSmrg# 4153354cdbSmrg# This script is compatible with the BSD install script, but was written 4253354cdbSmrg# from scratch. 4353354cdbSmrg 4453354cdbSmrgnl=' 4553354cdbSmrg' 4653354cdbSmrgIFS=" "" $nl" 4753354cdbSmrg 4853354cdbSmrg# set DOITPROG to echo to test this script 4953354cdbSmrg 5053354cdbSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5153354cdbSmrgdoit="${DOITPROG-}" 5253354cdbSmrgif test -z "$doit"; then 5353354cdbSmrg doit_exec=exec 5453354cdbSmrgelse 5553354cdbSmrg doit_exec=$doit 5653354cdbSmrgfi 5753354cdbSmrg 5853354cdbSmrg# Put in absolute file names if you don't have them in your path; 5953354cdbSmrg# or use environment vars. 6053354cdbSmrg 6153354cdbSmrgmvprog="${MVPROG-mv}" 6253354cdbSmrgcpprog="${CPPROG-cp}" 6353354cdbSmrgchmodprog="${CHMODPROG-chmod}" 6453354cdbSmrgchownprog="${CHOWNPROG-chown}" 6553354cdbSmrgchgrpprog="${CHGRPPROG-chgrp}" 6653354cdbSmrgstripprog="${STRIPPROG-strip}" 6753354cdbSmrgrmprog="${RMPROG-rm}" 6853354cdbSmrgmkdirprog="${MKDIRPROG-mkdir}" 6953354cdbSmrg 7053354cdbSmrgposix_glob= 7153354cdbSmrgposix_mkdir= 7253354cdbSmrg 7353354cdbSmrg# Desired mode of installed file. 7453354cdbSmrgmode=0755 7553354cdbSmrg 7653354cdbSmrgchmodcmd=$chmodprog 7753354cdbSmrgchowncmd= 7853354cdbSmrgchgrpcmd= 7953354cdbSmrgstripcmd= 8053354cdbSmrgrmcmd="$rmprog -f" 8153354cdbSmrgmvcmd="$mvprog" 8253354cdbSmrgsrc= 8353354cdbSmrgdst= 8453354cdbSmrgdir_arg= 8553354cdbSmrgdstarg= 8653354cdbSmrgno_target_directory= 8753354cdbSmrg 8853354cdbSmrgusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 8953354cdbSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 9053354cdbSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 9153354cdbSmrg or: $0 [OPTION]... -d DIRECTORIES... 9253354cdbSmrg 9353354cdbSmrgIn the 1st form, copy SRCFILE to DSTFILE. 9453354cdbSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 9553354cdbSmrgIn the 4th, create DIRECTORIES. 9653354cdbSmrg 9753354cdbSmrgOptions: 9853354cdbSmrg-c (ignored) 9953354cdbSmrg-d create directories instead of installing files. 10053354cdbSmrg-g GROUP $chgrpprog installed files to GROUP. 10153354cdbSmrg-m MODE $chmodprog installed files to MODE. 10253354cdbSmrg-o USER $chownprog installed files to USER. 10353354cdbSmrg-s $stripprog installed files. 10453354cdbSmrg-t DIRECTORY install into DIRECTORY. 10553354cdbSmrg-T report an error if DSTFILE is a directory. 10653354cdbSmrg--help display this help and exit. 10753354cdbSmrg--version display version info and exit. 10853354cdbSmrg 10953354cdbSmrgEnvironment variables override the default commands: 11053354cdbSmrg CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 11153354cdbSmrg" 11253354cdbSmrg 11353354cdbSmrgwhile test $# -ne 0; do 11453354cdbSmrg case $1 in 11553354cdbSmrg -c) shift 11653354cdbSmrg continue;; 11753354cdbSmrg 11853354cdbSmrg -d) dir_arg=true 11953354cdbSmrg shift 12053354cdbSmrg continue;; 12153354cdbSmrg 12253354cdbSmrg -g) chgrpcmd="$chgrpprog $2" 12353354cdbSmrg shift 12453354cdbSmrg shift 12553354cdbSmrg continue;; 12653354cdbSmrg 12753354cdbSmrg --help) echo "$usage"; exit $?;; 12853354cdbSmrg 12953354cdbSmrg -m) mode=$2 13053354cdbSmrg shift 13153354cdbSmrg shift 13253354cdbSmrg case $mode in 13353354cdbSmrg *' '* | *' '* | *' 13453354cdbSmrg'* | *'*'* | *'?'* | *'['*) 13553354cdbSmrg echo "$0: invalid mode: $mode" >&2 13653354cdbSmrg exit 1;; 13753354cdbSmrg esac 13853354cdbSmrg continue;; 13953354cdbSmrg 14053354cdbSmrg -o) chowncmd="$chownprog $2" 14153354cdbSmrg shift 14253354cdbSmrg shift 14353354cdbSmrg continue;; 14453354cdbSmrg 14553354cdbSmrg -s) stripcmd=$stripprog 14653354cdbSmrg shift 14753354cdbSmrg continue;; 14853354cdbSmrg 14953354cdbSmrg -t) dstarg=$2 15053354cdbSmrg shift 15153354cdbSmrg shift 15253354cdbSmrg continue;; 15353354cdbSmrg 15453354cdbSmrg -T) no_target_directory=true 15553354cdbSmrg shift 15653354cdbSmrg continue;; 15753354cdbSmrg 15853354cdbSmrg --version) echo "$0 $scriptversion"; exit $?;; 15953354cdbSmrg 16053354cdbSmrg --) shift 16153354cdbSmrg break;; 16253354cdbSmrg 16353354cdbSmrg -*) echo "$0: invalid option: $1" >&2 16453354cdbSmrg exit 1;; 16553354cdbSmrg 16653354cdbSmrg *) break;; 16753354cdbSmrg esac 16853354cdbSmrgdone 16953354cdbSmrg 17053354cdbSmrgif test $# -ne 0 && test -z "$dir_arg$dstarg"; then 17153354cdbSmrg # When -d is used, all remaining arguments are directories to create. 17253354cdbSmrg # When -t is used, the destination is already specified. 17353354cdbSmrg # Otherwise, the last argument is the destination. Remove it from $@. 17453354cdbSmrg for arg 17553354cdbSmrg do 17653354cdbSmrg if test -n "$dstarg"; then 17753354cdbSmrg # $@ is not empty: it contains at least $arg. 17853354cdbSmrg set fnord "$@" "$dstarg" 17953354cdbSmrg shift # fnord 18053354cdbSmrg fi 18153354cdbSmrg shift # arg 18253354cdbSmrg dstarg=$arg 18353354cdbSmrg done 18453354cdbSmrgfi 18553354cdbSmrg 18653354cdbSmrgif test $# -eq 0; then 18753354cdbSmrg if test -z "$dir_arg"; then 18853354cdbSmrg echo "$0: no input file specified." >&2 18953354cdbSmrg exit 1 19053354cdbSmrg fi 19153354cdbSmrg # It's OK to call `install-sh -d' without argument. 19253354cdbSmrg # This can happen when creating conditional directories. 19353354cdbSmrg exit 0 19453354cdbSmrgfi 19553354cdbSmrg 19653354cdbSmrgif test -z "$dir_arg"; then 19753354cdbSmrg trap '(exit $?); exit' 1 2 13 15 19853354cdbSmrg 19953354cdbSmrg # Set umask so as not to create temps with too-generous modes. 20053354cdbSmrg # However, 'strip' requires both read and write access to temps. 20153354cdbSmrg case $mode in 20253354cdbSmrg # Optimize common cases. 20353354cdbSmrg *644) cp_umask=133;; 20453354cdbSmrg *755) cp_umask=22;; 20553354cdbSmrg 20653354cdbSmrg *[0-7]) 20753354cdbSmrg if test -z "$stripcmd"; then 20853354cdbSmrg u_plus_rw= 20953354cdbSmrg else 21053354cdbSmrg u_plus_rw='% 200' 21153354cdbSmrg fi 21253354cdbSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21353354cdbSmrg *) 21453354cdbSmrg if test -z "$stripcmd"; then 21553354cdbSmrg u_plus_rw= 21653354cdbSmrg else 21753354cdbSmrg u_plus_rw=,u+rw 21853354cdbSmrg fi 21953354cdbSmrg cp_umask=$mode$u_plus_rw;; 22053354cdbSmrg esac 22153354cdbSmrgfi 22253354cdbSmrg 22353354cdbSmrgfor src 22453354cdbSmrgdo 22553354cdbSmrg # Protect names starting with `-'. 22653354cdbSmrg case $src in 22753354cdbSmrg -*) src=./$src ;; 22853354cdbSmrg esac 22953354cdbSmrg 23053354cdbSmrg if test -n "$dir_arg"; then 23153354cdbSmrg dst=$src 23253354cdbSmrg dstdir=$dst 23353354cdbSmrg test -d "$dstdir" 23453354cdbSmrg dstdir_status=$? 23553354cdbSmrg else 23653354cdbSmrg 23753354cdbSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 23853354cdbSmrg # might cause directories to be created, which would be especially bad 23953354cdbSmrg # if $src (and thus $dsttmp) contains '*'. 24053354cdbSmrg if test ! -f "$src" && test ! -d "$src"; then 24153354cdbSmrg echo "$0: $src does not exist." >&2 24253354cdbSmrg exit 1 24353354cdbSmrg fi 24453354cdbSmrg 24553354cdbSmrg if test -z "$dstarg"; then 24653354cdbSmrg echo "$0: no destination specified." >&2 24753354cdbSmrg exit 1 24853354cdbSmrg fi 24953354cdbSmrg 25053354cdbSmrg dst=$dstarg 25153354cdbSmrg # Protect names starting with `-'. 25253354cdbSmrg case $dst in 25353354cdbSmrg -*) dst=./$dst ;; 25453354cdbSmrg esac 25553354cdbSmrg 25653354cdbSmrg # If destination is a directory, append the input filename; won't work 25753354cdbSmrg # if double slashes aren't ignored. 25853354cdbSmrg if test -d "$dst"; then 25953354cdbSmrg if test -n "$no_target_directory"; then 26053354cdbSmrg echo "$0: $dstarg: Is a directory" >&2 26153354cdbSmrg exit 1 26253354cdbSmrg fi 26353354cdbSmrg dstdir=$dst 26453354cdbSmrg dst=$dstdir/`basename "$src"` 26553354cdbSmrg dstdir_status=0 26653354cdbSmrg else 26753354cdbSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 26853354cdbSmrg dstdir=` 26953354cdbSmrg (dirname "$dst") 2>/dev/null || 27053354cdbSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27153354cdbSmrg X"$dst" : 'X\(//\)[^/]' \| \ 27253354cdbSmrg X"$dst" : 'X\(//\)$' \| \ 27353354cdbSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 27453354cdbSmrg echo X"$dst" | 27553354cdbSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 27653354cdbSmrg s//\1/ 27753354cdbSmrg q 27853354cdbSmrg } 27953354cdbSmrg /^X\(\/\/\)[^/].*/{ 28053354cdbSmrg s//\1/ 28153354cdbSmrg q 28253354cdbSmrg } 28353354cdbSmrg /^X\(\/\/\)$/{ 28453354cdbSmrg s//\1/ 28553354cdbSmrg q 28653354cdbSmrg } 28753354cdbSmrg /^X\(\/\).*/{ 28853354cdbSmrg s//\1/ 28953354cdbSmrg q 29053354cdbSmrg } 29153354cdbSmrg s/.*/./; q' 29253354cdbSmrg ` 29353354cdbSmrg 29453354cdbSmrg test -d "$dstdir" 29553354cdbSmrg dstdir_status=$? 29653354cdbSmrg fi 29753354cdbSmrg fi 29853354cdbSmrg 29953354cdbSmrg obsolete_mkdir_used=false 30053354cdbSmrg 30153354cdbSmrg if test $dstdir_status != 0; then 30253354cdbSmrg case $posix_mkdir in 30353354cdbSmrg '') 30453354cdbSmrg # Create intermediate dirs using mode 755 as modified by the umask. 30553354cdbSmrg # This is like FreeBSD 'install' as of 1997-10-28. 30653354cdbSmrg umask=`umask` 30753354cdbSmrg case $stripcmd.$umask in 30853354cdbSmrg # Optimize common cases. 30953354cdbSmrg *[2367][2367]) mkdir_umask=$umask;; 31053354cdbSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31153354cdbSmrg 31253354cdbSmrg *[0-7]) 31353354cdbSmrg mkdir_umask=`expr $umask + 22 \ 31453354cdbSmrg - $umask % 100 % 40 + $umask % 20 \ 31553354cdbSmrg - $umask % 10 % 4 + $umask % 2 31653354cdbSmrg `;; 31753354cdbSmrg *) mkdir_umask=$umask,go-w;; 31853354cdbSmrg esac 31953354cdbSmrg 32053354cdbSmrg # With -d, create the new directory with the user-specified mode. 32153354cdbSmrg # Otherwise, rely on $mkdir_umask. 32253354cdbSmrg if test -n "$dir_arg"; then 32353354cdbSmrg mkdir_mode=-m$mode 32453354cdbSmrg else 32553354cdbSmrg mkdir_mode= 32653354cdbSmrg fi 32753354cdbSmrg 32853354cdbSmrg posix_mkdir=false 32953354cdbSmrg case $umask in 33053354cdbSmrg *[123567][0-7][0-7]) 33153354cdbSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33253354cdbSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33353354cdbSmrg ;; 33453354cdbSmrg *) 33553354cdbSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 33653354cdbSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 33753354cdbSmrg 33853354cdbSmrg if (umask $mkdir_umask && 33953354cdbSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34053354cdbSmrg then 34153354cdbSmrg if test -z "$dir_arg" || { 34253354cdbSmrg # Check for POSIX incompatibilities with -m. 34353354cdbSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 34453354cdbSmrg # other-writeable bit of parent directory when it shouldn't. 34553354cdbSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 34653354cdbSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 34753354cdbSmrg case $ls_ld_tmpdir in 34853354cdbSmrg d????-?r-*) different_mode=700;; 34953354cdbSmrg d????-?--*) different_mode=755;; 35053354cdbSmrg *) false;; 35153354cdbSmrg esac && 35253354cdbSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35353354cdbSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 35453354cdbSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 35553354cdbSmrg } 35653354cdbSmrg } 35753354cdbSmrg then posix_mkdir=: 35853354cdbSmrg fi 35953354cdbSmrg rmdir "$tmpdir/d" "$tmpdir" 36053354cdbSmrg else 36153354cdbSmrg # Remove any dirs left behind by ancient mkdir implementations. 36253354cdbSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36353354cdbSmrg fi 36453354cdbSmrg trap '' 0;; 36553354cdbSmrg esac;; 36653354cdbSmrg esac 36753354cdbSmrg 36853354cdbSmrg if 36953354cdbSmrg $posix_mkdir && ( 37053354cdbSmrg umask $mkdir_umask && 37153354cdbSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37253354cdbSmrg ) 37353354cdbSmrg then : 37453354cdbSmrg else 37553354cdbSmrg 37653354cdbSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 37753354cdbSmrg # or it failed possibly due to a race condition. Create the 37853354cdbSmrg # directory the slow way, step by step, checking for races as we go. 37953354cdbSmrg 38053354cdbSmrg case $dstdir in 38153354cdbSmrg /*) prefix=/ ;; 38253354cdbSmrg -*) prefix=./ ;; 38353354cdbSmrg *) prefix= ;; 38453354cdbSmrg esac 38553354cdbSmrg 38653354cdbSmrg case $posix_glob in 38753354cdbSmrg '') 38853354cdbSmrg if (set -f) 2>/dev/null; then 38953354cdbSmrg posix_glob=true 39053354cdbSmrg else 39153354cdbSmrg posix_glob=false 39253354cdbSmrg fi ;; 39353354cdbSmrg esac 39453354cdbSmrg 39553354cdbSmrg oIFS=$IFS 39653354cdbSmrg IFS=/ 39753354cdbSmrg $posix_glob && set -f 39853354cdbSmrg set fnord $dstdir 39953354cdbSmrg shift 40053354cdbSmrg $posix_glob && set +f 40153354cdbSmrg IFS=$oIFS 40253354cdbSmrg 40353354cdbSmrg prefixes= 40453354cdbSmrg 40553354cdbSmrg for d 40653354cdbSmrg do 40753354cdbSmrg test -z "$d" && continue 40853354cdbSmrg 40953354cdbSmrg prefix=$prefix$d 41053354cdbSmrg if test -d "$prefix"; then 41153354cdbSmrg prefixes= 41253354cdbSmrg else 41353354cdbSmrg if $posix_mkdir; then 41453354cdbSmrg (umask=$mkdir_umask && 41553354cdbSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41653354cdbSmrg # Don't fail if two instances are running concurrently. 41753354cdbSmrg test -d "$prefix" || exit 1 41853354cdbSmrg else 41953354cdbSmrg case $prefix in 42053354cdbSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42153354cdbSmrg *) qprefix=$prefix;; 42253354cdbSmrg esac 42353354cdbSmrg prefixes="$prefixes '$qprefix'" 42453354cdbSmrg fi 42553354cdbSmrg fi 42653354cdbSmrg prefix=$prefix/ 42753354cdbSmrg done 42853354cdbSmrg 42953354cdbSmrg if test -n "$prefixes"; then 43053354cdbSmrg # Don't fail if two instances are running concurrently. 43153354cdbSmrg (umask $mkdir_umask && 43253354cdbSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 43353354cdbSmrg test -d "$dstdir" || exit 1 43453354cdbSmrg obsolete_mkdir_used=true 43553354cdbSmrg fi 43653354cdbSmrg fi 43753354cdbSmrg fi 43853354cdbSmrg 43953354cdbSmrg if test -n "$dir_arg"; then 44053354cdbSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44153354cdbSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44253354cdbSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44353354cdbSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44453354cdbSmrg else 44553354cdbSmrg 44653354cdbSmrg # Make a couple of temp file names in the proper directory. 44753354cdbSmrg dsttmp=$dstdir/_inst.$$_ 44853354cdbSmrg rmtmp=$dstdir/_rm.$$_ 44953354cdbSmrg 45053354cdbSmrg # Trap to clean up those temp files at exit. 45153354cdbSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45253354cdbSmrg 45353354cdbSmrg # Copy the file name to the temp name. 45453354cdbSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45553354cdbSmrg 45653354cdbSmrg # and set any options; do chmod last to preserve setuid bits. 45753354cdbSmrg # 45853354cdbSmrg # If any of these fail, we abort the whole thing. If we want to 45953354cdbSmrg # ignore errors from any of these, just make sure not to ignore 46053354cdbSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46153354cdbSmrg # 46253354cdbSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 46353354cdbSmrg && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 46453354cdbSmrg && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ 46553354cdbSmrg && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46653354cdbSmrg 46753354cdbSmrg # Now rename the file to the real destination. 46853354cdbSmrg { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \ 46953354cdbSmrg || { 47053354cdbSmrg # The rename failed, perhaps because mv can't rename something else 47153354cdbSmrg # to itself, or perhaps because mv is so ancient that it does not 47253354cdbSmrg # support -f. 47353354cdbSmrg 47453354cdbSmrg # Now remove or move aside any old file at destination location. 47553354cdbSmrg # We try this two ways since rm can't unlink itself on some 47653354cdbSmrg # systems and the destination file might be busy for other 47753354cdbSmrg # reasons. In this case, the final cleanup might fail but the new 47853354cdbSmrg # file should still install successfully. 47953354cdbSmrg { 48053354cdbSmrg if test -f "$dst"; then 48153354cdbSmrg $doit $rmcmd -f "$dst" 2>/dev/null \ 48253354cdbSmrg || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \ 48353354cdbSmrg && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\ 48453354cdbSmrg || { 48553354cdbSmrg echo "$0: cannot unlink or rename $dst" >&2 48653354cdbSmrg (exit 1); exit 1 48753354cdbSmrg } 48853354cdbSmrg else 48953354cdbSmrg : 49053354cdbSmrg fi 49153354cdbSmrg } && 49253354cdbSmrg 49353354cdbSmrg # Now rename the file to the real destination. 49453354cdbSmrg $doit $mvcmd "$dsttmp" "$dst" 49553354cdbSmrg } 49653354cdbSmrg } || exit 1 49753354cdbSmrg 49853354cdbSmrg trap '' 0 49953354cdbSmrg fi 50053354cdbSmrgdone 50153354cdbSmrg 50253354cdbSmrg# Local variables: 50353354cdbSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 50453354cdbSmrg# time-stamp-start: "scriptversion=" 50553354cdbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 50653354cdbSmrg# time-stamp-end: "$" 50753354cdbSmrg# End: 508