install-sh revision e35d4d8e
132b578d3Smrg#!/bin/sh 232b578d3Smrg# install - install a program, script, or datafile 332b578d3Smrg 4e35d4d8eSmrgscriptversion=2011-01-19.21; # UTC 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. 512a51b5beSmrgdoit=${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 612a51b5beSmrgchgrpprog=${CHGRPPROG-chgrp} 622a51b5beSmrgchmodprog=${CHMODPROG-chmod} 632a51b5beSmrgchownprog=${CHOWNPROG-chown} 642a51b5beSmrgcmpprog=${CMPPROG-cmp} 652a51b5beSmrgcpprog=${CPPROG-cp} 662a51b5beSmrgmkdirprog=${MKDIRPROG-mkdir} 672a51b5beSmrgmvprog=${MVPROG-mv} 682a51b5beSmrgrmprog=${RMPROG-rm} 692a51b5beSmrgstripprog=${STRIPPROG-strip} 702a51b5beSmrg 712a51b5beSmrgposix_glob='?' 722a51b5beSmrginitialize_posix_glob=' 732a51b5beSmrg test "$posix_glob" != "?" || { 742a51b5beSmrg if (set -f) 2>/dev/null; then 752a51b5beSmrg posix_glob= 762a51b5beSmrg else 772a51b5beSmrg posix_glob=: 782a51b5beSmrg fi 792a51b5beSmrg } 802a51b5beSmrg' 8132b578d3Smrg 8232b578d3Smrgposix_mkdir= 8332b578d3Smrg 8432b578d3Smrg# Desired mode of installed file. 8532b578d3Smrgmode=0755 8632b578d3Smrg 872a51b5beSmrgchgrpcmd= 8832b578d3Smrgchmodcmd=$chmodprog 8932b578d3Smrgchowncmd= 902a51b5beSmrgmvcmd=$mvprog 91d31dbc53Smrgrmcmd="$rmprog -f" 922a51b5beSmrgstripcmd= 932a51b5beSmrg 9432b578d3Smrgsrc= 9532b578d3Smrgdst= 9632b578d3Smrgdir_arg= 972a51b5beSmrgdst_arg= 982a51b5beSmrg 992a51b5beSmrgcopy_on_change=false 10032b578d3Smrgno_target_directory= 10132b578d3Smrg 1022a51b5beSmrgusage="\ 1032a51b5beSmrgUsage: $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: 1132a51b5beSmrg --help display this help and exit. 1142a51b5beSmrg --version display version info and exit. 1152a51b5beSmrg 1162a51b5beSmrg -c (ignored) 1172a51b5beSmrg -C install only if different (preserve the last data modification time) 1182a51b5beSmrg -d create directories instead of installing files. 1192a51b5beSmrg -g GROUP $chgrpprog installed files to GROUP. 1202a51b5beSmrg -m MODE $chmodprog installed files to MODE. 1212a51b5beSmrg -o USER $chownprog installed files to USER. 1222a51b5beSmrg -s $stripprog installed files. 1232a51b5beSmrg -t DIRECTORY install into DIRECTORY. 1242a51b5beSmrg -T report an error if DSTFILE is a directory. 12532b578d3Smrg 12632b578d3SmrgEnvironment variables override the default commands: 1272a51b5beSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1282a51b5beSmrg RMPROG STRIPPROG 12932b578d3Smrg" 13032b578d3Smrg 13132b578d3Smrgwhile test $# -ne 0; do 13232b578d3Smrg case $1 in 1332a51b5beSmrg -c) ;; 1342a51b5beSmrg 1352a51b5beSmrg -C) copy_on_change=true;; 13632b578d3Smrg 1372a51b5beSmrg -d) dir_arg=true;; 13832b578d3Smrg 13932b578d3Smrg -g) chgrpcmd="$chgrpprog $2" 1402a51b5beSmrg 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 1512a51b5beSmrg shift;; 15232b578d3Smrg 15332b578d3Smrg -o) chowncmd="$chownprog $2" 1542a51b5beSmrg shift;; 15532b578d3Smrg 1562a51b5beSmrg -s) stripcmd=$stripprog;; 15732b578d3Smrg 1582a51b5beSmrg -t) dst_arg=$2 159e35d4d8eSmrg # Protect names problematic for `test' and other utilities. 160e35d4d8eSmrg case $dst_arg in 161e35d4d8eSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162e35d4d8eSmrg esac 1632a51b5beSmrg shift;; 16432b578d3Smrg 1652a51b5beSmrg -T) no_target_directory=true;; 16632b578d3Smrg 16732b578d3Smrg --version) echo "$0 $scriptversion"; exit $?;; 16832b578d3Smrg 16932b578d3Smrg --) shift 17032b578d3Smrg break;; 17132b578d3Smrg 17232b578d3Smrg -*) echo "$0: invalid option: $1" >&2 17332b578d3Smrg exit 1;; 17432b578d3Smrg 17532b578d3Smrg *) break;; 17632b578d3Smrg esac 1772a51b5beSmrg shift 17832b578d3Smrgdone 17932b578d3Smrg 1802a51b5beSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 18132b578d3Smrg # When -d is used, all remaining arguments are directories to create. 18232b578d3Smrg # When -t is used, the destination is already specified. 18332b578d3Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18432b578d3Smrg for arg 18532b578d3Smrg do 1862a51b5beSmrg if test -n "$dst_arg"; then 18732b578d3Smrg # $@ is not empty: it contains at least $arg. 1882a51b5beSmrg set fnord "$@" "$dst_arg" 18932b578d3Smrg shift # fnord 19032b578d3Smrg fi 19132b578d3Smrg shift # arg 1922a51b5beSmrg dst_arg=$arg 193e35d4d8eSmrg # Protect names problematic for `test' and other utilities. 194e35d4d8eSmrg case $dst_arg in 195e35d4d8eSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196e35d4d8eSmrg esac 19732b578d3Smrg done 19832b578d3Smrgfi 19932b578d3Smrg 20032b578d3Smrgif test $# -eq 0; then 20132b578d3Smrg if test -z "$dir_arg"; then 20232b578d3Smrg echo "$0: no input file specified." >&2 20332b578d3Smrg exit 1 20432b578d3Smrg fi 20532b578d3Smrg # It's OK to call `install-sh -d' without argument. 20632b578d3Smrg # This can happen when creating conditional directories. 20732b578d3Smrg exit 0 20832b578d3Smrgfi 20932b578d3Smrg 21032b578d3Smrgif test -z "$dir_arg"; then 211e35d4d8eSmrg do_exit='(exit $ret); exit $ret' 212e35d4d8eSmrg trap "ret=129; $do_exit" 1 213e35d4d8eSmrg trap "ret=130; $do_exit" 2 214e35d4d8eSmrg trap "ret=141; $do_exit" 13 215e35d4d8eSmrg trap "ret=143; $do_exit" 15 21632b578d3Smrg 21732b578d3Smrg # Set umask so as not to create temps with too-generous modes. 21832b578d3Smrg # However, 'strip' requires both read and write access to temps. 21932b578d3Smrg case $mode in 22032b578d3Smrg # Optimize common cases. 22132b578d3Smrg *644) cp_umask=133;; 22232b578d3Smrg *755) cp_umask=22;; 22332b578d3Smrg 22432b578d3Smrg *[0-7]) 22532b578d3Smrg if test -z "$stripcmd"; then 22632b578d3Smrg u_plus_rw= 22732b578d3Smrg else 22832b578d3Smrg u_plus_rw='% 200' 22932b578d3Smrg fi 23032b578d3Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23132b578d3Smrg *) 23232b578d3Smrg if test -z "$stripcmd"; then 23332b578d3Smrg u_plus_rw= 23432b578d3Smrg else 23532b578d3Smrg u_plus_rw=,u+rw 23632b578d3Smrg fi 23732b578d3Smrg cp_umask=$mode$u_plus_rw;; 23832b578d3Smrg esac 23932b578d3Smrgfi 24032b578d3Smrg 24132b578d3Smrgfor src 24232b578d3Smrgdo 243e35d4d8eSmrg # Protect names problematic for `test' and other utilities. 24432b578d3Smrg case $src in 245e35d4d8eSmrg -* | [=\(\)!]) src=./$src;; 24632b578d3Smrg esac 24732b578d3Smrg 24832b578d3Smrg if test -n "$dir_arg"; then 24932b578d3Smrg dst=$src 25032b578d3Smrg dstdir=$dst 25132b578d3Smrg test -d "$dstdir" 25232b578d3Smrg dstdir_status=$? 25332b578d3Smrg else 25432b578d3Smrg 25532b578d3Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 25632b578d3Smrg # might cause directories to be created, which would be especially bad 25732b578d3Smrg # if $src (and thus $dsttmp) contains '*'. 25832b578d3Smrg if test ! -f "$src" && test ! -d "$src"; then 25932b578d3Smrg echo "$0: $src does not exist." >&2 26032b578d3Smrg exit 1 26132b578d3Smrg fi 26232b578d3Smrg 2632a51b5beSmrg if test -z "$dst_arg"; then 26432b578d3Smrg echo "$0: no destination specified." >&2 26532b578d3Smrg exit 1 26632b578d3Smrg fi 2672a51b5beSmrg dst=$dst_arg 26832b578d3Smrg 26932b578d3Smrg # If destination is a directory, append the input filename; won't work 27032b578d3Smrg # if double slashes aren't ignored. 27132b578d3Smrg if test -d "$dst"; then 27232b578d3Smrg if test -n "$no_target_directory"; then 2732a51b5beSmrg echo "$0: $dst_arg: Is a directory" >&2 27432b578d3Smrg exit 1 27532b578d3Smrg fi 27632b578d3Smrg dstdir=$dst 27732b578d3Smrg dst=$dstdir/`basename "$src"` 27832b578d3Smrg dstdir_status=0 27932b578d3Smrg else 28032b578d3Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 28132b578d3Smrg dstdir=` 28232b578d3Smrg (dirname "$dst") 2>/dev/null || 28332b578d3Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 28432b578d3Smrg X"$dst" : 'X\(//\)[^/]' \| \ 28532b578d3Smrg X"$dst" : 'X\(//\)$' \| \ 28632b578d3Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28732b578d3Smrg echo X"$dst" | 28832b578d3Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28932b578d3Smrg s//\1/ 29032b578d3Smrg q 29132b578d3Smrg } 29232b578d3Smrg /^X\(\/\/\)[^/].*/{ 29332b578d3Smrg s//\1/ 29432b578d3Smrg q 29532b578d3Smrg } 29632b578d3Smrg /^X\(\/\/\)$/{ 29732b578d3Smrg s//\1/ 29832b578d3Smrg q 29932b578d3Smrg } 30032b578d3Smrg /^X\(\/\).*/{ 30132b578d3Smrg s//\1/ 30232b578d3Smrg q 30332b578d3Smrg } 30432b578d3Smrg s/.*/./; q' 30532b578d3Smrg ` 30632b578d3Smrg 30732b578d3Smrg test -d "$dstdir" 30832b578d3Smrg dstdir_status=$? 30932b578d3Smrg fi 31032b578d3Smrg fi 31132b578d3Smrg 31232b578d3Smrg obsolete_mkdir_used=false 31332b578d3Smrg 31432b578d3Smrg if test $dstdir_status != 0; then 31532b578d3Smrg case $posix_mkdir in 31632b578d3Smrg '') 31732b578d3Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31832b578d3Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31932b578d3Smrg umask=`umask` 32032b578d3Smrg case $stripcmd.$umask in 32132b578d3Smrg # Optimize common cases. 32232b578d3Smrg *[2367][2367]) mkdir_umask=$umask;; 32332b578d3Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 32432b578d3Smrg 32532b578d3Smrg *[0-7]) 32632b578d3Smrg mkdir_umask=`expr $umask + 22 \ 32732b578d3Smrg - $umask % 100 % 40 + $umask % 20 \ 32832b578d3Smrg - $umask % 10 % 4 + $umask % 2 32932b578d3Smrg `;; 33032b578d3Smrg *) mkdir_umask=$umask,go-w;; 33132b578d3Smrg esac 33232b578d3Smrg 33332b578d3Smrg # With -d, create the new directory with the user-specified mode. 33432b578d3Smrg # Otherwise, rely on $mkdir_umask. 33532b578d3Smrg if test -n "$dir_arg"; then 33632b578d3Smrg mkdir_mode=-m$mode 33732b578d3Smrg else 33832b578d3Smrg mkdir_mode= 33932b578d3Smrg fi 34032b578d3Smrg 34132b578d3Smrg posix_mkdir=false 34232b578d3Smrg case $umask in 34332b578d3Smrg *[123567][0-7][0-7]) 34432b578d3Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 34532b578d3Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 34632b578d3Smrg ;; 34732b578d3Smrg *) 34832b578d3Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34932b578d3Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 35032b578d3Smrg 35132b578d3Smrg if (umask $mkdir_umask && 35232b578d3Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 35332b578d3Smrg then 35432b578d3Smrg if test -z "$dir_arg" || { 35532b578d3Smrg # Check for POSIX incompatibilities with -m. 35632b578d3Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35732b578d3Smrg # other-writeable bit of parent directory when it shouldn't. 35832b578d3Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35932b578d3Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 36032b578d3Smrg case $ls_ld_tmpdir in 36132b578d3Smrg d????-?r-*) different_mode=700;; 36232b578d3Smrg d????-?--*) different_mode=755;; 36332b578d3Smrg *) false;; 36432b578d3Smrg esac && 36532b578d3Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 36632b578d3Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36732b578d3Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36832b578d3Smrg } 36932b578d3Smrg } 37032b578d3Smrg then posix_mkdir=: 37132b578d3Smrg fi 37232b578d3Smrg rmdir "$tmpdir/d" "$tmpdir" 37332b578d3Smrg else 37432b578d3Smrg # Remove any dirs left behind by ancient mkdir implementations. 37532b578d3Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 37632b578d3Smrg fi 37732b578d3Smrg trap '' 0;; 37832b578d3Smrg esac;; 37932b578d3Smrg esac 38032b578d3Smrg 38132b578d3Smrg if 38232b578d3Smrg $posix_mkdir && ( 38332b578d3Smrg umask $mkdir_umask && 38432b578d3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38532b578d3Smrg ) 38632b578d3Smrg then : 38732b578d3Smrg else 38832b578d3Smrg 38932b578d3Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 39032b578d3Smrg # or it failed possibly due to a race condition. Create the 39132b578d3Smrg # directory the slow way, step by step, checking for races as we go. 39232b578d3Smrg 39332b578d3Smrg case $dstdir in 3942a51b5beSmrg /*) prefix='/';; 395e35d4d8eSmrg [-=\(\)!]*) prefix='./';; 3962a51b5beSmrg *) prefix='';; 39732b578d3Smrg esac 39832b578d3Smrg 3992a51b5beSmrg eval "$initialize_posix_glob" 40032b578d3Smrg 40132b578d3Smrg oIFS=$IFS 40232b578d3Smrg IFS=/ 4032a51b5beSmrg $posix_glob set -f 40432b578d3Smrg set fnord $dstdir 40532b578d3Smrg shift 4062a51b5beSmrg $posix_glob set +f 40732b578d3Smrg IFS=$oIFS 40832b578d3Smrg 40932b578d3Smrg prefixes= 41032b578d3Smrg 41132b578d3Smrg for d 41232b578d3Smrg do 413e35d4d8eSmrg test X"$d" = X && continue 41432b578d3Smrg 41532b578d3Smrg prefix=$prefix$d 41632b578d3Smrg if test -d "$prefix"; then 41732b578d3Smrg prefixes= 41832b578d3Smrg else 41932b578d3Smrg if $posix_mkdir; then 42032b578d3Smrg (umask=$mkdir_umask && 42132b578d3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42232b578d3Smrg # Don't fail if two instances are running concurrently. 42332b578d3Smrg test -d "$prefix" || exit 1 42432b578d3Smrg else 42532b578d3Smrg case $prefix in 42632b578d3Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42732b578d3Smrg *) qprefix=$prefix;; 42832b578d3Smrg esac 42932b578d3Smrg prefixes="$prefixes '$qprefix'" 43032b578d3Smrg fi 43132b578d3Smrg fi 43232b578d3Smrg prefix=$prefix/ 43332b578d3Smrg done 43432b578d3Smrg 43532b578d3Smrg if test -n "$prefixes"; then 43632b578d3Smrg # Don't fail if two instances are running concurrently. 43732b578d3Smrg (umask $mkdir_umask && 43832b578d3Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43932b578d3Smrg test -d "$dstdir" || exit 1 44032b578d3Smrg obsolete_mkdir_used=true 44132b578d3Smrg fi 44232b578d3Smrg fi 44332b578d3Smrg fi 44432b578d3Smrg 44532b578d3Smrg if test -n "$dir_arg"; then 44632b578d3Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44732b578d3Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44832b578d3Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44932b578d3Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 45032b578d3Smrg else 45132b578d3Smrg 45232b578d3Smrg # Make a couple of temp file names in the proper directory. 45332b578d3Smrg dsttmp=$dstdir/_inst.$$_ 45432b578d3Smrg rmtmp=$dstdir/_rm.$$_ 45532b578d3Smrg 45632b578d3Smrg # Trap to clean up those temp files at exit. 45732b578d3Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45832b578d3Smrg 45932b578d3Smrg # Copy the file name to the temp name. 46032b578d3Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 46132b578d3Smrg 46232b578d3Smrg # and set any options; do chmod last to preserve setuid bits. 46332b578d3Smrg # 46432b578d3Smrg # If any of these fail, we abort the whole thing. If we want to 46532b578d3Smrg # ignore errors from any of these, just make sure not to ignore 46632b578d3Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46732b578d3Smrg # 4682a51b5beSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4692a51b5beSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4702a51b5beSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4712a51b5beSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4722a51b5beSmrg 4732a51b5beSmrg # If -C, don't bother to copy if it wouldn't change the file. 4742a51b5beSmrg if $copy_on_change && 4752a51b5beSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4762a51b5beSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4772a51b5beSmrg 4782a51b5beSmrg eval "$initialize_posix_glob" && 4792a51b5beSmrg $posix_glob set -f && 4802a51b5beSmrg set X $old && old=:$2:$4:$5:$6 && 4812a51b5beSmrg set X $new && new=:$2:$4:$5:$6 && 4822a51b5beSmrg $posix_glob set +f && 4832a51b5beSmrg 4842a51b5beSmrg test "$old" = "$new" && 4852a51b5beSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4862a51b5beSmrg then 4872a51b5beSmrg rm -f "$dsttmp" 4882a51b5beSmrg else 4892a51b5beSmrg # Rename the file to the real destination. 4902a51b5beSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4912a51b5beSmrg 4922a51b5beSmrg # The rename failed, perhaps because mv can't rename something else 4932a51b5beSmrg # to itself, or perhaps because mv is so ancient that it does not 4942a51b5beSmrg # support -f. 4952a51b5beSmrg { 4962a51b5beSmrg # Now remove or move aside any old file at destination location. 4972a51b5beSmrg # We try this two ways since rm can't unlink itself on some 4982a51b5beSmrg # systems and the destination file might be busy for other 4992a51b5beSmrg # reasons. In this case, the final cleanup might fail but the new 5002a51b5beSmrg # file should still install successfully. 5012a51b5beSmrg { 5022a51b5beSmrg test ! -f "$dst" || 5032a51b5beSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 5042a51b5beSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5052a51b5beSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 5062a51b5beSmrg } || 5072a51b5beSmrg { echo "$0: cannot unlink or rename $dst" >&2 5082a51b5beSmrg (exit 1); exit 1 5092a51b5beSmrg } 5102a51b5beSmrg } && 5112a51b5beSmrg 5122a51b5beSmrg # Now rename the file to the real destination. 5132a51b5beSmrg $doit $mvcmd "$dsttmp" "$dst" 5142a51b5beSmrg } 5152a51b5beSmrg fi || exit 1 51632b578d3Smrg 51732b578d3Smrg trap '' 0 51832b578d3Smrg fi 51932b578d3Smrgdone 52032b578d3Smrg 52132b578d3Smrg# Local variables: 52232b578d3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 52332b578d3Smrg# time-stamp-start: "scriptversion=" 52432b578d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5252a51b5beSmrg# time-stamp-time-zone: "UTC" 5262a51b5beSmrg# time-stamp-end: "; # UTC" 52732b578d3Smrg# End: 528