install-sh revision 0ad07f78
198049353Smrg#!/bin/sh 298049353Smrg# install - install a program, script, or datafile 30ad07f78Smrg 40ad07f78Smrgscriptversion=2009-04-28.21; # UTC 50ad07f78Smrg 698049353Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 798049353Smrg# later released in X11R6 (xc/config/util/install.sh) with the 898049353Smrg# following copyright and license. 998049353Smrg# 1098049353Smrg# Copyright (C) 1994 X Consortium 1198049353Smrg# 1298049353Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1398049353Smrg# of this software and associated documentation files (the "Software"), to 1498049353Smrg# deal in the Software without restriction, including without limitation the 1598049353Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1698049353Smrg# sell copies of the Software, and to permit persons to whom the Software is 1798049353Smrg# furnished to do so, subject to the following conditions: 1898049353Smrg# 1998049353Smrg# The above copyright notice and this permission notice shall be included in 2098049353Smrg# all copies or substantial portions of the Software. 2198049353Smrg# 2298049353Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2398049353Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2498049353Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2598049353Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2698049353Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2798049353Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2898049353Smrg# 2998049353Smrg# Except as contained in this notice, the name of the X Consortium shall not 3098049353Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3198049353Smrg# ings in this Software without prior written authorization from the X Consor- 3298049353Smrg# tium. 3398049353Smrg# 3498049353Smrg# 3598049353Smrg# FSF changes to this file are in the public domain. 3698049353Smrg# 3798049353Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3898049353Smrg# `make' implicit rules from creating a file called install from it 3998049353Smrg# when there is no Makefile. 4098049353Smrg# 4198049353Smrg# This script is compatible with the BSD install script, but was written 420ad07f78Smrg# from scratch. 4398049353Smrg 440ad07f78Smrgnl=' 450ad07f78Smrg' 460ad07f78SmrgIFS=" "" $nl" 4798049353Smrg 4898049353Smrg# set DOITPROG to echo to test this script 4998049353Smrg 5098049353Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 510ad07f78Smrgdoit=${DOITPROG-} 520ad07f78Smrgif test -z "$doit"; then 530ad07f78Smrg doit_exec=exec 5498049353Smrgelse 550ad07f78Smrg doit_exec=$doit 5698049353Smrgfi 5798049353Smrg 580ad07f78Smrg# Put in absolute file names if you don't have them in your path; 590ad07f78Smrg# or use environment vars. 600ad07f78Smrg 610ad07f78Smrgchgrpprog=${CHGRPPROG-chgrp} 620ad07f78Smrgchmodprog=${CHMODPROG-chmod} 630ad07f78Smrgchownprog=${CHOWNPROG-chown} 640ad07f78Smrgcmpprog=${CMPPROG-cmp} 650ad07f78Smrgcpprog=${CPPROG-cp} 660ad07f78Smrgmkdirprog=${MKDIRPROG-mkdir} 670ad07f78Smrgmvprog=${MVPROG-mv} 680ad07f78Smrgrmprog=${RMPROG-rm} 690ad07f78Smrgstripprog=${STRIPPROG-strip} 700ad07f78Smrg 710ad07f78Smrgposix_glob='?' 720ad07f78Smrginitialize_posix_glob=' 730ad07f78Smrg test "$posix_glob" != "?" || { 740ad07f78Smrg if (set -f) 2>/dev/null; then 750ad07f78Smrg posix_glob= 760ad07f78Smrg else 770ad07f78Smrg posix_glob=: 780ad07f78Smrg fi 790ad07f78Smrg } 800ad07f78Smrg' 810ad07f78Smrg 820ad07f78Smrgposix_mkdir= 830ad07f78Smrg 840ad07f78Smrg# Desired mode of installed file. 850ad07f78Smrgmode=0755 860ad07f78Smrg 870ad07f78Smrgchgrpcmd= 880ad07f78Smrgchmodcmd=$chmodprog 890ad07f78Smrgchowncmd= 900ad07f78Smrgmvcmd=$mvprog 910ad07f78Smrgrmcmd="$rmprog -f" 920ad07f78Smrgstripcmd= 9398049353Smrg 940ad07f78Smrgsrc= 950ad07f78Smrgdst= 960ad07f78Smrgdir_arg= 970ad07f78Smrgdst_arg= 9898049353Smrg 990ad07f78Smrgcopy_on_change=false 1000ad07f78Smrgno_target_directory= 10198049353Smrg 1020ad07f78Smrgusage="\ 1030ad07f78SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1040ad07f78Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1050ad07f78Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1060ad07f78Smrg or: $0 [OPTION]... -d DIRECTORIES... 10798049353Smrg 1080ad07f78SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1090ad07f78SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1100ad07f78SmrgIn the 4th, create DIRECTORIES. 11198049353Smrg 1120ad07f78SmrgOptions: 1130ad07f78Smrg --help display this help and exit. 1140ad07f78Smrg --version display version info and exit. 11598049353Smrg 1160ad07f78Smrg -c (ignored) 1170ad07f78Smrg -C install only if different (preserve the last data modification time) 1180ad07f78Smrg -d create directories instead of installing files. 1190ad07f78Smrg -g GROUP $chgrpprog installed files to GROUP. 1200ad07f78Smrg -m MODE $chmodprog installed files to MODE. 1210ad07f78Smrg -o USER $chownprog installed files to USER. 1220ad07f78Smrg -s $stripprog installed files. 1230ad07f78Smrg -t DIRECTORY install into DIRECTORY. 1240ad07f78Smrg -T report an error if DSTFILE is a directory. 12598049353Smrg 1260ad07f78SmrgEnvironment variables override the default commands: 1270ad07f78Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1280ad07f78Smrg RMPROG STRIPPROG 1290ad07f78Smrg" 13098049353Smrg 1310ad07f78Smrgwhile test $# -ne 0; do 1320ad07f78Smrg case $1 in 1330ad07f78Smrg -c) ;; 13498049353Smrg 1350ad07f78Smrg -C) copy_on_change=true;; 13698049353Smrg 1370ad07f78Smrg -d) dir_arg=true;; 13898049353Smrg 1390ad07f78Smrg -g) chgrpcmd="$chgrpprog $2" 1400ad07f78Smrg shift;; 14198049353Smrg 1420ad07f78Smrg --help) echo "$usage"; exit $?;; 14398049353Smrg 1440ad07f78Smrg -m) mode=$2 1450ad07f78Smrg case $mode in 1460ad07f78Smrg *' '* | *' '* | *' 1470ad07f78Smrg'* | *'*'* | *'?'* | *'['*) 1480ad07f78Smrg echo "$0: invalid mode: $mode" >&2 1490ad07f78Smrg exit 1;; 1500ad07f78Smrg esac 1510ad07f78Smrg shift;; 15298049353Smrg 1530ad07f78Smrg -o) chowncmd="$chownprog $2" 1540ad07f78Smrg shift;; 15598049353Smrg 1560ad07f78Smrg -s) stripcmd=$stripprog;; 15798049353Smrg 1580ad07f78Smrg -t) dst_arg=$2 1590ad07f78Smrg shift;; 16098049353Smrg 1610ad07f78Smrg -T) no_target_directory=true;; 16298049353Smrg 1630ad07f78Smrg --version) echo "$0 $scriptversion"; exit $?;; 16498049353Smrg 1650ad07f78Smrg --) shift 1660ad07f78Smrg break;; 16798049353Smrg 1680ad07f78Smrg -*) echo "$0: invalid option: $1" >&2 1690ad07f78Smrg exit 1;; 17098049353Smrg 1710ad07f78Smrg *) break;; 1720ad07f78Smrg esac 1730ad07f78Smrg shift 1740ad07f78Smrgdone 17598049353Smrg 1760ad07f78Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1770ad07f78Smrg # When -d is used, all remaining arguments are directories to create. 1780ad07f78Smrg # When -t is used, the destination is already specified. 1790ad07f78Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1800ad07f78Smrg for arg 1810ad07f78Smrg do 1820ad07f78Smrg if test -n "$dst_arg"; then 1830ad07f78Smrg # $@ is not empty: it contains at least $arg. 1840ad07f78Smrg set fnord "$@" "$dst_arg" 1850ad07f78Smrg shift # fnord 1860ad07f78Smrg fi 1870ad07f78Smrg shift # arg 1880ad07f78Smrg dst_arg=$arg 1890ad07f78Smrg done 1900ad07f78Smrgfi 19198049353Smrg 1920ad07f78Smrgif test $# -eq 0; then 1930ad07f78Smrg if test -z "$dir_arg"; then 1940ad07f78Smrg echo "$0: no input file specified." >&2 1950ad07f78Smrg exit 1 1960ad07f78Smrg fi 1970ad07f78Smrg # It's OK to call `install-sh -d' without argument. 1980ad07f78Smrg # This can happen when creating conditional directories. 1990ad07f78Smrg exit 0 2000ad07f78Smrgfi 20198049353Smrg 2020ad07f78Smrgif test -z "$dir_arg"; then 2030ad07f78Smrg trap '(exit $?); exit' 1 2 13 15 2040ad07f78Smrg 2050ad07f78Smrg # Set umask so as not to create temps with too-generous modes. 2060ad07f78Smrg # However, 'strip' requires both read and write access to temps. 2070ad07f78Smrg case $mode in 2080ad07f78Smrg # Optimize common cases. 2090ad07f78Smrg *644) cp_umask=133;; 2100ad07f78Smrg *755) cp_umask=22;; 2110ad07f78Smrg 2120ad07f78Smrg *[0-7]) 2130ad07f78Smrg if test -z "$stripcmd"; then 2140ad07f78Smrg u_plus_rw= 2150ad07f78Smrg else 2160ad07f78Smrg u_plus_rw='% 200' 2170ad07f78Smrg fi 2180ad07f78Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2190ad07f78Smrg *) 2200ad07f78Smrg if test -z "$stripcmd"; then 2210ad07f78Smrg u_plus_rw= 2220ad07f78Smrg else 2230ad07f78Smrg u_plus_rw=,u+rw 2240ad07f78Smrg fi 2250ad07f78Smrg cp_umask=$mode$u_plus_rw;; 2260ad07f78Smrg esac 2270ad07f78Smrgfi 22898049353Smrg 2290ad07f78Smrgfor src 2300ad07f78Smrgdo 2310ad07f78Smrg # Protect names starting with `-'. 2320ad07f78Smrg case $src in 2330ad07f78Smrg -*) src=./$src;; 2340ad07f78Smrg esac 2350ad07f78Smrg 2360ad07f78Smrg if test -n "$dir_arg"; then 2370ad07f78Smrg dst=$src 2380ad07f78Smrg dstdir=$dst 2390ad07f78Smrg test -d "$dstdir" 2400ad07f78Smrg dstdir_status=$? 2410ad07f78Smrg else 2420ad07f78Smrg 2430ad07f78Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2440ad07f78Smrg # might cause directories to be created, which would be especially bad 2450ad07f78Smrg # if $src (and thus $dsttmp) contains '*'. 2460ad07f78Smrg if test ! -f "$src" && test ! -d "$src"; then 2470ad07f78Smrg echo "$0: $src does not exist." >&2 2480ad07f78Smrg exit 1 2490ad07f78Smrg fi 2500ad07f78Smrg 2510ad07f78Smrg if test -z "$dst_arg"; then 2520ad07f78Smrg echo "$0: no destination specified." >&2 2530ad07f78Smrg exit 1 2540ad07f78Smrg fi 2550ad07f78Smrg 2560ad07f78Smrg dst=$dst_arg 2570ad07f78Smrg # Protect names starting with `-'. 2580ad07f78Smrg case $dst in 2590ad07f78Smrg -*) dst=./$dst;; 2600ad07f78Smrg esac 26198049353Smrg 2620ad07f78Smrg # If destination is a directory, append the input filename; won't work 2630ad07f78Smrg # if double slashes aren't ignored. 2640ad07f78Smrg if test -d "$dst"; then 2650ad07f78Smrg if test -n "$no_target_directory"; then 2660ad07f78Smrg echo "$0: $dst_arg: Is a directory" >&2 2670ad07f78Smrg exit 1 2680ad07f78Smrg fi 2690ad07f78Smrg dstdir=$dst 2700ad07f78Smrg dst=$dstdir/`basename "$src"` 2710ad07f78Smrg dstdir_status=0 2720ad07f78Smrg else 2730ad07f78Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2740ad07f78Smrg dstdir=` 2750ad07f78Smrg (dirname "$dst") 2>/dev/null || 2760ad07f78Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2770ad07f78Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2780ad07f78Smrg X"$dst" : 'X\(//\)$' \| \ 2790ad07f78Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2800ad07f78Smrg echo X"$dst" | 2810ad07f78Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2820ad07f78Smrg s//\1/ 2830ad07f78Smrg q 2840ad07f78Smrg } 2850ad07f78Smrg /^X\(\/\/\)[^/].*/{ 2860ad07f78Smrg s//\1/ 2870ad07f78Smrg q 2880ad07f78Smrg } 2890ad07f78Smrg /^X\(\/\/\)$/{ 2900ad07f78Smrg s//\1/ 2910ad07f78Smrg q 2920ad07f78Smrg } 2930ad07f78Smrg /^X\(\/\).*/{ 2940ad07f78Smrg s//\1/ 2950ad07f78Smrg q 2960ad07f78Smrg } 2970ad07f78Smrg s/.*/./; q' 2980ad07f78Smrg ` 2990ad07f78Smrg 3000ad07f78Smrg test -d "$dstdir" 3010ad07f78Smrg dstdir_status=$? 3020ad07f78Smrg fi 3030ad07f78Smrg fi 3040ad07f78Smrg 3050ad07f78Smrg obsolete_mkdir_used=false 3060ad07f78Smrg 3070ad07f78Smrg if test $dstdir_status != 0; then 3080ad07f78Smrg case $posix_mkdir in 3090ad07f78Smrg '') 3100ad07f78Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3110ad07f78Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3120ad07f78Smrg umask=`umask` 3130ad07f78Smrg case $stripcmd.$umask in 3140ad07f78Smrg # Optimize common cases. 3150ad07f78Smrg *[2367][2367]) mkdir_umask=$umask;; 3160ad07f78Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3170ad07f78Smrg 3180ad07f78Smrg *[0-7]) 3190ad07f78Smrg mkdir_umask=`expr $umask + 22 \ 3200ad07f78Smrg - $umask % 100 % 40 + $umask % 20 \ 3210ad07f78Smrg - $umask % 10 % 4 + $umask % 2 3220ad07f78Smrg `;; 3230ad07f78Smrg *) mkdir_umask=$umask,go-w;; 3240ad07f78Smrg esac 3250ad07f78Smrg 3260ad07f78Smrg # With -d, create the new directory with the user-specified mode. 3270ad07f78Smrg # Otherwise, rely on $mkdir_umask. 3280ad07f78Smrg if test -n "$dir_arg"; then 3290ad07f78Smrg mkdir_mode=-m$mode 33098049353Smrg else 3310ad07f78Smrg mkdir_mode= 33298049353Smrg fi 33398049353Smrg 3340ad07f78Smrg posix_mkdir=false 3350ad07f78Smrg case $umask in 3360ad07f78Smrg *[123567][0-7][0-7]) 3370ad07f78Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3380ad07f78Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3390ad07f78Smrg ;; 3400ad07f78Smrg *) 3410ad07f78Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3420ad07f78Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3430ad07f78Smrg 3440ad07f78Smrg if (umask $mkdir_umask && 3450ad07f78Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3460ad07f78Smrg then 3470ad07f78Smrg if test -z "$dir_arg" || { 3480ad07f78Smrg # Check for POSIX incompatibilities with -m. 3490ad07f78Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3500ad07f78Smrg # other-writeable bit of parent directory when it shouldn't. 3510ad07f78Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3520ad07f78Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3530ad07f78Smrg case $ls_ld_tmpdir in 3540ad07f78Smrg d????-?r-*) different_mode=700;; 3550ad07f78Smrg d????-?--*) different_mode=755;; 3560ad07f78Smrg *) false;; 3570ad07f78Smrg esac && 3580ad07f78Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3590ad07f78Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3600ad07f78Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3610ad07f78Smrg } 3620ad07f78Smrg } 3630ad07f78Smrg then posix_mkdir=: 3640ad07f78Smrg fi 3650ad07f78Smrg rmdir "$tmpdir/d" "$tmpdir" 3660ad07f78Smrg else 3670ad07f78Smrg # Remove any dirs left behind by ancient mkdir implementations. 3680ad07f78Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3690ad07f78Smrg fi 3700ad07f78Smrg trap '' 0;; 3710ad07f78Smrg esac;; 3720ad07f78Smrg esac 37398049353Smrg 3740ad07f78Smrg if 3750ad07f78Smrg $posix_mkdir && ( 3760ad07f78Smrg umask $mkdir_umask && 3770ad07f78Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3780ad07f78Smrg ) 3790ad07f78Smrg then : 3800ad07f78Smrg else 3810ad07f78Smrg 3820ad07f78Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3830ad07f78Smrg # or it failed possibly due to a race condition. Create the 3840ad07f78Smrg # directory the slow way, step by step, checking for races as we go. 3850ad07f78Smrg 3860ad07f78Smrg case $dstdir in 3870ad07f78Smrg /*) prefix='/';; 3880ad07f78Smrg -*) prefix='./';; 3890ad07f78Smrg *) prefix='';; 3900ad07f78Smrg esac 3910ad07f78Smrg 3920ad07f78Smrg eval "$initialize_posix_glob" 3930ad07f78Smrg 3940ad07f78Smrg oIFS=$IFS 3950ad07f78Smrg IFS=/ 3960ad07f78Smrg $posix_glob set -f 3970ad07f78Smrg set fnord $dstdir 3980ad07f78Smrg shift 3990ad07f78Smrg $posix_glob set +f 4000ad07f78Smrg IFS=$oIFS 4010ad07f78Smrg 4020ad07f78Smrg prefixes= 4030ad07f78Smrg 4040ad07f78Smrg for d 4050ad07f78Smrg do 4060ad07f78Smrg test -z "$d" && continue 4070ad07f78Smrg 4080ad07f78Smrg prefix=$prefix$d 4090ad07f78Smrg if test -d "$prefix"; then 4100ad07f78Smrg prefixes= 4110ad07f78Smrg else 4120ad07f78Smrg if $posix_mkdir; then 4130ad07f78Smrg (umask=$mkdir_umask && 4140ad07f78Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4150ad07f78Smrg # Don't fail if two instances are running concurrently. 4160ad07f78Smrg test -d "$prefix" || exit 1 4170ad07f78Smrg else 4180ad07f78Smrg case $prefix in 4190ad07f78Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4200ad07f78Smrg *) qprefix=$prefix;; 4210ad07f78Smrg esac 4220ad07f78Smrg prefixes="$prefixes '$qprefix'" 4230ad07f78Smrg fi 4240ad07f78Smrg fi 4250ad07f78Smrg prefix=$prefix/ 4260ad07f78Smrg done 4270ad07f78Smrg 4280ad07f78Smrg if test -n "$prefixes"; then 4290ad07f78Smrg # Don't fail if two instances are running concurrently. 4300ad07f78Smrg (umask $mkdir_umask && 4310ad07f78Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4320ad07f78Smrg test -d "$dstdir" || exit 1 4330ad07f78Smrg obsolete_mkdir_used=true 4340ad07f78Smrg fi 4350ad07f78Smrg fi 4360ad07f78Smrg fi 4370ad07f78Smrg 4380ad07f78Smrg if test -n "$dir_arg"; then 4390ad07f78Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4400ad07f78Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4410ad07f78Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4420ad07f78Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4430ad07f78Smrg else 4440ad07f78Smrg 4450ad07f78Smrg # Make a couple of temp file names in the proper directory. 4460ad07f78Smrg dsttmp=$dstdir/_inst.$$_ 4470ad07f78Smrg rmtmp=$dstdir/_rm.$$_ 4480ad07f78Smrg 4490ad07f78Smrg # Trap to clean up those temp files at exit. 4500ad07f78Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4510ad07f78Smrg 4520ad07f78Smrg # Copy the file name to the temp name. 4530ad07f78Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4540ad07f78Smrg 4550ad07f78Smrg # and set any options; do chmod last to preserve setuid bits. 4560ad07f78Smrg # 4570ad07f78Smrg # If any of these fail, we abort the whole thing. If we want to 4580ad07f78Smrg # ignore errors from any of these, just make sure not to ignore 4590ad07f78Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4600ad07f78Smrg # 4610ad07f78Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4620ad07f78Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4630ad07f78Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4640ad07f78Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4650ad07f78Smrg 4660ad07f78Smrg # If -C, don't bother to copy if it wouldn't change the file. 4670ad07f78Smrg if $copy_on_change && 4680ad07f78Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4690ad07f78Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4700ad07f78Smrg 4710ad07f78Smrg eval "$initialize_posix_glob" && 4720ad07f78Smrg $posix_glob set -f && 4730ad07f78Smrg set X $old && old=:$2:$4:$5:$6 && 4740ad07f78Smrg set X $new && new=:$2:$4:$5:$6 && 4750ad07f78Smrg $posix_glob set +f && 4760ad07f78Smrg 4770ad07f78Smrg test "$old" = "$new" && 4780ad07f78Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4790ad07f78Smrg then 4800ad07f78Smrg rm -f "$dsttmp" 4810ad07f78Smrg else 4820ad07f78Smrg # Rename the file to the real destination. 4830ad07f78Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4840ad07f78Smrg 4850ad07f78Smrg # The rename failed, perhaps because mv can't rename something else 4860ad07f78Smrg # to itself, or perhaps because mv is so ancient that it does not 4870ad07f78Smrg # support -f. 4880ad07f78Smrg { 4890ad07f78Smrg # Now remove or move aside any old file at destination location. 4900ad07f78Smrg # We try this two ways since rm can't unlink itself on some 4910ad07f78Smrg # systems and the destination file might be busy for other 4920ad07f78Smrg # reasons. In this case, the final cleanup might fail but the new 4930ad07f78Smrg # file should still install successfully. 4940ad07f78Smrg { 4950ad07f78Smrg test ! -f "$dst" || 4960ad07f78Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4970ad07f78Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4980ad07f78Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4990ad07f78Smrg } || 5000ad07f78Smrg { echo "$0: cannot unlink or rename $dst" >&2 5010ad07f78Smrg (exit 1); exit 1 5020ad07f78Smrg } 5030ad07f78Smrg } && 5040ad07f78Smrg 5050ad07f78Smrg # Now rename the file to the real destination. 5060ad07f78Smrg $doit $mvcmd "$dsttmp" "$dst" 5070ad07f78Smrg } 5080ad07f78Smrg fi || exit 1 5090ad07f78Smrg 5100ad07f78Smrg trap '' 0 5110ad07f78Smrg fi 5120ad07f78Smrgdone 51398049353Smrg 5140ad07f78Smrg# Local variables: 5150ad07f78Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5160ad07f78Smrg# time-stamp-start: "scriptversion=" 5170ad07f78Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5180ad07f78Smrg# time-stamp-time-zone: "UTC" 5190ad07f78Smrg# time-stamp-end: "; # UTC" 5200ad07f78Smrg# End: 521