1a0d3b6eaSmrg#!/bin/sh 2a0d3b6eaSmrg# install - install a program, script, or datafile 3a0d3b6eaSmrg 409113985Smrgscriptversion=2020-11-14.01; # UTC 5a0d3b6eaSmrg 6a0d3b6eaSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7a0d3b6eaSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8a0d3b6eaSmrg# following copyright and license. 9a0d3b6eaSmrg# 10a0d3b6eaSmrg# Copyright (C) 1994 X Consortium 11a0d3b6eaSmrg# 12a0d3b6eaSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13a0d3b6eaSmrg# of this software and associated documentation files (the "Software"), to 14a0d3b6eaSmrg# deal in the Software without restriction, including without limitation the 15a0d3b6eaSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16a0d3b6eaSmrg# sell copies of the Software, and to permit persons to whom the Software is 17a0d3b6eaSmrg# furnished to do so, subject to the following conditions: 18a0d3b6eaSmrg# 19a0d3b6eaSmrg# The above copyright notice and this permission notice shall be included in 20a0d3b6eaSmrg# all copies or substantial portions of the Software. 21a0d3b6eaSmrg# 22a0d3b6eaSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23a0d3b6eaSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24a0d3b6eaSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25a0d3b6eaSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26a0d3b6eaSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27a0d3b6eaSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28a0d3b6eaSmrg# 29a0d3b6eaSmrg# Except as contained in this notice, the name of the X Consortium shall not 30a0d3b6eaSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31a0d3b6eaSmrg# ings in this Software without prior written authorization from the X Consor- 32a0d3b6eaSmrg# tium. 33a0d3b6eaSmrg# 34a0d3b6eaSmrg# 35a0d3b6eaSmrg# FSF changes to this file are in the public domain. 36a0d3b6eaSmrg# 37a0d3b6eaSmrg# Calling this script install-sh is preferred over install.sh, to prevent 384a908991Smrg# 'make' implicit rules from creating a file called install from it 39a0d3b6eaSmrg# when there is no Makefile. 40a0d3b6eaSmrg# 41a0d3b6eaSmrg# This script is compatible with the BSD install script, but was written 42a0d3b6eaSmrg# from scratch. 43a0d3b6eaSmrg 444a908991Smrgtab=' ' 45a0d3b6eaSmrgnl=' 46a0d3b6eaSmrg' 474a908991SmrgIFS=" $tab$nl" 48a0d3b6eaSmrg 494a908991Smrg# Set DOITPROG to "echo" to test this script. 50a0d3b6eaSmrg 51f8a31ee4Smrgdoit=${DOITPROG-} 524a908991Smrgdoit_exec=${doit:-exec} 53a0d3b6eaSmrg 54a0d3b6eaSmrg# Put in absolute file names if you don't have them in your path; 55a0d3b6eaSmrg# or use environment vars. 56a0d3b6eaSmrg 57f8a31ee4Smrgchgrpprog=${CHGRPPROG-chgrp} 58f8a31ee4Smrgchmodprog=${CHMODPROG-chmod} 59f8a31ee4Smrgchownprog=${CHOWNPROG-chown} 60f8a31ee4Smrgcmpprog=${CMPPROG-cmp} 61f8a31ee4Smrgcpprog=${CPPROG-cp} 62f8a31ee4Smrgmkdirprog=${MKDIRPROG-mkdir} 63f8a31ee4Smrgmvprog=${MVPROG-mv} 64f8a31ee4Smrgrmprog=${RMPROG-rm} 65f8a31ee4Smrgstripprog=${STRIPPROG-strip} 66f8a31ee4Smrg 67a0d3b6eaSmrgposix_mkdir= 68a0d3b6eaSmrg 69a0d3b6eaSmrg# Desired mode of installed file. 70a0d3b6eaSmrgmode=0755 71a0d3b6eaSmrg 7209113985Smrg# Create dirs (including intermediate dirs) using mode 755. 7309113985Smrg# This is like GNU 'install' as of coreutils 8.32 (2020). 7409113985Smrgmkdir_umask=22 7509113985Smrg 7609113985Smrgbackupsuffix= 77f8a31ee4Smrgchgrpcmd= 78a0d3b6eaSmrgchmodcmd=$chmodprog 79a0d3b6eaSmrgchowncmd= 80f8a31ee4Smrgmvcmd=$mvprog 8162770414Smrgrmcmd="$rmprog -f" 82f8a31ee4Smrgstripcmd= 83f8a31ee4Smrg 84a0d3b6eaSmrgsrc= 85a0d3b6eaSmrgdst= 86a0d3b6eaSmrgdir_arg= 87f8a31ee4Smrgdst_arg= 88f8a31ee4Smrg 89f8a31ee4Smrgcopy_on_change=false 904a908991Smrgis_target_a_directory=possibly 91a0d3b6eaSmrg 92f8a31ee4Smrgusage="\ 93f8a31ee4SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 94a0d3b6eaSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 95a0d3b6eaSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 96a0d3b6eaSmrg or: $0 [OPTION]... -d DIRECTORIES... 97a0d3b6eaSmrg 98a0d3b6eaSmrgIn the 1st form, copy SRCFILE to DSTFILE. 99a0d3b6eaSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 100a0d3b6eaSmrgIn the 4th, create DIRECTORIES. 101a0d3b6eaSmrg 102a0d3b6eaSmrgOptions: 103f8a31ee4Smrg --help display this help and exit. 104f8a31ee4Smrg --version display version info and exit. 105f8a31ee4Smrg 106f8a31ee4Smrg -c (ignored) 10709113985Smrg -C install only if different (preserve data modification time) 108f8a31ee4Smrg -d create directories instead of installing files. 109f8a31ee4Smrg -g GROUP $chgrpprog installed files to GROUP. 110f8a31ee4Smrg -m MODE $chmodprog installed files to MODE. 111f8a31ee4Smrg -o USER $chownprog installed files to USER. 11209113985Smrg -p pass -p to $cpprog. 113f8a31ee4Smrg -s $stripprog installed files. 11409113985Smrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 115f8a31ee4Smrg -t DIRECTORY install into DIRECTORY. 116f8a31ee4Smrg -T report an error if DSTFILE is a directory. 117a0d3b6eaSmrg 118a0d3b6eaSmrgEnvironment variables override the default commands: 119f8a31ee4Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 120f8a31ee4Smrg RMPROG STRIPPROG 12109113985Smrg 12209113985SmrgBy default, rm is invoked with -f; when overridden with RMPROG, 12309113985Smrgit's up to you to specify -f if you want it. 12409113985Smrg 12509113985SmrgIf -S is not specified, no backups are attempted. 12609113985Smrg 12709113985SmrgEmail bug reports to bug-automake@gnu.org. 12809113985SmrgAutomake home page: https://www.gnu.org/software/automake/ 129a0d3b6eaSmrg" 130a0d3b6eaSmrg 131a0d3b6eaSmrgwhile test $# -ne 0; do 132a0d3b6eaSmrg case $1 in 133f8a31ee4Smrg -c) ;; 134f8a31ee4Smrg 135f8a31ee4Smrg -C) copy_on_change=true;; 136a0d3b6eaSmrg 137f8a31ee4Smrg -d) dir_arg=true;; 138a0d3b6eaSmrg 139a0d3b6eaSmrg -g) chgrpcmd="$chgrpprog $2" 1404a908991Smrg shift;; 141a0d3b6eaSmrg 142a0d3b6eaSmrg --help) echo "$usage"; exit $?;; 143a0d3b6eaSmrg 144a0d3b6eaSmrg -m) mode=$2 1454a908991Smrg case $mode in 1464a908991Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1474a908991Smrg echo "$0: invalid mode: $mode" >&2 1484a908991Smrg exit 1;; 1494a908991Smrg esac 1504a908991Smrg shift;; 151a0d3b6eaSmrg 152a0d3b6eaSmrg -o) chowncmd="$chownprog $2" 1534a908991Smrg shift;; 154a0d3b6eaSmrg 15509113985Smrg -p) cpprog="$cpprog -p";; 15609113985Smrg 157f8a31ee4Smrg -s) stripcmd=$stripprog;; 158a0d3b6eaSmrg 15909113985Smrg -S) backupsuffix="$2" 16009113985Smrg shift;; 16109113985Smrg 1624a908991Smrg -t) 1634a908991Smrg is_target_a_directory=always 1644a908991Smrg dst_arg=$2 1654a908991Smrg # Protect names problematic for 'test' and other utilities. 1664a908991Smrg case $dst_arg in 1674a908991Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1684a908991Smrg esac 1694a908991Smrg shift;; 170a0d3b6eaSmrg 1714a908991Smrg -T) is_target_a_directory=never;; 172a0d3b6eaSmrg 173a0d3b6eaSmrg --version) echo "$0 $scriptversion"; exit $?;; 174a0d3b6eaSmrg 1754a908991Smrg --) shift 1764a908991Smrg break;; 177a0d3b6eaSmrg 1784a908991Smrg -*) echo "$0: invalid option: $1" >&2 1794a908991Smrg exit 1;; 180a0d3b6eaSmrg 181a0d3b6eaSmrg *) break;; 182a0d3b6eaSmrg esac 183f8a31ee4Smrg shift 184a0d3b6eaSmrgdone 185a0d3b6eaSmrg 1864a908991Smrg# We allow the use of options -d and -T together, by making -d 1874a908991Smrg# take the precedence; this is for compatibility with GNU install. 1884a908991Smrg 1894a908991Smrgif test -n "$dir_arg"; then 1904a908991Smrg if test -n "$dst_arg"; then 1914a908991Smrg echo "$0: target directory not allowed when installing a directory." >&2 1924a908991Smrg exit 1 1934a908991Smrg fi 1944a908991Smrgfi 1954a908991Smrg 196f8a31ee4Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 197a0d3b6eaSmrg # When -d is used, all remaining arguments are directories to create. 198a0d3b6eaSmrg # When -t is used, the destination is already specified. 199a0d3b6eaSmrg # Otherwise, the last argument is the destination. Remove it from $@. 200a0d3b6eaSmrg for arg 201a0d3b6eaSmrg do 202f8a31ee4Smrg if test -n "$dst_arg"; then 203a0d3b6eaSmrg # $@ is not empty: it contains at least $arg. 204f8a31ee4Smrg set fnord "$@" "$dst_arg" 205a0d3b6eaSmrg shift # fnord 206a0d3b6eaSmrg fi 207a0d3b6eaSmrg shift # arg 208f8a31ee4Smrg dst_arg=$arg 2094a908991Smrg # Protect names problematic for 'test' and other utilities. 210966b534aSmrg case $dst_arg in 211966b534aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212966b534aSmrg esac 213a0d3b6eaSmrg done 214a0d3b6eaSmrgfi 215a0d3b6eaSmrg 216a0d3b6eaSmrgif test $# -eq 0; then 217a0d3b6eaSmrg if test -z "$dir_arg"; then 218a0d3b6eaSmrg echo "$0: no input file specified." >&2 219a0d3b6eaSmrg exit 1 220a0d3b6eaSmrg fi 2214a908991Smrg # It's OK to call 'install-sh -d' without argument. 222a0d3b6eaSmrg # This can happen when creating conditional directories. 223a0d3b6eaSmrg exit 0 224a0d3b6eaSmrgfi 225a0d3b6eaSmrg 2264a908991Smrgif test -z "$dir_arg"; then 2274a908991Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2284a908991Smrg if test ! -d "$dst_arg"; then 2294a908991Smrg echo "$0: $dst_arg: Is not a directory." >&2 2304a908991Smrg exit 1 2314a908991Smrg fi 2324a908991Smrg fi 2334a908991Smrgfi 2344a908991Smrg 235a0d3b6eaSmrgif test -z "$dir_arg"; then 236966b534aSmrg do_exit='(exit $ret); exit $ret' 237966b534aSmrg trap "ret=129; $do_exit" 1 238966b534aSmrg trap "ret=130; $do_exit" 2 239966b534aSmrg trap "ret=141; $do_exit" 13 240966b534aSmrg trap "ret=143; $do_exit" 15 241a0d3b6eaSmrg 242a0d3b6eaSmrg # Set umask so as not to create temps with too-generous modes. 243a0d3b6eaSmrg # However, 'strip' requires both read and write access to temps. 244a0d3b6eaSmrg case $mode in 245a0d3b6eaSmrg # Optimize common cases. 246a0d3b6eaSmrg *644) cp_umask=133;; 247a0d3b6eaSmrg *755) cp_umask=22;; 248a0d3b6eaSmrg 249a0d3b6eaSmrg *[0-7]) 250a0d3b6eaSmrg if test -z "$stripcmd"; then 2514a908991Smrg u_plus_rw= 252a0d3b6eaSmrg else 2534a908991Smrg u_plus_rw='% 200' 254a0d3b6eaSmrg fi 255a0d3b6eaSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 256a0d3b6eaSmrg *) 257a0d3b6eaSmrg if test -z "$stripcmd"; then 2584a908991Smrg u_plus_rw= 259a0d3b6eaSmrg else 2604a908991Smrg u_plus_rw=,u+rw 261a0d3b6eaSmrg fi 262a0d3b6eaSmrg cp_umask=$mode$u_plus_rw;; 263a0d3b6eaSmrg esac 264a0d3b6eaSmrgfi 265a0d3b6eaSmrg 266a0d3b6eaSmrgfor src 267a0d3b6eaSmrgdo 2684a908991Smrg # Protect names problematic for 'test' and other utilities. 269a0d3b6eaSmrg case $src in 270966b534aSmrg -* | [=\(\)!]) src=./$src;; 271a0d3b6eaSmrg esac 272a0d3b6eaSmrg 273a0d3b6eaSmrg if test -n "$dir_arg"; then 274a0d3b6eaSmrg dst=$src 275a0d3b6eaSmrg dstdir=$dst 276a0d3b6eaSmrg test -d "$dstdir" 277a0d3b6eaSmrg dstdir_status=$? 27809113985Smrg # Don't chown directories that already exist. 27909113985Smrg if test $dstdir_status = 0; then 28009113985Smrg chowncmd="" 28109113985Smrg fi 282a0d3b6eaSmrg else 283a0d3b6eaSmrg 284a0d3b6eaSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 285a0d3b6eaSmrg # might cause directories to be created, which would be especially bad 286a0d3b6eaSmrg # if $src (and thus $dsttmp) contains '*'. 287a0d3b6eaSmrg if test ! -f "$src" && test ! -d "$src"; then 288a0d3b6eaSmrg echo "$0: $src does not exist." >&2 289a0d3b6eaSmrg exit 1 290a0d3b6eaSmrg fi 291a0d3b6eaSmrg 292f8a31ee4Smrg if test -z "$dst_arg"; then 293a0d3b6eaSmrg echo "$0: no destination specified." >&2 294a0d3b6eaSmrg exit 1 295a0d3b6eaSmrg fi 296f8a31ee4Smrg dst=$dst_arg 297a0d3b6eaSmrg 29809113985Smrg # If destination is a directory, append the input filename. 299a0d3b6eaSmrg if test -d "$dst"; then 3004a908991Smrg if test "$is_target_a_directory" = never; then 3014a908991Smrg echo "$0: $dst_arg: Is a directory" >&2 3024a908991Smrg exit 1 303a0d3b6eaSmrg fi 304a0d3b6eaSmrg dstdir=$dst 30509113985Smrg dstbase=`basename "$src"` 30609113985Smrg case $dst in 30709113985Smrg */) dst=$dst$dstbase;; 30809113985Smrg *) dst=$dst/$dstbase;; 30909113985Smrg esac 310a0d3b6eaSmrg dstdir_status=0 311a0d3b6eaSmrg else 3124a908991Smrg dstdir=`dirname "$dst"` 313a0d3b6eaSmrg test -d "$dstdir" 314a0d3b6eaSmrg dstdir_status=$? 315a0d3b6eaSmrg fi 316a0d3b6eaSmrg fi 317a0d3b6eaSmrg 31809113985Smrg case $dstdir in 31909113985Smrg */) dstdirslash=$dstdir;; 32009113985Smrg *) dstdirslash=$dstdir/;; 32109113985Smrg esac 32209113985Smrg 323a0d3b6eaSmrg obsolete_mkdir_used=false 324a0d3b6eaSmrg 325a0d3b6eaSmrg if test $dstdir_status != 0; then 326a0d3b6eaSmrg case $posix_mkdir in 327a0d3b6eaSmrg '') 3284a908991Smrg # With -d, create the new directory with the user-specified mode. 3294a908991Smrg # Otherwise, rely on $mkdir_umask. 3304a908991Smrg if test -n "$dir_arg"; then 3314a908991Smrg mkdir_mode=-m$mode 3324a908991Smrg else 3334a908991Smrg mkdir_mode= 3344a908991Smrg fi 3354a908991Smrg 3364a908991Smrg posix_mkdir=false 33709113985Smrg # The $RANDOM variable is not portable (e.g., dash). Use it 33809113985Smrg # here however when possible just to lower collision chance. 33909113985Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34009113985Smrg 34109113985Smrg trap ' 34209113985Smrg ret=$? 34309113985Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 34409113985Smrg exit $ret 34509113985Smrg ' 0 34609113985Smrg 34709113985Smrg # Because "mkdir -p" follows existing symlinks and we likely work 34809113985Smrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 34909113985Smrg # directory is successfully created first before we actually test 35009113985Smrg # 'mkdir -p'. 35109113985Smrg if (umask $mkdir_umask && 35209113985Smrg $mkdirprog $mkdir_mode "$tmpdir" && 35309113985Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 35409113985Smrg then 35509113985Smrg if test -z "$dir_arg" || { 35609113985Smrg # Check for POSIX incompatibilities with -m. 35709113985Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35809113985Smrg # other-writable bit of parent directory when it shouldn't. 35909113985Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 36009113985Smrg test_tmpdir="$tmpdir/a" 36109113985Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 36209113985Smrg case $ls_ld_tmpdir in 36309113985Smrg d????-?r-*) different_mode=700;; 36409113985Smrg d????-?--*) different_mode=755;; 36509113985Smrg *) false;; 36609113985Smrg esac && 36709113985Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 36809113985Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 36909113985Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 37009113985Smrg } 37109113985Smrg } 37209113985Smrg then posix_mkdir=: 37309113985Smrg fi 37409113985Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 37509113985Smrg else 37609113985Smrg # Remove any dirs left behind by ancient mkdir implementations. 37709113985Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 37809113985Smrg fi 37909113985Smrg trap '' 0;; 380a0d3b6eaSmrg esac 381a0d3b6eaSmrg 382a0d3b6eaSmrg if 383a0d3b6eaSmrg $posix_mkdir && ( 3844a908991Smrg umask $mkdir_umask && 3854a908991Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 386a0d3b6eaSmrg ) 387a0d3b6eaSmrg then : 388a0d3b6eaSmrg else 389a0d3b6eaSmrg 39009113985Smrg # mkdir does not conform to POSIX, 391a0d3b6eaSmrg # or it failed possibly due to a race condition. Create the 392a0d3b6eaSmrg # directory the slow way, step by step, checking for races as we go. 393a0d3b6eaSmrg 394a0d3b6eaSmrg case $dstdir in 3954a908991Smrg /*) prefix='/';; 3964a908991Smrg [-=\(\)!]*) prefix='./';; 3974a908991Smrg *) prefix='';; 398a0d3b6eaSmrg esac 399a0d3b6eaSmrg 400a0d3b6eaSmrg oIFS=$IFS 401a0d3b6eaSmrg IFS=/ 4024a908991Smrg set -f 403a0d3b6eaSmrg set fnord $dstdir 404a0d3b6eaSmrg shift 4054a908991Smrg set +f 406a0d3b6eaSmrg IFS=$oIFS 407a0d3b6eaSmrg 408a0d3b6eaSmrg prefixes= 409a0d3b6eaSmrg 410a0d3b6eaSmrg for d 411a0d3b6eaSmrg do 4124a908991Smrg test X"$d" = X && continue 4134a908991Smrg 4144a908991Smrg prefix=$prefix$d 4154a908991Smrg if test -d "$prefix"; then 4164a908991Smrg prefixes= 4174a908991Smrg else 4184a908991Smrg if $posix_mkdir; then 41909113985Smrg (umask $mkdir_umask && 4204a908991Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4214a908991Smrg # Don't fail if two instances are running concurrently. 4224a908991Smrg test -d "$prefix" || exit 1 4234a908991Smrg else 4244a908991Smrg case $prefix in 4254a908991Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4264a908991Smrg *) qprefix=$prefix;; 4274a908991Smrg esac 4284a908991Smrg prefixes="$prefixes '$qprefix'" 4294a908991Smrg fi 4304a908991Smrg fi 4314a908991Smrg prefix=$prefix/ 432a0d3b6eaSmrg done 433a0d3b6eaSmrg 434a0d3b6eaSmrg if test -n "$prefixes"; then 4354a908991Smrg # Don't fail if two instances are running concurrently. 4364a908991Smrg (umask $mkdir_umask && 4374a908991Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4384a908991Smrg test -d "$dstdir" || exit 1 4394a908991Smrg obsolete_mkdir_used=true 440a0d3b6eaSmrg fi 441a0d3b6eaSmrg fi 442a0d3b6eaSmrg fi 443a0d3b6eaSmrg 444a0d3b6eaSmrg if test -n "$dir_arg"; then 445a0d3b6eaSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 446a0d3b6eaSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 447a0d3b6eaSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 448a0d3b6eaSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 449a0d3b6eaSmrg else 450a0d3b6eaSmrg 451a0d3b6eaSmrg # Make a couple of temp file names in the proper directory. 45209113985Smrg dsttmp=${dstdirslash}_inst.$$_ 45309113985Smrg rmtmp=${dstdirslash}_rm.$$_ 454a0d3b6eaSmrg 455a0d3b6eaSmrg # Trap to clean up those temp files at exit. 456a0d3b6eaSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 457a0d3b6eaSmrg 458a0d3b6eaSmrg # Copy the file name to the temp name. 45909113985Smrg (umask $cp_umask && 46009113985Smrg { test -z "$stripcmd" || { 46109113985Smrg # Create $dsttmp read-write so that cp doesn't create it read-only, 46209113985Smrg # which would cause strip to fail. 46309113985Smrg if test -z "$doit"; then 46409113985Smrg : >"$dsttmp" # No need to fork-exec 'touch'. 46509113985Smrg else 46609113985Smrg $doit touch "$dsttmp" 46709113985Smrg fi 46809113985Smrg } 46909113985Smrg } && 47009113985Smrg $doit_exec $cpprog "$src" "$dsttmp") && 471a0d3b6eaSmrg 472a0d3b6eaSmrg # and set any options; do chmod last to preserve setuid bits. 473a0d3b6eaSmrg # 474a0d3b6eaSmrg # If any of these fail, we abort the whole thing. If we want to 475a0d3b6eaSmrg # ignore errors from any of these, just make sure not to ignore 476a0d3b6eaSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 477a0d3b6eaSmrg # 478f8a31ee4Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 479f8a31ee4Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 480f8a31ee4Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 481f8a31ee4Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 482f8a31ee4Smrg 483f8a31ee4Smrg # If -C, don't bother to copy if it wouldn't change the file. 484f8a31ee4Smrg if $copy_on_change && 4854a908991Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4864a908991Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4874a908991Smrg set -f && 488f8a31ee4Smrg set X $old && old=:$2:$4:$5:$6 && 489f8a31ee4Smrg set X $new && new=:$2:$4:$5:$6 && 4904a908991Smrg set +f && 491f8a31ee4Smrg test "$old" = "$new" && 492f8a31ee4Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 493f8a31ee4Smrg then 494f8a31ee4Smrg rm -f "$dsttmp" 495f8a31ee4Smrg else 49609113985Smrg # If $backupsuffix is set, and the file being installed 49709113985Smrg # already exists, attempt a backup. Don't worry if it fails, 49809113985Smrg # e.g., if mv doesn't support -f. 49909113985Smrg if test -n "$backupsuffix" && test -f "$dst"; then 50009113985Smrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 50109113985Smrg fi 50209113985Smrg 503f8a31ee4Smrg # Rename the file to the real destination. 504f8a31ee4Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 505f8a31ee4Smrg 506f8a31ee4Smrg # The rename failed, perhaps because mv can't rename something else 507f8a31ee4Smrg # to itself, or perhaps because mv is so ancient that it does not 508f8a31ee4Smrg # support -f. 509f8a31ee4Smrg { 5104a908991Smrg # Now remove or move aside any old file at destination location. 5114a908991Smrg # We try this two ways since rm can't unlink itself on some 5124a908991Smrg # systems and the destination file might be busy for other 5134a908991Smrg # reasons. In this case, the final cleanup might fail but the new 5144a908991Smrg # file should still install successfully. 5154a908991Smrg { 5164a908991Smrg test ! -f "$dst" || 51709113985Smrg $doit $rmcmd "$dst" 2>/dev/null || 5184a908991Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 51909113985Smrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 5204a908991Smrg } || 5214a908991Smrg { echo "$0: cannot unlink or rename $dst" >&2 5224a908991Smrg (exit 1); exit 1 5234a908991Smrg } 5244a908991Smrg } && 5254a908991Smrg 5264a908991Smrg # Now rename the file to the real destination. 5274a908991Smrg $doit $mvcmd "$dsttmp" "$dst" 528f8a31ee4Smrg } 529f8a31ee4Smrg fi || exit 1 530a0d3b6eaSmrg 531a0d3b6eaSmrg trap '' 0 532a0d3b6eaSmrg fi 533a0d3b6eaSmrgdone 534a0d3b6eaSmrg 535a0d3b6eaSmrg# Local variables: 53609113985Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 537a0d3b6eaSmrg# time-stamp-start: "scriptversion=" 538a0d3b6eaSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 53909113985Smrg# time-stamp-time-zone: "UTC0" 540f8a31ee4Smrg# time-stamp-end: "; # UTC" 541a0d3b6eaSmrg# End: 542