install-sh revision 9ef7378b
1c19de146Smrg#!/bin/sh 2c19de146Smrg# install - install a program, script, or datafile 39ef7378bSmrg 49ef7378bSmrgscriptversion=2009-04-28.21; # UTC 59ef7378bSmrg 6c19de146Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7c19de146Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8c19de146Smrg# following copyright and license. 9c19de146Smrg# 10c19de146Smrg# Copyright (C) 1994 X Consortium 11c19de146Smrg# 12c19de146Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13c19de146Smrg# of this software and associated documentation files (the "Software"), to 14c19de146Smrg# deal in the Software without restriction, including without limitation the 15c19de146Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16c19de146Smrg# sell copies of the Software, and to permit persons to whom the Software is 17c19de146Smrg# furnished to do so, subject to the following conditions: 18c19de146Smrg# 19c19de146Smrg# The above copyright notice and this permission notice shall be included in 20c19de146Smrg# all copies or substantial portions of the Software. 21c19de146Smrg# 22c19de146Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23c19de146Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24c19de146Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25c19de146Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26c19de146Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27c19de146Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28c19de146Smrg# 29c19de146Smrg# Except as contained in this notice, the name of the X Consortium shall not 30c19de146Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31c19de146Smrg# ings in this Software without prior written authorization from the X Consor- 32c19de146Smrg# tium. 33c19de146Smrg# 34c19de146Smrg# 35c19de146Smrg# FSF changes to this file are in the public domain. 36c19de146Smrg# 37c19de146Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38c19de146Smrg# `make' implicit rules from creating a file called install from it 39c19de146Smrg# when there is no Makefile. 40c19de146Smrg# 41c19de146Smrg# This script is compatible with the BSD install script, but was written 429ef7378bSmrg# from scratch. 43c19de146Smrg 449ef7378bSmrgnl=' 459ef7378bSmrg' 469ef7378bSmrgIFS=" "" $nl" 47c19de146Smrg 48c19de146Smrg# set DOITPROG to echo to test this script 49c19de146Smrg 50c19de146Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 519ef7378bSmrgdoit=${DOITPROG-} 529ef7378bSmrgif test -z "$doit"; then 539ef7378bSmrg doit_exec=exec 54c19de146Smrgelse 559ef7378bSmrg doit_exec=$doit 56c19de146Smrgfi 57c19de146Smrg 589ef7378bSmrg# Put in absolute file names if you don't have them in your path; 599ef7378bSmrg# or use environment vars. 609ef7378bSmrg 619ef7378bSmrgchgrpprog=${CHGRPPROG-chgrp} 629ef7378bSmrgchmodprog=${CHMODPROG-chmod} 639ef7378bSmrgchownprog=${CHOWNPROG-chown} 649ef7378bSmrgcmpprog=${CMPPROG-cmp} 659ef7378bSmrgcpprog=${CPPROG-cp} 669ef7378bSmrgmkdirprog=${MKDIRPROG-mkdir} 679ef7378bSmrgmvprog=${MVPROG-mv} 689ef7378bSmrgrmprog=${RMPROG-rm} 699ef7378bSmrgstripprog=${STRIPPROG-strip} 709ef7378bSmrg 719ef7378bSmrgposix_glob='?' 729ef7378bSmrginitialize_posix_glob=' 739ef7378bSmrg test "$posix_glob" != "?" || { 749ef7378bSmrg if (set -f) 2>/dev/null; then 759ef7378bSmrg posix_glob= 769ef7378bSmrg else 779ef7378bSmrg posix_glob=: 789ef7378bSmrg fi 799ef7378bSmrg } 809ef7378bSmrg' 819ef7378bSmrg 829ef7378bSmrgposix_mkdir= 839ef7378bSmrg 849ef7378bSmrg# Desired mode of installed file. 859ef7378bSmrgmode=0755 869ef7378bSmrg 879ef7378bSmrgchgrpcmd= 889ef7378bSmrgchmodcmd=$chmodprog 899ef7378bSmrgchowncmd= 909ef7378bSmrgmvcmd=$mvprog 919ef7378bSmrgrmcmd="$rmprog -f" 929ef7378bSmrgstripcmd= 93c19de146Smrg 949ef7378bSmrgsrc= 959ef7378bSmrgdst= 969ef7378bSmrgdir_arg= 979ef7378bSmrgdst_arg= 98c19de146Smrg 999ef7378bSmrgcopy_on_change=false 1009ef7378bSmrgno_target_directory= 101c19de146Smrg 1029ef7378bSmrgusage="\ 1039ef7378bSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1049ef7378bSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1059ef7378bSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1069ef7378bSmrg or: $0 [OPTION]... -d DIRECTORIES... 107c19de146Smrg 1089ef7378bSmrgIn the 1st form, copy SRCFILE to DSTFILE. 1099ef7378bSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1109ef7378bSmrgIn the 4th, create DIRECTORIES. 111c19de146Smrg 1129ef7378bSmrgOptions: 1139ef7378bSmrg --help display this help and exit. 1149ef7378bSmrg --version display version info and exit. 115c19de146Smrg 1169ef7378bSmrg -c (ignored) 1179ef7378bSmrg -C install only if different (preserve the last data modification time) 1189ef7378bSmrg -d create directories instead of installing files. 1199ef7378bSmrg -g GROUP $chgrpprog installed files to GROUP. 1209ef7378bSmrg -m MODE $chmodprog installed files to MODE. 1219ef7378bSmrg -o USER $chownprog installed files to USER. 1229ef7378bSmrg -s $stripprog installed files. 1239ef7378bSmrg -t DIRECTORY install into DIRECTORY. 1249ef7378bSmrg -T report an error if DSTFILE is a directory. 125c19de146Smrg 1269ef7378bSmrgEnvironment variables override the default commands: 1279ef7378bSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1289ef7378bSmrg RMPROG STRIPPROG 1299ef7378bSmrg" 130c19de146Smrg 1319ef7378bSmrgwhile test $# -ne 0; do 1329ef7378bSmrg case $1 in 1339ef7378bSmrg -c) ;; 134c19de146Smrg 1359ef7378bSmrg -C) copy_on_change=true;; 136c19de146Smrg 1379ef7378bSmrg -d) dir_arg=true;; 138c19de146Smrg 1399ef7378bSmrg -g) chgrpcmd="$chgrpprog $2" 1409ef7378bSmrg shift;; 141c19de146Smrg 1429ef7378bSmrg --help) echo "$usage"; exit $?;; 143c19de146Smrg 1449ef7378bSmrg -m) mode=$2 1459ef7378bSmrg case $mode in 1469ef7378bSmrg *' '* | *' '* | *' 1479ef7378bSmrg'* | *'*'* | *'?'* | *'['*) 1489ef7378bSmrg echo "$0: invalid mode: $mode" >&2 1499ef7378bSmrg exit 1;; 1509ef7378bSmrg esac 1519ef7378bSmrg shift;; 152c19de146Smrg 1539ef7378bSmrg -o) chowncmd="$chownprog $2" 1549ef7378bSmrg shift;; 155c19de146Smrg 1569ef7378bSmrg -s) stripcmd=$stripprog;; 157c19de146Smrg 1589ef7378bSmrg -t) dst_arg=$2 1599ef7378bSmrg shift;; 160c19de146Smrg 1619ef7378bSmrg -T) no_target_directory=true;; 162c19de146Smrg 1639ef7378bSmrg --version) echo "$0 $scriptversion"; exit $?;; 164c19de146Smrg 1659ef7378bSmrg --) shift 1669ef7378bSmrg break;; 167c19de146Smrg 1689ef7378bSmrg -*) echo "$0: invalid option: $1" >&2 1699ef7378bSmrg exit 1;; 170c19de146Smrg 1719ef7378bSmrg *) break;; 1729ef7378bSmrg esac 1739ef7378bSmrg shift 1749ef7378bSmrgdone 175c19de146Smrg 1769ef7378bSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1779ef7378bSmrg # When -d is used, all remaining arguments are directories to create. 1789ef7378bSmrg # When -t is used, the destination is already specified. 1799ef7378bSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1809ef7378bSmrg for arg 1819ef7378bSmrg do 1829ef7378bSmrg if test -n "$dst_arg"; then 1839ef7378bSmrg # $@ is not empty: it contains at least $arg. 1849ef7378bSmrg set fnord "$@" "$dst_arg" 1859ef7378bSmrg shift # fnord 1869ef7378bSmrg fi 1879ef7378bSmrg shift # arg 1889ef7378bSmrg dst_arg=$arg 1899ef7378bSmrg done 1909ef7378bSmrgfi 191c19de146Smrg 1929ef7378bSmrgif test $# -eq 0; then 1939ef7378bSmrg if test -z "$dir_arg"; then 1949ef7378bSmrg echo "$0: no input file specified." >&2 1959ef7378bSmrg exit 1 1969ef7378bSmrg fi 1979ef7378bSmrg # It's OK to call `install-sh -d' without argument. 1989ef7378bSmrg # This can happen when creating conditional directories. 1999ef7378bSmrg exit 0 2009ef7378bSmrgfi 201c19de146Smrg 2029ef7378bSmrgif test -z "$dir_arg"; then 2039ef7378bSmrg trap '(exit $?); exit' 1 2 13 15 2049ef7378bSmrg 2059ef7378bSmrg # Set umask so as not to create temps with too-generous modes. 2069ef7378bSmrg # However, 'strip' requires both read and write access to temps. 2079ef7378bSmrg case $mode in 2089ef7378bSmrg # Optimize common cases. 2099ef7378bSmrg *644) cp_umask=133;; 2109ef7378bSmrg *755) cp_umask=22;; 2119ef7378bSmrg 2129ef7378bSmrg *[0-7]) 2139ef7378bSmrg if test -z "$stripcmd"; then 2149ef7378bSmrg u_plus_rw= 2159ef7378bSmrg else 2169ef7378bSmrg u_plus_rw='% 200' 2179ef7378bSmrg fi 2189ef7378bSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2199ef7378bSmrg *) 2209ef7378bSmrg if test -z "$stripcmd"; then 2219ef7378bSmrg u_plus_rw= 2229ef7378bSmrg else 2239ef7378bSmrg u_plus_rw=,u+rw 2249ef7378bSmrg fi 2259ef7378bSmrg cp_umask=$mode$u_plus_rw;; 2269ef7378bSmrg esac 2279ef7378bSmrgfi 228c19de146Smrg 2299ef7378bSmrgfor src 2309ef7378bSmrgdo 2319ef7378bSmrg # Protect names starting with `-'. 2329ef7378bSmrg case $src in 2339ef7378bSmrg -*) src=./$src;; 2349ef7378bSmrg esac 2359ef7378bSmrg 2369ef7378bSmrg if test -n "$dir_arg"; then 2379ef7378bSmrg dst=$src 2389ef7378bSmrg dstdir=$dst 2399ef7378bSmrg test -d "$dstdir" 2409ef7378bSmrg dstdir_status=$? 2419ef7378bSmrg else 2429ef7378bSmrg 2439ef7378bSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2449ef7378bSmrg # might cause directories to be created, which would be especially bad 2459ef7378bSmrg # if $src (and thus $dsttmp) contains '*'. 2469ef7378bSmrg if test ! -f "$src" && test ! -d "$src"; then 2479ef7378bSmrg echo "$0: $src does not exist." >&2 2489ef7378bSmrg exit 1 2499ef7378bSmrg fi 2509ef7378bSmrg 2519ef7378bSmrg if test -z "$dst_arg"; then 2529ef7378bSmrg echo "$0: no destination specified." >&2 2539ef7378bSmrg exit 1 2549ef7378bSmrg fi 2559ef7378bSmrg 2569ef7378bSmrg dst=$dst_arg 2579ef7378bSmrg # Protect names starting with `-'. 2589ef7378bSmrg case $dst in 2599ef7378bSmrg -*) dst=./$dst;; 2609ef7378bSmrg esac 261c19de146Smrg 2629ef7378bSmrg # If destination is a directory, append the input filename; won't work 2639ef7378bSmrg # if double slashes aren't ignored. 2649ef7378bSmrg if test -d "$dst"; then 2659ef7378bSmrg if test -n "$no_target_directory"; then 2669ef7378bSmrg echo "$0: $dst_arg: Is a directory" >&2 2679ef7378bSmrg exit 1 2689ef7378bSmrg fi 2699ef7378bSmrg dstdir=$dst 2709ef7378bSmrg dst=$dstdir/`basename "$src"` 2719ef7378bSmrg dstdir_status=0 2729ef7378bSmrg else 2739ef7378bSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2749ef7378bSmrg dstdir=` 2759ef7378bSmrg (dirname "$dst") 2>/dev/null || 2769ef7378bSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2779ef7378bSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2789ef7378bSmrg X"$dst" : 'X\(//\)$' \| \ 2799ef7378bSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2809ef7378bSmrg echo X"$dst" | 2819ef7378bSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2829ef7378bSmrg s//\1/ 2839ef7378bSmrg q 2849ef7378bSmrg } 2859ef7378bSmrg /^X\(\/\/\)[^/].*/{ 2869ef7378bSmrg s//\1/ 2879ef7378bSmrg q 2889ef7378bSmrg } 2899ef7378bSmrg /^X\(\/\/\)$/{ 2909ef7378bSmrg s//\1/ 2919ef7378bSmrg q 2929ef7378bSmrg } 2939ef7378bSmrg /^X\(\/\).*/{ 2949ef7378bSmrg s//\1/ 2959ef7378bSmrg q 2969ef7378bSmrg } 2979ef7378bSmrg s/.*/./; q' 2989ef7378bSmrg ` 2999ef7378bSmrg 3009ef7378bSmrg test -d "$dstdir" 3019ef7378bSmrg dstdir_status=$? 3029ef7378bSmrg fi 3039ef7378bSmrg fi 3049ef7378bSmrg 3059ef7378bSmrg obsolete_mkdir_used=false 3069ef7378bSmrg 3079ef7378bSmrg if test $dstdir_status != 0; then 3089ef7378bSmrg case $posix_mkdir in 3099ef7378bSmrg '') 3109ef7378bSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3119ef7378bSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3129ef7378bSmrg umask=`umask` 3139ef7378bSmrg case $stripcmd.$umask in 3149ef7378bSmrg # Optimize common cases. 3159ef7378bSmrg *[2367][2367]) mkdir_umask=$umask;; 3169ef7378bSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3179ef7378bSmrg 3189ef7378bSmrg *[0-7]) 3199ef7378bSmrg mkdir_umask=`expr $umask + 22 \ 3209ef7378bSmrg - $umask % 100 % 40 + $umask % 20 \ 3219ef7378bSmrg - $umask % 10 % 4 + $umask % 2 3229ef7378bSmrg `;; 3239ef7378bSmrg *) mkdir_umask=$umask,go-w;; 3249ef7378bSmrg esac 3259ef7378bSmrg 3269ef7378bSmrg # With -d, create the new directory with the user-specified mode. 3279ef7378bSmrg # Otherwise, rely on $mkdir_umask. 3289ef7378bSmrg if test -n "$dir_arg"; then 3299ef7378bSmrg mkdir_mode=-m$mode 330c19de146Smrg else 3319ef7378bSmrg mkdir_mode= 332c19de146Smrg fi 333c19de146Smrg 3349ef7378bSmrg posix_mkdir=false 3359ef7378bSmrg case $umask in 3369ef7378bSmrg *[123567][0-7][0-7]) 3379ef7378bSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3389ef7378bSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3399ef7378bSmrg ;; 3409ef7378bSmrg *) 3419ef7378bSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3429ef7378bSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3439ef7378bSmrg 3449ef7378bSmrg if (umask $mkdir_umask && 3459ef7378bSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3469ef7378bSmrg then 3479ef7378bSmrg if test -z "$dir_arg" || { 3489ef7378bSmrg # Check for POSIX incompatibilities with -m. 3499ef7378bSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3509ef7378bSmrg # other-writeable bit of parent directory when it shouldn't. 3519ef7378bSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3529ef7378bSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3539ef7378bSmrg case $ls_ld_tmpdir in 3549ef7378bSmrg d????-?r-*) different_mode=700;; 3559ef7378bSmrg d????-?--*) different_mode=755;; 3569ef7378bSmrg *) false;; 3579ef7378bSmrg esac && 3589ef7378bSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3599ef7378bSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3609ef7378bSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3619ef7378bSmrg } 3629ef7378bSmrg } 3639ef7378bSmrg then posix_mkdir=: 3649ef7378bSmrg fi 3659ef7378bSmrg rmdir "$tmpdir/d" "$tmpdir" 3669ef7378bSmrg else 3679ef7378bSmrg # Remove any dirs left behind by ancient mkdir implementations. 3689ef7378bSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3699ef7378bSmrg fi 3709ef7378bSmrg trap '' 0;; 3719ef7378bSmrg esac;; 3729ef7378bSmrg esac 373c19de146Smrg 3749ef7378bSmrg if 3759ef7378bSmrg $posix_mkdir && ( 3769ef7378bSmrg umask $mkdir_umask && 3779ef7378bSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3789ef7378bSmrg ) 3799ef7378bSmrg then : 3809ef7378bSmrg else 3819ef7378bSmrg 3829ef7378bSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3839ef7378bSmrg # or it failed possibly due to a race condition. Create the 3849ef7378bSmrg # directory the slow way, step by step, checking for races as we go. 3859ef7378bSmrg 3869ef7378bSmrg case $dstdir in 3879ef7378bSmrg /*) prefix='/';; 3889ef7378bSmrg -*) prefix='./';; 3899ef7378bSmrg *) prefix='';; 3909ef7378bSmrg esac 3919ef7378bSmrg 3929ef7378bSmrg eval "$initialize_posix_glob" 3939ef7378bSmrg 3949ef7378bSmrg oIFS=$IFS 3959ef7378bSmrg IFS=/ 3969ef7378bSmrg $posix_glob set -f 3979ef7378bSmrg set fnord $dstdir 3989ef7378bSmrg shift 3999ef7378bSmrg $posix_glob set +f 4009ef7378bSmrg IFS=$oIFS 4019ef7378bSmrg 4029ef7378bSmrg prefixes= 4039ef7378bSmrg 4049ef7378bSmrg for d 4059ef7378bSmrg do 4069ef7378bSmrg test -z "$d" && continue 4079ef7378bSmrg 4089ef7378bSmrg prefix=$prefix$d 4099ef7378bSmrg if test -d "$prefix"; then 4109ef7378bSmrg prefixes= 4119ef7378bSmrg else 4129ef7378bSmrg if $posix_mkdir; then 4139ef7378bSmrg (umask=$mkdir_umask && 4149ef7378bSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4159ef7378bSmrg # Don't fail if two instances are running concurrently. 4169ef7378bSmrg test -d "$prefix" || exit 1 4179ef7378bSmrg else 4189ef7378bSmrg case $prefix in 4199ef7378bSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4209ef7378bSmrg *) qprefix=$prefix;; 4219ef7378bSmrg esac 4229ef7378bSmrg prefixes="$prefixes '$qprefix'" 4239ef7378bSmrg fi 4249ef7378bSmrg fi 4259ef7378bSmrg prefix=$prefix/ 4269ef7378bSmrg done 4279ef7378bSmrg 4289ef7378bSmrg if test -n "$prefixes"; then 4299ef7378bSmrg # Don't fail if two instances are running concurrently. 4309ef7378bSmrg (umask $mkdir_umask && 4319ef7378bSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4329ef7378bSmrg test -d "$dstdir" || exit 1 4339ef7378bSmrg obsolete_mkdir_used=true 4349ef7378bSmrg fi 4359ef7378bSmrg fi 4369ef7378bSmrg fi 4379ef7378bSmrg 4389ef7378bSmrg if test -n "$dir_arg"; then 4399ef7378bSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4409ef7378bSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4419ef7378bSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4429ef7378bSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4439ef7378bSmrg else 4449ef7378bSmrg 4459ef7378bSmrg # Make a couple of temp file names in the proper directory. 4469ef7378bSmrg dsttmp=$dstdir/_inst.$$_ 4479ef7378bSmrg rmtmp=$dstdir/_rm.$$_ 4489ef7378bSmrg 4499ef7378bSmrg # Trap to clean up those temp files at exit. 4509ef7378bSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4519ef7378bSmrg 4529ef7378bSmrg # Copy the file name to the temp name. 4539ef7378bSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4549ef7378bSmrg 4559ef7378bSmrg # and set any options; do chmod last to preserve setuid bits. 4569ef7378bSmrg # 4579ef7378bSmrg # If any of these fail, we abort the whole thing. If we want to 4589ef7378bSmrg # ignore errors from any of these, just make sure not to ignore 4599ef7378bSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4609ef7378bSmrg # 4619ef7378bSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4629ef7378bSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4639ef7378bSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4649ef7378bSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4659ef7378bSmrg 4669ef7378bSmrg # If -C, don't bother to copy if it wouldn't change the file. 4679ef7378bSmrg if $copy_on_change && 4689ef7378bSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4699ef7378bSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4709ef7378bSmrg 4719ef7378bSmrg eval "$initialize_posix_glob" && 4729ef7378bSmrg $posix_glob set -f && 4739ef7378bSmrg set X $old && old=:$2:$4:$5:$6 && 4749ef7378bSmrg set X $new && new=:$2:$4:$5:$6 && 4759ef7378bSmrg $posix_glob set +f && 4769ef7378bSmrg 4779ef7378bSmrg test "$old" = "$new" && 4789ef7378bSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4799ef7378bSmrg then 4809ef7378bSmrg rm -f "$dsttmp" 4819ef7378bSmrg else 4829ef7378bSmrg # Rename the file to the real destination. 4839ef7378bSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4849ef7378bSmrg 4859ef7378bSmrg # The rename failed, perhaps because mv can't rename something else 4869ef7378bSmrg # to itself, or perhaps because mv is so ancient that it does not 4879ef7378bSmrg # support -f. 4889ef7378bSmrg { 4899ef7378bSmrg # Now remove or move aside any old file at destination location. 4909ef7378bSmrg # We try this two ways since rm can't unlink itself on some 4919ef7378bSmrg # systems and the destination file might be busy for other 4929ef7378bSmrg # reasons. In this case, the final cleanup might fail but the new 4939ef7378bSmrg # file should still install successfully. 4949ef7378bSmrg { 4959ef7378bSmrg test ! -f "$dst" || 4969ef7378bSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 4979ef7378bSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4989ef7378bSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4999ef7378bSmrg } || 5009ef7378bSmrg { echo "$0: cannot unlink or rename $dst" >&2 5019ef7378bSmrg (exit 1); exit 1 5029ef7378bSmrg } 5039ef7378bSmrg } && 5049ef7378bSmrg 5059ef7378bSmrg # Now rename the file to the real destination. 5069ef7378bSmrg $doit $mvcmd "$dsttmp" "$dst" 5079ef7378bSmrg } 5089ef7378bSmrg fi || exit 1 5099ef7378bSmrg 5109ef7378bSmrg trap '' 0 5119ef7378bSmrg fi 5129ef7378bSmrgdone 513c19de146Smrg 5149ef7378bSmrg# Local variables: 5159ef7378bSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5169ef7378bSmrg# time-stamp-start: "scriptversion=" 5179ef7378bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5189ef7378bSmrg# time-stamp-time-zone: "UTC" 5199ef7378bSmrg# time-stamp-end: "; # UTC" 5209ef7378bSmrg# End: 521