150806d53Smrg#!/bin/sh 250806d53Smrg# install - install a program, script, or datafile 350806d53Smrg 4e9f7eabcSmrgscriptversion=2020-11-14.01; # UTC 550806d53Smrg 650806d53Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 750806d53Smrg# later released in X11R6 (xc/config/util/install.sh) with the 850806d53Smrg# following copyright and license. 950806d53Smrg# 1050806d53Smrg# Copyright (C) 1994 X Consortium 1150806d53Smrg# 1250806d53Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1350806d53Smrg# of this software and associated documentation files (the "Software"), to 1450806d53Smrg# deal in the Software without restriction, including without limitation the 1550806d53Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1650806d53Smrg# sell copies of the Software, and to permit persons to whom the Software is 1750806d53Smrg# furnished to do so, subject to the following conditions: 1850806d53Smrg# 1950806d53Smrg# The above copyright notice and this permission notice shall be included in 2050806d53Smrg# all copies or substantial portions of the Software. 2150806d53Smrg# 2250806d53Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2350806d53Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2450806d53Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2550806d53Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2650806d53Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2750806d53Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2850806d53Smrg# 2950806d53Smrg# Except as contained in this notice, the name of the X Consortium shall not 3050806d53Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3150806d53Smrg# ings in this Software without prior written authorization from the X Consor- 3250806d53Smrg# tium. 3350806d53Smrg# 3450806d53Smrg# 3550806d53Smrg# FSF changes to this file are in the public domain. 3650806d53Smrg# 3750806d53Smrg# Calling this script install-sh is preferred over install.sh, to prevent 384a8d91dcSmrg# 'make' implicit rules from creating a file called install from it 3950806d53Smrg# when there is no Makefile. 4050806d53Smrg# 4150806d53Smrg# This script is compatible with the BSD install script, but was written 427965d9acSmrg# from scratch. 437965d9acSmrg 444a8d91dcSmrgtab=' ' 457965d9acSmrgnl=' 467965d9acSmrg' 474a8d91dcSmrgIFS=" $tab$nl" 4850806d53Smrg 494a8d91dcSmrg# Set DOITPROG to "echo" to test this script. 5050806d53Smrg 517965d9acSmrgdoit=${DOITPROG-} 524a8d91dcSmrgdoit_exec=${doit:-exec} 5350806d53Smrg 547965d9acSmrg# Put in absolute file names if you don't have them in your path; 557965d9acSmrg# or use environment vars. 567965d9acSmrg 577965d9acSmrgchgrpprog=${CHGRPPROG-chgrp} 587965d9acSmrgchmodprog=${CHMODPROG-chmod} 597965d9acSmrgchownprog=${CHOWNPROG-chown} 607965d9acSmrgcmpprog=${CMPPROG-cmp} 617965d9acSmrgcpprog=${CPPROG-cp} 627965d9acSmrgmkdirprog=${MKDIRPROG-mkdir} 637965d9acSmrgmvprog=${MVPROG-mv} 647965d9acSmrgrmprog=${RMPROG-rm} 657965d9acSmrgstripprog=${STRIPPROG-strip} 667965d9acSmrg 677965d9acSmrgposix_mkdir= 687965d9acSmrg 697965d9acSmrg# Desired mode of installed file. 707965d9acSmrgmode=0755 7150806d53Smrg 72e9f7eabcSmrg# Create dirs (including intermediate dirs) using mode 755. 73e9f7eabcSmrg# This is like GNU 'install' as of coreutils 8.32 (2020). 74e9f7eabcSmrgmkdir_umask=22 75e9f7eabcSmrg 76e9f7eabcSmrgbackupsuffix= 7750806d53Smrgchgrpcmd= 787965d9acSmrgchmodcmd=$chmodprog 797965d9acSmrgchowncmd= 807965d9acSmrgmvcmd=$mvprog 8150806d53Smrgrmcmd="$rmprog -f" 827965d9acSmrgstripcmd= 837965d9acSmrg 8450806d53Smrgsrc= 8550806d53Smrgdst= 8650806d53Smrgdir_arg= 877965d9acSmrgdst_arg= 887965d9acSmrg 897965d9acSmrgcopy_on_change=false 904a8d91dcSmrgis_target_a_directory=possibly 9150806d53Smrg 927965d9acSmrgusage="\ 937965d9acSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 9450806d53Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 9550806d53Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 9650806d53Smrg or: $0 [OPTION]... -d DIRECTORIES... 9750806d53Smrg 9850806d53SmrgIn the 1st form, copy SRCFILE to DSTFILE. 9950806d53SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 10050806d53SmrgIn the 4th, create DIRECTORIES. 10150806d53Smrg 10250806d53SmrgOptions: 1037965d9acSmrg --help display this help and exit. 1047965d9acSmrg --version display version info and exit. 1057965d9acSmrg 1067965d9acSmrg -c (ignored) 107e9f7eabcSmrg -C install only if different (preserve data modification time) 1087965d9acSmrg -d create directories instead of installing files. 1097965d9acSmrg -g GROUP $chgrpprog installed files to GROUP. 1107965d9acSmrg -m MODE $chmodprog installed files to MODE. 1117965d9acSmrg -o USER $chownprog installed files to USER. 112e9f7eabcSmrg -p pass -p to $cpprog. 1137965d9acSmrg -s $stripprog installed files. 114e9f7eabcSmrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 1157965d9acSmrg -t DIRECTORY install into DIRECTORY. 1167965d9acSmrg -T report an error if DSTFILE is a directory. 11750806d53Smrg 11850806d53SmrgEnvironment variables override the default commands: 1197965d9acSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1207965d9acSmrg RMPROG STRIPPROG 121e9f7eabcSmrg 122e9f7eabcSmrgBy default, rm is invoked with -f; when overridden with RMPROG, 123e9f7eabcSmrgit's up to you to specify -f if you want it. 124e9f7eabcSmrg 125e9f7eabcSmrgIf -S is not specified, no backups are attempted. 126e9f7eabcSmrg 127e9f7eabcSmrgEmail bug reports to bug-automake@gnu.org. 128e9f7eabcSmrgAutomake home page: https://www.gnu.org/software/automake/ 12950806d53Smrg" 13050806d53Smrg 1317965d9acSmrgwhile test $# -ne 0; do 13250806d53Smrg case $1 in 1337965d9acSmrg -c) ;; 1347965d9acSmrg 1357965d9acSmrg -C) copy_on_change=true;; 13650806d53Smrg 1377965d9acSmrg -d) dir_arg=true;; 13850806d53Smrg 13950806d53Smrg -g) chgrpcmd="$chgrpprog $2" 1404a8d91dcSmrg shift;; 14150806d53Smrg 14250806d53Smrg --help) echo "$usage"; exit $?;; 14350806d53Smrg 1447965d9acSmrg -m) mode=$2 1454a8d91dcSmrg case $mode in 1464a8d91dcSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1474a8d91dcSmrg echo "$0: invalid mode: $mode" >&2 1484a8d91dcSmrg exit 1;; 1494a8d91dcSmrg esac 1504a8d91dcSmrg shift;; 15150806d53Smrg 15250806d53Smrg -o) chowncmd="$chownprog $2" 1534a8d91dcSmrg shift;; 15450806d53Smrg 155e9f7eabcSmrg -p) cpprog="$cpprog -p";; 156e9f7eabcSmrg 1577965d9acSmrg -s) stripcmd=$stripprog;; 15850806d53Smrg 159e9f7eabcSmrg -S) backupsuffix="$2" 160e9f7eabcSmrg shift;; 161e9f7eabcSmrg 1624a8d91dcSmrg -t) 1634a8d91dcSmrg is_target_a_directory=always 1644a8d91dcSmrg dst_arg=$2 1654a8d91dcSmrg # Protect names problematic for 'test' and other utilities. 1664a8d91dcSmrg case $dst_arg in 1674a8d91dcSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1684a8d91dcSmrg esac 1694a8d91dcSmrg shift;; 17050806d53Smrg 1714a8d91dcSmrg -T) is_target_a_directory=never;; 17250806d53Smrg 17350806d53Smrg --version) echo "$0 $scriptversion"; exit $?;; 17450806d53Smrg 1754a8d91dcSmrg --) shift 1764a8d91dcSmrg break;; 1777965d9acSmrg 1784a8d91dcSmrg -*) echo "$0: invalid option: $1" >&2 1794a8d91dcSmrg exit 1;; 1807965d9acSmrg 1817965d9acSmrg *) break;; 18250806d53Smrg esac 1837965d9acSmrg shift 18450806d53Smrgdone 18550806d53Smrg 1864a8d91dcSmrg# We allow the use of options -d and -T together, by making -d 1874a8d91dcSmrg# take the precedence; this is for compatibility with GNU install. 1884a8d91dcSmrg 1894a8d91dcSmrgif test -n "$dir_arg"; then 1904a8d91dcSmrg if test -n "$dst_arg"; then 1914a8d91dcSmrg echo "$0: target directory not allowed when installing a directory." >&2 1924a8d91dcSmrg exit 1 1934a8d91dcSmrg fi 1944a8d91dcSmrgfi 1954a8d91dcSmrg 1967965d9acSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1977965d9acSmrg # When -d is used, all remaining arguments are directories to create. 1987965d9acSmrg # When -t is used, the destination is already specified. 1997965d9acSmrg # Otherwise, the last argument is the destination. Remove it from $@. 2007965d9acSmrg for arg 2017965d9acSmrg do 2027965d9acSmrg if test -n "$dst_arg"; then 2037965d9acSmrg # $@ is not empty: it contains at least $arg. 2047965d9acSmrg set fnord "$@" "$dst_arg" 2057965d9acSmrg shift # fnord 2067965d9acSmrg fi 2077965d9acSmrg shift # arg 2087965d9acSmrg dst_arg=$arg 2094a8d91dcSmrg # Protect names problematic for 'test' and other utilities. 210a73423d7Smrg case $dst_arg in 211a73423d7Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212a73423d7Smrg esac 2137965d9acSmrg done 2147965d9acSmrgfi 2157965d9acSmrg 2167965d9acSmrgif test $# -eq 0; then 21750806d53Smrg if test -z "$dir_arg"; then 21850806d53Smrg echo "$0: no input file specified." >&2 21950806d53Smrg exit 1 22050806d53Smrg fi 2214a8d91dcSmrg # It's OK to call 'install-sh -d' without argument. 22250806d53Smrg # This can happen when creating conditional directories. 22350806d53Smrg exit 0 22450806d53Smrgfi 22550806d53Smrg 2264a8d91dcSmrgif test -z "$dir_arg"; then 2274a8d91dcSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2284a8d91dcSmrg if test ! -d "$dst_arg"; then 2294a8d91dcSmrg echo "$0: $dst_arg: Is not a directory." >&2 2304a8d91dcSmrg exit 1 2314a8d91dcSmrg fi 2324a8d91dcSmrg fi 2334a8d91dcSmrgfi 2344a8d91dcSmrg 2357965d9acSmrgif test -z "$dir_arg"; then 236a73423d7Smrg do_exit='(exit $ret); exit $ret' 237a73423d7Smrg trap "ret=129; $do_exit" 1 238a73423d7Smrg trap "ret=130; $do_exit" 2 239a73423d7Smrg trap "ret=141; $do_exit" 13 240a73423d7Smrg trap "ret=143; $do_exit" 15 2417965d9acSmrg 2427965d9acSmrg # Set umask so as not to create temps with too-generous modes. 2437965d9acSmrg # However, 'strip' requires both read and write access to temps. 2447965d9acSmrg case $mode in 2457965d9acSmrg # Optimize common cases. 2467965d9acSmrg *644) cp_umask=133;; 2477965d9acSmrg *755) cp_umask=22;; 2487965d9acSmrg 2497965d9acSmrg *[0-7]) 2507965d9acSmrg if test -z "$stripcmd"; then 2514a8d91dcSmrg u_plus_rw= 2527965d9acSmrg else 2534a8d91dcSmrg u_plus_rw='% 200' 2547965d9acSmrg fi 2557965d9acSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2567965d9acSmrg *) 2577965d9acSmrg if test -z "$stripcmd"; then 2584a8d91dcSmrg u_plus_rw= 2597965d9acSmrg else 2604a8d91dcSmrg u_plus_rw=,u+rw 2617965d9acSmrg fi 2627965d9acSmrg cp_umask=$mode$u_plus_rw;; 2637965d9acSmrg esac 2647965d9acSmrgfi 2657965d9acSmrg 26650806d53Smrgfor src 26750806d53Smrgdo 2684a8d91dcSmrg # Protect names problematic for 'test' and other utilities. 26950806d53Smrg case $src in 270a73423d7Smrg -* | [=\(\)!]) src=./$src;; 27150806d53Smrg esac 27250806d53Smrg 27350806d53Smrg if test -n "$dir_arg"; then 27450806d53Smrg dst=$src 2757965d9acSmrg dstdir=$dst 2767965d9acSmrg test -d "$dstdir" 2777965d9acSmrg dstdir_status=$? 278e9f7eabcSmrg # Don't chown directories that already exist. 279e9f7eabcSmrg if test $dstdir_status = 0; then 280e9f7eabcSmrg chowncmd="" 281e9f7eabcSmrg fi 28250806d53Smrg else 2837965d9acSmrg 28450806d53Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 28550806d53Smrg # might cause directories to be created, which would be especially bad 28650806d53Smrg # if $src (and thus $dsttmp) contains '*'. 28750806d53Smrg if test ! -f "$src" && test ! -d "$src"; then 28850806d53Smrg echo "$0: $src does not exist." >&2 28950806d53Smrg exit 1 29050806d53Smrg fi 29150806d53Smrg 2927965d9acSmrg if test -z "$dst_arg"; then 29350806d53Smrg echo "$0: no destination specified." >&2 29450806d53Smrg exit 1 29550806d53Smrg fi 2967965d9acSmrg dst=$dst_arg 29750806d53Smrg 298e9f7eabcSmrg # If destination is a directory, append the input filename. 29950806d53Smrg if test -d "$dst"; then 3004a8d91dcSmrg if test "$is_target_a_directory" = never; then 3014a8d91dcSmrg echo "$0: $dst_arg: Is a directory" >&2 3024a8d91dcSmrg exit 1 30350806d53Smrg fi 3047965d9acSmrg dstdir=$dst 305e9f7eabcSmrg dstbase=`basename "$src"` 306e9f7eabcSmrg case $dst in 307e9f7eabcSmrg */) dst=$dst$dstbase;; 308e9f7eabcSmrg *) dst=$dst/$dstbase;; 309e9f7eabcSmrg esac 3107965d9acSmrg dstdir_status=0 3117965d9acSmrg else 3124a8d91dcSmrg dstdir=`dirname "$dst"` 3137965d9acSmrg test -d "$dstdir" 3147965d9acSmrg dstdir_status=$? 31550806d53Smrg fi 31650806d53Smrg fi 31750806d53Smrg 318e9f7eabcSmrg case $dstdir in 319e9f7eabcSmrg */) dstdirslash=$dstdir;; 320e9f7eabcSmrg *) dstdirslash=$dstdir/;; 321e9f7eabcSmrg esac 322e9f7eabcSmrg 3237965d9acSmrg obsolete_mkdir_used=false 3247965d9acSmrg 3257965d9acSmrg if test $dstdir_status != 0; then 3267965d9acSmrg case $posix_mkdir in 3277965d9acSmrg '') 3284a8d91dcSmrg # With -d, create the new directory with the user-specified mode. 3294a8d91dcSmrg # Otherwise, rely on $mkdir_umask. 3304a8d91dcSmrg if test -n "$dir_arg"; then 3314a8d91dcSmrg mkdir_mode=-m$mode 3324a8d91dcSmrg else 3334a8d91dcSmrg mkdir_mode= 3344a8d91dcSmrg fi 3354a8d91dcSmrg 3364a8d91dcSmrg posix_mkdir=false 337e9f7eabcSmrg # The $RANDOM variable is not portable (e.g., dash). Use it 338e9f7eabcSmrg # here however when possible just to lower collision chance. 339e9f7eabcSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 340e9f7eabcSmrg 341e9f7eabcSmrg trap ' 342e9f7eabcSmrg ret=$? 343e9f7eabcSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 344e9f7eabcSmrg exit $ret 345e9f7eabcSmrg ' 0 346e9f7eabcSmrg 347e9f7eabcSmrg # Because "mkdir -p" follows existing symlinks and we likely work 348e9f7eabcSmrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 349e9f7eabcSmrg # directory is successfully created first before we actually test 350e9f7eabcSmrg # 'mkdir -p'. 351e9f7eabcSmrg if (umask $mkdir_umask && 352e9f7eabcSmrg $mkdirprog $mkdir_mode "$tmpdir" && 353e9f7eabcSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 354e9f7eabcSmrg then 355e9f7eabcSmrg if test -z "$dir_arg" || { 356e9f7eabcSmrg # Check for POSIX incompatibilities with -m. 357e9f7eabcSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 358e9f7eabcSmrg # other-writable bit of parent directory when it shouldn't. 359e9f7eabcSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 360e9f7eabcSmrg test_tmpdir="$tmpdir/a" 361e9f7eabcSmrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 362e9f7eabcSmrg case $ls_ld_tmpdir in 363e9f7eabcSmrg d????-?r-*) different_mode=700;; 364e9f7eabcSmrg d????-?--*) different_mode=755;; 365e9f7eabcSmrg *) false;; 366e9f7eabcSmrg esac && 367e9f7eabcSmrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 368e9f7eabcSmrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 369e9f7eabcSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 370e9f7eabcSmrg } 371e9f7eabcSmrg } 372e9f7eabcSmrg then posix_mkdir=: 373e9f7eabcSmrg fi 374e9f7eabcSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 375e9f7eabcSmrg else 376e9f7eabcSmrg # Remove any dirs left behind by ancient mkdir implementations. 377e9f7eabcSmrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 378e9f7eabcSmrg fi 379e9f7eabcSmrg trap '' 0;; 3807965d9acSmrg esac 38150806d53Smrg 3827965d9acSmrg if 3837965d9acSmrg $posix_mkdir && ( 3844a8d91dcSmrg umask $mkdir_umask && 3854a8d91dcSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3867965d9acSmrg ) 3877965d9acSmrg then : 3887965d9acSmrg else 38950806d53Smrg 390e9f7eabcSmrg # mkdir does not conform to POSIX, 3917965d9acSmrg # or it failed possibly due to a race condition. Create the 3927965d9acSmrg # directory the slow way, step by step, checking for races as we go. 39350806d53Smrg 3947965d9acSmrg case $dstdir in 3954a8d91dcSmrg /*) prefix='/';; 3964a8d91dcSmrg [-=\(\)!]*) prefix='./';; 3974a8d91dcSmrg *) prefix='';; 3987965d9acSmrg esac 39950806d53Smrg 4007965d9acSmrg oIFS=$IFS 4017965d9acSmrg IFS=/ 4024a8d91dcSmrg set -f 4037965d9acSmrg set fnord $dstdir 40450806d53Smrg shift 4054a8d91dcSmrg set +f 4067965d9acSmrg IFS=$oIFS 4077965d9acSmrg 4087965d9acSmrg prefixes= 4097965d9acSmrg 4107965d9acSmrg for d 4117965d9acSmrg do 4124a8d91dcSmrg test X"$d" = X && continue 4134a8d91dcSmrg 4144a8d91dcSmrg prefix=$prefix$d 4154a8d91dcSmrg if test -d "$prefix"; then 4164a8d91dcSmrg prefixes= 4174a8d91dcSmrg else 4184a8d91dcSmrg if $posix_mkdir; then 419e9f7eabcSmrg (umask $mkdir_umask && 4204a8d91dcSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4214a8d91dcSmrg # Don't fail if two instances are running concurrently. 4224a8d91dcSmrg test -d "$prefix" || exit 1 4234a8d91dcSmrg else 4244a8d91dcSmrg case $prefix in 4254a8d91dcSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4264a8d91dcSmrg *) qprefix=$prefix;; 4274a8d91dcSmrg esac 4284a8d91dcSmrg prefixes="$prefixes '$qprefix'" 4294a8d91dcSmrg fi 4304a8d91dcSmrg fi 4314a8d91dcSmrg prefix=$prefix/ 4327965d9acSmrg done 4337965d9acSmrg 4347965d9acSmrg if test -n "$prefixes"; then 4354a8d91dcSmrg # Don't fail if two instances are running concurrently. 4364a8d91dcSmrg (umask $mkdir_umask && 4374a8d91dcSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4384a8d91dcSmrg test -d "$dstdir" || exit 1 4394a8d91dcSmrg obsolete_mkdir_used=true 44050806d53Smrg fi 4417965d9acSmrg fi 44250806d53Smrg fi 44350806d53Smrg 44450806d53Smrg if test -n "$dir_arg"; then 4457965d9acSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4467965d9acSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4477965d9acSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4487965d9acSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44950806d53Smrg else 45050806d53Smrg 45150806d53Smrg # Make a couple of temp file names in the proper directory. 452e9f7eabcSmrg dsttmp=${dstdirslash}_inst.$$_ 453e9f7eabcSmrg rmtmp=${dstdirslash}_rm.$$_ 45450806d53Smrg 45550806d53Smrg # Trap to clean up those temp files at exit. 45650806d53Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45750806d53Smrg 45850806d53Smrg # Copy the file name to the temp name. 459e9f7eabcSmrg (umask $cp_umask && 460e9f7eabcSmrg { test -z "$stripcmd" || { 461e9f7eabcSmrg # Create $dsttmp read-write so that cp doesn't create it read-only, 462e9f7eabcSmrg # which would cause strip to fail. 463e9f7eabcSmrg if test -z "$doit"; then 464e9f7eabcSmrg : >"$dsttmp" # No need to fork-exec 'touch'. 465e9f7eabcSmrg else 466e9f7eabcSmrg $doit touch "$dsttmp" 467e9f7eabcSmrg fi 468e9f7eabcSmrg } 469e9f7eabcSmrg } && 470e9f7eabcSmrg $doit_exec $cpprog "$src" "$dsttmp") && 47150806d53Smrg 47250806d53Smrg # and set any options; do chmod last to preserve setuid bits. 47350806d53Smrg # 47450806d53Smrg # If any of these fail, we abort the whole thing. If we want to 47550806d53Smrg # ignore errors from any of these, just make sure not to ignore 47650806d53Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 47750806d53Smrg # 4787965d9acSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4797965d9acSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4807965d9acSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4817965d9acSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4827965d9acSmrg 4837965d9acSmrg # If -C, don't bother to copy if it wouldn't change the file. 4847965d9acSmrg if $copy_on_change && 4854a8d91dcSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4864a8d91dcSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4874a8d91dcSmrg set -f && 4887965d9acSmrg set X $old && old=:$2:$4:$5:$6 && 4897965d9acSmrg set X $new && new=:$2:$4:$5:$6 && 4904a8d91dcSmrg set +f && 4917965d9acSmrg test "$old" = "$new" && 4927965d9acSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4937965d9acSmrg then 4947965d9acSmrg rm -f "$dsttmp" 4957965d9acSmrg else 496e9f7eabcSmrg # If $backupsuffix is set, and the file being installed 497e9f7eabcSmrg # already exists, attempt a backup. Don't worry if it fails, 498e9f7eabcSmrg # e.g., if mv doesn't support -f. 499e9f7eabcSmrg if test -n "$backupsuffix" && test -f "$dst"; then 500e9f7eabcSmrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 501e9f7eabcSmrg fi 502e9f7eabcSmrg 5037965d9acSmrg # Rename the file to the real destination. 5047965d9acSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 5057965d9acSmrg 5067965d9acSmrg # The rename failed, perhaps because mv can't rename something else 5077965d9acSmrg # to itself, or perhaps because mv is so ancient that it does not 5087965d9acSmrg # support -f. 5097965d9acSmrg { 5104a8d91dcSmrg # Now remove or move aside any old file at destination location. 5114a8d91dcSmrg # We try this two ways since rm can't unlink itself on some 5124a8d91dcSmrg # systems and the destination file might be busy for other 5134a8d91dcSmrg # reasons. In this case, the final cleanup might fail but the new 5144a8d91dcSmrg # file should still install successfully. 5154a8d91dcSmrg { 5164a8d91dcSmrg test ! -f "$dst" || 517e9f7eabcSmrg $doit $rmcmd "$dst" 2>/dev/null || 5184a8d91dcSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 519e9f7eabcSmrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 5204a8d91dcSmrg } || 5214a8d91dcSmrg { echo "$0: cannot unlink or rename $dst" >&2 5224a8d91dcSmrg (exit 1); exit 1 5234a8d91dcSmrg } 5244a8d91dcSmrg } && 5254a8d91dcSmrg 5264a8d91dcSmrg # Now rename the file to the real destination. 5274a8d91dcSmrg $doit $mvcmd "$dsttmp" "$dst" 5287965d9acSmrg } 5297965d9acSmrg fi || exit 1 5307965d9acSmrg 5317965d9acSmrg trap '' 0 5327965d9acSmrg fi 53350806d53Smrgdone 53450806d53Smrg 53550806d53Smrg# Local variables: 536e9f7eabcSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 53750806d53Smrg# time-stamp-start: "scriptversion=" 53850806d53Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 539e9f7eabcSmrg# time-stamp-time-zone: "UTC0" 540a73423d7Smrg# time-stamp-end: "; # UTC" 54150806d53Smrg# End: 542