install-sh revision 4e7590ef
1301ea0f4Smrg#!/bin/sh 2301ea0f4Smrg# install - install a program, script, or datafile 3301ea0f4Smrg 4ef6fb4a5Smrgscriptversion=2009-04-28.21; # UTC 5301ea0f4Smrg 6301ea0f4Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7301ea0f4Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8301ea0f4Smrg# following copyright and license. 9301ea0f4Smrg# 10301ea0f4Smrg# Copyright (C) 1994 X Consortium 11301ea0f4Smrg# 12301ea0f4Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13301ea0f4Smrg# of this software and associated documentation files (the "Software"), to 14301ea0f4Smrg# deal in the Software without restriction, including without limitation the 15301ea0f4Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16301ea0f4Smrg# sell copies of the Software, and to permit persons to whom the Software is 17301ea0f4Smrg# furnished to do so, subject to the following conditions: 18301ea0f4Smrg# 19301ea0f4Smrg# The above copyright notice and this permission notice shall be included in 20301ea0f4Smrg# all copies or substantial portions of the Software. 21301ea0f4Smrg# 22301ea0f4Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23301ea0f4Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24301ea0f4Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25301ea0f4Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26301ea0f4Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27301ea0f4Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28301ea0f4Smrg# 29301ea0f4Smrg# Except as contained in this notice, the name of the X Consortium shall not 30301ea0f4Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31301ea0f4Smrg# ings in this Software without prior written authorization from the X Consor- 32301ea0f4Smrg# tium. 33301ea0f4Smrg# 34301ea0f4Smrg# 35301ea0f4Smrg# FSF changes to this file are in the public domain. 36301ea0f4Smrg# 37301ea0f4Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38301ea0f4Smrg# `make' implicit rules from creating a file called install from it 39301ea0f4Smrg# when there is no Makefile. 40301ea0f4Smrg# 41301ea0f4Smrg# This script is compatible with the BSD install script, but was written 420cc67336Smrg# from scratch. 430cc67336Smrg 440cc67336Smrgnl=' 450cc67336Smrg' 460cc67336SmrgIFS=" "" $nl" 47301ea0f4Smrg 48301ea0f4Smrg# set DOITPROG to echo to test this script 49301ea0f4Smrg 50301ea0f4Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 510cc67336Smrgdoit=${DOITPROG-} 520cc67336Smrgif test -z "$doit"; then 530cc67336Smrg doit_exec=exec 540cc67336Smrgelse 550cc67336Smrg doit_exec=$doit 560cc67336Smrgfi 57301ea0f4Smrg 580cc67336Smrg# Put in absolute file names if you don't have them in your path; 590cc67336Smrg# or use environment vars. 600cc67336Smrg 610cc67336Smrgchgrpprog=${CHGRPPROG-chgrp} 620cc67336Smrgchmodprog=${CHMODPROG-chmod} 630cc67336Smrgchownprog=${CHOWNPROG-chown} 640cc67336Smrgcmpprog=${CMPPROG-cmp} 650cc67336Smrgcpprog=${CPPROG-cp} 660cc67336Smrgmkdirprog=${MKDIRPROG-mkdir} 670cc67336Smrgmvprog=${MVPROG-mv} 680cc67336Smrgrmprog=${RMPROG-rm} 690cc67336Smrgstripprog=${STRIPPROG-strip} 700cc67336Smrg 710cc67336Smrgposix_glob='?' 720cc67336Smrginitialize_posix_glob=' 730cc67336Smrg test "$posix_glob" != "?" || { 740cc67336Smrg if (set -f) 2>/dev/null; then 750cc67336Smrg posix_glob= 760cc67336Smrg else 770cc67336Smrg posix_glob=: 780cc67336Smrg fi 790cc67336Smrg } 800cc67336Smrg' 81301ea0f4Smrg 820cc67336Smrgposix_mkdir= 830cc67336Smrg 840cc67336Smrg# Desired mode of installed file. 850cc67336Smrgmode=0755 86301ea0f4Smrg 87301ea0f4Smrgchgrpcmd= 880cc67336Smrgchmodcmd=$chmodprog 890cc67336Smrgchowncmd= 900cc67336Smrgmvcmd=$mvprog 91301ea0f4Smrgrmcmd="$rmprog -f" 920cc67336Smrgstripcmd= 930cc67336Smrg 94301ea0f4Smrgsrc= 95301ea0f4Smrgdst= 96301ea0f4Smrgdir_arg= 970cc67336Smrgdst_arg= 980cc67336Smrg 990cc67336Smrgcopy_on_change=false 100301ea0f4Smrgno_target_directory= 101301ea0f4Smrg 1020cc67336Smrgusage="\ 1030cc67336SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104301ea0f4Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105301ea0f4Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106301ea0f4Smrg or: $0 [OPTION]... -d DIRECTORIES... 107301ea0f4Smrg 108301ea0f4SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109301ea0f4SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110301ea0f4SmrgIn the 4th, create DIRECTORIES. 111301ea0f4Smrg 112301ea0f4SmrgOptions: 1130cc67336Smrg --help display this help and exit. 1140cc67336Smrg --version display version info and exit. 1150cc67336Smrg 1160cc67336Smrg -c (ignored) 1170cc67336Smrg -C install only if different (preserve the last data modification time) 1180cc67336Smrg -d create directories instead of installing files. 1190cc67336Smrg -g GROUP $chgrpprog installed files to GROUP. 1200cc67336Smrg -m MODE $chmodprog installed files to MODE. 1210cc67336Smrg -o USER $chownprog installed files to USER. 1220cc67336Smrg -s $stripprog installed files. 1230cc67336Smrg -t DIRECTORY install into DIRECTORY. 1240cc67336Smrg -T report an error if DSTFILE is a directory. 125301ea0f4Smrg 126301ea0f4SmrgEnvironment variables override the default commands: 1270cc67336Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1280cc67336Smrg RMPROG STRIPPROG 129301ea0f4Smrg" 130301ea0f4Smrg 1310cc67336Smrgwhile test $# -ne 0; do 132301ea0f4Smrg case $1 in 1330cc67336Smrg -c) ;; 1340cc67336Smrg 1350cc67336Smrg -C) copy_on_change=true;; 136301ea0f4Smrg 1370cc67336Smrg -d) dir_arg=true;; 138301ea0f4Smrg 139301ea0f4Smrg -g) chgrpcmd="$chgrpprog $2" 1400cc67336Smrg shift;; 141301ea0f4Smrg 142301ea0f4Smrg --help) echo "$usage"; exit $?;; 143301ea0f4Smrg 1440cc67336Smrg -m) mode=$2 1450cc67336Smrg case $mode in 1460cc67336Smrg *' '* | *' '* | *' 1470cc67336Smrg'* | *'*'* | *'?'* | *'['*) 1480cc67336Smrg echo "$0: invalid mode: $mode" >&2 1490cc67336Smrg exit 1;; 1500cc67336Smrg esac 1510cc67336Smrg shift;; 152301ea0f4Smrg 153301ea0f4Smrg -o) chowncmd="$chownprog $2" 1540cc67336Smrg shift;; 155301ea0f4Smrg 1560cc67336Smrg -s) stripcmd=$stripprog;; 157301ea0f4Smrg 1580cc67336Smrg -t) dst_arg=$2 1590cc67336Smrg shift;; 160301ea0f4Smrg 1610cc67336Smrg -T) no_target_directory=true;; 162301ea0f4Smrg 163301ea0f4Smrg --version) echo "$0 $scriptversion"; exit $?;; 164301ea0f4Smrg 1650cc67336Smrg --) shift 166301ea0f4Smrg break;; 1670cc67336Smrg 1680cc67336Smrg -*) echo "$0: invalid option: $1" >&2 1690cc67336Smrg exit 1;; 1700cc67336Smrg 1710cc67336Smrg *) break;; 172301ea0f4Smrg esac 1730cc67336Smrg shift 174301ea0f4Smrgdone 175301ea0f4Smrg 1760cc67336Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1770cc67336Smrg # When -d is used, all remaining arguments are directories to create. 1780cc67336Smrg # When -t is used, the destination is already specified. 1790cc67336Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1800cc67336Smrg for arg 1810cc67336Smrg do 1820cc67336Smrg if test -n "$dst_arg"; then 1830cc67336Smrg # $@ is not empty: it contains at least $arg. 1840cc67336Smrg set fnord "$@" "$dst_arg" 1850cc67336Smrg shift # fnord 1860cc67336Smrg fi 1870cc67336Smrg shift # arg 1880cc67336Smrg dst_arg=$arg 1890cc67336Smrg done 1900cc67336Smrgfi 1910cc67336Smrg 1920cc67336Smrgif test $# -eq 0; then 193301ea0f4Smrg if test -z "$dir_arg"; then 194301ea0f4Smrg echo "$0: no input file specified." >&2 195301ea0f4Smrg exit 1 196301ea0f4Smrg fi 197301ea0f4Smrg # It's OK to call `install-sh -d' without argument. 198301ea0f4Smrg # This can happen when creating conditional directories. 199301ea0f4Smrg exit 0 200301ea0f4Smrgfi 201301ea0f4Smrg 2020cc67336Smrgif test -z "$dir_arg"; then 2030cc67336Smrg trap '(exit $?); exit' 1 2 13 15 2040cc67336Smrg 2050cc67336Smrg # Set umask so as not to create temps with too-generous modes. 2060cc67336Smrg # However, 'strip' requires both read and write access to temps. 2070cc67336Smrg case $mode in 2080cc67336Smrg # Optimize common cases. 2090cc67336Smrg *644) cp_umask=133;; 2100cc67336Smrg *755) cp_umask=22;; 2110cc67336Smrg 2120cc67336Smrg *[0-7]) 2130cc67336Smrg if test -z "$stripcmd"; then 2140cc67336Smrg u_plus_rw= 2150cc67336Smrg else 2160cc67336Smrg u_plus_rw='% 200' 2170cc67336Smrg fi 2180cc67336Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2190cc67336Smrg *) 2200cc67336Smrg if test -z "$stripcmd"; then 2210cc67336Smrg u_plus_rw= 2220cc67336Smrg else 2230cc67336Smrg u_plus_rw=,u+rw 2240cc67336Smrg fi 2250cc67336Smrg cp_umask=$mode$u_plus_rw;; 2260cc67336Smrg esac 2270cc67336Smrgfi 2280cc67336Smrg 229301ea0f4Smrgfor src 230301ea0f4Smrgdo 231301ea0f4Smrg # Protect names starting with `-'. 232301ea0f4Smrg case $src in 2330cc67336Smrg -*) src=./$src;; 234301ea0f4Smrg esac 235301ea0f4Smrg 236301ea0f4Smrg if test -n "$dir_arg"; then 237301ea0f4Smrg dst=$src 2380cc67336Smrg dstdir=$dst 2390cc67336Smrg test -d "$dstdir" 2400cc67336Smrg dstdir_status=$? 241301ea0f4Smrg else 2420cc67336Smrg 243301ea0f4Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 244301ea0f4Smrg # might cause directories to be created, which would be especially bad 245301ea0f4Smrg # if $src (and thus $dsttmp) contains '*'. 246301ea0f4Smrg if test ! -f "$src" && test ! -d "$src"; then 247301ea0f4Smrg echo "$0: $src does not exist." >&2 248301ea0f4Smrg exit 1 249301ea0f4Smrg fi 250301ea0f4Smrg 2510cc67336Smrg if test -z "$dst_arg"; then 252301ea0f4Smrg echo "$0: no destination specified." >&2 253301ea0f4Smrg exit 1 254301ea0f4Smrg fi 255301ea0f4Smrg 2560cc67336Smrg dst=$dst_arg 257301ea0f4Smrg # Protect names starting with `-'. 258301ea0f4Smrg case $dst in 2590cc67336Smrg -*) dst=./$dst;; 260301ea0f4Smrg esac 261301ea0f4Smrg 262301ea0f4Smrg # If destination is a directory, append the input filename; won't work 263301ea0f4Smrg # if double slashes aren't ignored. 264301ea0f4Smrg if test -d "$dst"; then 265301ea0f4Smrg if test -n "$no_target_directory"; then 2660cc67336Smrg echo "$0: $dst_arg: Is a directory" >&2 267301ea0f4Smrg exit 1 268301ea0f4Smrg fi 2690cc67336Smrg dstdir=$dst 2700cc67336Smrg dst=$dstdir/`basename "$src"` 2710cc67336Smrg dstdir_status=0 2720cc67336Smrg else 2730cc67336Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2740cc67336Smrg dstdir=` 2750cc67336Smrg (dirname "$dst") 2>/dev/null || 2760cc67336Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2770cc67336Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2780cc67336Smrg X"$dst" : 'X\(//\)$' \| \ 2790cc67336Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2800cc67336Smrg echo X"$dst" | 2810cc67336Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2820cc67336Smrg s//\1/ 2830cc67336Smrg q 2840cc67336Smrg } 2850cc67336Smrg /^X\(\/\/\)[^/].*/{ 2860cc67336Smrg s//\1/ 2870cc67336Smrg q 2880cc67336Smrg } 2890cc67336Smrg /^X\(\/\/\)$/{ 2900cc67336Smrg s//\1/ 2910cc67336Smrg q 2920cc67336Smrg } 2930cc67336Smrg /^X\(\/\).*/{ 2940cc67336Smrg s//\1/ 2950cc67336Smrg q 2960cc67336Smrg } 2970cc67336Smrg s/.*/./; q' 2980cc67336Smrg ` 2990cc67336Smrg 3000cc67336Smrg test -d "$dstdir" 3010cc67336Smrg dstdir_status=$? 302301ea0f4Smrg fi 303301ea0f4Smrg fi 304301ea0f4Smrg 3050cc67336Smrg obsolete_mkdir_used=false 3060cc67336Smrg 3070cc67336Smrg if test $dstdir_status != 0; then 3080cc67336Smrg case $posix_mkdir in 3090cc67336Smrg '') 3100cc67336Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3110cc67336Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3120cc67336Smrg umask=`umask` 3130cc67336Smrg case $stripcmd.$umask in 3140cc67336Smrg # Optimize common cases. 3150cc67336Smrg *[2367][2367]) mkdir_umask=$umask;; 3160cc67336Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3170cc67336Smrg 3180cc67336Smrg *[0-7]) 3190cc67336Smrg mkdir_umask=`expr $umask + 22 \ 3200cc67336Smrg - $umask % 100 % 40 + $umask % 20 \ 3210cc67336Smrg - $umask % 10 % 4 + $umask % 2 3220cc67336Smrg `;; 3230cc67336Smrg *) mkdir_umask=$umask,go-w;; 3240cc67336Smrg esac 3250cc67336Smrg 3260cc67336Smrg # With -d, create the new directory with the user-specified mode. 3270cc67336Smrg # Otherwise, rely on $mkdir_umask. 3280cc67336Smrg if test -n "$dir_arg"; then 3290cc67336Smrg mkdir_mode=-m$mode 3300cc67336Smrg else 3310cc67336Smrg mkdir_mode= 3320cc67336Smrg fi 3330cc67336Smrg 3340cc67336Smrg posix_mkdir=false 3350cc67336Smrg case $umask in 3360cc67336Smrg *[123567][0-7][0-7]) 3370cc67336Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3380cc67336Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3390cc67336Smrg ;; 3400cc67336Smrg *) 3410cc67336Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3420cc67336Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3430cc67336Smrg 3440cc67336Smrg if (umask $mkdir_umask && 3450cc67336Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3460cc67336Smrg then 3470cc67336Smrg if test -z "$dir_arg" || { 3480cc67336Smrg # Check for POSIX incompatibilities with -m. 3490cc67336Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3500cc67336Smrg # other-writeable bit of parent directory when it shouldn't. 3510cc67336Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3520cc67336Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3530cc67336Smrg case $ls_ld_tmpdir in 3540cc67336Smrg d????-?r-*) different_mode=700;; 3550cc67336Smrg d????-?--*) different_mode=755;; 3560cc67336Smrg *) false;; 3570cc67336Smrg esac && 3580cc67336Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3590cc67336Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3600cc67336Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3610cc67336Smrg } 3620cc67336Smrg } 3630cc67336Smrg then posix_mkdir=: 3640cc67336Smrg fi 3650cc67336Smrg rmdir "$tmpdir/d" "$tmpdir" 3660cc67336Smrg else 3670cc67336Smrg # Remove any dirs left behind by ancient mkdir implementations. 3680cc67336Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3690cc67336Smrg fi 3700cc67336Smrg trap '' 0;; 3710cc67336Smrg esac;; 3720cc67336Smrg esac 373301ea0f4Smrg 3740cc67336Smrg if 3750cc67336Smrg $posix_mkdir && ( 3760cc67336Smrg umask $mkdir_umask && 3770cc67336Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3780cc67336Smrg ) 3790cc67336Smrg then : 3800cc67336Smrg else 381301ea0f4Smrg 3820cc67336Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3830cc67336Smrg # or it failed possibly due to a race condition. Create the 3840cc67336Smrg # directory the slow way, step by step, checking for races as we go. 385301ea0f4Smrg 3860cc67336Smrg case $dstdir in 3870cc67336Smrg /*) prefix='/';; 3880cc67336Smrg -*) prefix='./';; 3890cc67336Smrg *) prefix='';; 3900cc67336Smrg esac 391301ea0f4Smrg 3920cc67336Smrg eval "$initialize_posix_glob" 393301ea0f4Smrg 3940cc67336Smrg oIFS=$IFS 3950cc67336Smrg IFS=/ 3960cc67336Smrg $posix_glob set -f 3970cc67336Smrg set fnord $dstdir 398301ea0f4Smrg shift 3990cc67336Smrg $posix_glob set +f 4000cc67336Smrg IFS=$oIFS 4010cc67336Smrg 4020cc67336Smrg prefixes= 4030cc67336Smrg 4040cc67336Smrg for d 4050cc67336Smrg do 4060cc67336Smrg test -z "$d" && continue 4070cc67336Smrg 4080cc67336Smrg prefix=$prefix$d 4090cc67336Smrg if test -d "$prefix"; then 4100cc67336Smrg prefixes= 4110cc67336Smrg else 4120cc67336Smrg if $posix_mkdir; then 4130cc67336Smrg (umask=$mkdir_umask && 4140cc67336Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4150cc67336Smrg # Don't fail if two instances are running concurrently. 4160cc67336Smrg test -d "$prefix" || exit 1 4170cc67336Smrg else 4180cc67336Smrg case $prefix in 4190cc67336Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4200cc67336Smrg *) qprefix=$prefix;; 4210cc67336Smrg esac 4220cc67336Smrg prefixes="$prefixes '$qprefix'" 4230cc67336Smrg fi 4240cc67336Smrg fi 4250cc67336Smrg prefix=$prefix/ 4260cc67336Smrg done 4270cc67336Smrg 4280cc67336Smrg if test -n "$prefixes"; then 4290cc67336Smrg # Don't fail if two instances are running concurrently. 4300cc67336Smrg (umask $mkdir_umask && 4310cc67336Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4320cc67336Smrg test -d "$dstdir" || exit 1 4330cc67336Smrg obsolete_mkdir_used=true 434301ea0f4Smrg fi 4350cc67336Smrg fi 436301ea0f4Smrg fi 437301ea0f4Smrg 438301ea0f4Smrg if test -n "$dir_arg"; then 4390cc67336Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4400cc67336Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4410cc67336Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4420cc67336Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 443301ea0f4Smrg else 444301ea0f4Smrg 445301ea0f4Smrg # Make a couple of temp file names in the proper directory. 446301ea0f4Smrg dsttmp=$dstdir/_inst.$$_ 447301ea0f4Smrg rmtmp=$dstdir/_rm.$$_ 448301ea0f4Smrg 449301ea0f4Smrg # Trap to clean up those temp files at exit. 450301ea0f4Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 451301ea0f4Smrg 452301ea0f4Smrg # Copy the file name to the temp name. 4530cc67336Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 454301ea0f4Smrg 455301ea0f4Smrg # and set any options; do chmod last to preserve setuid bits. 456301ea0f4Smrg # 457301ea0f4Smrg # If any of these fail, we abort the whole thing. If we want to 458301ea0f4Smrg # ignore errors from any of these, just make sure not to ignore 459301ea0f4Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 460301ea0f4Smrg # 4610cc67336Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4620cc67336Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4630cc67336Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4640cc67336Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4650cc67336Smrg 4660cc67336Smrg # If -C, don't bother to copy if it wouldn't change the file. 4670cc67336Smrg if $copy_on_change && 4680cc67336Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4690cc67336Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4700cc67336Smrg 4710cc67336Smrg eval "$initialize_posix_glob" && 4720cc67336Smrg $posix_glob set -f && 4730cc67336Smrg set X $old && old=:$2:$4:$5:$6 && 4740cc67336Smrg set X $new && new=:$2:$4:$5:$6 && 4750cc67336Smrg $posix_glob set +f && 4760cc67336Smrg 4770cc67336Smrg test "$old" = "$new" && 4780cc67336Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4790cc67336Smrg then 4800cc67336Smrg rm -f "$dsttmp" 4810cc67336Smrg else 4820cc67336Smrg # Rename the file to the real destination. 4830cc67336Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4840cc67336Smrg 4850cc67336Smrg # The rename failed, perhaps because mv can't rename something else 4860cc67336Smrg # to itself, or perhaps because mv is so ancient that it does not 4870cc67336Smrg # support -f. 4880cc67336Smrg { 4890cc67336Smrg # Now remove or move aside any old file at destination location. 4900cc67336Smrg # We try this two ways since rm can't unlink itself on some 4910cc67336Smrg # systems and the destination file might be busy for other 4920cc67336Smrg # reasons. In this case, the final cleanup might fail but the new 4930cc67336Smrg # file should still install successfully. 4940cc67336Smrg { 4950cc67336Smrg test ! -f "$dst" || 4960cc67336Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4970cc67336Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4980cc67336Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4990cc67336Smrg } || 5000cc67336Smrg { echo "$0: cannot unlink or rename $dst" >&2 5010cc67336Smrg (exit 1); exit 1 5020cc67336Smrg } 5030cc67336Smrg } && 5040cc67336Smrg 5050cc67336Smrg # Now rename the file to the real destination. 5060cc67336Smrg $doit $mvcmd "$dsttmp" "$dst" 5070cc67336Smrg } 5080cc67336Smrg fi || exit 1 5090cc67336Smrg 5100cc67336Smrg trap '' 0 5110cc67336Smrg fi 512301ea0f4Smrgdone 513301ea0f4Smrg 514301ea0f4Smrg# Local variables: 515301ea0f4Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 516301ea0f4Smrg# time-stamp-start: "scriptversion=" 517301ea0f4Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 518ef6fb4a5Smrg# time-stamp-time-zone: "UTC" 519ef6fb4a5Smrg# time-stamp-end: "; # UTC" 520301ea0f4Smrg# End: 521