install-sh revision 80b026c6
19aa228fdSmrg#!/bin/sh 29aa228fdSmrg# install - install a program, script, or datafile 39aa228fdSmrg 480b026c6Smrgscriptversion=2011-01-19.21; # UTC 59aa228fdSmrg 69aa228fdSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 79aa228fdSmrg# later released in X11R6 (xc/config/util/install.sh) with the 89aa228fdSmrg# following copyright and license. 99aa228fdSmrg# 109aa228fdSmrg# Copyright (C) 1994 X Consortium 119aa228fdSmrg# 129aa228fdSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 139aa228fdSmrg# of this software and associated documentation files (the "Software"), to 149aa228fdSmrg# deal in the Software without restriction, including without limitation the 159aa228fdSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 169aa228fdSmrg# sell copies of the Software, and to permit persons to whom the Software is 179aa228fdSmrg# furnished to do so, subject to the following conditions: 189aa228fdSmrg# 199aa228fdSmrg# The above copyright notice and this permission notice shall be included in 209aa228fdSmrg# all copies or substantial portions of the Software. 219aa228fdSmrg# 229aa228fdSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239aa228fdSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 249aa228fdSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259aa228fdSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 269aa228fdSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 279aa228fdSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 289aa228fdSmrg# 299aa228fdSmrg# Except as contained in this notice, the name of the X Consortium shall not 309aa228fdSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 319aa228fdSmrg# ings in this Software without prior written authorization from the X Consor- 329aa228fdSmrg# tium. 339aa228fdSmrg# 349aa228fdSmrg# 359aa228fdSmrg# FSF changes to this file are in the public domain. 369aa228fdSmrg# 379aa228fdSmrg# Calling this script install-sh is preferred over install.sh, to prevent 389aa228fdSmrg# `make' implicit rules from creating a file called install from it 399aa228fdSmrg# when there is no Makefile. 409aa228fdSmrg# 419aa228fdSmrg# This script is compatible with the BSD install script, but was written 429aa228fdSmrg# from scratch. 439aa228fdSmrg 449aa228fdSmrgnl=' 459aa228fdSmrg' 469aa228fdSmrgIFS=" "" $nl" 479aa228fdSmrg 489aa228fdSmrg# set DOITPROG to echo to test this script 499aa228fdSmrg 509aa228fdSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 518f65982aSmrgdoit=${DOITPROG-} 529aa228fdSmrgif test -z "$doit"; then 539aa228fdSmrg doit_exec=exec 549aa228fdSmrgelse 559aa228fdSmrg doit_exec=$doit 569aa228fdSmrgfi 579aa228fdSmrg 589aa228fdSmrg# Put in absolute file names if you don't have them in your path; 599aa228fdSmrg# or use environment vars. 609aa228fdSmrg 618f65982aSmrgchgrpprog=${CHGRPPROG-chgrp} 628f65982aSmrgchmodprog=${CHMODPROG-chmod} 638f65982aSmrgchownprog=${CHOWNPROG-chown} 648f65982aSmrgcmpprog=${CMPPROG-cmp} 658f65982aSmrgcpprog=${CPPROG-cp} 668f65982aSmrgmkdirprog=${MKDIRPROG-mkdir} 678f65982aSmrgmvprog=${MVPROG-mv} 688f65982aSmrgrmprog=${RMPROG-rm} 698f65982aSmrgstripprog=${STRIPPROG-strip} 708f65982aSmrg 718f65982aSmrgposix_glob='?' 728f65982aSmrginitialize_posix_glob=' 738f65982aSmrg test "$posix_glob" != "?" || { 748f65982aSmrg if (set -f) 2>/dev/null; then 758f65982aSmrg posix_glob= 768f65982aSmrg else 778f65982aSmrg posix_glob=: 788f65982aSmrg fi 798f65982aSmrg } 808f65982aSmrg' 819aa228fdSmrg 829aa228fdSmrgposix_mkdir= 839aa228fdSmrg 849aa228fdSmrg# Desired mode of installed file. 859aa228fdSmrgmode=0755 869aa228fdSmrg 878f65982aSmrgchgrpcmd= 889aa228fdSmrgchmodcmd=$chmodprog 899aa228fdSmrgchowncmd= 908f65982aSmrgmvcmd=$mvprog 919aa228fdSmrgrmcmd="$rmprog -f" 928f65982aSmrgstripcmd= 938f65982aSmrg 949aa228fdSmrgsrc= 959aa228fdSmrgdst= 969aa228fdSmrgdir_arg= 978f65982aSmrgdst_arg= 988f65982aSmrg 998f65982aSmrgcopy_on_change=false 1009aa228fdSmrgno_target_directory= 1019aa228fdSmrg 1028f65982aSmrgusage="\ 1038f65982aSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1049aa228fdSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1059aa228fdSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1069aa228fdSmrg or: $0 [OPTION]... -d DIRECTORIES... 1079aa228fdSmrg 1089aa228fdSmrgIn the 1st form, copy SRCFILE to DSTFILE. 1099aa228fdSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1109aa228fdSmrgIn the 4th, create DIRECTORIES. 1119aa228fdSmrg 1129aa228fdSmrgOptions: 1138f65982aSmrg --help display this help and exit. 1148f65982aSmrg --version display version info and exit. 1158f65982aSmrg 1168f65982aSmrg -c (ignored) 1178f65982aSmrg -C install only if different (preserve the last data modification time) 1188f65982aSmrg -d create directories instead of installing files. 1198f65982aSmrg -g GROUP $chgrpprog installed files to GROUP. 1208f65982aSmrg -m MODE $chmodprog installed files to MODE. 1218f65982aSmrg -o USER $chownprog installed files to USER. 1228f65982aSmrg -s $stripprog installed files. 1238f65982aSmrg -t DIRECTORY install into DIRECTORY. 1248f65982aSmrg -T report an error if DSTFILE is a directory. 1259aa228fdSmrg 1269aa228fdSmrgEnvironment variables override the default commands: 1278f65982aSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1288f65982aSmrg RMPROG STRIPPROG 1299aa228fdSmrg" 1309aa228fdSmrg 1319aa228fdSmrgwhile test $# -ne 0; do 1329aa228fdSmrg case $1 in 1338f65982aSmrg -c) ;; 1348f65982aSmrg 1358f65982aSmrg -C) copy_on_change=true;; 1369aa228fdSmrg 1378f65982aSmrg -d) dir_arg=true;; 1389aa228fdSmrg 1399aa228fdSmrg -g) chgrpcmd="$chgrpprog $2" 1408f65982aSmrg shift;; 1419aa228fdSmrg 1429aa228fdSmrg --help) echo "$usage"; exit $?;; 1439aa228fdSmrg 1449aa228fdSmrg -m) mode=$2 1459aa228fdSmrg case $mode in 1469aa228fdSmrg *' '* | *' '* | *' 1479aa228fdSmrg'* | *'*'* | *'?'* | *'['*) 1489aa228fdSmrg echo "$0: invalid mode: $mode" >&2 1499aa228fdSmrg exit 1;; 1509aa228fdSmrg esac 1518f65982aSmrg shift;; 1529aa228fdSmrg 1539aa228fdSmrg -o) chowncmd="$chownprog $2" 1548f65982aSmrg shift;; 1559aa228fdSmrg 1568f65982aSmrg -s) stripcmd=$stripprog;; 1579aa228fdSmrg 1588f65982aSmrg -t) dst_arg=$2 15980b026c6Smrg # Protect names problematic for `test' and other utilities. 16080b026c6Smrg case $dst_arg in 16180b026c6Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16280b026c6Smrg esac 1638f65982aSmrg shift;; 1649aa228fdSmrg 1658f65982aSmrg -T) no_target_directory=true;; 1669aa228fdSmrg 1679aa228fdSmrg --version) echo "$0 $scriptversion"; exit $?;; 1689aa228fdSmrg 1699aa228fdSmrg --) shift 1709aa228fdSmrg break;; 1719aa228fdSmrg 1729aa228fdSmrg -*) echo "$0: invalid option: $1" >&2 1739aa228fdSmrg exit 1;; 1749aa228fdSmrg 1759aa228fdSmrg *) break;; 1769aa228fdSmrg esac 1778f65982aSmrg shift 1789aa228fdSmrgdone 1799aa228fdSmrg 1808f65982aSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1819aa228fdSmrg # When -d is used, all remaining arguments are directories to create. 1829aa228fdSmrg # When -t is used, the destination is already specified. 1839aa228fdSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1849aa228fdSmrg for arg 1859aa228fdSmrg do 1868f65982aSmrg if test -n "$dst_arg"; then 1879aa228fdSmrg # $@ is not empty: it contains at least $arg. 1888f65982aSmrg set fnord "$@" "$dst_arg" 1899aa228fdSmrg shift # fnord 1909aa228fdSmrg fi 1919aa228fdSmrg shift # arg 1928f65982aSmrg dst_arg=$arg 19380b026c6Smrg # Protect names problematic for `test' and other utilities. 19480b026c6Smrg case $dst_arg in 19580b026c6Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19680b026c6Smrg esac 1979aa228fdSmrg done 1989aa228fdSmrgfi 1999aa228fdSmrg 2009aa228fdSmrgif test $# -eq 0; then 2019aa228fdSmrg if test -z "$dir_arg"; then 2029aa228fdSmrg echo "$0: no input file specified." >&2 2039aa228fdSmrg exit 1 2049aa228fdSmrg fi 2059aa228fdSmrg # It's OK to call `install-sh -d' without argument. 2069aa228fdSmrg # This can happen when creating conditional directories. 2079aa228fdSmrg exit 0 2089aa228fdSmrgfi 2099aa228fdSmrg 2109aa228fdSmrgif test -z "$dir_arg"; then 21180b026c6Smrg do_exit='(exit $ret); exit $ret' 21280b026c6Smrg trap "ret=129; $do_exit" 1 21380b026c6Smrg trap "ret=130; $do_exit" 2 21480b026c6Smrg trap "ret=141; $do_exit" 13 21580b026c6Smrg trap "ret=143; $do_exit" 15 2169aa228fdSmrg 2179aa228fdSmrg # Set umask so as not to create temps with too-generous modes. 2189aa228fdSmrg # However, 'strip' requires both read and write access to temps. 2199aa228fdSmrg case $mode in 2209aa228fdSmrg # Optimize common cases. 2219aa228fdSmrg *644) cp_umask=133;; 2229aa228fdSmrg *755) cp_umask=22;; 2239aa228fdSmrg 2249aa228fdSmrg *[0-7]) 2259aa228fdSmrg if test -z "$stripcmd"; then 2269aa228fdSmrg u_plus_rw= 2279aa228fdSmrg else 2289aa228fdSmrg u_plus_rw='% 200' 2299aa228fdSmrg fi 2309aa228fdSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2319aa228fdSmrg *) 2329aa228fdSmrg if test -z "$stripcmd"; then 2339aa228fdSmrg u_plus_rw= 2349aa228fdSmrg else 2359aa228fdSmrg u_plus_rw=,u+rw 2369aa228fdSmrg fi 2379aa228fdSmrg cp_umask=$mode$u_plus_rw;; 2389aa228fdSmrg esac 2399aa228fdSmrgfi 2409aa228fdSmrg 2419aa228fdSmrgfor src 2429aa228fdSmrgdo 24380b026c6Smrg # Protect names problematic for `test' and other utilities. 2449aa228fdSmrg case $src in 24580b026c6Smrg -* | [=\(\)!]) src=./$src;; 2469aa228fdSmrg esac 2479aa228fdSmrg 2489aa228fdSmrg if test -n "$dir_arg"; then 2499aa228fdSmrg dst=$src 2509aa228fdSmrg dstdir=$dst 2519aa228fdSmrg test -d "$dstdir" 2529aa228fdSmrg dstdir_status=$? 2539aa228fdSmrg else 2549aa228fdSmrg 2559aa228fdSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2569aa228fdSmrg # might cause directories to be created, which would be especially bad 2579aa228fdSmrg # if $src (and thus $dsttmp) contains '*'. 2589aa228fdSmrg if test ! -f "$src" && test ! -d "$src"; then 2599aa228fdSmrg echo "$0: $src does not exist." >&2 2609aa228fdSmrg exit 1 2619aa228fdSmrg fi 2629aa228fdSmrg 2638f65982aSmrg if test -z "$dst_arg"; then 2649aa228fdSmrg echo "$0: no destination specified." >&2 2659aa228fdSmrg exit 1 2669aa228fdSmrg fi 2678f65982aSmrg dst=$dst_arg 2689aa228fdSmrg 2699aa228fdSmrg # If destination is a directory, append the input filename; won't work 2709aa228fdSmrg # if double slashes aren't ignored. 2719aa228fdSmrg if test -d "$dst"; then 2729aa228fdSmrg if test -n "$no_target_directory"; then 2738f65982aSmrg echo "$0: $dst_arg: Is a directory" >&2 2749aa228fdSmrg exit 1 2759aa228fdSmrg fi 2769aa228fdSmrg dstdir=$dst 2779aa228fdSmrg dst=$dstdir/`basename "$src"` 2789aa228fdSmrg dstdir_status=0 2799aa228fdSmrg else 2809aa228fdSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2819aa228fdSmrg dstdir=` 2829aa228fdSmrg (dirname "$dst") 2>/dev/null || 2839aa228fdSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2849aa228fdSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2859aa228fdSmrg X"$dst" : 'X\(//\)$' \| \ 2869aa228fdSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2879aa228fdSmrg echo X"$dst" | 2889aa228fdSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2899aa228fdSmrg s//\1/ 2909aa228fdSmrg q 2919aa228fdSmrg } 2929aa228fdSmrg /^X\(\/\/\)[^/].*/{ 2939aa228fdSmrg s//\1/ 2949aa228fdSmrg q 2959aa228fdSmrg } 2969aa228fdSmrg /^X\(\/\/\)$/{ 2979aa228fdSmrg s//\1/ 2989aa228fdSmrg q 2999aa228fdSmrg } 3009aa228fdSmrg /^X\(\/\).*/{ 3019aa228fdSmrg s//\1/ 3029aa228fdSmrg q 3039aa228fdSmrg } 3049aa228fdSmrg s/.*/./; q' 3059aa228fdSmrg ` 3069aa228fdSmrg 3079aa228fdSmrg test -d "$dstdir" 3089aa228fdSmrg dstdir_status=$? 3099aa228fdSmrg fi 3109aa228fdSmrg fi 3119aa228fdSmrg 3129aa228fdSmrg obsolete_mkdir_used=false 3139aa228fdSmrg 3149aa228fdSmrg if test $dstdir_status != 0; then 3159aa228fdSmrg case $posix_mkdir in 3169aa228fdSmrg '') 3179aa228fdSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3189aa228fdSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3199aa228fdSmrg umask=`umask` 3209aa228fdSmrg case $stripcmd.$umask in 3219aa228fdSmrg # Optimize common cases. 3229aa228fdSmrg *[2367][2367]) mkdir_umask=$umask;; 3239aa228fdSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3249aa228fdSmrg 3259aa228fdSmrg *[0-7]) 3269aa228fdSmrg mkdir_umask=`expr $umask + 22 \ 3279aa228fdSmrg - $umask % 100 % 40 + $umask % 20 \ 3289aa228fdSmrg - $umask % 10 % 4 + $umask % 2 3299aa228fdSmrg `;; 3309aa228fdSmrg *) mkdir_umask=$umask,go-w;; 3319aa228fdSmrg esac 3329aa228fdSmrg 3339aa228fdSmrg # With -d, create the new directory with the user-specified mode. 3349aa228fdSmrg # Otherwise, rely on $mkdir_umask. 3359aa228fdSmrg if test -n "$dir_arg"; then 3369aa228fdSmrg mkdir_mode=-m$mode 3379aa228fdSmrg else 3389aa228fdSmrg mkdir_mode= 3399aa228fdSmrg fi 3409aa228fdSmrg 3419aa228fdSmrg posix_mkdir=false 3429aa228fdSmrg case $umask in 3439aa228fdSmrg *[123567][0-7][0-7]) 3449aa228fdSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3459aa228fdSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3469aa228fdSmrg ;; 3479aa228fdSmrg *) 3489aa228fdSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3499aa228fdSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3509aa228fdSmrg 3519aa228fdSmrg if (umask $mkdir_umask && 3529aa228fdSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3539aa228fdSmrg then 3549aa228fdSmrg if test -z "$dir_arg" || { 3559aa228fdSmrg # Check for POSIX incompatibilities with -m. 3569aa228fdSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3579aa228fdSmrg # other-writeable bit of parent directory when it shouldn't. 3589aa228fdSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3599aa228fdSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3609aa228fdSmrg case $ls_ld_tmpdir in 3619aa228fdSmrg d????-?r-*) different_mode=700;; 3629aa228fdSmrg d????-?--*) different_mode=755;; 3639aa228fdSmrg *) false;; 3649aa228fdSmrg esac && 3659aa228fdSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3669aa228fdSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3679aa228fdSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3689aa228fdSmrg } 3699aa228fdSmrg } 3709aa228fdSmrg then posix_mkdir=: 3719aa228fdSmrg fi 3729aa228fdSmrg rmdir "$tmpdir/d" "$tmpdir" 3739aa228fdSmrg else 3749aa228fdSmrg # Remove any dirs left behind by ancient mkdir implementations. 3759aa228fdSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3769aa228fdSmrg fi 3779aa228fdSmrg trap '' 0;; 3789aa228fdSmrg esac;; 3799aa228fdSmrg esac 3809aa228fdSmrg 3819aa228fdSmrg if 3829aa228fdSmrg $posix_mkdir && ( 3839aa228fdSmrg umask $mkdir_umask && 3849aa228fdSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3859aa228fdSmrg ) 3869aa228fdSmrg then : 3879aa228fdSmrg else 3889aa228fdSmrg 3899aa228fdSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3909aa228fdSmrg # or it failed possibly due to a race condition. Create the 3919aa228fdSmrg # directory the slow way, step by step, checking for races as we go. 3929aa228fdSmrg 3939aa228fdSmrg case $dstdir in 3948f65982aSmrg /*) prefix='/';; 39580b026c6Smrg [-=\(\)!]*) prefix='./';; 3968f65982aSmrg *) prefix='';; 3979aa228fdSmrg esac 3989aa228fdSmrg 3998f65982aSmrg eval "$initialize_posix_glob" 4009aa228fdSmrg 4019aa228fdSmrg oIFS=$IFS 4029aa228fdSmrg IFS=/ 4038f65982aSmrg $posix_glob set -f 4049aa228fdSmrg set fnord $dstdir 4059aa228fdSmrg shift 4068f65982aSmrg $posix_glob set +f 4079aa228fdSmrg IFS=$oIFS 4089aa228fdSmrg 4099aa228fdSmrg prefixes= 4109aa228fdSmrg 4119aa228fdSmrg for d 4129aa228fdSmrg do 41380b026c6Smrg test X"$d" = X && continue 4149aa228fdSmrg 4159aa228fdSmrg prefix=$prefix$d 4169aa228fdSmrg if test -d "$prefix"; then 4179aa228fdSmrg prefixes= 4189aa228fdSmrg else 4199aa228fdSmrg if $posix_mkdir; then 4209aa228fdSmrg (umask=$mkdir_umask && 4219aa228fdSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4229aa228fdSmrg # Don't fail if two instances are running concurrently. 4239aa228fdSmrg test -d "$prefix" || exit 1 4249aa228fdSmrg else 4259aa228fdSmrg case $prefix in 4269aa228fdSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4279aa228fdSmrg *) qprefix=$prefix;; 4289aa228fdSmrg esac 4299aa228fdSmrg prefixes="$prefixes '$qprefix'" 4309aa228fdSmrg fi 4319aa228fdSmrg fi 4329aa228fdSmrg prefix=$prefix/ 4339aa228fdSmrg done 4349aa228fdSmrg 4359aa228fdSmrg if test -n "$prefixes"; then 4369aa228fdSmrg # Don't fail if two instances are running concurrently. 4379aa228fdSmrg (umask $mkdir_umask && 4389aa228fdSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4399aa228fdSmrg test -d "$dstdir" || exit 1 4409aa228fdSmrg obsolete_mkdir_used=true 4419aa228fdSmrg fi 4429aa228fdSmrg fi 4439aa228fdSmrg fi 4449aa228fdSmrg 4459aa228fdSmrg if test -n "$dir_arg"; then 4469aa228fdSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4479aa228fdSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4489aa228fdSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4499aa228fdSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4509aa228fdSmrg else 4519aa228fdSmrg 4529aa228fdSmrg # Make a couple of temp file names in the proper directory. 4539aa228fdSmrg dsttmp=$dstdir/_inst.$$_ 4549aa228fdSmrg rmtmp=$dstdir/_rm.$$_ 4559aa228fdSmrg 4569aa228fdSmrg # Trap to clean up those temp files at exit. 4579aa228fdSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4589aa228fdSmrg 4599aa228fdSmrg # Copy the file name to the temp name. 4609aa228fdSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4619aa228fdSmrg 4629aa228fdSmrg # and set any options; do chmod last to preserve setuid bits. 4639aa228fdSmrg # 4649aa228fdSmrg # If any of these fail, we abort the whole thing. If we want to 4659aa228fdSmrg # ignore errors from any of these, just make sure not to ignore 4669aa228fdSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4679aa228fdSmrg # 4688f65982aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4698f65982aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4708f65982aSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4718f65982aSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4728f65982aSmrg 4738f65982aSmrg # If -C, don't bother to copy if it wouldn't change the file. 4748f65982aSmrg if $copy_on_change && 4758f65982aSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4768f65982aSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4778f65982aSmrg 4788f65982aSmrg eval "$initialize_posix_glob" && 4798f65982aSmrg $posix_glob set -f && 4808f65982aSmrg set X $old && old=:$2:$4:$5:$6 && 4818f65982aSmrg set X $new && new=:$2:$4:$5:$6 && 4828f65982aSmrg $posix_glob set +f && 4838f65982aSmrg 4848f65982aSmrg test "$old" = "$new" && 4858f65982aSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4868f65982aSmrg then 4878f65982aSmrg rm -f "$dsttmp" 4888f65982aSmrg else 4898f65982aSmrg # Rename the file to the real destination. 4908f65982aSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4918f65982aSmrg 4928f65982aSmrg # The rename failed, perhaps because mv can't rename something else 4938f65982aSmrg # to itself, or perhaps because mv is so ancient that it does not 4948f65982aSmrg # support -f. 4958f65982aSmrg { 4968f65982aSmrg # Now remove or move aside any old file at destination location. 4978f65982aSmrg # We try this two ways since rm can't unlink itself on some 4988f65982aSmrg # systems and the destination file might be busy for other 4998f65982aSmrg # reasons. In this case, the final cleanup might fail but the new 5008f65982aSmrg # file should still install successfully. 5018f65982aSmrg { 5028f65982aSmrg test ! -f "$dst" || 5038f65982aSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 5048f65982aSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5058f65982aSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 5068f65982aSmrg } || 5078f65982aSmrg { echo "$0: cannot unlink or rename $dst" >&2 5088f65982aSmrg (exit 1); exit 1 5098f65982aSmrg } 5108f65982aSmrg } && 5118f65982aSmrg 5128f65982aSmrg # Now rename the file to the real destination. 5138f65982aSmrg $doit $mvcmd "$dsttmp" "$dst" 5148f65982aSmrg } 5158f65982aSmrg fi || exit 1 5169aa228fdSmrg 5179aa228fdSmrg trap '' 0 5189aa228fdSmrg fi 5199aa228fdSmrgdone 5209aa228fdSmrg 5219aa228fdSmrg# Local variables: 5229aa228fdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5239aa228fdSmrg# time-stamp-start: "scriptversion=" 5249aa228fdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5258f65982aSmrg# time-stamp-time-zone: "UTC" 5268f65982aSmrg# time-stamp-end: "; # UTC" 5279aa228fdSmrg# End: 528