install-sh revision 1016ad83
11016ad83Smrg#!/bin/sh 21016ad83Smrg# install - install a program, script, or datafile 31016ad83Smrg 41016ad83Smrgscriptversion=2011-11-20.07; # UTC 51016ad83Smrg 61016ad83Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71016ad83Smrg# later released in X11R6 (xc/config/util/install.sh) with the 81016ad83Smrg# following copyright and license. 91016ad83Smrg# 101016ad83Smrg# Copyright (C) 1994 X Consortium 111016ad83Smrg# 121016ad83Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131016ad83Smrg# of this software and associated documentation files (the "Software"), to 141016ad83Smrg# deal in the Software without restriction, including without limitation the 151016ad83Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161016ad83Smrg# sell copies of the Software, and to permit persons to whom the Software is 171016ad83Smrg# furnished to do so, subject to the following conditions: 181016ad83Smrg# 191016ad83Smrg# The above copyright notice and this permission notice shall be included in 201016ad83Smrg# all copies or substantial portions of the Software. 211016ad83Smrg# 221016ad83Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231016ad83Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241016ad83Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251016ad83Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261016ad83Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271016ad83Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281016ad83Smrg# 291016ad83Smrg# Except as contained in this notice, the name of the X Consortium shall not 301016ad83Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 311016ad83Smrg# ings in this Software without prior written authorization from the X Consor- 321016ad83Smrg# tium. 331016ad83Smrg# 341016ad83Smrg# 351016ad83Smrg# FSF changes to this file are in the public domain. 361016ad83Smrg# 371016ad83Smrg# Calling this script install-sh is preferred over install.sh, to prevent 381016ad83Smrg# 'make' implicit rules from creating a file called install from it 391016ad83Smrg# when there is no Makefile. 401016ad83Smrg# 411016ad83Smrg# This script is compatible with the BSD install script, but was written 421016ad83Smrg# from scratch. 431016ad83Smrg 441016ad83Smrgnl=' 451016ad83Smrg' 461016ad83SmrgIFS=" "" $nl" 471016ad83Smrg 481016ad83Smrg# set DOITPROG to echo to test this script 491016ad83Smrg 501016ad83Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 511016ad83Smrgdoit=${DOITPROG-} 521016ad83Smrgif test -z "$doit"; then 531016ad83Smrg doit_exec=exec 541016ad83Smrgelse 551016ad83Smrg doit_exec=$doit 561016ad83Smrgfi 571016ad83Smrg 581016ad83Smrg# Put in absolute file names if you don't have them in your path; 591016ad83Smrg# or use environment vars. 601016ad83Smrg 611016ad83Smrgchgrpprog=${CHGRPPROG-chgrp} 621016ad83Smrgchmodprog=${CHMODPROG-chmod} 631016ad83Smrgchownprog=${CHOWNPROG-chown} 641016ad83Smrgcmpprog=${CMPPROG-cmp} 651016ad83Smrgcpprog=${CPPROG-cp} 661016ad83Smrgmkdirprog=${MKDIRPROG-mkdir} 671016ad83Smrgmvprog=${MVPROG-mv} 681016ad83Smrgrmprog=${RMPROG-rm} 691016ad83Smrgstripprog=${STRIPPROG-strip} 701016ad83Smrg 711016ad83Smrgposix_glob='?' 721016ad83Smrginitialize_posix_glob=' 731016ad83Smrg test "$posix_glob" != "?" || { 741016ad83Smrg if (set -f) 2>/dev/null; then 751016ad83Smrg posix_glob= 761016ad83Smrg else 771016ad83Smrg posix_glob=: 781016ad83Smrg fi 791016ad83Smrg } 801016ad83Smrg' 811016ad83Smrg 821016ad83Smrgposix_mkdir= 831016ad83Smrg 841016ad83Smrg# Desired mode of installed file. 851016ad83Smrgmode=0755 861016ad83Smrg 871016ad83Smrgchgrpcmd= 881016ad83Smrgchmodcmd=$chmodprog 891016ad83Smrgchowncmd= 901016ad83Smrgmvcmd=$mvprog 911016ad83Smrgrmcmd="$rmprog -f" 921016ad83Smrgstripcmd= 931016ad83Smrg 941016ad83Smrgsrc= 951016ad83Smrgdst= 961016ad83Smrgdir_arg= 971016ad83Smrgdst_arg= 981016ad83Smrg 991016ad83Smrgcopy_on_change=false 1001016ad83Smrgno_target_directory= 1011016ad83Smrg 1021016ad83Smrgusage="\ 1031016ad83SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1041016ad83Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1051016ad83Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1061016ad83Smrg or: $0 [OPTION]... -d DIRECTORIES... 1071016ad83Smrg 1081016ad83SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1091016ad83SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1101016ad83SmrgIn the 4th, create DIRECTORIES. 1111016ad83Smrg 1121016ad83SmrgOptions: 1131016ad83Smrg --help display this help and exit. 1141016ad83Smrg --version display version info and exit. 1151016ad83Smrg 1161016ad83Smrg -c (ignored) 1171016ad83Smrg -C install only if different (preserve the last data modification time) 1181016ad83Smrg -d create directories instead of installing files. 1191016ad83Smrg -g GROUP $chgrpprog installed files to GROUP. 1201016ad83Smrg -m MODE $chmodprog installed files to MODE. 1211016ad83Smrg -o USER $chownprog installed files to USER. 1221016ad83Smrg -s $stripprog installed files. 1231016ad83Smrg -t DIRECTORY install into DIRECTORY. 1241016ad83Smrg -T report an error if DSTFILE is a directory. 1251016ad83Smrg 1261016ad83SmrgEnvironment variables override the default commands: 1271016ad83Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1281016ad83Smrg RMPROG STRIPPROG 1291016ad83Smrg" 1301016ad83Smrg 1311016ad83Smrgwhile test $# -ne 0; do 1321016ad83Smrg case $1 in 1331016ad83Smrg -c) ;; 1341016ad83Smrg 1351016ad83Smrg -C) copy_on_change=true;; 1361016ad83Smrg 1371016ad83Smrg -d) dir_arg=true;; 1381016ad83Smrg 1391016ad83Smrg -g) chgrpcmd="$chgrpprog $2" 1401016ad83Smrg shift;; 1411016ad83Smrg 1421016ad83Smrg --help) echo "$usage"; exit $?;; 1431016ad83Smrg 1441016ad83Smrg -m) mode=$2 1451016ad83Smrg case $mode in 1461016ad83Smrg *' '* | *' '* | *' 1471016ad83Smrg'* | *'*'* | *'?'* | *'['*) 1481016ad83Smrg echo "$0: invalid mode: $mode" >&2 1491016ad83Smrg exit 1;; 1501016ad83Smrg esac 1511016ad83Smrg shift;; 1521016ad83Smrg 1531016ad83Smrg -o) chowncmd="$chownprog $2" 1541016ad83Smrg shift;; 1551016ad83Smrg 1561016ad83Smrg -s) stripcmd=$stripprog;; 1571016ad83Smrg 1581016ad83Smrg -t) dst_arg=$2 1591016ad83Smrg # Protect names problematic for 'test' and other utilities. 1601016ad83Smrg case $dst_arg in 1611016ad83Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1621016ad83Smrg esac 1631016ad83Smrg shift;; 1641016ad83Smrg 1651016ad83Smrg -T) no_target_directory=true;; 1661016ad83Smrg 1671016ad83Smrg --version) echo "$0 $scriptversion"; exit $?;; 1681016ad83Smrg 1691016ad83Smrg --) shift 1701016ad83Smrg break;; 1711016ad83Smrg 1721016ad83Smrg -*) echo "$0: invalid option: $1" >&2 1731016ad83Smrg exit 1;; 1741016ad83Smrg 1751016ad83Smrg *) break;; 1761016ad83Smrg esac 1771016ad83Smrg shift 1781016ad83Smrgdone 1791016ad83Smrg 1801016ad83Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1811016ad83Smrg # When -d is used, all remaining arguments are directories to create. 1821016ad83Smrg # When -t is used, the destination is already specified. 1831016ad83Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1841016ad83Smrg for arg 1851016ad83Smrg do 1861016ad83Smrg if test -n "$dst_arg"; then 1871016ad83Smrg # $@ is not empty: it contains at least $arg. 1881016ad83Smrg set fnord "$@" "$dst_arg" 1891016ad83Smrg shift # fnord 1901016ad83Smrg fi 1911016ad83Smrg shift # arg 1921016ad83Smrg dst_arg=$arg 1931016ad83Smrg # Protect names problematic for 'test' and other utilities. 1941016ad83Smrg case $dst_arg in 1951016ad83Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1961016ad83Smrg esac 1971016ad83Smrg done 1981016ad83Smrgfi 1991016ad83Smrg 2001016ad83Smrgif test $# -eq 0; then 2011016ad83Smrg if test -z "$dir_arg"; then 2021016ad83Smrg echo "$0: no input file specified." >&2 2031016ad83Smrg exit 1 2041016ad83Smrg fi 2051016ad83Smrg # It's OK to call 'install-sh -d' without argument. 2061016ad83Smrg # This can happen when creating conditional directories. 2071016ad83Smrg exit 0 2081016ad83Smrgfi 2091016ad83Smrg 2101016ad83Smrgif test -z "$dir_arg"; then 2111016ad83Smrg do_exit='(exit $ret); exit $ret' 2121016ad83Smrg trap "ret=129; $do_exit" 1 2131016ad83Smrg trap "ret=130; $do_exit" 2 2141016ad83Smrg trap "ret=141; $do_exit" 13 2151016ad83Smrg trap "ret=143; $do_exit" 15 2161016ad83Smrg 2171016ad83Smrg # Set umask so as not to create temps with too-generous modes. 2181016ad83Smrg # However, 'strip' requires both read and write access to temps. 2191016ad83Smrg case $mode in 2201016ad83Smrg # Optimize common cases. 2211016ad83Smrg *644) cp_umask=133;; 2221016ad83Smrg *755) cp_umask=22;; 2231016ad83Smrg 2241016ad83Smrg *[0-7]) 2251016ad83Smrg if test -z "$stripcmd"; then 2261016ad83Smrg u_plus_rw= 2271016ad83Smrg else 2281016ad83Smrg u_plus_rw='% 200' 2291016ad83Smrg fi 2301016ad83Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2311016ad83Smrg *) 2321016ad83Smrg if test -z "$stripcmd"; then 2331016ad83Smrg u_plus_rw= 2341016ad83Smrg else 2351016ad83Smrg u_plus_rw=,u+rw 2361016ad83Smrg fi 2371016ad83Smrg cp_umask=$mode$u_plus_rw;; 2381016ad83Smrg esac 2391016ad83Smrgfi 2401016ad83Smrg 2411016ad83Smrgfor src 2421016ad83Smrgdo 2431016ad83Smrg # Protect names problematic for 'test' and other utilities. 2441016ad83Smrg case $src in 2451016ad83Smrg -* | [=\(\)!]) src=./$src;; 2461016ad83Smrg esac 2471016ad83Smrg 2481016ad83Smrg if test -n "$dir_arg"; then 2491016ad83Smrg dst=$src 2501016ad83Smrg dstdir=$dst 2511016ad83Smrg test -d "$dstdir" 2521016ad83Smrg dstdir_status=$? 2531016ad83Smrg else 2541016ad83Smrg 2551016ad83Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2561016ad83Smrg # might cause directories to be created, which would be especially bad 2571016ad83Smrg # if $src (and thus $dsttmp) contains '*'. 2581016ad83Smrg if test ! -f "$src" && test ! -d "$src"; then 2591016ad83Smrg echo "$0: $src does not exist." >&2 2601016ad83Smrg exit 1 2611016ad83Smrg fi 2621016ad83Smrg 2631016ad83Smrg if test -z "$dst_arg"; then 2641016ad83Smrg echo "$0: no destination specified." >&2 2651016ad83Smrg exit 1 2661016ad83Smrg fi 2671016ad83Smrg dst=$dst_arg 2681016ad83Smrg 2691016ad83Smrg # If destination is a directory, append the input filename; won't work 2701016ad83Smrg # if double slashes aren't ignored. 2711016ad83Smrg if test -d "$dst"; then 2721016ad83Smrg if test -n "$no_target_directory"; then 2731016ad83Smrg echo "$0: $dst_arg: Is a directory" >&2 2741016ad83Smrg exit 1 2751016ad83Smrg fi 2761016ad83Smrg dstdir=$dst 2771016ad83Smrg dst=$dstdir/`basename "$src"` 2781016ad83Smrg dstdir_status=0 2791016ad83Smrg else 2801016ad83Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2811016ad83Smrg dstdir=` 2821016ad83Smrg (dirname "$dst") 2>/dev/null || 2831016ad83Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2841016ad83Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2851016ad83Smrg X"$dst" : 'X\(//\)$' \| \ 2861016ad83Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2871016ad83Smrg echo X"$dst" | 2881016ad83Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2891016ad83Smrg s//\1/ 2901016ad83Smrg q 2911016ad83Smrg } 2921016ad83Smrg /^X\(\/\/\)[^/].*/{ 2931016ad83Smrg s//\1/ 2941016ad83Smrg q 2951016ad83Smrg } 2961016ad83Smrg /^X\(\/\/\)$/{ 2971016ad83Smrg s//\1/ 2981016ad83Smrg q 2991016ad83Smrg } 3001016ad83Smrg /^X\(\/\).*/{ 3011016ad83Smrg s//\1/ 3021016ad83Smrg q 3031016ad83Smrg } 3041016ad83Smrg s/.*/./; q' 3051016ad83Smrg ` 3061016ad83Smrg 3071016ad83Smrg test -d "$dstdir" 3081016ad83Smrg dstdir_status=$? 3091016ad83Smrg fi 3101016ad83Smrg fi 3111016ad83Smrg 3121016ad83Smrg obsolete_mkdir_used=false 3131016ad83Smrg 3141016ad83Smrg if test $dstdir_status != 0; then 3151016ad83Smrg case $posix_mkdir in 3161016ad83Smrg '') 3171016ad83Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3181016ad83Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3191016ad83Smrg umask=`umask` 3201016ad83Smrg case $stripcmd.$umask in 3211016ad83Smrg # Optimize common cases. 3221016ad83Smrg *[2367][2367]) mkdir_umask=$umask;; 3231016ad83Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3241016ad83Smrg 3251016ad83Smrg *[0-7]) 3261016ad83Smrg mkdir_umask=`expr $umask + 22 \ 3271016ad83Smrg - $umask % 100 % 40 + $umask % 20 \ 3281016ad83Smrg - $umask % 10 % 4 + $umask % 2 3291016ad83Smrg `;; 3301016ad83Smrg *) mkdir_umask=$umask,go-w;; 3311016ad83Smrg esac 3321016ad83Smrg 3331016ad83Smrg # With -d, create the new directory with the user-specified mode. 3341016ad83Smrg # Otherwise, rely on $mkdir_umask. 3351016ad83Smrg if test -n "$dir_arg"; then 3361016ad83Smrg mkdir_mode=-m$mode 3371016ad83Smrg else 3381016ad83Smrg mkdir_mode= 3391016ad83Smrg fi 3401016ad83Smrg 3411016ad83Smrg posix_mkdir=false 3421016ad83Smrg case $umask in 3431016ad83Smrg *[123567][0-7][0-7]) 3441016ad83Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3451016ad83Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3461016ad83Smrg ;; 3471016ad83Smrg *) 3481016ad83Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3491016ad83Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3501016ad83Smrg 3511016ad83Smrg if (umask $mkdir_umask && 3521016ad83Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3531016ad83Smrg then 3541016ad83Smrg if test -z "$dir_arg" || { 3551016ad83Smrg # Check for POSIX incompatibilities with -m. 3561016ad83Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3571016ad83Smrg # other-writable bit of parent directory when it shouldn't. 3581016ad83Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3591016ad83Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3601016ad83Smrg case $ls_ld_tmpdir in 3611016ad83Smrg d????-?r-*) different_mode=700;; 3621016ad83Smrg d????-?--*) different_mode=755;; 3631016ad83Smrg *) false;; 3641016ad83Smrg esac && 3651016ad83Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3661016ad83Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3671016ad83Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3681016ad83Smrg } 3691016ad83Smrg } 3701016ad83Smrg then posix_mkdir=: 3711016ad83Smrg fi 3721016ad83Smrg rmdir "$tmpdir/d" "$tmpdir" 3731016ad83Smrg else 3741016ad83Smrg # Remove any dirs left behind by ancient mkdir implementations. 3751016ad83Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3761016ad83Smrg fi 3771016ad83Smrg trap '' 0;; 3781016ad83Smrg esac;; 3791016ad83Smrg esac 3801016ad83Smrg 3811016ad83Smrg if 3821016ad83Smrg $posix_mkdir && ( 3831016ad83Smrg umask $mkdir_umask && 3841016ad83Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3851016ad83Smrg ) 3861016ad83Smrg then : 3871016ad83Smrg else 3881016ad83Smrg 3891016ad83Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3901016ad83Smrg # or it failed possibly due to a race condition. Create the 3911016ad83Smrg # directory the slow way, step by step, checking for races as we go. 3921016ad83Smrg 3931016ad83Smrg case $dstdir in 3941016ad83Smrg /*) prefix='/';; 3951016ad83Smrg [-=\(\)!]*) prefix='./';; 3961016ad83Smrg *) prefix='';; 3971016ad83Smrg esac 3981016ad83Smrg 3991016ad83Smrg eval "$initialize_posix_glob" 4001016ad83Smrg 4011016ad83Smrg oIFS=$IFS 4021016ad83Smrg IFS=/ 4031016ad83Smrg $posix_glob set -f 4041016ad83Smrg set fnord $dstdir 4051016ad83Smrg shift 4061016ad83Smrg $posix_glob set +f 4071016ad83Smrg IFS=$oIFS 4081016ad83Smrg 4091016ad83Smrg prefixes= 4101016ad83Smrg 4111016ad83Smrg for d 4121016ad83Smrg do 4131016ad83Smrg test X"$d" = X && continue 4141016ad83Smrg 4151016ad83Smrg prefix=$prefix$d 4161016ad83Smrg if test -d "$prefix"; then 4171016ad83Smrg prefixes= 4181016ad83Smrg else 4191016ad83Smrg if $posix_mkdir; then 4201016ad83Smrg (umask=$mkdir_umask && 4211016ad83Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4221016ad83Smrg # Don't fail if two instances are running concurrently. 4231016ad83Smrg test -d "$prefix" || exit 1 4241016ad83Smrg else 4251016ad83Smrg case $prefix in 4261016ad83Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4271016ad83Smrg *) qprefix=$prefix;; 4281016ad83Smrg esac 4291016ad83Smrg prefixes="$prefixes '$qprefix'" 4301016ad83Smrg fi 4311016ad83Smrg fi 4321016ad83Smrg prefix=$prefix/ 4331016ad83Smrg done 4341016ad83Smrg 4351016ad83Smrg if test -n "$prefixes"; then 4361016ad83Smrg # Don't fail if two instances are running concurrently. 4371016ad83Smrg (umask $mkdir_umask && 4381016ad83Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4391016ad83Smrg test -d "$dstdir" || exit 1 4401016ad83Smrg obsolete_mkdir_used=true 4411016ad83Smrg fi 4421016ad83Smrg fi 4431016ad83Smrg fi 4441016ad83Smrg 4451016ad83Smrg if test -n "$dir_arg"; then 4461016ad83Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4471016ad83Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4481016ad83Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4491016ad83Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4501016ad83Smrg else 4511016ad83Smrg 4521016ad83Smrg # Make a couple of temp file names in the proper directory. 4531016ad83Smrg dsttmp=$dstdir/_inst.$$_ 4541016ad83Smrg rmtmp=$dstdir/_rm.$$_ 4551016ad83Smrg 4561016ad83Smrg # Trap to clean up those temp files at exit. 4571016ad83Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4581016ad83Smrg 4591016ad83Smrg # Copy the file name to the temp name. 4601016ad83Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4611016ad83Smrg 4621016ad83Smrg # and set any options; do chmod last to preserve setuid bits. 4631016ad83Smrg # 4641016ad83Smrg # If any of these fail, we abort the whole thing. If we want to 4651016ad83Smrg # ignore errors from any of these, just make sure not to ignore 4661016ad83Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4671016ad83Smrg # 4681016ad83Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4691016ad83Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4701016ad83Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4711016ad83Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4721016ad83Smrg 4731016ad83Smrg # If -C, don't bother to copy if it wouldn't change the file. 4741016ad83Smrg if $copy_on_change && 4751016ad83Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4761016ad83Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4771016ad83Smrg 4781016ad83Smrg eval "$initialize_posix_glob" && 4791016ad83Smrg $posix_glob set -f && 4801016ad83Smrg set X $old && old=:$2:$4:$5:$6 && 4811016ad83Smrg set X $new && new=:$2:$4:$5:$6 && 4821016ad83Smrg $posix_glob set +f && 4831016ad83Smrg 4841016ad83Smrg test "$old" = "$new" && 4851016ad83Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4861016ad83Smrg then 4871016ad83Smrg rm -f "$dsttmp" 4881016ad83Smrg else 4891016ad83Smrg # Rename the file to the real destination. 4901016ad83Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4911016ad83Smrg 4921016ad83Smrg # The rename failed, perhaps because mv can't rename something else 4931016ad83Smrg # to itself, or perhaps because mv is so ancient that it does not 4941016ad83Smrg # support -f. 4951016ad83Smrg { 4961016ad83Smrg # Now remove or move aside any old file at destination location. 4971016ad83Smrg # We try this two ways since rm can't unlink itself on some 4981016ad83Smrg # systems and the destination file might be busy for other 4991016ad83Smrg # reasons. In this case, the final cleanup might fail but the new 5001016ad83Smrg # file should still install successfully. 5011016ad83Smrg { 5021016ad83Smrg test ! -f "$dst" || 5031016ad83Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 5041016ad83Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5051016ad83Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 5061016ad83Smrg } || 5071016ad83Smrg { echo "$0: cannot unlink or rename $dst" >&2 5081016ad83Smrg (exit 1); exit 1 5091016ad83Smrg } 5101016ad83Smrg } && 5111016ad83Smrg 5121016ad83Smrg # Now rename the file to the real destination. 5131016ad83Smrg $doit $mvcmd "$dsttmp" "$dst" 5141016ad83Smrg } 5151016ad83Smrg fi || exit 1 5161016ad83Smrg 5171016ad83Smrg trap '' 0 5181016ad83Smrg fi 5191016ad83Smrgdone 5201016ad83Smrg 5211016ad83Smrg# Local variables: 5221016ad83Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5231016ad83Smrg# time-stamp-start: "scriptversion=" 5241016ad83Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5251016ad83Smrg# time-stamp-time-zone: "UTC" 5261016ad83Smrg# time-stamp-end: "; # UTC" 5271016ad83Smrg# End: 528