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