install-sh revision 25ad54ca
1e4da13eeSmacallan#!/bin/sh 2e4da13eeSmacallan# install - install a program, script, or datafile 3e4da13eeSmacallan 425ad54caSmrgscriptversion=2020-11-14.01; # UTC 5e4da13eeSmacallan 6e4da13eeSmacallan# This originates from X11R5 (mit/util/scripts/install.sh), which was 7e4da13eeSmacallan# later released in X11R6 (xc/config/util/install.sh) with the 8e4da13eeSmacallan# following copyright and license. 9e4da13eeSmacallan# 10e4da13eeSmacallan# Copyright (C) 1994 X Consortium 11e4da13eeSmacallan# 12e4da13eeSmacallan# Permission is hereby granted, free of charge, to any person obtaining a copy 13e4da13eeSmacallan# of this software and associated documentation files (the "Software"), to 14e4da13eeSmacallan# deal in the Software without restriction, including without limitation the 15e4da13eeSmacallan# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16e4da13eeSmacallan# sell copies of the Software, and to permit persons to whom the Software is 17e4da13eeSmacallan# furnished to do so, subject to the following conditions: 18e4da13eeSmacallan# 19e4da13eeSmacallan# The above copyright notice and this permission notice shall be included in 20e4da13eeSmacallan# all copies or substantial portions of the Software. 21e4da13eeSmacallan# 22e4da13eeSmacallan# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23e4da13eeSmacallan# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24e4da13eeSmacallan# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25e4da13eeSmacallan# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26e4da13eeSmacallan# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27e4da13eeSmacallan# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28e4da13eeSmacallan# 29e4da13eeSmacallan# Except as contained in this notice, the name of the X Consortium shall not 30e4da13eeSmacallan# be used in advertising or otherwise to promote the sale, use or other deal- 31e4da13eeSmacallan# ings in this Software without prior written authorization from the X Consor- 32e4da13eeSmacallan# tium. 33e4da13eeSmacallan# 34e4da13eeSmacallan# 35e4da13eeSmacallan# FSF changes to this file are in the public domain. 36e4da13eeSmacallan# 37e4da13eeSmacallan# Calling this script install-sh is preferred over install.sh, to prevent 3865d490d0Smrg# 'make' implicit rules from creating a file called install from it 39e4da13eeSmacallan# when there is no Makefile. 40e4da13eeSmacallan# 41e4da13eeSmacallan# This script is compatible with the BSD install script, but was written 42e4da13eeSmacallan# from scratch. 43e4da13eeSmacallan 4425ad54caSmrgtab=' ' 45e4da13eeSmacallannl=' 46e4da13eeSmacallan' 4725ad54caSmrgIFS=" $tab$nl" 48e4da13eeSmacallan 4925ad54caSmrg# Set DOITPROG to "echo" to test this script. 50e4da13eeSmacallan 51e4da13eeSmacallandoit=${DOITPROG-} 5225ad54caSmrgdoit_exec=${doit:-exec} 53e4da13eeSmacallan 54e4da13eeSmacallan# Put in absolute file names if you don't have them in your path; 55e4da13eeSmacallan# or use environment vars. 56e4da13eeSmacallan 57e4da13eeSmacallanchgrpprog=${CHGRPPROG-chgrp} 58e4da13eeSmacallanchmodprog=${CHMODPROG-chmod} 59e4da13eeSmacallanchownprog=${CHOWNPROG-chown} 60e4da13eeSmacallancmpprog=${CMPPROG-cmp} 61e4da13eeSmacallancpprog=${CPPROG-cp} 62e4da13eeSmacallanmkdirprog=${MKDIRPROG-mkdir} 63e4da13eeSmacallanmvprog=${MVPROG-mv} 64e4da13eeSmacallanrmprog=${RMPROG-rm} 65e4da13eeSmacallanstripprog=${STRIPPROG-strip} 66e4da13eeSmacallan 67e4da13eeSmacallanposix_mkdir= 68e4da13eeSmacallan 69e4da13eeSmacallan# Desired mode of installed file. 70e4da13eeSmacallanmode=0755 71e4da13eeSmacallan 7225ad54caSmrg# Create dirs (including intermediate dirs) using mode 755. 7325ad54caSmrg# This is like GNU 'install' as of coreutils 8.32 (2020). 7425ad54caSmrgmkdir_umask=22 7525ad54caSmrg 7625ad54caSmrgbackupsuffix= 77e4da13eeSmacallanchgrpcmd= 78e4da13eeSmacallanchmodcmd=$chmodprog 79e4da13eeSmacallanchowncmd= 80e4da13eeSmacallanmvcmd=$mvprog 81e4da13eeSmacallanrmcmd="$rmprog -f" 82e4da13eeSmacallanstripcmd= 83e4da13eeSmacallan 84e4da13eeSmacallansrc= 85e4da13eeSmacallandst= 86e4da13eeSmacallandir_arg= 87e4da13eeSmacallandst_arg= 88e4da13eeSmacallan 89e4da13eeSmacallancopy_on_change=false 9025ad54caSmrgis_target_a_directory=possibly 91e4da13eeSmacallan 92e4da13eeSmacallanusage="\ 93e4da13eeSmacallanUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 94e4da13eeSmacallan or: $0 [OPTION]... SRCFILES... DIRECTORY 95e4da13eeSmacallan or: $0 [OPTION]... -t DIRECTORY SRCFILES... 96e4da13eeSmacallan or: $0 [OPTION]... -d DIRECTORIES... 97e4da13eeSmacallan 98e4da13eeSmacallanIn the 1st form, copy SRCFILE to DSTFILE. 99e4da13eeSmacallanIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 100e4da13eeSmacallanIn the 4th, create DIRECTORIES. 101e4da13eeSmacallan 102e4da13eeSmacallanOptions: 103e4da13eeSmacallan --help display this help and exit. 104e4da13eeSmacallan --version display version info and exit. 105e4da13eeSmacallan 106e4da13eeSmacallan -c (ignored) 10725ad54caSmrg -C install only if different (preserve data modification time) 108e4da13eeSmacallan -d create directories instead of installing files. 109e4da13eeSmacallan -g GROUP $chgrpprog installed files to GROUP. 110e4da13eeSmacallan -m MODE $chmodprog installed files to MODE. 111e4da13eeSmacallan -o USER $chownprog installed files to USER. 11225ad54caSmrg -p pass -p to $cpprog. 113e4da13eeSmacallan -s $stripprog installed files. 11425ad54caSmrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 115e4da13eeSmacallan -t DIRECTORY install into DIRECTORY. 116e4da13eeSmacallan -T report an error if DSTFILE is a directory. 117e4da13eeSmacallan 118e4da13eeSmacallanEnvironment variables override the default commands: 119e4da13eeSmacallan CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 120e4da13eeSmacallan RMPROG STRIPPROG 12125ad54caSmrg 12225ad54caSmrgBy default, rm is invoked with -f; when overridden with RMPROG, 12325ad54caSmrgit's up to you to specify -f if you want it. 12425ad54caSmrg 12525ad54caSmrgIf -S is not specified, no backups are attempted. 12625ad54caSmrg 12725ad54caSmrgEmail bug reports to bug-automake@gnu.org. 12825ad54caSmrgAutomake home page: https://www.gnu.org/software/automake/ 129e4da13eeSmacallan" 130e4da13eeSmacallan 131e4da13eeSmacallanwhile test $# -ne 0; do 132e4da13eeSmacallan case $1 in 133e4da13eeSmacallan -c) ;; 134e4da13eeSmacallan 135e4da13eeSmacallan -C) copy_on_change=true;; 136e4da13eeSmacallan 137e4da13eeSmacallan -d) dir_arg=true;; 138e4da13eeSmacallan 139e4da13eeSmacallan -g) chgrpcmd="$chgrpprog $2" 14025ad54caSmrg shift;; 141e4da13eeSmacallan 142e4da13eeSmacallan --help) echo "$usage"; exit $?;; 143e4da13eeSmacallan 144e4da13eeSmacallan -m) mode=$2 14525ad54caSmrg case $mode in 14625ad54caSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 14725ad54caSmrg echo "$0: invalid mode: $mode" >&2 14825ad54caSmrg exit 1;; 14925ad54caSmrg esac 15025ad54caSmrg shift;; 151e4da13eeSmacallan 152e4da13eeSmacallan -o) chowncmd="$chownprog $2" 15325ad54caSmrg shift;; 15425ad54caSmrg 15525ad54caSmrg -p) cpprog="$cpprog -p";; 156e4da13eeSmacallan 157e4da13eeSmacallan -s) stripcmd=$stripprog;; 158e4da13eeSmacallan 15925ad54caSmrg -S) backupsuffix="$2" 16025ad54caSmrg shift;; 161e4da13eeSmacallan 16225ad54caSmrg -t) 16325ad54caSmrg is_target_a_directory=always 16425ad54caSmrg dst_arg=$2 16525ad54caSmrg # Protect names problematic for 'test' and other utilities. 16625ad54caSmrg case $dst_arg in 16725ad54caSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16825ad54caSmrg esac 16925ad54caSmrg shift;; 17025ad54caSmrg 17125ad54caSmrg -T) is_target_a_directory=never;; 172e4da13eeSmacallan 173e4da13eeSmacallan --version) echo "$0 $scriptversion"; exit $?;; 174e4da13eeSmacallan 17525ad54caSmrg --) shift 17625ad54caSmrg break;; 177e4da13eeSmacallan 17825ad54caSmrg -*) echo "$0: invalid option: $1" >&2 17925ad54caSmrg exit 1;; 180e4da13eeSmacallan 181e4da13eeSmacallan *) break;; 182e4da13eeSmacallan esac 183e4da13eeSmacallan shift 184e4da13eeSmacallandone 185e4da13eeSmacallan 18625ad54caSmrg# We allow the use of options -d and -T together, by making -d 18725ad54caSmrg# take the precedence; this is for compatibility with GNU install. 18825ad54caSmrg 18925ad54caSmrgif test -n "$dir_arg"; then 19025ad54caSmrg if test -n "$dst_arg"; then 19125ad54caSmrg echo "$0: target directory not allowed when installing a directory." >&2 19225ad54caSmrg exit 1 19325ad54caSmrg fi 19425ad54caSmrgfi 19525ad54caSmrg 196e4da13eeSmacallanif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 197e4da13eeSmacallan # When -d is used, all remaining arguments are directories to create. 198e4da13eeSmacallan # When -t is used, the destination is already specified. 199e4da13eeSmacallan # Otherwise, the last argument is the destination. Remove it from $@. 200e4da13eeSmacallan for arg 201e4da13eeSmacallan do 202e4da13eeSmacallan if test -n "$dst_arg"; then 203e4da13eeSmacallan # $@ is not empty: it contains at least $arg. 204e4da13eeSmacallan set fnord "$@" "$dst_arg" 205e4da13eeSmacallan shift # fnord 206e4da13eeSmacallan fi 207e4da13eeSmacallan shift # arg 208e4da13eeSmacallan dst_arg=$arg 20965d490d0Smrg # Protect names problematic for 'test' and other utilities. 21065d490d0Smrg case $dst_arg in 21165d490d0Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 21265d490d0Smrg esac 213e4da13eeSmacallan done 214e4da13eeSmacallanfi 215e4da13eeSmacallan 216e4da13eeSmacallanif test $# -eq 0; then 217e4da13eeSmacallan if test -z "$dir_arg"; then 218e4da13eeSmacallan echo "$0: no input file specified." >&2 219e4da13eeSmacallan exit 1 220e4da13eeSmacallan fi 22165d490d0Smrg # It's OK to call 'install-sh -d' without argument. 222e4da13eeSmacallan # This can happen when creating conditional directories. 223e4da13eeSmacallan exit 0 224e4da13eeSmacallanfi 225e4da13eeSmacallan 22625ad54caSmrgif test -z "$dir_arg"; then 22725ad54caSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 22825ad54caSmrg if test ! -d "$dst_arg"; then 22925ad54caSmrg echo "$0: $dst_arg: Is not a directory." >&2 23025ad54caSmrg exit 1 23125ad54caSmrg fi 23225ad54caSmrg fi 23325ad54caSmrgfi 23425ad54caSmrg 235e4da13eeSmacallanif test -z "$dir_arg"; then 23665d490d0Smrg do_exit='(exit $ret); exit $ret' 23765d490d0Smrg trap "ret=129; $do_exit" 1 23865d490d0Smrg trap "ret=130; $do_exit" 2 23965d490d0Smrg trap "ret=141; $do_exit" 13 24065d490d0Smrg trap "ret=143; $do_exit" 15 241e4da13eeSmacallan 242e4da13eeSmacallan # Set umask so as not to create temps with too-generous modes. 243e4da13eeSmacallan # However, 'strip' requires both read and write access to temps. 244e4da13eeSmacallan case $mode in 245e4da13eeSmacallan # Optimize common cases. 246e4da13eeSmacallan *644) cp_umask=133;; 247e4da13eeSmacallan *755) cp_umask=22;; 248e4da13eeSmacallan 249e4da13eeSmacallan *[0-7]) 250e4da13eeSmacallan if test -z "$stripcmd"; then 25125ad54caSmrg u_plus_rw= 252e4da13eeSmacallan else 25325ad54caSmrg u_plus_rw='% 200' 254e4da13eeSmacallan fi 255e4da13eeSmacallan cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 256e4da13eeSmacallan *) 257e4da13eeSmacallan if test -z "$stripcmd"; then 25825ad54caSmrg u_plus_rw= 259e4da13eeSmacallan else 26025ad54caSmrg u_plus_rw=,u+rw 261e4da13eeSmacallan fi 262e4da13eeSmacallan cp_umask=$mode$u_plus_rw;; 263e4da13eeSmacallan esac 264e4da13eeSmacallanfi 265e4da13eeSmacallan 266e4da13eeSmacallanfor src 267e4da13eeSmacallando 26865d490d0Smrg # Protect names problematic for 'test' and other utilities. 269e4da13eeSmacallan case $src in 27065d490d0Smrg -* | [=\(\)!]) src=./$src;; 271e4da13eeSmacallan esac 272e4da13eeSmacallan 273e4da13eeSmacallan if test -n "$dir_arg"; then 274e4da13eeSmacallan dst=$src 275e4da13eeSmacallan dstdir=$dst 276e4da13eeSmacallan test -d "$dstdir" 277e4da13eeSmacallan dstdir_status=$? 27825ad54caSmrg # Don't chown directories that already exist. 27925ad54caSmrg if test $dstdir_status = 0; then 28025ad54caSmrg chowncmd="" 28125ad54caSmrg fi 282e4da13eeSmacallan else 283e4da13eeSmacallan 284e4da13eeSmacallan # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 285e4da13eeSmacallan # might cause directories to be created, which would be especially bad 286e4da13eeSmacallan # if $src (and thus $dsttmp) contains '*'. 287e4da13eeSmacallan if test ! -f "$src" && test ! -d "$src"; then 288e4da13eeSmacallan echo "$0: $src does not exist." >&2 289e4da13eeSmacallan exit 1 290e4da13eeSmacallan fi 291e4da13eeSmacallan 292e4da13eeSmacallan if test -z "$dst_arg"; then 293e4da13eeSmacallan echo "$0: no destination specified." >&2 294e4da13eeSmacallan exit 1 295e4da13eeSmacallan fi 296e4da13eeSmacallan dst=$dst_arg 297e4da13eeSmacallan 29825ad54caSmrg # If destination is a directory, append the input filename. 299e4da13eeSmacallan if test -d "$dst"; then 30025ad54caSmrg if test "$is_target_a_directory" = never; then 30125ad54caSmrg echo "$0: $dst_arg: Is a directory" >&2 30225ad54caSmrg exit 1 303e4da13eeSmacallan fi 304e4da13eeSmacallan dstdir=$dst 30525ad54caSmrg dstbase=`basename "$src"` 30625ad54caSmrg case $dst in 30725ad54caSmrg */) dst=$dst$dstbase;; 30825ad54caSmrg *) dst=$dst/$dstbase;; 30925ad54caSmrg esac 310e4da13eeSmacallan dstdir_status=0 311e4da13eeSmacallan else 31225ad54caSmrg dstdir=`dirname "$dst"` 313e4da13eeSmacallan test -d "$dstdir" 314e4da13eeSmacallan dstdir_status=$? 315e4da13eeSmacallan fi 316e4da13eeSmacallan fi 317e4da13eeSmacallan 31825ad54caSmrg case $dstdir in 31925ad54caSmrg */) dstdirslash=$dstdir;; 32025ad54caSmrg *) dstdirslash=$dstdir/;; 32125ad54caSmrg esac 32225ad54caSmrg 323e4da13eeSmacallan obsolete_mkdir_used=false 324e4da13eeSmacallan 325e4da13eeSmacallan if test $dstdir_status != 0; then 326e4da13eeSmacallan case $posix_mkdir in 327e4da13eeSmacallan '') 32825ad54caSmrg # With -d, create the new directory with the user-specified mode. 32925ad54caSmrg # Otherwise, rely on $mkdir_umask. 33025ad54caSmrg if test -n "$dir_arg"; then 33125ad54caSmrg mkdir_mode=-m$mode 33225ad54caSmrg else 33325ad54caSmrg mkdir_mode= 33425ad54caSmrg fi 33525ad54caSmrg 33625ad54caSmrg posix_mkdir=false 33725ad54caSmrg # The $RANDOM variable is not portable (e.g., dash). Use it 33825ad54caSmrg # here however when possible just to lower collision chance. 33925ad54caSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34025ad54caSmrg 34125ad54caSmrg trap ' 34225ad54caSmrg ret=$? 34325ad54caSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 34425ad54caSmrg exit $ret 34525ad54caSmrg ' 0 34625ad54caSmrg 34725ad54caSmrg # Because "mkdir -p" follows existing symlinks and we likely work 34825ad54caSmrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 34925ad54caSmrg # directory is successfully created first before we actually test 35025ad54caSmrg # 'mkdir -p'. 35125ad54caSmrg if (umask $mkdir_umask && 35225ad54caSmrg $mkdirprog $mkdir_mode "$tmpdir" && 35325ad54caSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 35425ad54caSmrg then 35525ad54caSmrg if test -z "$dir_arg" || { 35625ad54caSmrg # Check for POSIX incompatibilities with -m. 35725ad54caSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35825ad54caSmrg # other-writable bit of parent directory when it shouldn't. 35925ad54caSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 36025ad54caSmrg test_tmpdir="$tmpdir/a" 36125ad54caSmrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 36225ad54caSmrg case $ls_ld_tmpdir in 36325ad54caSmrg d????-?r-*) different_mode=700;; 36425ad54caSmrg d????-?--*) different_mode=755;; 36525ad54caSmrg *) false;; 36625ad54caSmrg esac && 36725ad54caSmrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 36825ad54caSmrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 36925ad54caSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 37025ad54caSmrg } 37125ad54caSmrg } 37225ad54caSmrg then posix_mkdir=: 37325ad54caSmrg fi 37425ad54caSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 375e4da13eeSmacallan else 37625ad54caSmrg # Remove any dirs left behind by ancient mkdir implementations. 37725ad54caSmrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 378e4da13eeSmacallan fi 37925ad54caSmrg trap '' 0;; 380e4da13eeSmacallan esac 381e4da13eeSmacallan 382e4da13eeSmacallan if 383e4da13eeSmacallan $posix_mkdir && ( 38425ad54caSmrg umask $mkdir_umask && 38525ad54caSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 386e4da13eeSmacallan ) 387e4da13eeSmacallan then : 388e4da13eeSmacallan else 389e4da13eeSmacallan 39025ad54caSmrg # mkdir does not conform to POSIX, 391e4da13eeSmacallan # or it failed possibly due to a race condition. Create the 392e4da13eeSmacallan # directory the slow way, step by step, checking for races as we go. 393e4da13eeSmacallan 394e4da13eeSmacallan case $dstdir in 39525ad54caSmrg /*) prefix='/';; 39625ad54caSmrg [-=\(\)!]*) prefix='./';; 39725ad54caSmrg *) prefix='';; 398e4da13eeSmacallan esac 399e4da13eeSmacallan 400e4da13eeSmacallan oIFS=$IFS 401e4da13eeSmacallan IFS=/ 40225ad54caSmrg set -f 403e4da13eeSmacallan set fnord $dstdir 404e4da13eeSmacallan shift 40525ad54caSmrg set +f 406e4da13eeSmacallan IFS=$oIFS 407e4da13eeSmacallan 408e4da13eeSmacallan prefixes= 409e4da13eeSmacallan 410e4da13eeSmacallan for d 411e4da13eeSmacallan do 41225ad54caSmrg test X"$d" = X && continue 41325ad54caSmrg 41425ad54caSmrg prefix=$prefix$d 41525ad54caSmrg if test -d "$prefix"; then 41625ad54caSmrg prefixes= 41725ad54caSmrg else 41825ad54caSmrg if $posix_mkdir; then 41925ad54caSmrg (umask $mkdir_umask && 42025ad54caSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42125ad54caSmrg # Don't fail if two instances are running concurrently. 42225ad54caSmrg test -d "$prefix" || exit 1 42325ad54caSmrg else 42425ad54caSmrg case $prefix in 42525ad54caSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42625ad54caSmrg *) qprefix=$prefix;; 42725ad54caSmrg esac 42825ad54caSmrg prefixes="$prefixes '$qprefix'" 42925ad54caSmrg fi 43025ad54caSmrg fi 43125ad54caSmrg prefix=$prefix/ 432e4da13eeSmacallan done 433e4da13eeSmacallan 434e4da13eeSmacallan if test -n "$prefixes"; then 43525ad54caSmrg # Don't fail if two instances are running concurrently. 43625ad54caSmrg (umask $mkdir_umask && 43725ad54caSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 43825ad54caSmrg test -d "$dstdir" || exit 1 43925ad54caSmrg obsolete_mkdir_used=true 440e4da13eeSmacallan fi 441e4da13eeSmacallan fi 442e4da13eeSmacallan fi 443e4da13eeSmacallan 444e4da13eeSmacallan if test -n "$dir_arg"; then 445e4da13eeSmacallan { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 446e4da13eeSmacallan { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 447e4da13eeSmacallan { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 448e4da13eeSmacallan test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 449e4da13eeSmacallan else 450e4da13eeSmacallan 451e4da13eeSmacallan # Make a couple of temp file names in the proper directory. 45225ad54caSmrg dsttmp=${dstdirslash}_inst.$$_ 45325ad54caSmrg rmtmp=${dstdirslash}_rm.$$_ 454e4da13eeSmacallan 455e4da13eeSmacallan # Trap to clean up those temp files at exit. 456e4da13eeSmacallan trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 457e4da13eeSmacallan 458e4da13eeSmacallan # Copy the file name to the temp name. 45925ad54caSmrg (umask $cp_umask && 46025ad54caSmrg { test -z "$stripcmd" || { 46125ad54caSmrg # Create $dsttmp read-write so that cp doesn't create it read-only, 46225ad54caSmrg # which would cause strip to fail. 46325ad54caSmrg if test -z "$doit"; then 46425ad54caSmrg : >"$dsttmp" # No need to fork-exec 'touch'. 46525ad54caSmrg else 46625ad54caSmrg $doit touch "$dsttmp" 46725ad54caSmrg fi 46825ad54caSmrg } 46925ad54caSmrg } && 47025ad54caSmrg $doit_exec $cpprog "$src" "$dsttmp") && 471e4da13eeSmacallan 472e4da13eeSmacallan # and set any options; do chmod last to preserve setuid bits. 473e4da13eeSmacallan # 474e4da13eeSmacallan # If any of these fail, we abort the whole thing. If we want to 475e4da13eeSmacallan # ignore errors from any of these, just make sure not to ignore 476e4da13eeSmacallan # errors from the above "$doit $cpprog $src $dsttmp" command. 477e4da13eeSmacallan # 478e4da13eeSmacallan { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 479e4da13eeSmacallan { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 480e4da13eeSmacallan { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 481e4da13eeSmacallan { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 482e4da13eeSmacallan 483e4da13eeSmacallan # If -C, don't bother to copy if it wouldn't change the file. 484e4da13eeSmacallan if $copy_on_change && 48525ad54caSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 48625ad54caSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 48725ad54caSmrg set -f && 488e4da13eeSmacallan set X $old && old=:$2:$4:$5:$6 && 489e4da13eeSmacallan set X $new && new=:$2:$4:$5:$6 && 49025ad54caSmrg set +f && 491e4da13eeSmacallan test "$old" = "$new" && 492e4da13eeSmacallan $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 493e4da13eeSmacallan then 494e4da13eeSmacallan rm -f "$dsttmp" 495e4da13eeSmacallan else 49625ad54caSmrg # If $backupsuffix is set, and the file being installed 49725ad54caSmrg # already exists, attempt a backup. Don't worry if it fails, 49825ad54caSmrg # e.g., if mv doesn't support -f. 49925ad54caSmrg if test -n "$backupsuffix" && test -f "$dst"; then 50025ad54caSmrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 50125ad54caSmrg fi 50225ad54caSmrg 503e4da13eeSmacallan # Rename the file to the real destination. 504e4da13eeSmacallan $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 505e4da13eeSmacallan 506e4da13eeSmacallan # The rename failed, perhaps because mv can't rename something else 507e4da13eeSmacallan # to itself, or perhaps because mv is so ancient that it does not 508e4da13eeSmacallan # support -f. 509e4da13eeSmacallan { 51025ad54caSmrg # Now remove or move aside any old file at destination location. 51125ad54caSmrg # We try this two ways since rm can't unlink itself on some 51225ad54caSmrg # systems and the destination file might be busy for other 51325ad54caSmrg # reasons. In this case, the final cleanup might fail but the new 51425ad54caSmrg # file should still install successfully. 51525ad54caSmrg { 51625ad54caSmrg test ! -f "$dst" || 51725ad54caSmrg $doit $rmcmd "$dst" 2>/dev/null || 51825ad54caSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 51925ad54caSmrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 52025ad54caSmrg } || 52125ad54caSmrg { echo "$0: cannot unlink or rename $dst" >&2 52225ad54caSmrg (exit 1); exit 1 52325ad54caSmrg } 52425ad54caSmrg } && 52525ad54caSmrg 52625ad54caSmrg # Now rename the file to the real destination. 52725ad54caSmrg $doit $mvcmd "$dsttmp" "$dst" 528e4da13eeSmacallan } 529e4da13eeSmacallan fi || exit 1 530e4da13eeSmacallan 531e4da13eeSmacallan trap '' 0 532e4da13eeSmacallan fi 533e4da13eeSmacallandone 534e4da13eeSmacallan 535e4da13eeSmacallan# Local variables: 53625ad54caSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 537e4da13eeSmacallan# time-stamp-start: "scriptversion=" 538e4da13eeSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H" 53925ad54caSmrg# time-stamp-time-zone: "UTC0" 54065d490d0Smrg# time-stamp-end: "; # UTC" 541e4da13eeSmacallan# End: 542