install-sh revision 32b578d3
132b578d3Smrg#!/bin/sh 232b578d3Smrg# install - install a program, script, or datafile 332b578d3Smrg 432b578d3Smrgscriptversion=2006-12-25.00 532b578d3Smrg 632b578d3Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 732b578d3Smrg# later released in X11R6 (xc/config/util/install.sh) with the 832b578d3Smrg# following copyright and license. 932b578d3Smrg# 1032b578d3Smrg# Copyright (C) 1994 X Consortium 1132b578d3Smrg# 1232b578d3Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1332b578d3Smrg# of this software and associated documentation files (the "Software"), to 1432b578d3Smrg# deal in the Software without restriction, including without limitation the 1532b578d3Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1632b578d3Smrg# sell copies of the Software, and to permit persons to whom the Software is 1732b578d3Smrg# furnished to do so, subject to the following conditions: 1832b578d3Smrg# 1932b578d3Smrg# The above copyright notice and this permission notice shall be included in 2032b578d3Smrg# all copies or substantial portions of the Software. 2132b578d3Smrg# 2232b578d3Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2332b578d3Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2432b578d3Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2532b578d3Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2632b578d3Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2732b578d3Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2832b578d3Smrg# 2932b578d3Smrg# Except as contained in this notice, the name of the X Consortium shall not 3032b578d3Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3132b578d3Smrg# ings in this Software without prior written authorization from the X Consor- 3232b578d3Smrg# tium. 3332b578d3Smrg# 3432b578d3Smrg# 3532b578d3Smrg# FSF changes to this file are in the public domain. 3632b578d3Smrg# 3732b578d3Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3832b578d3Smrg# `make' implicit rules from creating a file called install from it 3932b578d3Smrg# when there is no Makefile. 4032b578d3Smrg# 4132b578d3Smrg# This script is compatible with the BSD install script, but was written 4232b578d3Smrg# from scratch. 4332b578d3Smrg 4432b578d3Smrgnl=' 4532b578d3Smrg' 4632b578d3SmrgIFS=" "" $nl" 4732b578d3Smrg 4832b578d3Smrg# set DOITPROG to echo to test this script 4932b578d3Smrg 5032b578d3Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5132b578d3Smrgdoit=${DOITPROG-} 5232b578d3Smrgif test -z "$doit"; then 5332b578d3Smrg doit_exec=exec 5432b578d3Smrgelse 5532b578d3Smrg doit_exec=$doit 5632b578d3Smrgfi 5732b578d3Smrg 5832b578d3Smrg# Put in absolute file names if you don't have them in your path; 5932b578d3Smrg# or use environment vars. 6032b578d3Smrg 6132b578d3Smrgchgrpprog=${CHGRPPROG-chgrp} 6232b578d3Smrgchmodprog=${CHMODPROG-chmod} 6332b578d3Smrgchownprog=${CHOWNPROG-chown} 6432b578d3Smrgcmpprog=${CMPPROG-cmp} 6532b578d3Smrgcpprog=${CPPROG-cp} 6632b578d3Smrgmkdirprog=${MKDIRPROG-mkdir} 6732b578d3Smrgmvprog=${MVPROG-mv} 6832b578d3Smrgrmprog=${RMPROG-rm} 6932b578d3Smrgstripprog=${STRIPPROG-strip} 7032b578d3Smrg 7132b578d3Smrgposix_glob='?' 7232b578d3Smrginitialize_posix_glob=' 7332b578d3Smrg test "$posix_glob" != "?" || { 7432b578d3Smrg if (set -f) 2>/dev/null; then 7532b578d3Smrg posix_glob= 7632b578d3Smrg else 7732b578d3Smrg posix_glob=: 7832b578d3Smrg fi 7932b578d3Smrg } 8032b578d3Smrg' 8132b578d3Smrg 8232b578d3Smrgposix_mkdir= 8332b578d3Smrg 8432b578d3Smrg# Desired mode of installed file. 8532b578d3Smrgmode=0755 8632b578d3Smrg 8732b578d3Smrgchgrpcmd= 8832b578d3Smrgchmodcmd=$chmodprog 8932b578d3Smrgchowncmd= 9032b578d3Smrgmvcmd=$mvprog 9132b578d3Smrgrmcmd="$rmprog -f" 9232b578d3Smrgstripcmd= 9332b578d3Smrg 9432b578d3Smrgsrc= 9532b578d3Smrgdst= 9632b578d3Smrgdir_arg= 9732b578d3Smrgdst_arg= 9832b578d3Smrg 9932b578d3Smrgcopy_on_change=false 10032b578d3Smrgno_target_directory= 10132b578d3Smrg 10232b578d3Smrgusage="\ 10332b578d3SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10432b578d3Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10532b578d3Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10632b578d3Smrg or: $0 [OPTION]... -d DIRECTORIES... 10732b578d3Smrg 10832b578d3SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10932b578d3SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11032b578d3SmrgIn the 4th, create DIRECTORIES. 11132b578d3Smrg 11232b578d3SmrgOptions: 11332b578d3Smrg --help display this help and exit. 11432b578d3Smrg --version display version info and exit. 11532b578d3Smrg 11632b578d3Smrg -c (ignored) 11732b578d3Smrg -C install only if different (preserve the last data modification time) 11832b578d3Smrg -d create directories instead of installing files. 11932b578d3Smrg -g GROUP $chgrpprog installed files to GROUP. 12032b578d3Smrg -m MODE $chmodprog installed files to MODE. 12132b578d3Smrg -o USER $chownprog installed files to USER. 12232b578d3Smrg -s $stripprog installed files. 12332b578d3Smrg -t DIRECTORY install into DIRECTORY. 12432b578d3Smrg -T report an error if DSTFILE is a directory. 12532b578d3Smrg 12632b578d3SmrgEnvironment variables override the default commands: 12732b578d3Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12832b578d3Smrg RMPROG STRIPPROG 12932b578d3Smrg" 13032b578d3Smrg 13132b578d3Smrgwhile test $# -ne 0; do 13232b578d3Smrg case $1 in 13332b578d3Smrg -c) ;; 13432b578d3Smrg 13532b578d3Smrg -C) copy_on_change=true;; 13632b578d3Smrg 13732b578d3Smrg -d) dir_arg=true;; 13832b578d3Smrg 13932b578d3Smrg -g) chgrpcmd="$chgrpprog $2" 14032b578d3Smrg shift;; 14132b578d3Smrg 14232b578d3Smrg --help) echo "$usage"; exit $?;; 14332b578d3Smrg 14432b578d3Smrg -m) mode=$2 14532b578d3Smrg case $mode in 14632b578d3Smrg *' '* | *' '* | *' 14732b578d3Smrg'* | *'*'* | *'?'* | *'['*) 14832b578d3Smrg echo "$0: invalid mode: $mode" >&2 14932b578d3Smrg exit 1;; 15032b578d3Smrg esac 15132b578d3Smrg shift;; 15232b578d3Smrg 15332b578d3Smrg -o) chowncmd="$chownprog $2" 15432b578d3Smrg shift;; 15532b578d3Smrg 15632b578d3Smrg -s) stripcmd=$stripprog;; 15732b578d3Smrg 15832b578d3Smrg -t) dst_arg=$2 15932b578d3Smrg shift;; 16032b578d3Smrg 16132b578d3Smrg -T) no_target_directory=true;; 16232b578d3Smrg 16332b578d3Smrg --version) echo "$0 $scriptversion"; exit $?;; 16432b578d3Smrg 16532b578d3Smrg --) shift 16632b578d3Smrg break;; 16732b578d3Smrg 16832b578d3Smrg -*) echo "$0: invalid option: $1" >&2 16932b578d3Smrg exit 1;; 17032b578d3Smrg 17132b578d3Smrg *) break;; 17232b578d3Smrg esac 17332b578d3Smrg shift 17432b578d3Smrgdone 17532b578d3Smrg 17632b578d3Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17732b578d3Smrg # When -d is used, all remaining arguments are directories to create. 17832b578d3Smrg # When -t is used, the destination is already specified. 17932b578d3Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18032b578d3Smrg for arg 18132b578d3Smrg do 18232b578d3Smrg if test -n "$dst_arg"; then 18332b578d3Smrg # $@ is not empty: it contains at least $arg. 18432b578d3Smrg set fnord "$@" "$dst_arg" 18532b578d3Smrg shift # fnord 18632b578d3Smrg fi 18732b578d3Smrg shift # arg 18832b578d3Smrg dst_arg=$arg 18932b578d3Smrg done 19032b578d3Smrgfi 19132b578d3Smrg 19232b578d3Smrgif test $# -eq 0; then 19332b578d3Smrg if test -z "$dir_arg"; then 19432b578d3Smrg echo "$0: no input file specified." >&2 19532b578d3Smrg exit 1 19632b578d3Smrg fi 19732b578d3Smrg # It's OK to call `install-sh -d' without argument. 19832b578d3Smrg # This can happen when creating conditional directories. 19932b578d3Smrg exit 0 20032b578d3Smrgfi 20132b578d3Smrg 20232b578d3Smrgif test -z "$dir_arg"; then 20332b578d3Smrg trap '(exit $?); exit' 1 2 13 15 20432b578d3Smrg 20532b578d3Smrg # Set umask so as not to create temps with too-generous modes. 20632b578d3Smrg # However, 'strip' requires both read and write access to temps. 20732b578d3Smrg case $mode in 20832b578d3Smrg # Optimize common cases. 20932b578d3Smrg *644) cp_umask=133;; 21032b578d3Smrg *755) cp_umask=22;; 21132b578d3Smrg 21232b578d3Smrg *[0-7]) 21332b578d3Smrg if test -z "$stripcmd"; then 21432b578d3Smrg u_plus_rw= 21532b578d3Smrg else 21632b578d3Smrg u_plus_rw='% 200' 21732b578d3Smrg fi 21832b578d3Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21932b578d3Smrg *) 22032b578d3Smrg if test -z "$stripcmd"; then 22132b578d3Smrg u_plus_rw= 22232b578d3Smrg else 22332b578d3Smrg u_plus_rw=,u+rw 22432b578d3Smrg fi 22532b578d3Smrg cp_umask=$mode$u_plus_rw;; 22632b578d3Smrg esac 22732b578d3Smrgfi 22832b578d3Smrg 22932b578d3Smrgfor src 23032b578d3Smrgdo 23132b578d3Smrg # Protect names starting with `-'. 23232b578d3Smrg case $src in 23332b578d3Smrg -*) src=./$src;; 23432b578d3Smrg esac 23532b578d3Smrg 23632b578d3Smrg if test -n "$dir_arg"; then 23732b578d3Smrg dst=$src 23832b578d3Smrg dstdir=$dst 23932b578d3Smrg test -d "$dstdir" 24032b578d3Smrg dstdir_status=$? 24132b578d3Smrg else 24232b578d3Smrg 24332b578d3Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24432b578d3Smrg # might cause directories to be created, which would be especially bad 24532b578d3Smrg # if $src (and thus $dsttmp) contains '*'. 24632b578d3Smrg if test ! -f "$src" && test ! -d "$src"; then 24732b578d3Smrg echo "$0: $src does not exist." >&2 24832b578d3Smrg exit 1 24932b578d3Smrg fi 25032b578d3Smrg 25132b578d3Smrg if test -z "$dst_arg"; then 25232b578d3Smrg echo "$0: no destination specified." >&2 25332b578d3Smrg exit 1 25432b578d3Smrg fi 25532b578d3Smrg 25632b578d3Smrg dst=$dst_arg 25732b578d3Smrg # Protect names starting with `-'. 25832b578d3Smrg case $dst in 25932b578d3Smrg -*) dst=./$dst;; 26032b578d3Smrg esac 26132b578d3Smrg 26232b578d3Smrg # If destination is a directory, append the input filename; won't work 26332b578d3Smrg # if double slashes aren't ignored. 26432b578d3Smrg if test -d "$dst"; then 26532b578d3Smrg if test -n "$no_target_directory"; then 26632b578d3Smrg echo "$0: $dst_arg: Is a directory" >&2 26732b578d3Smrg exit 1 26832b578d3Smrg fi 26932b578d3Smrg dstdir=$dst 27032b578d3Smrg dst=$dstdir/`basename "$src"` 27132b578d3Smrg dstdir_status=0 27232b578d3Smrg else 27332b578d3Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 27432b578d3Smrg dstdir=` 27532b578d3Smrg (dirname "$dst") 2>/dev/null || 27632b578d3Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27732b578d3Smrg X"$dst" : 'X\(//\)[^/]' \| \ 27832b578d3Smrg X"$dst" : 'X\(//\)$' \| \ 27932b578d3Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28032b578d3Smrg echo X"$dst" | 28132b578d3Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28232b578d3Smrg s//\1/ 28332b578d3Smrg q 28432b578d3Smrg } 28532b578d3Smrg /^X\(\/\/\)[^/].*/{ 28632b578d3Smrg s//\1/ 28732b578d3Smrg q 28832b578d3Smrg } 28932b578d3Smrg /^X\(\/\/\)$/{ 29032b578d3Smrg s//\1/ 29132b578d3Smrg q 29232b578d3Smrg } 29332b578d3Smrg /^X\(\/\).*/{ 29432b578d3Smrg s//\1/ 29532b578d3Smrg q 29632b578d3Smrg } 29732b578d3Smrg s/.*/./; q' 29832b578d3Smrg ` 29932b578d3Smrg 30032b578d3Smrg test -d "$dstdir" 30132b578d3Smrg dstdir_status=$? 30232b578d3Smrg fi 30332b578d3Smrg fi 30432b578d3Smrg 30532b578d3Smrg obsolete_mkdir_used=false 30632b578d3Smrg 30732b578d3Smrg if test $dstdir_status != 0; then 30832b578d3Smrg case $posix_mkdir in 30932b578d3Smrg '') 31032b578d3Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31132b578d3Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31232b578d3Smrg umask=`umask` 31332b578d3Smrg case $stripcmd.$umask in 31432b578d3Smrg # Optimize common cases. 31532b578d3Smrg *[2367][2367]) mkdir_umask=$umask;; 31632b578d3Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31732b578d3Smrg 31832b578d3Smrg *[0-7]) 31932b578d3Smrg mkdir_umask=`expr $umask + 22 \ 32032b578d3Smrg - $umask % 100 % 40 + $umask % 20 \ 32132b578d3Smrg - $umask % 10 % 4 + $umask % 2 32232b578d3Smrg `;; 32332b578d3Smrg *) mkdir_umask=$umask,go-w;; 32432b578d3Smrg esac 32532b578d3Smrg 32632b578d3Smrg # With -d, create the new directory with the user-specified mode. 32732b578d3Smrg # Otherwise, rely on $mkdir_umask. 32832b578d3Smrg if test -n "$dir_arg"; then 32932b578d3Smrg mkdir_mode=-m$mode 33032b578d3Smrg else 33132b578d3Smrg mkdir_mode= 33232b578d3Smrg fi 33332b578d3Smrg 33432b578d3Smrg posix_mkdir=false 33532b578d3Smrg case $umask in 33632b578d3Smrg *[123567][0-7][0-7]) 33732b578d3Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33832b578d3Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33932b578d3Smrg ;; 34032b578d3Smrg *) 34132b578d3Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34232b578d3Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34332b578d3Smrg 34432b578d3Smrg if (umask $mkdir_umask && 34532b578d3Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34632b578d3Smrg then 34732b578d3Smrg if test -z "$dir_arg" || { 34832b578d3Smrg # Check for POSIX incompatibilities with -m. 34932b578d3Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35032b578d3Smrg # other-writeable bit of parent directory when it shouldn't. 35132b578d3Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35232b578d3Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 35332b578d3Smrg case $ls_ld_tmpdir in 35432b578d3Smrg d????-?r-*) different_mode=700;; 35532b578d3Smrg d????-?--*) different_mode=755;; 35632b578d3Smrg *) false;; 35732b578d3Smrg esac && 35832b578d3Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35932b578d3Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36032b578d3Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36132b578d3Smrg } 36232b578d3Smrg } 36332b578d3Smrg then posix_mkdir=: 36432b578d3Smrg fi 36532b578d3Smrg rmdir "$tmpdir/d" "$tmpdir" 36632b578d3Smrg else 36732b578d3Smrg # Remove any dirs left behind by ancient mkdir implementations. 36832b578d3Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36932b578d3Smrg fi 37032b578d3Smrg trap '' 0;; 37132b578d3Smrg esac;; 37232b578d3Smrg esac 37332b578d3Smrg 37432b578d3Smrg if 37532b578d3Smrg $posix_mkdir && ( 37632b578d3Smrg umask $mkdir_umask && 37732b578d3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37832b578d3Smrg ) 37932b578d3Smrg then : 38032b578d3Smrg else 38132b578d3Smrg 38232b578d3Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38332b578d3Smrg # or it failed possibly due to a race condition. Create the 38432b578d3Smrg # directory the slow way, step by step, checking for races as we go. 38532b578d3Smrg 38632b578d3Smrg case $dstdir in 38732b578d3Smrg /*) prefix='/';; 38832b578d3Smrg -*) prefix='./';; 38932b578d3Smrg *) prefix='';; 39032b578d3Smrg esac 39132b578d3Smrg 39232b578d3Smrg eval "$initialize_posix_glob" 39332b578d3Smrg 39432b578d3Smrg oIFS=$IFS 39532b578d3Smrg IFS=/ 39632b578d3Smrg $posix_glob set -f 39732b578d3Smrg set fnord $dstdir 39832b578d3Smrg shift 39932b578d3Smrg $posix_glob set +f 40032b578d3Smrg IFS=$oIFS 40132b578d3Smrg 40232b578d3Smrg prefixes= 40332b578d3Smrg 40432b578d3Smrg for d 40532b578d3Smrg do 40632b578d3Smrg test -z "$d" && continue 40732b578d3Smrg 40832b578d3Smrg prefix=$prefix$d 40932b578d3Smrg if test -d "$prefix"; then 41032b578d3Smrg prefixes= 41132b578d3Smrg else 41232b578d3Smrg if $posix_mkdir; then 41332b578d3Smrg (umask=$mkdir_umask && 41432b578d3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41532b578d3Smrg # Don't fail if two instances are running concurrently. 41632b578d3Smrg test -d "$prefix" || exit 1 41732b578d3Smrg else 41832b578d3Smrg case $prefix in 41932b578d3Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42032b578d3Smrg *) qprefix=$prefix;; 42132b578d3Smrg esac 42232b578d3Smrg prefixes="$prefixes '$qprefix'" 42332b578d3Smrg fi 42432b578d3Smrg fi 42532b578d3Smrg prefix=$prefix/ 42632b578d3Smrg done 42732b578d3Smrg 42832b578d3Smrg if test -n "$prefixes"; then 42932b578d3Smrg # Don't fail if two instances are running concurrently. 43032b578d3Smrg (umask $mkdir_umask && 43132b578d3Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43232b578d3Smrg test -d "$dstdir" || exit 1 43332b578d3Smrg obsolete_mkdir_used=true 43432b578d3Smrg fi 43532b578d3Smrg fi 43632b578d3Smrg fi 43732b578d3Smrg 43832b578d3Smrg if test -n "$dir_arg"; then 43932b578d3Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44032b578d3Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44132b578d3Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44232b578d3Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44332b578d3Smrg else 44432b578d3Smrg 44532b578d3Smrg # Make a couple of temp file names in the proper directory. 44632b578d3Smrg dsttmp=$dstdir/_inst.$$_ 44732b578d3Smrg rmtmp=$dstdir/_rm.$$_ 44832b578d3Smrg 44932b578d3Smrg # Trap to clean up those temp files at exit. 45032b578d3Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45132b578d3Smrg 45232b578d3Smrg # Copy the file name to the temp name. 45332b578d3Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45432b578d3Smrg 45532b578d3Smrg # and set any options; do chmod last to preserve setuid bits. 45632b578d3Smrg # 45732b578d3Smrg # If any of these fail, we abort the whole thing. If we want to 45832b578d3Smrg # ignore errors from any of these, just make sure not to ignore 45932b578d3Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46032b578d3Smrg # 46132b578d3Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46232b578d3Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46332b578d3Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46432b578d3Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46532b578d3Smrg 46632b578d3Smrg # If -C, don't bother to copy if it wouldn't change the file. 46732b578d3Smrg if $copy_on_change && 46832b578d3Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46932b578d3Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47032b578d3Smrg 47132b578d3Smrg eval "$initialize_posix_glob" && 47232b578d3Smrg $posix_glob set -f && 47332b578d3Smrg set X $old && old=:$2:$4:$5:$6 && 47432b578d3Smrg set X $new && new=:$2:$4:$5:$6 && 47532b578d3Smrg $posix_glob set +f && 47632b578d3Smrg 47732b578d3Smrg test "$old" = "$new" && 47832b578d3Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47932b578d3Smrg then 48032b578d3Smrg rm -f "$dsttmp" 48132b578d3Smrg else 48232b578d3Smrg # Rename the file to the real destination. 48332b578d3Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48432b578d3Smrg 48532b578d3Smrg # The rename failed, perhaps because mv can't rename something else 48632b578d3Smrg # to itself, or perhaps because mv is so ancient that it does not 48732b578d3Smrg # support -f. 48832b578d3Smrg { 48932b578d3Smrg # Now remove or move aside any old file at destination location. 49032b578d3Smrg # We try this two ways since rm can't unlink itself on some 49132b578d3Smrg # systems and the destination file might be busy for other 49232b578d3Smrg # reasons. In this case, the final cleanup might fail but the new 49332b578d3Smrg # file should still install successfully. 49432b578d3Smrg { 49532b578d3Smrg test ! -f "$dst" || 49632b578d3Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 49732b578d3Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49832b578d3Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49932b578d3Smrg } || 50032b578d3Smrg { echo "$0: cannot unlink or rename $dst" >&2 50132b578d3Smrg (exit 1); exit 1 50232b578d3Smrg } 50332b578d3Smrg } && 50432b578d3Smrg 50532b578d3Smrg # Now rename the file to the real destination. 50632b578d3Smrg $doit $mvcmd "$dsttmp" "$dst" 50732b578d3Smrg } 50832b578d3Smrg fi || exit 1 50932b578d3Smrg 51032b578d3Smrg trap '' 0 51132b578d3Smrg fi 51232b578d3Smrgdone 51332b578d3Smrg 51432b578d3Smrg# Local variables: 51532b578d3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 51632b578d3Smrg# time-stamp-start: "scriptversion=" 51732b578d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 51832b578d3Smrg# time-stamp-end: "$" 51932b578d3Smrg# End: 520