install-sh revision 23a0898a
123a0898aSmrg#!/bin/sh 223a0898aSmrg# install - install a program, script, or datafile 323a0898aSmrg 423a0898aSmrgscriptversion=2006-12-25.00 523a0898aSmrg 623a0898aSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 723a0898aSmrg# later released in X11R6 (xc/config/util/install.sh) with the 823a0898aSmrg# following copyright and license. 923a0898aSmrg# 1023a0898aSmrg# Copyright (C) 1994 X Consortium 1123a0898aSmrg# 1223a0898aSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1323a0898aSmrg# of this software and associated documentation files (the "Software"), to 1423a0898aSmrg# deal in the Software without restriction, including without limitation the 1523a0898aSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1623a0898aSmrg# sell copies of the Software, and to permit persons to whom the Software is 1723a0898aSmrg# furnished to do so, subject to the following conditions: 1823a0898aSmrg# 1923a0898aSmrg# The above copyright notice and this permission notice shall be included in 2023a0898aSmrg# all copies or substantial portions of the Software. 2123a0898aSmrg# 2223a0898aSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2323a0898aSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2423a0898aSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2523a0898aSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2623a0898aSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2723a0898aSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2823a0898aSmrg# 2923a0898aSmrg# Except as contained in this notice, the name of the X Consortium shall not 3023a0898aSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 3123a0898aSmrg# ings in this Software without prior written authorization from the X Consor- 3223a0898aSmrg# tium. 3323a0898aSmrg# 3423a0898aSmrg# 3523a0898aSmrg# FSF changes to this file are in the public domain. 3623a0898aSmrg# 3723a0898aSmrg# Calling this script install-sh is preferred over install.sh, to prevent 3823a0898aSmrg# `make' implicit rules from creating a file called install from it 3923a0898aSmrg# when there is no Makefile. 4023a0898aSmrg# 4123a0898aSmrg# This script is compatible with the BSD install script, but was written 4223a0898aSmrg# from scratch. 4323a0898aSmrg 4423a0898aSmrgnl=' 4523a0898aSmrg' 4623a0898aSmrgIFS=" "" $nl" 4723a0898aSmrg 4823a0898aSmrg# set DOITPROG to echo to test this script 4923a0898aSmrg 5023a0898aSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5123a0898aSmrgdoit=${DOITPROG-} 5223a0898aSmrgif test -z "$doit"; then 5323a0898aSmrg doit_exec=exec 5423a0898aSmrgelse 5523a0898aSmrg doit_exec=$doit 5623a0898aSmrgfi 5723a0898aSmrg 5823a0898aSmrg# Put in absolute file names if you don't have them in your path; 5923a0898aSmrg# or use environment vars. 6023a0898aSmrg 6123a0898aSmrgchgrpprog=${CHGRPPROG-chgrp} 6223a0898aSmrgchmodprog=${CHMODPROG-chmod} 6323a0898aSmrgchownprog=${CHOWNPROG-chown} 6423a0898aSmrgcmpprog=${CMPPROG-cmp} 6523a0898aSmrgcpprog=${CPPROG-cp} 6623a0898aSmrgmkdirprog=${MKDIRPROG-mkdir} 6723a0898aSmrgmvprog=${MVPROG-mv} 6823a0898aSmrgrmprog=${RMPROG-rm} 6923a0898aSmrgstripprog=${STRIPPROG-strip} 7023a0898aSmrg 7123a0898aSmrgposix_glob='?' 7223a0898aSmrginitialize_posix_glob=' 7323a0898aSmrg test "$posix_glob" != "?" || { 7423a0898aSmrg if (set -f) 2>/dev/null; then 7523a0898aSmrg posix_glob= 7623a0898aSmrg else 7723a0898aSmrg posix_glob=: 7823a0898aSmrg fi 7923a0898aSmrg } 8023a0898aSmrg' 8123a0898aSmrg 8223a0898aSmrgposix_mkdir= 8323a0898aSmrg 8423a0898aSmrg# Desired mode of installed file. 8523a0898aSmrgmode=0755 8623a0898aSmrg 8723a0898aSmrgchgrpcmd= 8823a0898aSmrgchmodcmd=$chmodprog 8923a0898aSmrgchowncmd= 9023a0898aSmrgmvcmd=$mvprog 9123a0898aSmrgrmcmd="$rmprog -f" 9223a0898aSmrgstripcmd= 9323a0898aSmrg 9423a0898aSmrgsrc= 9523a0898aSmrgdst= 9623a0898aSmrgdir_arg= 9723a0898aSmrgdst_arg= 9823a0898aSmrg 9923a0898aSmrgcopy_on_change=false 10023a0898aSmrgno_target_directory= 10123a0898aSmrg 10223a0898aSmrgusage="\ 10323a0898aSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10423a0898aSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10523a0898aSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10623a0898aSmrg or: $0 [OPTION]... -d DIRECTORIES... 10723a0898aSmrg 10823a0898aSmrgIn the 1st form, copy SRCFILE to DSTFILE. 10923a0898aSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11023a0898aSmrgIn the 4th, create DIRECTORIES. 11123a0898aSmrg 11223a0898aSmrgOptions: 11323a0898aSmrg --help display this help and exit. 11423a0898aSmrg --version display version info and exit. 11523a0898aSmrg 11623a0898aSmrg -c (ignored) 11723a0898aSmrg -C install only if different (preserve the last data modification time) 11823a0898aSmrg -d create directories instead of installing files. 11923a0898aSmrg -g GROUP $chgrpprog installed files to GROUP. 12023a0898aSmrg -m MODE $chmodprog installed files to MODE. 12123a0898aSmrg -o USER $chownprog installed files to USER. 12223a0898aSmrg -s $stripprog installed files. 12323a0898aSmrg -t DIRECTORY install into DIRECTORY. 12423a0898aSmrg -T report an error if DSTFILE is a directory. 12523a0898aSmrg 12623a0898aSmrgEnvironment variables override the default commands: 12723a0898aSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12823a0898aSmrg RMPROG STRIPPROG 12923a0898aSmrg" 13023a0898aSmrg 13123a0898aSmrgwhile test $# -ne 0; do 13223a0898aSmrg case $1 in 13323a0898aSmrg -c) ;; 13423a0898aSmrg 13523a0898aSmrg -C) copy_on_change=true;; 13623a0898aSmrg 13723a0898aSmrg -d) dir_arg=true;; 13823a0898aSmrg 13923a0898aSmrg -g) chgrpcmd="$chgrpprog $2" 14023a0898aSmrg shift;; 14123a0898aSmrg 14223a0898aSmrg --help) echo "$usage"; exit $?;; 14323a0898aSmrg 14423a0898aSmrg -m) mode=$2 14523a0898aSmrg case $mode in 14623a0898aSmrg *' '* | *' '* | *' 14723a0898aSmrg'* | *'*'* | *'?'* | *'['*) 14823a0898aSmrg echo "$0: invalid mode: $mode" >&2 14923a0898aSmrg exit 1;; 15023a0898aSmrg esac 15123a0898aSmrg shift;; 15223a0898aSmrg 15323a0898aSmrg -o) chowncmd="$chownprog $2" 15423a0898aSmrg shift;; 15523a0898aSmrg 15623a0898aSmrg -s) stripcmd=$stripprog;; 15723a0898aSmrg 15823a0898aSmrg -t) dst_arg=$2 15923a0898aSmrg shift;; 16023a0898aSmrg 16123a0898aSmrg -T) no_target_directory=true;; 16223a0898aSmrg 16323a0898aSmrg --version) echo "$0 $scriptversion"; exit $?;; 16423a0898aSmrg 16523a0898aSmrg --) shift 16623a0898aSmrg break;; 16723a0898aSmrg 16823a0898aSmrg -*) echo "$0: invalid option: $1" >&2 16923a0898aSmrg exit 1;; 17023a0898aSmrg 17123a0898aSmrg *) break;; 17223a0898aSmrg esac 17323a0898aSmrg shift 17423a0898aSmrgdone 17523a0898aSmrg 17623a0898aSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17723a0898aSmrg # When -d is used, all remaining arguments are directories to create. 17823a0898aSmrg # When -t is used, the destination is already specified. 17923a0898aSmrg # Otherwise, the last argument is the destination. Remove it from $@. 18023a0898aSmrg for arg 18123a0898aSmrg do 18223a0898aSmrg if test -n "$dst_arg"; then 18323a0898aSmrg # $@ is not empty: it contains at least $arg. 18423a0898aSmrg set fnord "$@" "$dst_arg" 18523a0898aSmrg shift # fnord 18623a0898aSmrg fi 18723a0898aSmrg shift # arg 18823a0898aSmrg dst_arg=$arg 18923a0898aSmrg done 19023a0898aSmrgfi 19123a0898aSmrg 19223a0898aSmrgif test $# -eq 0; then 19323a0898aSmrg if test -z "$dir_arg"; then 19423a0898aSmrg echo "$0: no input file specified." >&2 19523a0898aSmrg exit 1 19623a0898aSmrg fi 19723a0898aSmrg # It's OK to call `install-sh -d' without argument. 19823a0898aSmrg # This can happen when creating conditional directories. 19923a0898aSmrg exit 0 20023a0898aSmrgfi 20123a0898aSmrg 20223a0898aSmrgif test -z "$dir_arg"; then 20323a0898aSmrg trap '(exit $?); exit' 1 2 13 15 20423a0898aSmrg 20523a0898aSmrg # Set umask so as not to create temps with too-generous modes. 20623a0898aSmrg # However, 'strip' requires both read and write access to temps. 20723a0898aSmrg case $mode in 20823a0898aSmrg # Optimize common cases. 20923a0898aSmrg *644) cp_umask=133;; 21023a0898aSmrg *755) cp_umask=22;; 21123a0898aSmrg 21223a0898aSmrg *[0-7]) 21323a0898aSmrg if test -z "$stripcmd"; then 21423a0898aSmrg u_plus_rw= 21523a0898aSmrg else 21623a0898aSmrg u_plus_rw='% 200' 21723a0898aSmrg fi 21823a0898aSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21923a0898aSmrg *) 22023a0898aSmrg if test -z "$stripcmd"; then 22123a0898aSmrg u_plus_rw= 22223a0898aSmrg else 22323a0898aSmrg u_plus_rw=,u+rw 22423a0898aSmrg fi 22523a0898aSmrg cp_umask=$mode$u_plus_rw;; 22623a0898aSmrg esac 22723a0898aSmrgfi 22823a0898aSmrg 22923a0898aSmrgfor src 23023a0898aSmrgdo 23123a0898aSmrg # Protect names starting with `-'. 23223a0898aSmrg case $src in 23323a0898aSmrg -*) src=./$src;; 23423a0898aSmrg esac 23523a0898aSmrg 23623a0898aSmrg if test -n "$dir_arg"; then 23723a0898aSmrg dst=$src 23823a0898aSmrg dstdir=$dst 23923a0898aSmrg test -d "$dstdir" 24023a0898aSmrg dstdir_status=$? 24123a0898aSmrg else 24223a0898aSmrg 24323a0898aSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24423a0898aSmrg # might cause directories to be created, which would be especially bad 24523a0898aSmrg # if $src (and thus $dsttmp) contains '*'. 24623a0898aSmrg if test ! -f "$src" && test ! -d "$src"; then 24723a0898aSmrg echo "$0: $src does not exist." >&2 24823a0898aSmrg exit 1 24923a0898aSmrg fi 25023a0898aSmrg 25123a0898aSmrg if test -z "$dst_arg"; then 25223a0898aSmrg echo "$0: no destination specified." >&2 25323a0898aSmrg exit 1 25423a0898aSmrg fi 25523a0898aSmrg 25623a0898aSmrg dst=$dst_arg 25723a0898aSmrg # Protect names starting with `-'. 25823a0898aSmrg case $dst in 25923a0898aSmrg -*) dst=./$dst;; 26023a0898aSmrg esac 26123a0898aSmrg 26223a0898aSmrg # If destination is a directory, append the input filename; won't work 26323a0898aSmrg # if double slashes aren't ignored. 26423a0898aSmrg if test -d "$dst"; then 26523a0898aSmrg if test -n "$no_target_directory"; then 26623a0898aSmrg echo "$0: $dst_arg: Is a directory" >&2 26723a0898aSmrg exit 1 26823a0898aSmrg fi 26923a0898aSmrg dstdir=$dst 27023a0898aSmrg dst=$dstdir/`basename "$src"` 27123a0898aSmrg dstdir_status=0 27223a0898aSmrg else 27323a0898aSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 27423a0898aSmrg dstdir=` 27523a0898aSmrg (dirname "$dst") 2>/dev/null || 27623a0898aSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27723a0898aSmrg X"$dst" : 'X\(//\)[^/]' \| \ 27823a0898aSmrg X"$dst" : 'X\(//\)$' \| \ 27923a0898aSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28023a0898aSmrg echo X"$dst" | 28123a0898aSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28223a0898aSmrg s//\1/ 28323a0898aSmrg q 28423a0898aSmrg } 28523a0898aSmrg /^X\(\/\/\)[^/].*/{ 28623a0898aSmrg s//\1/ 28723a0898aSmrg q 28823a0898aSmrg } 28923a0898aSmrg /^X\(\/\/\)$/{ 29023a0898aSmrg s//\1/ 29123a0898aSmrg q 29223a0898aSmrg } 29323a0898aSmrg /^X\(\/\).*/{ 29423a0898aSmrg s//\1/ 29523a0898aSmrg q 29623a0898aSmrg } 29723a0898aSmrg s/.*/./; q' 29823a0898aSmrg ` 29923a0898aSmrg 30023a0898aSmrg test -d "$dstdir" 30123a0898aSmrg dstdir_status=$? 30223a0898aSmrg fi 30323a0898aSmrg fi 30423a0898aSmrg 30523a0898aSmrg obsolete_mkdir_used=false 30623a0898aSmrg 30723a0898aSmrg if test $dstdir_status != 0; then 30823a0898aSmrg case $posix_mkdir in 30923a0898aSmrg '') 31023a0898aSmrg # Create intermediate dirs using mode 755 as modified by the umask. 31123a0898aSmrg # This is like FreeBSD 'install' as of 1997-10-28. 31223a0898aSmrg umask=`umask` 31323a0898aSmrg case $stripcmd.$umask in 31423a0898aSmrg # Optimize common cases. 31523a0898aSmrg *[2367][2367]) mkdir_umask=$umask;; 31623a0898aSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31723a0898aSmrg 31823a0898aSmrg *[0-7]) 31923a0898aSmrg mkdir_umask=`expr $umask + 22 \ 32023a0898aSmrg - $umask % 100 % 40 + $umask % 20 \ 32123a0898aSmrg - $umask % 10 % 4 + $umask % 2 32223a0898aSmrg `;; 32323a0898aSmrg *) mkdir_umask=$umask,go-w;; 32423a0898aSmrg esac 32523a0898aSmrg 32623a0898aSmrg # With -d, create the new directory with the user-specified mode. 32723a0898aSmrg # Otherwise, rely on $mkdir_umask. 32823a0898aSmrg if test -n "$dir_arg"; then 32923a0898aSmrg mkdir_mode=-m$mode 33023a0898aSmrg else 33123a0898aSmrg mkdir_mode= 33223a0898aSmrg fi 33323a0898aSmrg 33423a0898aSmrg posix_mkdir=false 33523a0898aSmrg case $umask in 33623a0898aSmrg *[123567][0-7][0-7]) 33723a0898aSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33823a0898aSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33923a0898aSmrg ;; 34023a0898aSmrg *) 34123a0898aSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34223a0898aSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34323a0898aSmrg 34423a0898aSmrg if (umask $mkdir_umask && 34523a0898aSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34623a0898aSmrg then 34723a0898aSmrg if test -z "$dir_arg" || { 34823a0898aSmrg # Check for POSIX incompatibilities with -m. 34923a0898aSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35023a0898aSmrg # other-writeable bit of parent directory when it shouldn't. 35123a0898aSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35223a0898aSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 35323a0898aSmrg case $ls_ld_tmpdir in 35423a0898aSmrg d????-?r-*) different_mode=700;; 35523a0898aSmrg d????-?--*) different_mode=755;; 35623a0898aSmrg *) false;; 35723a0898aSmrg esac && 35823a0898aSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35923a0898aSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36023a0898aSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36123a0898aSmrg } 36223a0898aSmrg } 36323a0898aSmrg then posix_mkdir=: 36423a0898aSmrg fi 36523a0898aSmrg rmdir "$tmpdir/d" "$tmpdir" 36623a0898aSmrg else 36723a0898aSmrg # Remove any dirs left behind by ancient mkdir implementations. 36823a0898aSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36923a0898aSmrg fi 37023a0898aSmrg trap '' 0;; 37123a0898aSmrg esac;; 37223a0898aSmrg esac 37323a0898aSmrg 37423a0898aSmrg if 37523a0898aSmrg $posix_mkdir && ( 37623a0898aSmrg umask $mkdir_umask && 37723a0898aSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37823a0898aSmrg ) 37923a0898aSmrg then : 38023a0898aSmrg else 38123a0898aSmrg 38223a0898aSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38323a0898aSmrg # or it failed possibly due to a race condition. Create the 38423a0898aSmrg # directory the slow way, step by step, checking for races as we go. 38523a0898aSmrg 38623a0898aSmrg case $dstdir in 38723a0898aSmrg /*) prefix='/';; 38823a0898aSmrg -*) prefix='./';; 38923a0898aSmrg *) prefix='';; 39023a0898aSmrg esac 39123a0898aSmrg 39223a0898aSmrg eval "$initialize_posix_glob" 39323a0898aSmrg 39423a0898aSmrg oIFS=$IFS 39523a0898aSmrg IFS=/ 39623a0898aSmrg $posix_glob set -f 39723a0898aSmrg set fnord $dstdir 39823a0898aSmrg shift 39923a0898aSmrg $posix_glob set +f 40023a0898aSmrg IFS=$oIFS 40123a0898aSmrg 40223a0898aSmrg prefixes= 40323a0898aSmrg 40423a0898aSmrg for d 40523a0898aSmrg do 40623a0898aSmrg test -z "$d" && continue 40723a0898aSmrg 40823a0898aSmrg prefix=$prefix$d 40923a0898aSmrg if test -d "$prefix"; then 41023a0898aSmrg prefixes= 41123a0898aSmrg else 41223a0898aSmrg if $posix_mkdir; then 41323a0898aSmrg (umask=$mkdir_umask && 41423a0898aSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41523a0898aSmrg # Don't fail if two instances are running concurrently. 41623a0898aSmrg test -d "$prefix" || exit 1 41723a0898aSmrg else 41823a0898aSmrg case $prefix in 41923a0898aSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42023a0898aSmrg *) qprefix=$prefix;; 42123a0898aSmrg esac 42223a0898aSmrg prefixes="$prefixes '$qprefix'" 42323a0898aSmrg fi 42423a0898aSmrg fi 42523a0898aSmrg prefix=$prefix/ 42623a0898aSmrg done 42723a0898aSmrg 42823a0898aSmrg if test -n "$prefixes"; then 42923a0898aSmrg # Don't fail if two instances are running concurrently. 43023a0898aSmrg (umask $mkdir_umask && 43123a0898aSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 43223a0898aSmrg test -d "$dstdir" || exit 1 43323a0898aSmrg obsolete_mkdir_used=true 43423a0898aSmrg fi 43523a0898aSmrg fi 43623a0898aSmrg fi 43723a0898aSmrg 43823a0898aSmrg if test -n "$dir_arg"; then 43923a0898aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44023a0898aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44123a0898aSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44223a0898aSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44323a0898aSmrg else 44423a0898aSmrg 44523a0898aSmrg # Make a couple of temp file names in the proper directory. 44623a0898aSmrg dsttmp=$dstdir/_inst.$$_ 44723a0898aSmrg rmtmp=$dstdir/_rm.$$_ 44823a0898aSmrg 44923a0898aSmrg # Trap to clean up those temp files at exit. 45023a0898aSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45123a0898aSmrg 45223a0898aSmrg # Copy the file name to the temp name. 45323a0898aSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45423a0898aSmrg 45523a0898aSmrg # and set any options; do chmod last to preserve setuid bits. 45623a0898aSmrg # 45723a0898aSmrg # If any of these fail, we abort the whole thing. If we want to 45823a0898aSmrg # ignore errors from any of these, just make sure not to ignore 45923a0898aSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46023a0898aSmrg # 46123a0898aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46223a0898aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46323a0898aSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46423a0898aSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46523a0898aSmrg 46623a0898aSmrg # If -C, don't bother to copy if it wouldn't change the file. 46723a0898aSmrg if $copy_on_change && 46823a0898aSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46923a0898aSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47023a0898aSmrg 47123a0898aSmrg eval "$initialize_posix_glob" && 47223a0898aSmrg $posix_glob set -f && 47323a0898aSmrg set X $old && old=:$2:$4:$5:$6 && 47423a0898aSmrg set X $new && new=:$2:$4:$5:$6 && 47523a0898aSmrg $posix_glob set +f && 47623a0898aSmrg 47723a0898aSmrg test "$old" = "$new" && 47823a0898aSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47923a0898aSmrg then 48023a0898aSmrg rm -f "$dsttmp" 48123a0898aSmrg else 48223a0898aSmrg # Rename the file to the real destination. 48323a0898aSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48423a0898aSmrg 48523a0898aSmrg # The rename failed, perhaps because mv can't rename something else 48623a0898aSmrg # to itself, or perhaps because mv is so ancient that it does not 48723a0898aSmrg # support -f. 48823a0898aSmrg { 48923a0898aSmrg # Now remove or move aside any old file at destination location. 49023a0898aSmrg # We try this two ways since rm can't unlink itself on some 49123a0898aSmrg # systems and the destination file might be busy for other 49223a0898aSmrg # reasons. In this case, the final cleanup might fail but the new 49323a0898aSmrg # file should still install successfully. 49423a0898aSmrg { 49523a0898aSmrg test ! -f "$dst" || 49623a0898aSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 49723a0898aSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49823a0898aSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49923a0898aSmrg } || 50023a0898aSmrg { echo "$0: cannot unlink or rename $dst" >&2 50123a0898aSmrg (exit 1); exit 1 50223a0898aSmrg } 50323a0898aSmrg } && 50423a0898aSmrg 50523a0898aSmrg # Now rename the file to the real destination. 50623a0898aSmrg $doit $mvcmd "$dsttmp" "$dst" 50723a0898aSmrg } 50823a0898aSmrg fi || exit 1 50923a0898aSmrg 51023a0898aSmrg trap '' 0 51123a0898aSmrg fi 51223a0898aSmrgdone 51323a0898aSmrg 51423a0898aSmrg# Local variables: 51523a0898aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 51623a0898aSmrg# time-stamp-start: "scriptversion=" 51723a0898aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 51823a0898aSmrg# time-stamp-end: "$" 51923a0898aSmrg# End: 520