145bc899bSmrg#!/bin/sh 245bc899bSmrg# install - install a program, script, or datafile 345bc899bSmrg 4e8b4ed9fSmrgscriptversion=2020-11-14.01; # UTC 545bc899bSmrg 645bc899bSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 745bc899bSmrg# later released in X11R6 (xc/config/util/install.sh) with the 845bc899bSmrg# following copyright and license. 945bc899bSmrg# 1045bc899bSmrg# Copyright (C) 1994 X Consortium 1145bc899bSmrg# 1245bc899bSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1345bc899bSmrg# of this software and associated documentation files (the "Software"), to 1445bc899bSmrg# deal in the Software without restriction, including without limitation the 1545bc899bSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1645bc899bSmrg# sell copies of the Software, and to permit persons to whom the Software is 1745bc899bSmrg# furnished to do so, subject to the following conditions: 1845bc899bSmrg# 1945bc899bSmrg# The above copyright notice and this permission notice shall be included in 2045bc899bSmrg# all copies or substantial portions of the Software. 2145bc899bSmrg# 2245bc899bSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2345bc899bSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2445bc899bSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2545bc899bSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2645bc899bSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2745bc899bSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2845bc899bSmrg# 2945bc899bSmrg# Except as contained in this notice, the name of the X Consortium shall not 3045bc899bSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 3145bc899bSmrg# ings in this Software without prior written authorization from the X Consor- 3245bc899bSmrg# tium. 3345bc899bSmrg# 3445bc899bSmrg# 3545bc899bSmrg# FSF changes to this file are in the public domain. 3645bc899bSmrg# 3745bc899bSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38c97b1c41Smrg# 'make' implicit rules from creating a file called install from it 3945bc899bSmrg# when there is no Makefile. 4045bc899bSmrg# 4145bc899bSmrg# This script is compatible with the BSD install script, but was written 4250f2e948Smrg# from scratch. 4350f2e948Smrg 4457ba8e8bSmrgtab=' ' 4550f2e948Smrgnl=' 4650f2e948Smrg' 4757ba8e8bSmrgIFS=" $tab$nl" 4845bc899bSmrg 4957ba8e8bSmrg# Set DOITPROG to "echo" to test this script. 5045bc899bSmrg 5150f2e948Smrgdoit=${DOITPROG-} 5257ba8e8bSmrgdoit_exec=${doit:-exec} 5345bc899bSmrg 5450f2e948Smrg# Put in absolute file names if you don't have them in your path; 5550f2e948Smrg# or use environment vars. 5650f2e948Smrg 5750f2e948Smrgchgrpprog=${CHGRPPROG-chgrp} 5850f2e948Smrgchmodprog=${CHMODPROG-chmod} 5950f2e948Smrgchownprog=${CHOWNPROG-chown} 6050f2e948Smrgcmpprog=${CMPPROG-cmp} 6150f2e948Smrgcpprog=${CPPROG-cp} 6250f2e948Smrgmkdirprog=${MKDIRPROG-mkdir} 6350f2e948Smrgmvprog=${MVPROG-mv} 6450f2e948Smrgrmprog=${RMPROG-rm} 6550f2e948Smrgstripprog=${STRIPPROG-strip} 6650f2e948Smrg 6750f2e948Smrgposix_mkdir= 6850f2e948Smrg 6950f2e948Smrg# Desired mode of installed file. 7050f2e948Smrgmode=0755 7145bc899bSmrg 72e8b4ed9fSmrg# Create dirs (including intermediate dirs) using mode 755. 73e8b4ed9fSmrg# This is like GNU 'install' as of coreutils 8.32 (2020). 74e8b4ed9fSmrgmkdir_umask=22 75e8b4ed9fSmrg 76e8b4ed9fSmrgbackupsuffix= 77226fade8Smrgchgrpcmd= 7850f2e948Smrgchmodcmd=$chmodprog 7950f2e948Smrgchowncmd= 8050f2e948Smrgmvcmd=$mvprog 81226fade8Smrgrmcmd="$rmprog -f" 8250f2e948Smrgstripcmd= 8350f2e948Smrg 8445bc899bSmrgsrc= 8545bc899bSmrgdst= 8645bc899bSmrgdir_arg= 8750f2e948Smrgdst_arg= 8850f2e948Smrg 8950f2e948Smrgcopy_on_change=false 9057ba8e8bSmrgis_target_a_directory=possibly 9145bc899bSmrg 9250f2e948Smrgusage="\ 9350f2e948SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 9445bc899bSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 9545bc899bSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 9645bc899bSmrg or: $0 [OPTION]... -d DIRECTORIES... 9745bc899bSmrg 9845bc899bSmrgIn the 1st form, copy SRCFILE to DSTFILE. 9945bc899bSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 10045bc899bSmrgIn the 4th, create DIRECTORIES. 10145bc899bSmrg 10245bc899bSmrgOptions: 10350f2e948Smrg --help display this help and exit. 10450f2e948Smrg --version display version info and exit. 10550f2e948Smrg 10650f2e948Smrg -c (ignored) 107e8b4ed9fSmrg -C install only if different (preserve data modification time) 10850f2e948Smrg -d create directories instead of installing files. 10950f2e948Smrg -g GROUP $chgrpprog installed files to GROUP. 11050f2e948Smrg -m MODE $chmodprog installed files to MODE. 11150f2e948Smrg -o USER $chownprog installed files to USER. 112e8b4ed9fSmrg -p pass -p to $cpprog. 11350f2e948Smrg -s $stripprog installed files. 114e8b4ed9fSmrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 11550f2e948Smrg -t DIRECTORY install into DIRECTORY. 11650f2e948Smrg -T report an error if DSTFILE is a directory. 11745bc899bSmrg 11845bc899bSmrgEnvironment variables override the default commands: 11950f2e948Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12050f2e948Smrg RMPROG STRIPPROG 121e8b4ed9fSmrg 122e8b4ed9fSmrgBy default, rm is invoked with -f; when overridden with RMPROG, 123e8b4ed9fSmrgit's up to you to specify -f if you want it. 124e8b4ed9fSmrg 125e8b4ed9fSmrgIf -S is not specified, no backups are attempted. 126e8b4ed9fSmrg 127e8b4ed9fSmrgEmail bug reports to bug-automake@gnu.org. 128e8b4ed9fSmrgAutomake home page: https://www.gnu.org/software/automake/ 12945bc899bSmrg" 13045bc899bSmrg 13150f2e948Smrgwhile test $# -ne 0; do 13245bc899bSmrg case $1 in 13350f2e948Smrg -c) ;; 13450f2e948Smrg 13550f2e948Smrg -C) copy_on_change=true;; 13645bc899bSmrg 13750f2e948Smrg -d) dir_arg=true;; 13845bc899bSmrg 13945bc899bSmrg -g) chgrpcmd="$chgrpprog $2" 14057ba8e8bSmrg shift;; 14145bc899bSmrg 14245bc899bSmrg --help) echo "$usage"; exit $?;; 14345bc899bSmrg 14450f2e948Smrg -m) mode=$2 14557ba8e8bSmrg case $mode in 14657ba8e8bSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 14757ba8e8bSmrg echo "$0: invalid mode: $mode" >&2 14857ba8e8bSmrg exit 1;; 14957ba8e8bSmrg esac 15057ba8e8bSmrg shift;; 15145bc899bSmrg 15245bc899bSmrg -o) chowncmd="$chownprog $2" 15357ba8e8bSmrg shift;; 15445bc899bSmrg 155e8b4ed9fSmrg -p) cpprog="$cpprog -p";; 156e8b4ed9fSmrg 15750f2e948Smrg -s) stripcmd=$stripprog;; 15845bc899bSmrg 159e8b4ed9fSmrg -S) backupsuffix="$2" 160e8b4ed9fSmrg shift;; 161e8b4ed9fSmrg 16257ba8e8bSmrg -t) 16357ba8e8bSmrg is_target_a_directory=always 16457ba8e8bSmrg dst_arg=$2 16557ba8e8bSmrg # Protect names problematic for 'test' and other utilities. 16657ba8e8bSmrg case $dst_arg in 16757ba8e8bSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16857ba8e8bSmrg esac 16957ba8e8bSmrg shift;; 17045bc899bSmrg 17157ba8e8bSmrg -T) is_target_a_directory=never;; 17245bc899bSmrg 17345bc899bSmrg --version) echo "$0 $scriptversion"; exit $?;; 17445bc899bSmrg 17557ba8e8bSmrg --) shift 17657ba8e8bSmrg break;; 17750f2e948Smrg 17857ba8e8bSmrg -*) echo "$0: invalid option: $1" >&2 17957ba8e8bSmrg exit 1;; 18050f2e948Smrg 18150f2e948Smrg *) break;; 18245bc899bSmrg esac 18350f2e948Smrg shift 18445bc899bSmrgdone 18545bc899bSmrg 18657ba8e8bSmrg# We allow the use of options -d and -T together, by making -d 18757ba8e8bSmrg# take the precedence; this is for compatibility with GNU install. 18857ba8e8bSmrg 18957ba8e8bSmrgif test -n "$dir_arg"; then 19057ba8e8bSmrg if test -n "$dst_arg"; then 19157ba8e8bSmrg echo "$0: target directory not allowed when installing a directory." >&2 19257ba8e8bSmrg exit 1 19357ba8e8bSmrg fi 19457ba8e8bSmrgfi 19557ba8e8bSmrg 19650f2e948Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 19750f2e948Smrg # When -d is used, all remaining arguments are directories to create. 19850f2e948Smrg # When -t is used, the destination is already specified. 19950f2e948Smrg # Otherwise, the last argument is the destination. Remove it from $@. 20050f2e948Smrg for arg 20150f2e948Smrg do 20250f2e948Smrg if test -n "$dst_arg"; then 20350f2e948Smrg # $@ is not empty: it contains at least $arg. 20450f2e948Smrg set fnord "$@" "$dst_arg" 20550f2e948Smrg shift # fnord 20650f2e948Smrg fi 20750f2e948Smrg shift # arg 20850f2e948Smrg dst_arg=$arg 209c97b1c41Smrg # Protect names problematic for 'test' and other utilities. 210b40a6198Smrg case $dst_arg in 211b40a6198Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212b40a6198Smrg esac 21350f2e948Smrg done 21450f2e948Smrgfi 21550f2e948Smrg 21650f2e948Smrgif test $# -eq 0; then 21745bc899bSmrg if test -z "$dir_arg"; then 21845bc899bSmrg echo "$0: no input file specified." >&2 21945bc899bSmrg exit 1 22045bc899bSmrg fi 221c97b1c41Smrg # It's OK to call 'install-sh -d' without argument. 22245bc899bSmrg # This can happen when creating conditional directories. 22345bc899bSmrg exit 0 22445bc899bSmrgfi 22545bc899bSmrg 22657ba8e8bSmrgif test -z "$dir_arg"; then 22757ba8e8bSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 22857ba8e8bSmrg if test ! -d "$dst_arg"; then 22957ba8e8bSmrg echo "$0: $dst_arg: Is not a directory." >&2 23057ba8e8bSmrg exit 1 23157ba8e8bSmrg fi 23257ba8e8bSmrg fi 23357ba8e8bSmrgfi 23457ba8e8bSmrg 23550f2e948Smrgif test -z "$dir_arg"; then 236b40a6198Smrg do_exit='(exit $ret); exit $ret' 237b40a6198Smrg trap "ret=129; $do_exit" 1 238b40a6198Smrg trap "ret=130; $do_exit" 2 239b40a6198Smrg trap "ret=141; $do_exit" 13 240b40a6198Smrg trap "ret=143; $do_exit" 15 24150f2e948Smrg 24250f2e948Smrg # Set umask so as not to create temps with too-generous modes. 24350f2e948Smrg # However, 'strip' requires both read and write access to temps. 24450f2e948Smrg case $mode in 24550f2e948Smrg # Optimize common cases. 24650f2e948Smrg *644) cp_umask=133;; 24750f2e948Smrg *755) cp_umask=22;; 24850f2e948Smrg 24950f2e948Smrg *[0-7]) 25050f2e948Smrg if test -z "$stripcmd"; then 25157ba8e8bSmrg u_plus_rw= 25250f2e948Smrg else 25357ba8e8bSmrg u_plus_rw='% 200' 25450f2e948Smrg fi 25550f2e948Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 25650f2e948Smrg *) 25750f2e948Smrg if test -z "$stripcmd"; then 25857ba8e8bSmrg u_plus_rw= 25950f2e948Smrg else 26057ba8e8bSmrg u_plus_rw=,u+rw 26150f2e948Smrg fi 26250f2e948Smrg cp_umask=$mode$u_plus_rw;; 26350f2e948Smrg esac 26450f2e948Smrgfi 26550f2e948Smrg 26645bc899bSmrgfor src 26745bc899bSmrgdo 268c97b1c41Smrg # Protect names problematic for 'test' and other utilities. 26945bc899bSmrg case $src in 270b40a6198Smrg -* | [=\(\)!]) src=./$src;; 27145bc899bSmrg esac 27245bc899bSmrg 27345bc899bSmrg if test -n "$dir_arg"; then 27445bc899bSmrg dst=$src 27550f2e948Smrg dstdir=$dst 27650f2e948Smrg test -d "$dstdir" 27750f2e948Smrg dstdir_status=$? 278e8b4ed9fSmrg # Don't chown directories that already exist. 279e8b4ed9fSmrg if test $dstdir_status = 0; then 280e8b4ed9fSmrg chowncmd="" 281e8b4ed9fSmrg fi 282226fade8Smrg else 28350f2e948Smrg 28445bc899bSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 28545bc899bSmrg # might cause directories to be created, which would be especially bad 28645bc899bSmrg # if $src (and thus $dsttmp) contains '*'. 28745bc899bSmrg if test ! -f "$src" && test ! -d "$src"; then 28845bc899bSmrg echo "$0: $src does not exist." >&2 28945bc899bSmrg exit 1 29045bc899bSmrg fi 29145bc899bSmrg 29250f2e948Smrg if test -z "$dst_arg"; then 29345bc899bSmrg echo "$0: no destination specified." >&2 29445bc899bSmrg exit 1 29545bc899bSmrg fi 29650f2e948Smrg dst=$dst_arg 29745bc899bSmrg 298a0c41156Smrg # If destination is a directory, append the input filename. 29945bc899bSmrg if test -d "$dst"; then 30057ba8e8bSmrg if test "$is_target_a_directory" = never; then 30157ba8e8bSmrg echo "$0: $dst_arg: Is a directory" >&2 30257ba8e8bSmrg exit 1 30345bc899bSmrg fi 30450f2e948Smrg dstdir=$dst 305a0c41156Smrg dstbase=`basename "$src"` 306a0c41156Smrg case $dst in 307a0c41156Smrg */) dst=$dst$dstbase;; 308a0c41156Smrg *) dst=$dst/$dstbase;; 309a0c41156Smrg esac 31050f2e948Smrg dstdir_status=0 31150f2e948Smrg else 31257ba8e8bSmrg dstdir=`dirname "$dst"` 31350f2e948Smrg test -d "$dstdir" 31450f2e948Smrg dstdir_status=$? 31545bc899bSmrg fi 31645bc899bSmrg fi 31745bc899bSmrg 318a0c41156Smrg case $dstdir in 319a0c41156Smrg */) dstdirslash=$dstdir;; 320a0c41156Smrg *) dstdirslash=$dstdir/;; 321a0c41156Smrg esac 322a0c41156Smrg 32350f2e948Smrg obsolete_mkdir_used=false 32450f2e948Smrg 32550f2e948Smrg if test $dstdir_status != 0; then 32650f2e948Smrg case $posix_mkdir in 32750f2e948Smrg '') 32857ba8e8bSmrg # With -d, create the new directory with the user-specified mode. 32957ba8e8bSmrg # Otherwise, rely on $mkdir_umask. 33057ba8e8bSmrg if test -n "$dir_arg"; then 33157ba8e8bSmrg mkdir_mode=-m$mode 33257ba8e8bSmrg else 33357ba8e8bSmrg mkdir_mode= 33457ba8e8bSmrg fi 33557ba8e8bSmrg 33657ba8e8bSmrg posix_mkdir=false 337e8b4ed9fSmrg # The $RANDOM variable is not portable (e.g., dash). Use it 338e8b4ed9fSmrg # here however when possible just to lower collision chance. 339e8b4ed9fSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 340e8b4ed9fSmrg 341e8b4ed9fSmrg trap ' 342e8b4ed9fSmrg ret=$? 343e8b4ed9fSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 344e8b4ed9fSmrg exit $ret 345e8b4ed9fSmrg ' 0 346e8b4ed9fSmrg 347e8b4ed9fSmrg # Because "mkdir -p" follows existing symlinks and we likely work 348e8b4ed9fSmrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 349e8b4ed9fSmrg # directory is successfully created first before we actually test 350e8b4ed9fSmrg # 'mkdir -p'. 351e8b4ed9fSmrg if (umask $mkdir_umask && 352e8b4ed9fSmrg $mkdirprog $mkdir_mode "$tmpdir" && 353e8b4ed9fSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 354e8b4ed9fSmrg then 355e8b4ed9fSmrg if test -z "$dir_arg" || { 356e8b4ed9fSmrg # Check for POSIX incompatibilities with -m. 357e8b4ed9fSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 358e8b4ed9fSmrg # other-writable bit of parent directory when it shouldn't. 359e8b4ed9fSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 360e8b4ed9fSmrg test_tmpdir="$tmpdir/a" 361e8b4ed9fSmrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 362e8b4ed9fSmrg case $ls_ld_tmpdir in 363e8b4ed9fSmrg d????-?r-*) different_mode=700;; 364e8b4ed9fSmrg d????-?--*) different_mode=755;; 365e8b4ed9fSmrg *) false;; 366e8b4ed9fSmrg esac && 367e8b4ed9fSmrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 368e8b4ed9fSmrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 369e8b4ed9fSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 370e8b4ed9fSmrg } 371e8b4ed9fSmrg } 372e8b4ed9fSmrg then posix_mkdir=: 373e8b4ed9fSmrg fi 374e8b4ed9fSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 375e8b4ed9fSmrg else 376e8b4ed9fSmrg # Remove any dirs left behind by ancient mkdir implementations. 377e8b4ed9fSmrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 378e8b4ed9fSmrg fi 379e8b4ed9fSmrg trap '' 0;; 38050f2e948Smrg esac 38145bc899bSmrg 38250f2e948Smrg if 38350f2e948Smrg $posix_mkdir && ( 38457ba8e8bSmrg umask $mkdir_umask && 38557ba8e8bSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38650f2e948Smrg ) 38750f2e948Smrg then : 38850f2e948Smrg else 38945bc899bSmrg 390e8b4ed9fSmrg # mkdir does not conform to POSIX, 39150f2e948Smrg # or it failed possibly due to a race condition. Create the 39250f2e948Smrg # directory the slow way, step by step, checking for races as we go. 39345bc899bSmrg 39450f2e948Smrg case $dstdir in 39557ba8e8bSmrg /*) prefix='/';; 39657ba8e8bSmrg [-=\(\)!]*) prefix='./';; 39757ba8e8bSmrg *) prefix='';; 39850f2e948Smrg esac 39945bc899bSmrg 40050f2e948Smrg oIFS=$IFS 40150f2e948Smrg IFS=/ 40257ba8e8bSmrg set -f 40350f2e948Smrg set fnord $dstdir 40445bc899bSmrg shift 40557ba8e8bSmrg set +f 40650f2e948Smrg IFS=$oIFS 40750f2e948Smrg 40850f2e948Smrg prefixes= 40950f2e948Smrg 41050f2e948Smrg for d 41150f2e948Smrg do 41257ba8e8bSmrg test X"$d" = X && continue 41357ba8e8bSmrg 41457ba8e8bSmrg prefix=$prefix$d 41557ba8e8bSmrg if test -d "$prefix"; then 41657ba8e8bSmrg prefixes= 41757ba8e8bSmrg else 41857ba8e8bSmrg if $posix_mkdir; then 419e8b4ed9fSmrg (umask $mkdir_umask && 42057ba8e8bSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42157ba8e8bSmrg # Don't fail if two instances are running concurrently. 42257ba8e8bSmrg test -d "$prefix" || exit 1 42357ba8e8bSmrg else 42457ba8e8bSmrg case $prefix in 42557ba8e8bSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42657ba8e8bSmrg *) qprefix=$prefix;; 42757ba8e8bSmrg esac 42857ba8e8bSmrg prefixes="$prefixes '$qprefix'" 42957ba8e8bSmrg fi 43057ba8e8bSmrg fi 43157ba8e8bSmrg prefix=$prefix/ 43250f2e948Smrg done 43350f2e948Smrg 43450f2e948Smrg if test -n "$prefixes"; then 43557ba8e8bSmrg # Don't fail if two instances are running concurrently. 43657ba8e8bSmrg (umask $mkdir_umask && 43757ba8e8bSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 43857ba8e8bSmrg test -d "$dstdir" || exit 1 43957ba8e8bSmrg obsolete_mkdir_used=true 44045bc899bSmrg fi 44150f2e948Smrg fi 44245bc899bSmrg fi 44345bc899bSmrg 44445bc899bSmrg if test -n "$dir_arg"; then 44550f2e948Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44650f2e948Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44750f2e948Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44850f2e948Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44945bc899bSmrg else 45045bc899bSmrg 45145bc899bSmrg # Make a couple of temp file names in the proper directory. 452a0c41156Smrg dsttmp=${dstdirslash}_inst.$$_ 453a0c41156Smrg rmtmp=${dstdirslash}_rm.$$_ 45445bc899bSmrg 45545bc899bSmrg # Trap to clean up those temp files at exit. 45645bc899bSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45745bc899bSmrg 45845bc899bSmrg # Copy the file name to the temp name. 459e8b4ed9fSmrg (umask $cp_umask && 460e8b4ed9fSmrg { test -z "$stripcmd" || { 461e8b4ed9fSmrg # Create $dsttmp read-write so that cp doesn't create it read-only, 462e8b4ed9fSmrg # which would cause strip to fail. 463e8b4ed9fSmrg if test -z "$doit"; then 464e8b4ed9fSmrg : >"$dsttmp" # No need to fork-exec 'touch'. 465e8b4ed9fSmrg else 466e8b4ed9fSmrg $doit touch "$dsttmp" 467e8b4ed9fSmrg fi 468e8b4ed9fSmrg } 469e8b4ed9fSmrg } && 470e8b4ed9fSmrg $doit_exec $cpprog "$src" "$dsttmp") && 47145bc899bSmrg 47245bc899bSmrg # and set any options; do chmod last to preserve setuid bits. 47345bc899bSmrg # 47445bc899bSmrg # If any of these fail, we abort the whole thing. If we want to 47545bc899bSmrg # ignore errors from any of these, just make sure not to ignore 47645bc899bSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 47745bc899bSmrg # 47850f2e948Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 47950f2e948Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 48050f2e948Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 48150f2e948Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 48250f2e948Smrg 48350f2e948Smrg # If -C, don't bother to copy if it wouldn't change the file. 48450f2e948Smrg if $copy_on_change && 48557ba8e8bSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 48657ba8e8bSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 48757ba8e8bSmrg set -f && 48850f2e948Smrg set X $old && old=:$2:$4:$5:$6 && 48950f2e948Smrg set X $new && new=:$2:$4:$5:$6 && 49057ba8e8bSmrg set +f && 49150f2e948Smrg test "$old" = "$new" && 49250f2e948Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 49350f2e948Smrg then 49450f2e948Smrg rm -f "$dsttmp" 49550f2e948Smrg else 496e8b4ed9fSmrg # If $backupsuffix is set, and the file being installed 497e8b4ed9fSmrg # already exists, attempt a backup. Don't worry if it fails, 498e8b4ed9fSmrg # e.g., if mv doesn't support -f. 499e8b4ed9fSmrg if test -n "$backupsuffix" && test -f "$dst"; then 500e8b4ed9fSmrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 501e8b4ed9fSmrg fi 502e8b4ed9fSmrg 50350f2e948Smrg # Rename the file to the real destination. 50450f2e948Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 50550f2e948Smrg 50650f2e948Smrg # The rename failed, perhaps because mv can't rename something else 50750f2e948Smrg # to itself, or perhaps because mv is so ancient that it does not 50850f2e948Smrg # support -f. 50950f2e948Smrg { 51057ba8e8bSmrg # Now remove or move aside any old file at destination location. 51157ba8e8bSmrg # We try this two ways since rm can't unlink itself on some 51257ba8e8bSmrg # systems and the destination file might be busy for other 51357ba8e8bSmrg # reasons. In this case, the final cleanup might fail but the new 51457ba8e8bSmrg # file should still install successfully. 51557ba8e8bSmrg { 51657ba8e8bSmrg test ! -f "$dst" || 517e8b4ed9fSmrg $doit $rmcmd "$dst" 2>/dev/null || 51857ba8e8bSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 519e8b4ed9fSmrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 52057ba8e8bSmrg } || 52157ba8e8bSmrg { echo "$0: cannot unlink or rename $dst" >&2 52257ba8e8bSmrg (exit 1); exit 1 52357ba8e8bSmrg } 52457ba8e8bSmrg } && 52557ba8e8bSmrg 52657ba8e8bSmrg # Now rename the file to the real destination. 52757ba8e8bSmrg $doit $mvcmd "$dsttmp" "$dst" 52850f2e948Smrg } 52950f2e948Smrg fi || exit 1 53050f2e948Smrg 53150f2e948Smrg trap '' 0 53250f2e948Smrg fi 53345bc899bSmrgdone 53445bc899bSmrg 53545bc899bSmrg# Local variables: 536a0c41156Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 53745bc899bSmrg# time-stamp-start: "scriptversion=" 53845bc899bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 539f2408745Smrg# time-stamp-time-zone: "UTC0" 540b40a6198Smrg# time-stamp-end: "; # UTC" 54145bc899bSmrg# End: 542