install-sh revision 9418810d
19bd41f2cSmrg#!/bin/sh 29bd41f2cSmrg# install - install a program, script, or datafile 39bd41f2cSmrg 49418810dSmrgscriptversion=2009-04-28.21; # UTC 59bd41f2cSmrg 69bd41f2cSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 79bd41f2cSmrg# later released in X11R6 (xc/config/util/install.sh) with the 89bd41f2cSmrg# following copyright and license. 99bd41f2cSmrg# 109bd41f2cSmrg# Copyright (C) 1994 X Consortium 119bd41f2cSmrg# 129bd41f2cSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 139bd41f2cSmrg# of this software and associated documentation files (the "Software"), to 149bd41f2cSmrg# deal in the Software without restriction, including without limitation the 159bd41f2cSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 169bd41f2cSmrg# sell copies of the Software, and to permit persons to whom the Software is 179bd41f2cSmrg# furnished to do so, subject to the following conditions: 189bd41f2cSmrg# 199bd41f2cSmrg# The above copyright notice and this permission notice shall be included in 209bd41f2cSmrg# all copies or substantial portions of the Software. 219bd41f2cSmrg# 229bd41f2cSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239bd41f2cSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 249bd41f2cSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259bd41f2cSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 269bd41f2cSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 279bd41f2cSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 289bd41f2cSmrg# 299bd41f2cSmrg# Except as contained in this notice, the name of the X Consortium shall not 309bd41f2cSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 319bd41f2cSmrg# ings in this Software without prior written authorization from the X Consor- 329bd41f2cSmrg# tium. 339bd41f2cSmrg# 349bd41f2cSmrg# 359bd41f2cSmrg# FSF changes to this file are in the public domain. 369bd41f2cSmrg# 379bd41f2cSmrg# Calling this script install-sh is preferred over install.sh, to prevent 389bd41f2cSmrg# `make' implicit rules from creating a file called install from it 399bd41f2cSmrg# when there is no Makefile. 409bd41f2cSmrg# 419bd41f2cSmrg# This script is compatible with the BSD install script, but was written 429418810dSmrg# from scratch. 439418810dSmrg 449418810dSmrgnl=' 459418810dSmrg' 469418810dSmrgIFS=" "" $nl" 479bd41f2cSmrg 489bd41f2cSmrg# set DOITPROG to echo to test this script 499bd41f2cSmrg 509bd41f2cSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 519418810dSmrgdoit=${DOITPROG-} 529418810dSmrgif test -z "$doit"; then 539418810dSmrg doit_exec=exec 549418810dSmrgelse 559418810dSmrg doit_exec=$doit 569418810dSmrgfi 579bd41f2cSmrg 589418810dSmrg# Put in absolute file names if you don't have them in your path; 599418810dSmrg# or use environment vars. 609418810dSmrg 619418810dSmrgchgrpprog=${CHGRPPROG-chgrp} 629418810dSmrgchmodprog=${CHMODPROG-chmod} 639418810dSmrgchownprog=${CHOWNPROG-chown} 649418810dSmrgcmpprog=${CMPPROG-cmp} 659418810dSmrgcpprog=${CPPROG-cp} 669418810dSmrgmkdirprog=${MKDIRPROG-mkdir} 679418810dSmrgmvprog=${MVPROG-mv} 689418810dSmrgrmprog=${RMPROG-rm} 699418810dSmrgstripprog=${STRIPPROG-strip} 709418810dSmrg 719418810dSmrgposix_glob='?' 729418810dSmrginitialize_posix_glob=' 739418810dSmrg test "$posix_glob" != "?" || { 749418810dSmrg if (set -f) 2>/dev/null; then 759418810dSmrg posix_glob= 769418810dSmrg else 779418810dSmrg posix_glob=: 789418810dSmrg fi 799418810dSmrg } 809418810dSmrg' 819bd41f2cSmrg 829418810dSmrgposix_mkdir= 839418810dSmrg 849418810dSmrg# Desired mode of installed file. 859418810dSmrgmode=0755 869bd41f2cSmrg 879bd41f2cSmrgchgrpcmd= 889418810dSmrgchmodcmd=$chmodprog 899418810dSmrgchowncmd= 909418810dSmrgmvcmd=$mvprog 919bd41f2cSmrgrmcmd="$rmprog -f" 929418810dSmrgstripcmd= 939418810dSmrg 949bd41f2cSmrgsrc= 959bd41f2cSmrgdst= 969bd41f2cSmrgdir_arg= 979418810dSmrgdst_arg= 989418810dSmrg 999418810dSmrgcopy_on_change=false 1009bd41f2cSmrgno_target_directory= 1019bd41f2cSmrg 1029418810dSmrgusage="\ 1039418810dSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1049bd41f2cSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1059bd41f2cSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1069bd41f2cSmrg or: $0 [OPTION]... -d DIRECTORIES... 1079bd41f2cSmrg 1089bd41f2cSmrgIn the 1st form, copy SRCFILE to DSTFILE. 1099bd41f2cSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1109bd41f2cSmrgIn the 4th, create DIRECTORIES. 1119bd41f2cSmrg 1129bd41f2cSmrgOptions: 1139418810dSmrg --help display this help and exit. 1149418810dSmrg --version display version info and exit. 1159418810dSmrg 1169418810dSmrg -c (ignored) 1179418810dSmrg -C install only if different (preserve the last data modification time) 1189418810dSmrg -d create directories instead of installing files. 1199418810dSmrg -g GROUP $chgrpprog installed files to GROUP. 1209418810dSmrg -m MODE $chmodprog installed files to MODE. 1219418810dSmrg -o USER $chownprog installed files to USER. 1229418810dSmrg -s $stripprog installed files. 1239418810dSmrg -t DIRECTORY install into DIRECTORY. 1249418810dSmrg -T report an error if DSTFILE is a directory. 1259bd41f2cSmrg 1269bd41f2cSmrgEnvironment variables override the default commands: 1279418810dSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1289418810dSmrg RMPROG STRIPPROG 1299bd41f2cSmrg" 1309bd41f2cSmrg 1319418810dSmrgwhile test $# -ne 0; do 1329bd41f2cSmrg case $1 in 1339418810dSmrg -c) ;; 1349418810dSmrg 1359418810dSmrg -C) copy_on_change=true;; 1369bd41f2cSmrg 1379418810dSmrg -d) dir_arg=true;; 1389bd41f2cSmrg 1399bd41f2cSmrg -g) chgrpcmd="$chgrpprog $2" 1409418810dSmrg shift;; 1419bd41f2cSmrg 1429bd41f2cSmrg --help) echo "$usage"; exit $?;; 1439bd41f2cSmrg 1449418810dSmrg -m) mode=$2 1459418810dSmrg case $mode in 1469418810dSmrg *' '* | *' '* | *' 1479418810dSmrg'* | *'*'* | *'?'* | *'['*) 1489418810dSmrg echo "$0: invalid mode: $mode" >&2 1499418810dSmrg exit 1;; 1509418810dSmrg esac 1519418810dSmrg shift;; 1529bd41f2cSmrg 1539bd41f2cSmrg -o) chowncmd="$chownprog $2" 1549418810dSmrg shift;; 1559bd41f2cSmrg 1569418810dSmrg -s) stripcmd=$stripprog;; 1579bd41f2cSmrg 1589418810dSmrg -t) dst_arg=$2 1599418810dSmrg shift;; 1609bd41f2cSmrg 1619418810dSmrg -T) no_target_directory=true;; 1629bd41f2cSmrg 1639bd41f2cSmrg --version) echo "$0 $scriptversion"; exit $?;; 1649bd41f2cSmrg 1659418810dSmrg --) shift 1669bd41f2cSmrg break;; 1679418810dSmrg 1689418810dSmrg -*) echo "$0: invalid option: $1" >&2 1699418810dSmrg exit 1;; 1709418810dSmrg 1719418810dSmrg *) break;; 1729bd41f2cSmrg esac 1739418810dSmrg shift 1749bd41f2cSmrgdone 1759bd41f2cSmrg 1769418810dSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1779418810dSmrg # When -d is used, all remaining arguments are directories to create. 1789418810dSmrg # When -t is used, the destination is already specified. 1799418810dSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1809418810dSmrg for arg 1819418810dSmrg do 1829418810dSmrg if test -n "$dst_arg"; then 1839418810dSmrg # $@ is not empty: it contains at least $arg. 1849418810dSmrg set fnord "$@" "$dst_arg" 1859418810dSmrg shift # fnord 1869418810dSmrg fi 1879418810dSmrg shift # arg 1889418810dSmrg dst_arg=$arg 1899418810dSmrg done 1909418810dSmrgfi 1919418810dSmrg 1929418810dSmrgif test $# -eq 0; then 1939bd41f2cSmrg if test -z "$dir_arg"; then 1949bd41f2cSmrg echo "$0: no input file specified." >&2 1959bd41f2cSmrg exit 1 1969bd41f2cSmrg fi 1979bd41f2cSmrg # It's OK to call `install-sh -d' without argument. 1989bd41f2cSmrg # This can happen when creating conditional directories. 1999bd41f2cSmrg exit 0 2009bd41f2cSmrgfi 2019bd41f2cSmrg 2029418810dSmrgif test -z "$dir_arg"; then 2039418810dSmrg trap '(exit $?); exit' 1 2 13 15 2049418810dSmrg 2059418810dSmrg # Set umask so as not to create temps with too-generous modes. 2069418810dSmrg # However, 'strip' requires both read and write access to temps. 2079418810dSmrg case $mode in 2089418810dSmrg # Optimize common cases. 2099418810dSmrg *644) cp_umask=133;; 2109418810dSmrg *755) cp_umask=22;; 2119418810dSmrg 2129418810dSmrg *[0-7]) 2139418810dSmrg if test -z "$stripcmd"; then 2149418810dSmrg u_plus_rw= 2159418810dSmrg else 2169418810dSmrg u_plus_rw='% 200' 2179418810dSmrg fi 2189418810dSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2199418810dSmrg *) 2209418810dSmrg if test -z "$stripcmd"; then 2219418810dSmrg u_plus_rw= 2229418810dSmrg else 2239418810dSmrg u_plus_rw=,u+rw 2249418810dSmrg fi 2259418810dSmrg cp_umask=$mode$u_plus_rw;; 2269418810dSmrg esac 2279418810dSmrgfi 2289418810dSmrg 2299bd41f2cSmrgfor src 2309bd41f2cSmrgdo 2319bd41f2cSmrg # Protect names starting with `-'. 2329bd41f2cSmrg case $src in 2339418810dSmrg -*) src=./$src;; 2349bd41f2cSmrg esac 2359bd41f2cSmrg 2369bd41f2cSmrg if test -n "$dir_arg"; then 2379bd41f2cSmrg dst=$src 2389418810dSmrg dstdir=$dst 2399418810dSmrg test -d "$dstdir" 2409418810dSmrg dstdir_status=$? 241d075918cSmrg else 2429418810dSmrg 2439bd41f2cSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2449bd41f2cSmrg # might cause directories to be created, which would be especially bad 2459bd41f2cSmrg # if $src (and thus $dsttmp) contains '*'. 2469bd41f2cSmrg if test ! -f "$src" && test ! -d "$src"; then 2479bd41f2cSmrg echo "$0: $src does not exist." >&2 2489bd41f2cSmrg exit 1 2499bd41f2cSmrg fi 2509bd41f2cSmrg 2519418810dSmrg if test -z "$dst_arg"; then 2529bd41f2cSmrg echo "$0: no destination specified." >&2 2539bd41f2cSmrg exit 1 2549bd41f2cSmrg fi 2559bd41f2cSmrg 2569418810dSmrg dst=$dst_arg 2579bd41f2cSmrg # Protect names starting with `-'. 2589bd41f2cSmrg case $dst in 2599418810dSmrg -*) dst=./$dst;; 2609bd41f2cSmrg esac 2619bd41f2cSmrg 2629bd41f2cSmrg # If destination is a directory, append the input filename; won't work 2639bd41f2cSmrg # if double slashes aren't ignored. 2649bd41f2cSmrg if test -d "$dst"; then 2659bd41f2cSmrg if test -n "$no_target_directory"; then 2669418810dSmrg echo "$0: $dst_arg: Is a directory" >&2 2679bd41f2cSmrg exit 1 2689bd41f2cSmrg fi 2699418810dSmrg dstdir=$dst 2709418810dSmrg dst=$dstdir/`basename "$src"` 2719418810dSmrg dstdir_status=0 2729418810dSmrg else 2739418810dSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2749418810dSmrg dstdir=` 2759418810dSmrg (dirname "$dst") 2>/dev/null || 2769418810dSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2779418810dSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2789418810dSmrg X"$dst" : 'X\(//\)$' \| \ 2799418810dSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2809418810dSmrg echo X"$dst" | 2819418810dSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2829418810dSmrg s//\1/ 2839418810dSmrg q 2849418810dSmrg } 2859418810dSmrg /^X\(\/\/\)[^/].*/{ 2869418810dSmrg s//\1/ 2879418810dSmrg q 2889418810dSmrg } 2899418810dSmrg /^X\(\/\/\)$/{ 2909418810dSmrg s//\1/ 2919418810dSmrg q 2929418810dSmrg } 2939418810dSmrg /^X\(\/\).*/{ 2949418810dSmrg s//\1/ 2959418810dSmrg q 2969418810dSmrg } 2979418810dSmrg s/.*/./; q' 2989418810dSmrg ` 2999418810dSmrg 3009418810dSmrg test -d "$dstdir" 3019418810dSmrg dstdir_status=$? 3029bd41f2cSmrg fi 3039bd41f2cSmrg fi 3049bd41f2cSmrg 3059418810dSmrg obsolete_mkdir_used=false 3069418810dSmrg 3079418810dSmrg if test $dstdir_status != 0; then 3089418810dSmrg case $posix_mkdir in 3099418810dSmrg '') 3109418810dSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3119418810dSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3129418810dSmrg umask=`umask` 3139418810dSmrg case $stripcmd.$umask in 3149418810dSmrg # Optimize common cases. 3159418810dSmrg *[2367][2367]) mkdir_umask=$umask;; 3169418810dSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3179418810dSmrg 3189418810dSmrg *[0-7]) 3199418810dSmrg mkdir_umask=`expr $umask + 22 \ 3209418810dSmrg - $umask % 100 % 40 + $umask % 20 \ 3219418810dSmrg - $umask % 10 % 4 + $umask % 2 3229418810dSmrg `;; 3239418810dSmrg *) mkdir_umask=$umask,go-w;; 3249418810dSmrg esac 3259418810dSmrg 3269418810dSmrg # With -d, create the new directory with the user-specified mode. 3279418810dSmrg # Otherwise, rely on $mkdir_umask. 3289418810dSmrg if test -n "$dir_arg"; then 3299418810dSmrg mkdir_mode=-m$mode 3309418810dSmrg else 3319418810dSmrg mkdir_mode= 3329418810dSmrg fi 3339418810dSmrg 3349418810dSmrg posix_mkdir=false 3359418810dSmrg case $umask in 3369418810dSmrg *[123567][0-7][0-7]) 3379418810dSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3389418810dSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3399418810dSmrg ;; 3409418810dSmrg *) 3419418810dSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3429418810dSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3439418810dSmrg 3449418810dSmrg if (umask $mkdir_umask && 3459418810dSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3469418810dSmrg then 3479418810dSmrg if test -z "$dir_arg" || { 3489418810dSmrg # Check for POSIX incompatibilities with -m. 3499418810dSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3509418810dSmrg # other-writeable bit of parent directory when it shouldn't. 3519418810dSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3529418810dSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3539418810dSmrg case $ls_ld_tmpdir in 3549418810dSmrg d????-?r-*) different_mode=700;; 3559418810dSmrg d????-?--*) different_mode=755;; 3569418810dSmrg *) false;; 3579418810dSmrg esac && 3589418810dSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3599418810dSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3609418810dSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3619418810dSmrg } 3629418810dSmrg } 3639418810dSmrg then posix_mkdir=: 3649418810dSmrg fi 3659418810dSmrg rmdir "$tmpdir/d" "$tmpdir" 3669418810dSmrg else 3679418810dSmrg # Remove any dirs left behind by ancient mkdir implementations. 3689418810dSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3699418810dSmrg fi 3709418810dSmrg trap '' 0;; 3719418810dSmrg esac;; 3729418810dSmrg esac 3739bd41f2cSmrg 3749418810dSmrg if 3759418810dSmrg $posix_mkdir && ( 3769418810dSmrg umask $mkdir_umask && 3779418810dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3789418810dSmrg ) 3799418810dSmrg then : 3809418810dSmrg else 381d075918cSmrg 3829418810dSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3839418810dSmrg # or it failed possibly due to a race condition. Create the 3849418810dSmrg # directory the slow way, step by step, checking for races as we go. 3859bd41f2cSmrg 3869418810dSmrg case $dstdir in 3879418810dSmrg /*) prefix='/';; 3889418810dSmrg -*) prefix='./';; 3899418810dSmrg *) prefix='';; 3909418810dSmrg esac 391d075918cSmrg 3929418810dSmrg eval "$initialize_posix_glob" 393d075918cSmrg 3949418810dSmrg oIFS=$IFS 3959418810dSmrg IFS=/ 3969418810dSmrg $posix_glob set -f 3979418810dSmrg set fnord $dstdir 3989bd41f2cSmrg shift 3999418810dSmrg $posix_glob set +f 4009418810dSmrg IFS=$oIFS 4019418810dSmrg 4029418810dSmrg prefixes= 4039418810dSmrg 4049418810dSmrg for d 4059418810dSmrg do 4069418810dSmrg test -z "$d" && continue 4079418810dSmrg 4089418810dSmrg prefix=$prefix$d 4099418810dSmrg if test -d "$prefix"; then 4109418810dSmrg prefixes= 4119418810dSmrg else 4129418810dSmrg if $posix_mkdir; then 4139418810dSmrg (umask=$mkdir_umask && 4149418810dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4159418810dSmrg # Don't fail if two instances are running concurrently. 4169418810dSmrg test -d "$prefix" || exit 1 4179418810dSmrg else 4189418810dSmrg case $prefix in 4199418810dSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4209418810dSmrg *) qprefix=$prefix;; 4219418810dSmrg esac 4229418810dSmrg prefixes="$prefixes '$qprefix'" 4239418810dSmrg fi 4249418810dSmrg fi 4259418810dSmrg prefix=$prefix/ 4269418810dSmrg done 4279418810dSmrg 4289418810dSmrg if test -n "$prefixes"; then 4299418810dSmrg # Don't fail if two instances are running concurrently. 4309418810dSmrg (umask $mkdir_umask && 4319418810dSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4329418810dSmrg test -d "$dstdir" || exit 1 4339418810dSmrg obsolete_mkdir_used=true 4349bd41f2cSmrg fi 4359418810dSmrg fi 4369bd41f2cSmrg fi 4379bd41f2cSmrg 4389bd41f2cSmrg if test -n "$dir_arg"; then 4399418810dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4409418810dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4419418810dSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4429418810dSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4439bd41f2cSmrg else 4449bd41f2cSmrg 4459bd41f2cSmrg # Make a couple of temp file names in the proper directory. 4469bd41f2cSmrg dsttmp=$dstdir/_inst.$$_ 4479bd41f2cSmrg rmtmp=$dstdir/_rm.$$_ 4489bd41f2cSmrg 4499bd41f2cSmrg # Trap to clean up those temp files at exit. 4509bd41f2cSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4519bd41f2cSmrg 4529bd41f2cSmrg # Copy the file name to the temp name. 4539418810dSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4549bd41f2cSmrg 4559bd41f2cSmrg # and set any options; do chmod last to preserve setuid bits. 4569bd41f2cSmrg # 4579bd41f2cSmrg # If any of these fail, we abort the whole thing. If we want to 4589bd41f2cSmrg # ignore errors from any of these, just make sure not to ignore 4599bd41f2cSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4609bd41f2cSmrg # 4619418810dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4629418810dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4639418810dSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4649418810dSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4659418810dSmrg 4669418810dSmrg # If -C, don't bother to copy if it wouldn't change the file. 4679418810dSmrg if $copy_on_change && 4689418810dSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4699418810dSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4709418810dSmrg 4719418810dSmrg eval "$initialize_posix_glob" && 4729418810dSmrg $posix_glob set -f && 4739418810dSmrg set X $old && old=:$2:$4:$5:$6 && 4749418810dSmrg set X $new && new=:$2:$4:$5:$6 && 4759418810dSmrg $posix_glob set +f && 4769418810dSmrg 4779418810dSmrg test "$old" = "$new" && 4789418810dSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4799418810dSmrg then 4809418810dSmrg rm -f "$dsttmp" 4819418810dSmrg else 4829418810dSmrg # Rename the file to the real destination. 4839418810dSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4849418810dSmrg 4859418810dSmrg # The rename failed, perhaps because mv can't rename something else 4869418810dSmrg # to itself, or perhaps because mv is so ancient that it does not 4879418810dSmrg # support -f. 4889418810dSmrg { 4899418810dSmrg # Now remove or move aside any old file at destination location. 4909418810dSmrg # We try this two ways since rm can't unlink itself on some 4919418810dSmrg # systems and the destination file might be busy for other 4929418810dSmrg # reasons. In this case, the final cleanup might fail but the new 4939418810dSmrg # file should still install successfully. 4949418810dSmrg { 4959418810dSmrg test ! -f "$dst" || 4969418810dSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 4979418810dSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4989418810dSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4999418810dSmrg } || 5009418810dSmrg { echo "$0: cannot unlink or rename $dst" >&2 5019418810dSmrg (exit 1); exit 1 5029418810dSmrg } 5039418810dSmrg } && 5049418810dSmrg 5059418810dSmrg # Now rename the file to the real destination. 5069418810dSmrg $doit $mvcmd "$dsttmp" "$dst" 5079418810dSmrg } 5089418810dSmrg fi || exit 1 5099418810dSmrg 5109418810dSmrg trap '' 0 5119418810dSmrg fi 5129bd41f2cSmrgdone 5139bd41f2cSmrg 5149bd41f2cSmrg# Local variables: 5159bd41f2cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5169bd41f2cSmrg# time-stamp-start: "scriptversion=" 5179bd41f2cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5189418810dSmrg# time-stamp-time-zone: "UTC" 5199418810dSmrg# time-stamp-end: "; # UTC" 5209bd41f2cSmrg# End: 521