install-sh revision 70728a38
18c9fbc29Smrg#!/bin/sh 28c9fbc29Smrg# install - install a program, script, or datafile 38c9fbc29Smrg 470728a38Smrgscriptversion=2013-12-25.23; # UTC 58c9fbc29Smrg 68c9fbc29Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 78c9fbc29Smrg# later released in X11R6 (xc/config/util/install.sh) with the 88c9fbc29Smrg# following copyright and license. 98c9fbc29Smrg# 108c9fbc29Smrg# Copyright (C) 1994 X Consortium 118c9fbc29Smrg# 128c9fbc29Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 138c9fbc29Smrg# of this software and associated documentation files (the "Software"), to 148c9fbc29Smrg# deal in the Software without restriction, including without limitation the 158c9fbc29Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168c9fbc29Smrg# sell copies of the Software, and to permit persons to whom the Software is 178c9fbc29Smrg# furnished to do so, subject to the following conditions: 188c9fbc29Smrg# 198c9fbc29Smrg# The above copyright notice and this permission notice shall be included in 208c9fbc29Smrg# all copies or substantial portions of the Software. 218c9fbc29Smrg# 228c9fbc29Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238c9fbc29Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 248c9fbc29Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 258c9fbc29Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 268c9fbc29Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 278c9fbc29Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 288c9fbc29Smrg# 298c9fbc29Smrg# Except as contained in this notice, the name of the X Consortium shall not 308c9fbc29Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 318c9fbc29Smrg# ings in this Software without prior written authorization from the X Consor- 328c9fbc29Smrg# tium. 338c9fbc29Smrg# 348c9fbc29Smrg# 358c9fbc29Smrg# FSF changes to this file are in the public domain. 368c9fbc29Smrg# 378c9fbc29Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3870728a38Smrg# 'make' implicit rules from creating a file called install from it 398c9fbc29Smrg# when there is no Makefile. 408c9fbc29Smrg# 418c9fbc29Smrg# This script is compatible with the BSD install script, but was written 428c9fbc29Smrg# from scratch. 438c9fbc29Smrg 4470728a38Smrgtab=' ' 458c9fbc29Smrgnl=' 468c9fbc29Smrg' 4770728a38SmrgIFS=" $tab$nl" 488c9fbc29Smrg 4970728a38Smrg# Set DOITPROG to "echo" to test this script. 508c9fbc29Smrg 514e411241Smrgdoit=${DOITPROG-} 5270728a38Smrgdoit_exec=${doit:-exec} 538c9fbc29Smrg 548c9fbc29Smrg# Put in absolute file names if you don't have them in your path; 558c9fbc29Smrg# or use environment vars. 568c9fbc29Smrg 574e411241Smrgchgrpprog=${CHGRPPROG-chgrp} 584e411241Smrgchmodprog=${CHMODPROG-chmod} 594e411241Smrgchownprog=${CHOWNPROG-chown} 604e411241Smrgcmpprog=${CMPPROG-cmp} 614e411241Smrgcpprog=${CPPROG-cp} 624e411241Smrgmkdirprog=${MKDIRPROG-mkdir} 634e411241Smrgmvprog=${MVPROG-mv} 644e411241Smrgrmprog=${RMPROG-rm} 654e411241Smrgstripprog=${STRIPPROG-strip} 664e411241Smrg 678c9fbc29Smrgposix_mkdir= 688c9fbc29Smrg 698c9fbc29Smrg# Desired mode of installed file. 708c9fbc29Smrgmode=0755 718c9fbc29Smrg 724e411241Smrgchgrpcmd= 738c9fbc29Smrgchmodcmd=$chmodprog 748c9fbc29Smrgchowncmd= 754e411241Smrgmvcmd=$mvprog 768c9fbc29Smrgrmcmd="$rmprog -f" 774e411241Smrgstripcmd= 784e411241Smrg 798c9fbc29Smrgsrc= 808c9fbc29Smrgdst= 818c9fbc29Smrgdir_arg= 824e411241Smrgdst_arg= 834e411241Smrg 844e411241Smrgcopy_on_change=false 8570728a38Smrgis_target_a_directory=possibly 868c9fbc29Smrg 874e411241Smrgusage="\ 884e411241SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 898c9fbc29Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 908c9fbc29Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 918c9fbc29Smrg or: $0 [OPTION]... -d DIRECTORIES... 928c9fbc29Smrg 938c9fbc29SmrgIn the 1st form, copy SRCFILE to DSTFILE. 948c9fbc29SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 958c9fbc29SmrgIn the 4th, create DIRECTORIES. 968c9fbc29Smrg 978c9fbc29SmrgOptions: 984e411241Smrg --help display this help and exit. 994e411241Smrg --version display version info and exit. 1004e411241Smrg 1014e411241Smrg -c (ignored) 1024e411241Smrg -C install only if different (preserve the last data modification time) 1034e411241Smrg -d create directories instead of installing files. 1044e411241Smrg -g GROUP $chgrpprog installed files to GROUP. 1054e411241Smrg -m MODE $chmodprog installed files to MODE. 1064e411241Smrg -o USER $chownprog installed files to USER. 1074e411241Smrg -s $stripprog installed files. 1084e411241Smrg -t DIRECTORY install into DIRECTORY. 1094e411241Smrg -T report an error if DSTFILE is a directory. 1108c9fbc29Smrg 1118c9fbc29SmrgEnvironment variables override the default commands: 1124e411241Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1134e411241Smrg RMPROG STRIPPROG 1148c9fbc29Smrg" 1158c9fbc29Smrg 1168c9fbc29Smrgwhile test $# -ne 0; do 1178c9fbc29Smrg case $1 in 1184e411241Smrg -c) ;; 1194e411241Smrg 1204e411241Smrg -C) copy_on_change=true;; 1218c9fbc29Smrg 1224e411241Smrg -d) dir_arg=true;; 1238c9fbc29Smrg 1248c9fbc29Smrg -g) chgrpcmd="$chgrpprog $2" 12570728a38Smrg shift;; 1268c9fbc29Smrg 1278c9fbc29Smrg --help) echo "$usage"; exit $?;; 1288c9fbc29Smrg 1298c9fbc29Smrg -m) mode=$2 13070728a38Smrg case $mode in 13170728a38Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 13270728a38Smrg echo "$0: invalid mode: $mode" >&2 13370728a38Smrg exit 1;; 13470728a38Smrg esac 13570728a38Smrg shift;; 1368c9fbc29Smrg 1378c9fbc29Smrg -o) chowncmd="$chownprog $2" 13870728a38Smrg shift;; 1398c9fbc29Smrg 1404e411241Smrg -s) stripcmd=$stripprog;; 1418c9fbc29Smrg 14270728a38Smrg -t) 14370728a38Smrg is_target_a_directory=always 14470728a38Smrg dst_arg=$2 14570728a38Smrg # Protect names problematic for 'test' and other utilities. 14670728a38Smrg case $dst_arg in 14770728a38Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 14870728a38Smrg esac 14970728a38Smrg shift;; 1508c9fbc29Smrg 15170728a38Smrg -T) is_target_a_directory=never;; 1528c9fbc29Smrg 1538c9fbc29Smrg --version) echo "$0 $scriptversion"; exit $?;; 1548c9fbc29Smrg 15570728a38Smrg --) shift 15670728a38Smrg break;; 1578c9fbc29Smrg 15870728a38Smrg -*) echo "$0: invalid option: $1" >&2 15970728a38Smrg exit 1;; 1608c9fbc29Smrg 1618c9fbc29Smrg *) break;; 1628c9fbc29Smrg esac 1634e411241Smrg shift 1648c9fbc29Smrgdone 1658c9fbc29Smrg 16670728a38Smrg# We allow the use of options -d and -T together, by making -d 16770728a38Smrg# take the precedence; this is for compatibility with GNU install. 16870728a38Smrg 16970728a38Smrgif test -n "$dir_arg"; then 17070728a38Smrg if test -n "$dst_arg"; then 17170728a38Smrg echo "$0: target directory not allowed when installing a directory." >&2 17270728a38Smrg exit 1 17370728a38Smrg fi 17470728a38Smrgfi 17570728a38Smrg 1764e411241Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1778c9fbc29Smrg # When -d is used, all remaining arguments are directories to create. 1788c9fbc29Smrg # When -t is used, the destination is already specified. 1798c9fbc29Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1808c9fbc29Smrg for arg 1818c9fbc29Smrg do 1824e411241Smrg if test -n "$dst_arg"; then 1838c9fbc29Smrg # $@ is not empty: it contains at least $arg. 1844e411241Smrg set fnord "$@" "$dst_arg" 1858c9fbc29Smrg shift # fnord 1868c9fbc29Smrg fi 1878c9fbc29Smrg shift # arg 1884e411241Smrg dst_arg=$arg 18970728a38Smrg # Protect names problematic for 'test' and other utilities. 19070728a38Smrg case $dst_arg in 19170728a38Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19270728a38Smrg esac 1938c9fbc29Smrg done 1948c9fbc29Smrgfi 1958c9fbc29Smrg 1968c9fbc29Smrgif test $# -eq 0; then 1978c9fbc29Smrg if test -z "$dir_arg"; then 1988c9fbc29Smrg echo "$0: no input file specified." >&2 1998c9fbc29Smrg exit 1 2008c9fbc29Smrg fi 20170728a38Smrg # It's OK to call 'install-sh -d' without argument. 2028c9fbc29Smrg # This can happen when creating conditional directories. 2038c9fbc29Smrg exit 0 2048c9fbc29Smrgfi 2058c9fbc29Smrg 2068c9fbc29Smrgif test -z "$dir_arg"; then 20770728a38Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 20870728a38Smrg if test ! -d "$dst_arg"; then 20970728a38Smrg echo "$0: $dst_arg: Is not a directory." >&2 21070728a38Smrg exit 1 21170728a38Smrg fi 21270728a38Smrg fi 21370728a38Smrgfi 21470728a38Smrg 21570728a38Smrgif test -z "$dir_arg"; then 21670728a38Smrg do_exit='(exit $ret); exit $ret' 21770728a38Smrg trap "ret=129; $do_exit" 1 21870728a38Smrg trap "ret=130; $do_exit" 2 21970728a38Smrg trap "ret=141; $do_exit" 13 22070728a38Smrg trap "ret=143; $do_exit" 15 2218c9fbc29Smrg 2228c9fbc29Smrg # Set umask so as not to create temps with too-generous modes. 2238c9fbc29Smrg # However, 'strip' requires both read and write access to temps. 2248c9fbc29Smrg case $mode in 2258c9fbc29Smrg # Optimize common cases. 2268c9fbc29Smrg *644) cp_umask=133;; 2278c9fbc29Smrg *755) cp_umask=22;; 2288c9fbc29Smrg 2298c9fbc29Smrg *[0-7]) 2308c9fbc29Smrg if test -z "$stripcmd"; then 23170728a38Smrg u_plus_rw= 2328c9fbc29Smrg else 23370728a38Smrg u_plus_rw='% 200' 2348c9fbc29Smrg fi 2358c9fbc29Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2368c9fbc29Smrg *) 2378c9fbc29Smrg if test -z "$stripcmd"; then 23870728a38Smrg u_plus_rw= 2398c9fbc29Smrg else 24070728a38Smrg u_plus_rw=,u+rw 2418c9fbc29Smrg fi 2428c9fbc29Smrg cp_umask=$mode$u_plus_rw;; 2438c9fbc29Smrg esac 2448c9fbc29Smrgfi 2458c9fbc29Smrg 2468c9fbc29Smrgfor src 2478c9fbc29Smrgdo 24870728a38Smrg # Protect names problematic for 'test' and other utilities. 2498c9fbc29Smrg case $src in 25070728a38Smrg -* | [=\(\)!]) src=./$src;; 2518c9fbc29Smrg esac 2528c9fbc29Smrg 2538c9fbc29Smrg if test -n "$dir_arg"; then 2548c9fbc29Smrg dst=$src 2558c9fbc29Smrg dstdir=$dst 2568c9fbc29Smrg test -d "$dstdir" 2578c9fbc29Smrg dstdir_status=$? 2588c9fbc29Smrg else 2598c9fbc29Smrg 2608c9fbc29Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2618c9fbc29Smrg # might cause directories to be created, which would be especially bad 2628c9fbc29Smrg # if $src (and thus $dsttmp) contains '*'. 2638c9fbc29Smrg if test ! -f "$src" && test ! -d "$src"; then 2648c9fbc29Smrg echo "$0: $src does not exist." >&2 2658c9fbc29Smrg exit 1 2668c9fbc29Smrg fi 2678c9fbc29Smrg 2684e411241Smrg if test -z "$dst_arg"; then 2698c9fbc29Smrg echo "$0: no destination specified." >&2 2708c9fbc29Smrg exit 1 2718c9fbc29Smrg fi 2724e411241Smrg dst=$dst_arg 2738c9fbc29Smrg 2748c9fbc29Smrg # If destination is a directory, append the input filename; won't work 2758c9fbc29Smrg # if double slashes aren't ignored. 2768c9fbc29Smrg if test -d "$dst"; then 27770728a38Smrg if test "$is_target_a_directory" = never; then 27870728a38Smrg echo "$0: $dst_arg: Is a directory" >&2 27970728a38Smrg exit 1 2808c9fbc29Smrg fi 2818c9fbc29Smrg dstdir=$dst 2828c9fbc29Smrg dst=$dstdir/`basename "$src"` 2838c9fbc29Smrg dstdir_status=0 2848c9fbc29Smrg else 28570728a38Smrg dstdir=`dirname "$dst"` 2868c9fbc29Smrg test -d "$dstdir" 2878c9fbc29Smrg dstdir_status=$? 2888c9fbc29Smrg fi 2898c9fbc29Smrg fi 2908c9fbc29Smrg 2918c9fbc29Smrg obsolete_mkdir_used=false 2928c9fbc29Smrg 2938c9fbc29Smrg if test $dstdir_status != 0; then 2948c9fbc29Smrg case $posix_mkdir in 2958c9fbc29Smrg '') 29670728a38Smrg # Create intermediate dirs using mode 755 as modified by the umask. 29770728a38Smrg # This is like FreeBSD 'install' as of 1997-10-28. 29870728a38Smrg umask=`umask` 29970728a38Smrg case $stripcmd.$umask in 30070728a38Smrg # Optimize common cases. 30170728a38Smrg *[2367][2367]) mkdir_umask=$umask;; 30270728a38Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 30370728a38Smrg 30470728a38Smrg *[0-7]) 30570728a38Smrg mkdir_umask=`expr $umask + 22 \ 30670728a38Smrg - $umask % 100 % 40 + $umask % 20 \ 30770728a38Smrg - $umask % 10 % 4 + $umask % 2 30870728a38Smrg `;; 30970728a38Smrg *) mkdir_umask=$umask,go-w;; 31070728a38Smrg esac 31170728a38Smrg 31270728a38Smrg # With -d, create the new directory with the user-specified mode. 31370728a38Smrg # Otherwise, rely on $mkdir_umask. 31470728a38Smrg if test -n "$dir_arg"; then 31570728a38Smrg mkdir_mode=-m$mode 31670728a38Smrg else 31770728a38Smrg mkdir_mode= 31870728a38Smrg fi 31970728a38Smrg 32070728a38Smrg posix_mkdir=false 32170728a38Smrg case $umask in 32270728a38Smrg *[123567][0-7][0-7]) 32370728a38Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 32470728a38Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 32570728a38Smrg ;; 32670728a38Smrg *) 32770728a38Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 32870728a38Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 32970728a38Smrg 33070728a38Smrg if (umask $mkdir_umask && 33170728a38Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 33270728a38Smrg then 33370728a38Smrg if test -z "$dir_arg" || { 33470728a38Smrg # Check for POSIX incompatibilities with -m. 33570728a38Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 33670728a38Smrg # other-writable bit of parent directory when it shouldn't. 33770728a38Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 33870728a38Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 33970728a38Smrg case $ls_ld_tmpdir in 34070728a38Smrg d????-?r-*) different_mode=700;; 34170728a38Smrg d????-?--*) different_mode=755;; 34270728a38Smrg *) false;; 34370728a38Smrg esac && 34470728a38Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 34570728a38Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 34670728a38Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 34770728a38Smrg } 34870728a38Smrg } 34970728a38Smrg then posix_mkdir=: 35070728a38Smrg fi 35170728a38Smrg rmdir "$tmpdir/d" "$tmpdir" 35270728a38Smrg else 35370728a38Smrg # Remove any dirs left behind by ancient mkdir implementations. 35470728a38Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 35570728a38Smrg fi 35670728a38Smrg trap '' 0;; 35770728a38Smrg esac;; 3588c9fbc29Smrg esac 3598c9fbc29Smrg 3608c9fbc29Smrg if 3618c9fbc29Smrg $posix_mkdir && ( 36270728a38Smrg umask $mkdir_umask && 36370728a38Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3648c9fbc29Smrg ) 3658c9fbc29Smrg then : 3668c9fbc29Smrg else 3678c9fbc29Smrg 3688c9fbc29Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3698c9fbc29Smrg # or it failed possibly due to a race condition. Create the 3708c9fbc29Smrg # directory the slow way, step by step, checking for races as we go. 3718c9fbc29Smrg 3728c9fbc29Smrg case $dstdir in 37370728a38Smrg /*) prefix='/';; 37470728a38Smrg [-=\(\)!]*) prefix='./';; 37570728a38Smrg *) prefix='';; 3768c9fbc29Smrg esac 3778c9fbc29Smrg 3788c9fbc29Smrg oIFS=$IFS 3798c9fbc29Smrg IFS=/ 38070728a38Smrg set -f 3818c9fbc29Smrg set fnord $dstdir 3828c9fbc29Smrg shift 38370728a38Smrg set +f 3848c9fbc29Smrg IFS=$oIFS 3858c9fbc29Smrg 3868c9fbc29Smrg prefixes= 3878c9fbc29Smrg 3888c9fbc29Smrg for d 3898c9fbc29Smrg do 39070728a38Smrg test X"$d" = X && continue 39170728a38Smrg 39270728a38Smrg prefix=$prefix$d 39370728a38Smrg if test -d "$prefix"; then 39470728a38Smrg prefixes= 39570728a38Smrg else 39670728a38Smrg if $posix_mkdir; then 39770728a38Smrg (umask=$mkdir_umask && 39870728a38Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 39970728a38Smrg # Don't fail if two instances are running concurrently. 40070728a38Smrg test -d "$prefix" || exit 1 40170728a38Smrg else 40270728a38Smrg case $prefix in 40370728a38Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 40470728a38Smrg *) qprefix=$prefix;; 40570728a38Smrg esac 40670728a38Smrg prefixes="$prefixes '$qprefix'" 40770728a38Smrg fi 40870728a38Smrg fi 40970728a38Smrg prefix=$prefix/ 4108c9fbc29Smrg done 4118c9fbc29Smrg 4128c9fbc29Smrg if test -n "$prefixes"; then 41370728a38Smrg # Don't fail if two instances are running concurrently. 41470728a38Smrg (umask $mkdir_umask && 41570728a38Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 41670728a38Smrg test -d "$dstdir" || exit 1 41770728a38Smrg obsolete_mkdir_used=true 4188c9fbc29Smrg fi 4198c9fbc29Smrg fi 4208c9fbc29Smrg fi 4218c9fbc29Smrg 4228c9fbc29Smrg if test -n "$dir_arg"; then 4238c9fbc29Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4248c9fbc29Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4258c9fbc29Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4268c9fbc29Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4278c9fbc29Smrg else 4288c9fbc29Smrg 4298c9fbc29Smrg # Make a couple of temp file names in the proper directory. 4308c9fbc29Smrg dsttmp=$dstdir/_inst.$$_ 4318c9fbc29Smrg rmtmp=$dstdir/_rm.$$_ 4328c9fbc29Smrg 4338c9fbc29Smrg # Trap to clean up those temp files at exit. 4348c9fbc29Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4358c9fbc29Smrg 4368c9fbc29Smrg # Copy the file name to the temp name. 4378c9fbc29Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4388c9fbc29Smrg 4398c9fbc29Smrg # and set any options; do chmod last to preserve setuid bits. 4408c9fbc29Smrg # 4418c9fbc29Smrg # If any of these fail, we abort the whole thing. If we want to 4428c9fbc29Smrg # ignore errors from any of these, just make sure not to ignore 4438c9fbc29Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4448c9fbc29Smrg # 4454e411241Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4464e411241Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4474e411241Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4484e411241Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4494e411241Smrg 4504e411241Smrg # If -C, don't bother to copy if it wouldn't change the file. 4514e411241Smrg if $copy_on_change && 45270728a38Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 45370728a38Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 45470728a38Smrg set -f && 4554e411241Smrg set X $old && old=:$2:$4:$5:$6 && 4564e411241Smrg set X $new && new=:$2:$4:$5:$6 && 45770728a38Smrg set +f && 4584e411241Smrg test "$old" = "$new" && 4594e411241Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4604e411241Smrg then 4614e411241Smrg rm -f "$dsttmp" 4624e411241Smrg else 4634e411241Smrg # Rename the file to the real destination. 4644e411241Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4654e411241Smrg 4664e411241Smrg # The rename failed, perhaps because mv can't rename something else 4674e411241Smrg # to itself, or perhaps because mv is so ancient that it does not 4684e411241Smrg # support -f. 4694e411241Smrg { 47070728a38Smrg # Now remove or move aside any old file at destination location. 47170728a38Smrg # We try this two ways since rm can't unlink itself on some 47270728a38Smrg # systems and the destination file might be busy for other 47370728a38Smrg # reasons. In this case, the final cleanup might fail but the new 47470728a38Smrg # file should still install successfully. 47570728a38Smrg { 47670728a38Smrg test ! -f "$dst" || 47770728a38Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 47870728a38Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 47970728a38Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 48070728a38Smrg } || 48170728a38Smrg { echo "$0: cannot unlink or rename $dst" >&2 48270728a38Smrg (exit 1); exit 1 48370728a38Smrg } 48470728a38Smrg } && 48570728a38Smrg 48670728a38Smrg # Now rename the file to the real destination. 48770728a38Smrg $doit $mvcmd "$dsttmp" "$dst" 4884e411241Smrg } 4894e411241Smrg fi || exit 1 4908c9fbc29Smrg 4918c9fbc29Smrg trap '' 0 4928c9fbc29Smrg fi 4938c9fbc29Smrgdone 4948c9fbc29Smrg 4958c9fbc29Smrg# Local variables: 4968c9fbc29Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 4978c9fbc29Smrg# time-stamp-start: "scriptversion=" 4988c9fbc29Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 4994e411241Smrg# time-stamp-time-zone: "UTC" 5004e411241Smrg# time-stamp-end: "; # UTC" 5018c9fbc29Smrg# End: 502