install-sh revision 43f32c10
143f32c10Smrg#!/bin/sh 243f32c10Smrg# install - install a program, script, or datafile 343f32c10Smrg 443f32c10Smrgscriptversion=2006-12-25.00 543f32c10Smrg 643f32c10Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 743f32c10Smrg# later released in X11R6 (xc/config/util/install.sh) with the 843f32c10Smrg# following copyright and license. 943f32c10Smrg# 1043f32c10Smrg# Copyright (C) 1994 X Consortium 1143f32c10Smrg# 1243f32c10Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1343f32c10Smrg# of this software and associated documentation files (the "Software"), to 1443f32c10Smrg# deal in the Software without restriction, including without limitation the 1543f32c10Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1643f32c10Smrg# sell copies of the Software, and to permit persons to whom the Software is 1743f32c10Smrg# furnished to do so, subject to the following conditions: 1843f32c10Smrg# 1943f32c10Smrg# The above copyright notice and this permission notice shall be included in 2043f32c10Smrg# all copies or substantial portions of the Software. 2143f32c10Smrg# 2243f32c10Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2343f32c10Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2443f32c10Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2543f32c10Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2643f32c10Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2743f32c10Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2843f32c10Smrg# 2943f32c10Smrg# Except as contained in this notice, the name of the X Consortium shall not 3043f32c10Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3143f32c10Smrg# ings in this Software without prior written authorization from the X Consor- 3243f32c10Smrg# tium. 3343f32c10Smrg# 3443f32c10Smrg# 3543f32c10Smrg# FSF changes to this file are in the public domain. 3643f32c10Smrg# 3743f32c10Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3843f32c10Smrg# `make' implicit rules from creating a file called install from it 3943f32c10Smrg# when there is no Makefile. 4043f32c10Smrg# 4143f32c10Smrg# This script is compatible with the BSD install script, but was written 4243f32c10Smrg# from scratch. 4343f32c10Smrg 4443f32c10Smrgnl=' 4543f32c10Smrg' 4643f32c10SmrgIFS=" "" $nl" 4743f32c10Smrg 4843f32c10Smrg# set DOITPROG to echo to test this script 4943f32c10Smrg 5043f32c10Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5143f32c10Smrgdoit=${DOITPROG-} 5243f32c10Smrgif test -z "$doit"; then 5343f32c10Smrg doit_exec=exec 5443f32c10Smrgelse 5543f32c10Smrg doit_exec=$doit 5643f32c10Smrgfi 5743f32c10Smrg 5843f32c10Smrg# Put in absolute file names if you don't have them in your path; 5943f32c10Smrg# or use environment vars. 6043f32c10Smrg 6143f32c10Smrgchgrpprog=${CHGRPPROG-chgrp} 6243f32c10Smrgchmodprog=${CHMODPROG-chmod} 6343f32c10Smrgchownprog=${CHOWNPROG-chown} 6443f32c10Smrgcmpprog=${CMPPROG-cmp} 6543f32c10Smrgcpprog=${CPPROG-cp} 6643f32c10Smrgmkdirprog=${MKDIRPROG-mkdir} 6743f32c10Smrgmvprog=${MVPROG-mv} 6843f32c10Smrgrmprog=${RMPROG-rm} 6943f32c10Smrgstripprog=${STRIPPROG-strip} 7043f32c10Smrg 7143f32c10Smrgposix_glob='?' 7243f32c10Smrginitialize_posix_glob=' 7343f32c10Smrg test "$posix_glob" != "?" || { 7443f32c10Smrg if (set -f) 2>/dev/null; then 7543f32c10Smrg posix_glob= 7643f32c10Smrg else 7743f32c10Smrg posix_glob=: 7843f32c10Smrg fi 7943f32c10Smrg } 8043f32c10Smrg' 8143f32c10Smrg 8243f32c10Smrgposix_mkdir= 8343f32c10Smrg 8443f32c10Smrg# Desired mode of installed file. 8543f32c10Smrgmode=0755 8643f32c10Smrg 8743f32c10Smrgchgrpcmd= 8843f32c10Smrgchmodcmd=$chmodprog 8943f32c10Smrgchowncmd= 9043f32c10Smrgmvcmd=$mvprog 9143f32c10Smrgrmcmd="$rmprog -f" 9243f32c10Smrgstripcmd= 9343f32c10Smrg 9443f32c10Smrgsrc= 9543f32c10Smrgdst= 9643f32c10Smrgdir_arg= 9743f32c10Smrgdst_arg= 9843f32c10Smrg 9943f32c10Smrgcopy_on_change=false 10043f32c10Smrgno_target_directory= 10143f32c10Smrg 10243f32c10Smrgusage="\ 10343f32c10SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10443f32c10Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10543f32c10Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10643f32c10Smrg or: $0 [OPTION]... -d DIRECTORIES... 10743f32c10Smrg 10843f32c10SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10943f32c10SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11043f32c10SmrgIn the 4th, create DIRECTORIES. 11143f32c10Smrg 11243f32c10SmrgOptions: 11343f32c10Smrg --help display this help and exit. 11443f32c10Smrg --version display version info and exit. 11543f32c10Smrg 11643f32c10Smrg -c (ignored) 11743f32c10Smrg -C install only if different (preserve the last data modification time) 11843f32c10Smrg -d create directories instead of installing files. 11943f32c10Smrg -g GROUP $chgrpprog installed files to GROUP. 12043f32c10Smrg -m MODE $chmodprog installed files to MODE. 12143f32c10Smrg -o USER $chownprog installed files to USER. 12243f32c10Smrg -s $stripprog installed files. 12343f32c10Smrg -t DIRECTORY install into DIRECTORY. 12443f32c10Smrg -T report an error if DSTFILE is a directory. 12543f32c10Smrg 12643f32c10SmrgEnvironment variables override the default commands: 12743f32c10Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12843f32c10Smrg RMPROG STRIPPROG 12943f32c10Smrg" 13043f32c10Smrg 13143f32c10Smrgwhile test $# -ne 0; do 13243f32c10Smrg case $1 in 13343f32c10Smrg -c) ;; 13443f32c10Smrg 13543f32c10Smrg -C) copy_on_change=true;; 13643f32c10Smrg 13743f32c10Smrg -d) dir_arg=true;; 13843f32c10Smrg 13943f32c10Smrg -g) chgrpcmd="$chgrpprog $2" 14043f32c10Smrg shift;; 14143f32c10Smrg 14243f32c10Smrg --help) echo "$usage"; exit $?;; 14343f32c10Smrg 14443f32c10Smrg -m) mode=$2 14543f32c10Smrg case $mode in 14643f32c10Smrg *' '* | *' '* | *' 14743f32c10Smrg'* | *'*'* | *'?'* | *'['*) 14843f32c10Smrg echo "$0: invalid mode: $mode" >&2 14943f32c10Smrg exit 1;; 15043f32c10Smrg esac 15143f32c10Smrg shift;; 15243f32c10Smrg 15343f32c10Smrg -o) chowncmd="$chownprog $2" 15443f32c10Smrg shift;; 15543f32c10Smrg 15643f32c10Smrg -s) stripcmd=$stripprog;; 15743f32c10Smrg 15843f32c10Smrg -t) dst_arg=$2 15943f32c10Smrg shift;; 16043f32c10Smrg 16143f32c10Smrg -T) no_target_directory=true;; 16243f32c10Smrg 16343f32c10Smrg --version) echo "$0 $scriptversion"; exit $?;; 16443f32c10Smrg 16543f32c10Smrg --) shift 16643f32c10Smrg break;; 16743f32c10Smrg 16843f32c10Smrg -*) echo "$0: invalid option: $1" >&2 16943f32c10Smrg exit 1;; 17043f32c10Smrg 17143f32c10Smrg *) break;; 17243f32c10Smrg esac 17343f32c10Smrg shift 17443f32c10Smrgdone 17543f32c10Smrg 17643f32c10Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 17743f32c10Smrg # When -d is used, all remaining arguments are directories to create. 17843f32c10Smrg # When -t is used, the destination is already specified. 17943f32c10Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18043f32c10Smrg for arg 18143f32c10Smrg do 18243f32c10Smrg if test -n "$dst_arg"; then 18343f32c10Smrg # $@ is not empty: it contains at least $arg. 18443f32c10Smrg set fnord "$@" "$dst_arg" 18543f32c10Smrg shift # fnord 18643f32c10Smrg fi 18743f32c10Smrg shift # arg 18843f32c10Smrg dst_arg=$arg 18943f32c10Smrg done 19043f32c10Smrgfi 19143f32c10Smrg 19243f32c10Smrgif test $# -eq 0; then 19343f32c10Smrg if test -z "$dir_arg"; then 19443f32c10Smrg echo "$0: no input file specified." >&2 19543f32c10Smrg exit 1 19643f32c10Smrg fi 19743f32c10Smrg # It's OK to call `install-sh -d' without argument. 19843f32c10Smrg # This can happen when creating conditional directories. 19943f32c10Smrg exit 0 20043f32c10Smrgfi 20143f32c10Smrg 20243f32c10Smrgif test -z "$dir_arg"; then 20343f32c10Smrg trap '(exit $?); exit' 1 2 13 15 20443f32c10Smrg 20543f32c10Smrg # Set umask so as not to create temps with too-generous modes. 20643f32c10Smrg # However, 'strip' requires both read and write access to temps. 20743f32c10Smrg case $mode in 20843f32c10Smrg # Optimize common cases. 20943f32c10Smrg *644) cp_umask=133;; 21043f32c10Smrg *755) cp_umask=22;; 21143f32c10Smrg 21243f32c10Smrg *[0-7]) 21343f32c10Smrg if test -z "$stripcmd"; then 21443f32c10Smrg u_plus_rw= 21543f32c10Smrg else 21643f32c10Smrg u_plus_rw='% 200' 21743f32c10Smrg fi 21843f32c10Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21943f32c10Smrg *) 22043f32c10Smrg if test -z "$stripcmd"; then 22143f32c10Smrg u_plus_rw= 22243f32c10Smrg else 22343f32c10Smrg u_plus_rw=,u+rw 22443f32c10Smrg fi 22543f32c10Smrg cp_umask=$mode$u_plus_rw;; 22643f32c10Smrg esac 22743f32c10Smrgfi 22843f32c10Smrg 22943f32c10Smrgfor src 23043f32c10Smrgdo 23143f32c10Smrg # Protect names starting with `-'. 23243f32c10Smrg case $src in 23343f32c10Smrg -*) src=./$src;; 23443f32c10Smrg esac 23543f32c10Smrg 23643f32c10Smrg if test -n "$dir_arg"; then 23743f32c10Smrg dst=$src 23843f32c10Smrg dstdir=$dst 23943f32c10Smrg test -d "$dstdir" 24043f32c10Smrg dstdir_status=$? 24143f32c10Smrg else 24243f32c10Smrg 24343f32c10Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24443f32c10Smrg # might cause directories to be created, which would be especially bad 24543f32c10Smrg # if $src (and thus $dsttmp) contains '*'. 24643f32c10Smrg if test ! -f "$src" && test ! -d "$src"; then 24743f32c10Smrg echo "$0: $src does not exist." >&2 24843f32c10Smrg exit 1 24943f32c10Smrg fi 25043f32c10Smrg 25143f32c10Smrg if test -z "$dst_arg"; then 25243f32c10Smrg echo "$0: no destination specified." >&2 25343f32c10Smrg exit 1 25443f32c10Smrg fi 25543f32c10Smrg 25643f32c10Smrg dst=$dst_arg 25743f32c10Smrg # Protect names starting with `-'. 25843f32c10Smrg case $dst in 25943f32c10Smrg -*) dst=./$dst;; 26043f32c10Smrg esac 26143f32c10Smrg 26243f32c10Smrg # If destination is a directory, append the input filename; won't work 26343f32c10Smrg # if double slashes aren't ignored. 26443f32c10Smrg if test -d "$dst"; then 26543f32c10Smrg if test -n "$no_target_directory"; then 26643f32c10Smrg echo "$0: $dst_arg: Is a directory" >&2 26743f32c10Smrg exit 1 26843f32c10Smrg fi 26943f32c10Smrg dstdir=$dst 27043f32c10Smrg dst=$dstdir/`basename "$src"` 27143f32c10Smrg dstdir_status=0 27243f32c10Smrg else 27343f32c10Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 27443f32c10Smrg dstdir=` 27543f32c10Smrg (dirname "$dst") 2>/dev/null || 27643f32c10Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27743f32c10Smrg X"$dst" : 'X\(//\)[^/]' \| \ 27843f32c10Smrg X"$dst" : 'X\(//\)$' \| \ 27943f32c10Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28043f32c10Smrg echo X"$dst" | 28143f32c10Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28243f32c10Smrg s//\1/ 28343f32c10Smrg q 28443f32c10Smrg } 28543f32c10Smrg /^X\(\/\/\)[^/].*/{ 28643f32c10Smrg s//\1/ 28743f32c10Smrg q 28843f32c10Smrg } 28943f32c10Smrg /^X\(\/\/\)$/{ 29043f32c10Smrg s//\1/ 29143f32c10Smrg q 29243f32c10Smrg } 29343f32c10Smrg /^X\(\/\).*/{ 29443f32c10Smrg s//\1/ 29543f32c10Smrg q 29643f32c10Smrg } 29743f32c10Smrg s/.*/./; q' 29843f32c10Smrg ` 29943f32c10Smrg 30043f32c10Smrg test -d "$dstdir" 30143f32c10Smrg dstdir_status=$? 30243f32c10Smrg fi 30343f32c10Smrg fi 30443f32c10Smrg 30543f32c10Smrg obsolete_mkdir_used=false 30643f32c10Smrg 30743f32c10Smrg if test $dstdir_status != 0; then 30843f32c10Smrg case $posix_mkdir in 30943f32c10Smrg '') 31043f32c10Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31143f32c10Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31243f32c10Smrg umask=`umask` 31343f32c10Smrg case $stripcmd.$umask in 31443f32c10Smrg # Optimize common cases. 31543f32c10Smrg *[2367][2367]) mkdir_umask=$umask;; 31643f32c10Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31743f32c10Smrg 31843f32c10Smrg *[0-7]) 31943f32c10Smrg mkdir_umask=`expr $umask + 22 \ 32043f32c10Smrg - $umask % 100 % 40 + $umask % 20 \ 32143f32c10Smrg - $umask % 10 % 4 + $umask % 2 32243f32c10Smrg `;; 32343f32c10Smrg *) mkdir_umask=$umask,go-w;; 32443f32c10Smrg esac 32543f32c10Smrg 32643f32c10Smrg # With -d, create the new directory with the user-specified mode. 32743f32c10Smrg # Otherwise, rely on $mkdir_umask. 32843f32c10Smrg if test -n "$dir_arg"; then 32943f32c10Smrg mkdir_mode=-m$mode 33043f32c10Smrg else 33143f32c10Smrg mkdir_mode= 33243f32c10Smrg fi 33343f32c10Smrg 33443f32c10Smrg posix_mkdir=false 33543f32c10Smrg case $umask in 33643f32c10Smrg *[123567][0-7][0-7]) 33743f32c10Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 33843f32c10Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33943f32c10Smrg ;; 34043f32c10Smrg *) 34143f32c10Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34243f32c10Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 34343f32c10Smrg 34443f32c10Smrg if (umask $mkdir_umask && 34543f32c10Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34643f32c10Smrg then 34743f32c10Smrg if test -z "$dir_arg" || { 34843f32c10Smrg # Check for POSIX incompatibilities with -m. 34943f32c10Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35043f32c10Smrg # other-writeable bit of parent directory when it shouldn't. 35143f32c10Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35243f32c10Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 35343f32c10Smrg case $ls_ld_tmpdir in 35443f32c10Smrg d????-?r-*) different_mode=700;; 35543f32c10Smrg d????-?--*) different_mode=755;; 35643f32c10Smrg *) false;; 35743f32c10Smrg esac && 35843f32c10Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35943f32c10Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36043f32c10Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36143f32c10Smrg } 36243f32c10Smrg } 36343f32c10Smrg then posix_mkdir=: 36443f32c10Smrg fi 36543f32c10Smrg rmdir "$tmpdir/d" "$tmpdir" 36643f32c10Smrg else 36743f32c10Smrg # Remove any dirs left behind by ancient mkdir implementations. 36843f32c10Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36943f32c10Smrg fi 37043f32c10Smrg trap '' 0;; 37143f32c10Smrg esac;; 37243f32c10Smrg esac 37343f32c10Smrg 37443f32c10Smrg if 37543f32c10Smrg $posix_mkdir && ( 37643f32c10Smrg umask $mkdir_umask && 37743f32c10Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37843f32c10Smrg ) 37943f32c10Smrg then : 38043f32c10Smrg else 38143f32c10Smrg 38243f32c10Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 38343f32c10Smrg # or it failed possibly due to a race condition. Create the 38443f32c10Smrg # directory the slow way, step by step, checking for races as we go. 38543f32c10Smrg 38643f32c10Smrg case $dstdir in 38743f32c10Smrg /*) prefix='/';; 38843f32c10Smrg -*) prefix='./';; 38943f32c10Smrg *) prefix='';; 39043f32c10Smrg esac 39143f32c10Smrg 39243f32c10Smrg eval "$initialize_posix_glob" 39343f32c10Smrg 39443f32c10Smrg oIFS=$IFS 39543f32c10Smrg IFS=/ 39643f32c10Smrg $posix_glob set -f 39743f32c10Smrg set fnord $dstdir 39843f32c10Smrg shift 39943f32c10Smrg $posix_glob set +f 40043f32c10Smrg IFS=$oIFS 40143f32c10Smrg 40243f32c10Smrg prefixes= 40343f32c10Smrg 40443f32c10Smrg for d 40543f32c10Smrg do 40643f32c10Smrg test -z "$d" && continue 40743f32c10Smrg 40843f32c10Smrg prefix=$prefix$d 40943f32c10Smrg if test -d "$prefix"; then 41043f32c10Smrg prefixes= 41143f32c10Smrg else 41243f32c10Smrg if $posix_mkdir; then 41343f32c10Smrg (umask=$mkdir_umask && 41443f32c10Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41543f32c10Smrg # Don't fail if two instances are running concurrently. 41643f32c10Smrg test -d "$prefix" || exit 1 41743f32c10Smrg else 41843f32c10Smrg case $prefix in 41943f32c10Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42043f32c10Smrg *) qprefix=$prefix;; 42143f32c10Smrg esac 42243f32c10Smrg prefixes="$prefixes '$qprefix'" 42343f32c10Smrg fi 42443f32c10Smrg fi 42543f32c10Smrg prefix=$prefix/ 42643f32c10Smrg done 42743f32c10Smrg 42843f32c10Smrg if test -n "$prefixes"; then 42943f32c10Smrg # Don't fail if two instances are running concurrently. 43043f32c10Smrg (umask $mkdir_umask && 43143f32c10Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43243f32c10Smrg test -d "$dstdir" || exit 1 43343f32c10Smrg obsolete_mkdir_used=true 43443f32c10Smrg fi 43543f32c10Smrg fi 43643f32c10Smrg fi 43743f32c10Smrg 43843f32c10Smrg if test -n "$dir_arg"; then 43943f32c10Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44043f32c10Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44143f32c10Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44243f32c10Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44343f32c10Smrg else 44443f32c10Smrg 44543f32c10Smrg # Make a couple of temp file names in the proper directory. 44643f32c10Smrg dsttmp=$dstdir/_inst.$$_ 44743f32c10Smrg rmtmp=$dstdir/_rm.$$_ 44843f32c10Smrg 44943f32c10Smrg # Trap to clean up those temp files at exit. 45043f32c10Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45143f32c10Smrg 45243f32c10Smrg # Copy the file name to the temp name. 45343f32c10Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45443f32c10Smrg 45543f32c10Smrg # and set any options; do chmod last to preserve setuid bits. 45643f32c10Smrg # 45743f32c10Smrg # If any of these fail, we abort the whole thing. If we want to 45843f32c10Smrg # ignore errors from any of these, just make sure not to ignore 45943f32c10Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46043f32c10Smrg # 46143f32c10Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46243f32c10Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 46343f32c10Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 46443f32c10Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46543f32c10Smrg 46643f32c10Smrg # If -C, don't bother to copy if it wouldn't change the file. 46743f32c10Smrg if $copy_on_change && 46843f32c10Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 46943f32c10Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47043f32c10Smrg 47143f32c10Smrg eval "$initialize_posix_glob" && 47243f32c10Smrg $posix_glob set -f && 47343f32c10Smrg set X $old && old=:$2:$4:$5:$6 && 47443f32c10Smrg set X $new && new=:$2:$4:$5:$6 && 47543f32c10Smrg $posix_glob set +f && 47643f32c10Smrg 47743f32c10Smrg test "$old" = "$new" && 47843f32c10Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 47943f32c10Smrg then 48043f32c10Smrg rm -f "$dsttmp" 48143f32c10Smrg else 48243f32c10Smrg # Rename the file to the real destination. 48343f32c10Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 48443f32c10Smrg 48543f32c10Smrg # The rename failed, perhaps because mv can't rename something else 48643f32c10Smrg # to itself, or perhaps because mv is so ancient that it does not 48743f32c10Smrg # support -f. 48843f32c10Smrg { 48943f32c10Smrg # Now remove or move aside any old file at destination location. 49043f32c10Smrg # We try this two ways since rm can't unlink itself on some 49143f32c10Smrg # systems and the destination file might be busy for other 49243f32c10Smrg # reasons. In this case, the final cleanup might fail but the new 49343f32c10Smrg # file should still install successfully. 49443f32c10Smrg { 49543f32c10Smrg test ! -f "$dst" || 49643f32c10Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 49743f32c10Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 49843f32c10Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 49943f32c10Smrg } || 50043f32c10Smrg { echo "$0: cannot unlink or rename $dst" >&2 50143f32c10Smrg (exit 1); exit 1 50243f32c10Smrg } 50343f32c10Smrg } && 50443f32c10Smrg 50543f32c10Smrg # Now rename the file to the real destination. 50643f32c10Smrg $doit $mvcmd "$dsttmp" "$dst" 50743f32c10Smrg } 50843f32c10Smrg fi || exit 1 50943f32c10Smrg 51043f32c10Smrg trap '' 0 51143f32c10Smrg fi 51243f32c10Smrgdone 51343f32c10Smrg 51443f32c10Smrg# Local variables: 51543f32c10Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 51643f32c10Smrg# time-stamp-start: "scriptversion=" 51743f32c10Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 51843f32c10Smrg# time-stamp-end: "$" 51943f32c10Smrg# End: 520