12c7c4e3dSmrg#!/bin/sh 22c7c4e3dSmrg# install - install a program, script, or datafile 38650bb69Smrg 4c1e8faa6Smrgscriptversion=2024-06-19.01; # UTC 58650bb69Smrg 62c7c4e3dSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 72c7c4e3dSmrg# later released in X11R6 (xc/config/util/install.sh) with the 82c7c4e3dSmrg# following copyright and license. 92c7c4e3dSmrg# 102c7c4e3dSmrg# Copyright (C) 1994 X Consortium 112c7c4e3dSmrg# 122c7c4e3dSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 132c7c4e3dSmrg# of this software and associated documentation files (the "Software"), to 142c7c4e3dSmrg# deal in the Software without restriction, including without limitation the 152c7c4e3dSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 162c7c4e3dSmrg# sell copies of the Software, and to permit persons to whom the Software is 172c7c4e3dSmrg# furnished to do so, subject to the following conditions: 182c7c4e3dSmrg# 192c7c4e3dSmrg# The above copyright notice and this permission notice shall be included in 202c7c4e3dSmrg# all copies or substantial portions of the Software. 212c7c4e3dSmrg# 222c7c4e3dSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 232c7c4e3dSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 242c7c4e3dSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 252c7c4e3dSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 262c7c4e3dSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 272c7c4e3dSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 282c7c4e3dSmrg# 292c7c4e3dSmrg# Except as contained in this notice, the name of the X Consortium shall not 302c7c4e3dSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 312c7c4e3dSmrg# ings in this Software without prior written authorization from the X Consor- 322c7c4e3dSmrg# tium. 332c7c4e3dSmrg# 342c7c4e3dSmrg# 352c7c4e3dSmrg# FSF changes to this file are in the public domain. 362c7c4e3dSmrg# 372c7c4e3dSmrg# Calling this script install-sh is preferred over install.sh, to prevent 382becc446Smrg# 'make' implicit rules from creating a file called install from it 392c7c4e3dSmrg# when there is no Makefile. 402c7c4e3dSmrg# 412c7c4e3dSmrg# This script is compatible with the BSD install script, but was written 428650bb69Smrg# from scratch. 432c7c4e3dSmrg 442becc446Smrgtab=' ' 458650bb69Smrgnl=' 468650bb69Smrg' 472becc446SmrgIFS=" $tab$nl" 482c7c4e3dSmrg 492becc446Smrg# Set DOITPROG to "echo" to test this script. 502c7c4e3dSmrg 518650bb69Smrgdoit=${DOITPROG-} 522becc446Smrgdoit_exec=${doit:-exec} 532c7c4e3dSmrg 548650bb69Smrg# Put in absolute file names if you don't have them in your path; 558650bb69Smrg# or use environment vars. 568650bb69Smrg 578650bb69Smrgchgrpprog=${CHGRPPROG-chgrp} 588650bb69Smrgchmodprog=${CHMODPROG-chmod} 598650bb69Smrgchownprog=${CHOWNPROG-chown} 608650bb69Smrgcmpprog=${CMPPROG-cmp} 618650bb69Smrgcpprog=${CPPROG-cp} 628650bb69Smrgmkdirprog=${MKDIRPROG-mkdir} 638650bb69Smrgmvprog=${MVPROG-mv} 648650bb69Smrgrmprog=${RMPROG-rm} 658650bb69Smrgstripprog=${STRIPPROG-strip} 668650bb69Smrg 678650bb69Smrgposix_mkdir= 688650bb69Smrg 698650bb69Smrg# Desired mode of installed file. 708650bb69Smrgmode=0755 718650bb69Smrg 723458e6c2Smrg# Create dirs (including intermediate dirs) using mode 755. 733458e6c2Smrg# This is like GNU 'install' as of coreutils 8.32 (2020). 743458e6c2Smrgmkdir_umask=22 753458e6c2Smrg 763458e6c2Smrgbackupsuffix= 778650bb69Smrgchgrpcmd= 788650bb69Smrgchmodcmd=$chmodprog 798650bb69Smrgchowncmd= 808650bb69Smrgmvcmd=$mvprog 818650bb69Smrgrmcmd="$rmprog -f" 828650bb69Smrgstripcmd= 832c7c4e3dSmrg 848650bb69Smrgsrc= 858650bb69Smrgdst= 868650bb69Smrgdir_arg= 878650bb69Smrgdst_arg= 882c7c4e3dSmrg 898650bb69Smrgcopy_on_change=false 902becc446Smrgis_target_a_directory=possibly 912c7c4e3dSmrg 928650bb69Smrgusage="\ 938650bb69SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 948650bb69Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 958650bb69Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 968650bb69Smrg or: $0 [OPTION]... -d DIRECTORIES... 972c7c4e3dSmrg 988650bb69SmrgIn the 1st form, copy SRCFILE to DSTFILE. 998650bb69SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1008650bb69SmrgIn the 4th, create DIRECTORIES. 1012c7c4e3dSmrg 1028650bb69SmrgOptions: 1038650bb69Smrg --help display this help and exit. 1048650bb69Smrg --version display version info and exit. 1052c7c4e3dSmrg 1068650bb69Smrg -c (ignored) 1073458e6c2Smrg -C install only if different (preserve data modification time) 1088650bb69Smrg -d create directories instead of installing files. 1098650bb69Smrg -g GROUP $chgrpprog installed files to GROUP. 1108650bb69Smrg -m MODE $chmodprog installed files to MODE. 1118650bb69Smrg -o USER $chownprog installed files to USER. 1123458e6c2Smrg -p pass -p to $cpprog. 1138650bb69Smrg -s $stripprog installed files. 1143458e6c2Smrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 1158650bb69Smrg -t DIRECTORY install into DIRECTORY. 1168650bb69Smrg -T report an error if DSTFILE is a directory. 1172c7c4e3dSmrg 1188650bb69SmrgEnvironment variables override the default commands: 1198650bb69Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1208650bb69Smrg RMPROG STRIPPROG 1213458e6c2Smrg 1223458e6c2SmrgBy default, rm is invoked with -f; when overridden with RMPROG, 1233458e6c2Smrgit's up to you to specify -f if you want it. 1243458e6c2Smrg 1253458e6c2SmrgIf -S is not specified, no backups are attempted. 1263458e6c2Smrg 127c1e8faa6SmrgReport bugs to <bug-automake@gnu.org>. 128c1e8faa6SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 129c1e8faa6SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>." 1302c7c4e3dSmrg 1318650bb69Smrgwhile test $# -ne 0; do 1328650bb69Smrg case $1 in 1338650bb69Smrg -c) ;; 1342c7c4e3dSmrg 1358650bb69Smrg -C) copy_on_change=true;; 1362c7c4e3dSmrg 1378650bb69Smrg -d) dir_arg=true;; 1382c7c4e3dSmrg 1398650bb69Smrg -g) chgrpcmd="$chgrpprog $2" 1402becc446Smrg shift;; 1412c7c4e3dSmrg 1428650bb69Smrg --help) echo "$usage"; exit $?;; 1432c7c4e3dSmrg 1448650bb69Smrg -m) mode=$2 1452becc446Smrg case $mode in 1462becc446Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1472becc446Smrg echo "$0: invalid mode: $mode" >&2 1482becc446Smrg exit 1;; 1492becc446Smrg esac 1502becc446Smrg shift;; 1512c7c4e3dSmrg 1528650bb69Smrg -o) chowncmd="$chownprog $2" 1532becc446Smrg shift;; 1542c7c4e3dSmrg 1553458e6c2Smrg -p) cpprog="$cpprog -p";; 1563458e6c2Smrg 1578650bb69Smrg -s) stripcmd=$stripprog;; 1582c7c4e3dSmrg 1593458e6c2Smrg -S) backupsuffix="$2" 1603458e6c2Smrg shift;; 1613458e6c2Smrg 1622becc446Smrg -t) 1632becc446Smrg is_target_a_directory=always 1642becc446Smrg dst_arg=$2 1652becc446Smrg # Protect names problematic for 'test' and other utilities. 1662becc446Smrg case $dst_arg in 1672becc446Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1682becc446Smrg esac 1692becc446Smrg shift;; 1702c7c4e3dSmrg 1712becc446Smrg -T) is_target_a_directory=never;; 1722c7c4e3dSmrg 173c1e8faa6Smrg --version) echo "$0 (GNU Automake) $scriptversion"; exit $?;; 1742c7c4e3dSmrg 1752becc446Smrg --) shift 1762becc446Smrg break;; 1772c7c4e3dSmrg 1782becc446Smrg -*) echo "$0: invalid option: $1" >&2 1792becc446Smrg exit 1;; 1802c7c4e3dSmrg 1818650bb69Smrg *) break;; 1828650bb69Smrg esac 1838650bb69Smrg shift 1848650bb69Smrgdone 1852c7c4e3dSmrg 1862becc446Smrg# We allow the use of options -d and -T together, by making -d 1872becc446Smrg# take the precedence; this is for compatibility with GNU install. 1882becc446Smrg 1892becc446Smrgif test -n "$dir_arg"; then 1902becc446Smrg if test -n "$dst_arg"; then 1912becc446Smrg echo "$0: target directory not allowed when installing a directory." >&2 1922becc446Smrg exit 1 1932becc446Smrg fi 1942becc446Smrgfi 1952becc446Smrg 1968650bb69Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1978650bb69Smrg # When -d is used, all remaining arguments are directories to create. 1988650bb69Smrg # When -t is used, the destination is already specified. 1998650bb69Smrg # Otherwise, the last argument is the destination. Remove it from $@. 2008650bb69Smrg for arg 2018650bb69Smrg do 2028650bb69Smrg if test -n "$dst_arg"; then 2038650bb69Smrg # $@ is not empty: it contains at least $arg. 2048650bb69Smrg set fnord "$@" "$dst_arg" 2058650bb69Smrg shift # fnord 2068650bb69Smrg fi 2078650bb69Smrg shift # arg 2088650bb69Smrg dst_arg=$arg 2092becc446Smrg # Protect names problematic for 'test' and other utilities. 2102becc446Smrg case $dst_arg in 2112becc446Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 2122becc446Smrg esac 2138650bb69Smrg done 2148650bb69Smrgfi 2152c7c4e3dSmrg 2168650bb69Smrgif test $# -eq 0; then 2178650bb69Smrg if test -z "$dir_arg"; then 2188650bb69Smrg echo "$0: no input file specified." >&2 2198650bb69Smrg exit 1 2208650bb69Smrg fi 2212becc446Smrg # It's OK to call 'install-sh -d' without argument. 2228650bb69Smrg # This can happen when creating conditional directories. 2238650bb69Smrg exit 0 2248650bb69Smrgfi 2252c7c4e3dSmrg 2268650bb69Smrgif test -z "$dir_arg"; then 2272becc446Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 2282becc446Smrg if test ! -d "$dst_arg"; then 2292becc446Smrg echo "$0: $dst_arg: Is not a directory." >&2 2302becc446Smrg exit 1 2312becc446Smrg fi 2322becc446Smrg fi 2332becc446Smrgfi 2342becc446Smrg 2352becc446Smrgif test -z "$dir_arg"; then 2362becc446Smrg do_exit='(exit $ret); exit $ret' 2372becc446Smrg trap "ret=129; $do_exit" 1 2382becc446Smrg trap "ret=130; $do_exit" 2 2392becc446Smrg trap "ret=141; $do_exit" 13 2402becc446Smrg trap "ret=143; $do_exit" 15 2418650bb69Smrg 2428650bb69Smrg # Set umask so as not to create temps with too-generous modes. 2438650bb69Smrg # However, 'strip' requires both read and write access to temps. 2448650bb69Smrg case $mode in 2458650bb69Smrg # Optimize common cases. 2468650bb69Smrg *644) cp_umask=133;; 2478650bb69Smrg *755) cp_umask=22;; 2488650bb69Smrg 2498650bb69Smrg *[0-7]) 2508650bb69Smrg if test -z "$stripcmd"; then 2512becc446Smrg u_plus_rw= 2528650bb69Smrg else 2532becc446Smrg u_plus_rw='% 200' 2548650bb69Smrg fi 2558650bb69Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2568650bb69Smrg *) 2578650bb69Smrg if test -z "$stripcmd"; then 2582becc446Smrg u_plus_rw= 2598650bb69Smrg else 2602becc446Smrg u_plus_rw=,u+rw 2618650bb69Smrg fi 2628650bb69Smrg cp_umask=$mode$u_plus_rw;; 2638650bb69Smrg esac 2648650bb69Smrgfi 2652c7c4e3dSmrg 2668650bb69Smrgfor src 2678650bb69Smrgdo 2682becc446Smrg # Protect names problematic for 'test' and other utilities. 2698650bb69Smrg case $src in 2702becc446Smrg -* | [=\(\)!]) src=./$src;; 2718650bb69Smrg esac 2728650bb69Smrg 2738650bb69Smrg if test -n "$dir_arg"; then 2748650bb69Smrg dst=$src 2758650bb69Smrg dstdir=$dst 2768650bb69Smrg test -d "$dstdir" 2778650bb69Smrg dstdir_status=$? 2783458e6c2Smrg # Don't chown directories that already exist. 2793458e6c2Smrg if test $dstdir_status = 0; then 2803458e6c2Smrg chowncmd="" 2813458e6c2Smrg fi 2828650bb69Smrg else 2838650bb69Smrg 2848650bb69Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2858650bb69Smrg # might cause directories to be created, which would be especially bad 2868650bb69Smrg # if $src (and thus $dsttmp) contains '*'. 2878650bb69Smrg if test ! -f "$src" && test ! -d "$src"; then 2888650bb69Smrg echo "$0: $src does not exist." >&2 2898650bb69Smrg exit 1 2908650bb69Smrg fi 2918650bb69Smrg 2928650bb69Smrg if test -z "$dst_arg"; then 2938650bb69Smrg echo "$0: no destination specified." >&2 2948650bb69Smrg exit 1 2958650bb69Smrg fi 2968650bb69Smrg dst=$dst_arg 2972c7c4e3dSmrg 2983458e6c2Smrg # If destination is a directory, append the input filename. 2998650bb69Smrg if test -d "$dst"; then 3002becc446Smrg if test "$is_target_a_directory" = never; then 3012becc446Smrg echo "$0: $dst_arg: Is a directory" >&2 3022becc446Smrg exit 1 3038650bb69Smrg fi 3048650bb69Smrg dstdir=$dst 3053458e6c2Smrg dstbase=`basename "$src"` 3063458e6c2Smrg case $dst in 3073458e6c2Smrg */) dst=$dst$dstbase;; 3083458e6c2Smrg *) dst=$dst/$dstbase;; 3093458e6c2Smrg esac 3108650bb69Smrg dstdir_status=0 3118650bb69Smrg else 3122becc446Smrg dstdir=`dirname "$dst"` 3138650bb69Smrg test -d "$dstdir" 3148650bb69Smrg dstdir_status=$? 3158650bb69Smrg fi 3168650bb69Smrg fi 3178650bb69Smrg 3183458e6c2Smrg case $dstdir in 3193458e6c2Smrg */) dstdirslash=$dstdir;; 3203458e6c2Smrg *) dstdirslash=$dstdir/;; 3213458e6c2Smrg esac 3223458e6c2Smrg 3238650bb69Smrg obsolete_mkdir_used=false 3248650bb69Smrg 3258650bb69Smrg if test $dstdir_status != 0; then 3268650bb69Smrg case $posix_mkdir in 3278650bb69Smrg '') 3282becc446Smrg # With -d, create the new directory with the user-specified mode. 3292becc446Smrg # Otherwise, rely on $mkdir_umask. 3302becc446Smrg if test -n "$dir_arg"; then 3312becc446Smrg mkdir_mode=-m$mode 3322becc446Smrg else 3332becc446Smrg mkdir_mode= 3342becc446Smrg fi 3352becc446Smrg 3362becc446Smrg posix_mkdir=false 3373458e6c2Smrg # The $RANDOM variable is not portable (e.g., dash). Use it 3383458e6c2Smrg # here however when possible just to lower collision chance. 3393458e6c2Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3403458e6c2Smrg 3413458e6c2Smrg trap ' 3423458e6c2Smrg ret=$? 3433458e6c2Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 3443458e6c2Smrg exit $ret 3453458e6c2Smrg ' 0 3463458e6c2Smrg 3473458e6c2Smrg # Because "mkdir -p" follows existing symlinks and we likely work 348c1e8faa6Smrg # directly in world-writable /tmp, make sure that the '$tmpdir' 3493458e6c2Smrg # directory is successfully created first before we actually test 3503458e6c2Smrg # 'mkdir -p'. 3513458e6c2Smrg if (umask $mkdir_umask && 3523458e6c2Smrg $mkdirprog $mkdir_mode "$tmpdir" && 3533458e6c2Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 3543458e6c2Smrg then 3553458e6c2Smrg if test -z "$dir_arg" || { 356c1e8faa6Smrg # Check for POSIX incompatibility with -m. 3573458e6c2Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3583458e6c2Smrg # other-writable bit of parent directory when it shouldn't. 3593458e6c2Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3603458e6c2Smrg test_tmpdir="$tmpdir/a" 3613458e6c2Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 3623458e6c2Smrg case $ls_ld_tmpdir in 3633458e6c2Smrg d????-?r-*) different_mode=700;; 3643458e6c2Smrg d????-?--*) different_mode=755;; 3653458e6c2Smrg *) false;; 3663458e6c2Smrg esac && 3673458e6c2Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 3683458e6c2Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 3693458e6c2Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3703458e6c2Smrg } 3713458e6c2Smrg } 3723458e6c2Smrg then posix_mkdir=: 3733458e6c2Smrg fi 3743458e6c2Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 3753458e6c2Smrg else 3763458e6c2Smrg # Remove any dirs left behind by ancient mkdir implementations. 3773458e6c2Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 3783458e6c2Smrg fi 3793458e6c2Smrg trap '' 0;; 3808650bb69Smrg esac 3812c7c4e3dSmrg 3828650bb69Smrg if 3838650bb69Smrg $posix_mkdir && ( 3842becc446Smrg umask $mkdir_umask && 3852becc446Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3868650bb69Smrg ) 3878650bb69Smrg then : 3888650bb69Smrg else 3898650bb69Smrg 3903458e6c2Smrg # mkdir does not conform to POSIX, 3918650bb69Smrg # or it failed possibly due to a race condition. Create the 3928650bb69Smrg # directory the slow way, step by step, checking for races as we go. 3938650bb69Smrg 3948650bb69Smrg case $dstdir in 3952becc446Smrg /*) prefix='/';; 3962becc446Smrg [-=\(\)!]*) prefix='./';; 3972becc446Smrg *) prefix='';; 3988650bb69Smrg esac 3998650bb69Smrg 4008650bb69Smrg oIFS=$IFS 4018650bb69Smrg IFS=/ 4022becc446Smrg set -f 4038650bb69Smrg set fnord $dstdir 4048650bb69Smrg shift 4052becc446Smrg set +f 4068650bb69Smrg IFS=$oIFS 4078650bb69Smrg 4088650bb69Smrg prefixes= 4098650bb69Smrg 4108650bb69Smrg for d 4118650bb69Smrg do 4122becc446Smrg test X"$d" = X && continue 4132becc446Smrg 4142becc446Smrg prefix=$prefix$d 4152becc446Smrg if test -d "$prefix"; then 4162becc446Smrg prefixes= 4172becc446Smrg else 4182becc446Smrg if $posix_mkdir; then 4193458e6c2Smrg (umask $mkdir_umask && 4202becc446Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4212becc446Smrg # Don't fail if two instances are running concurrently. 4222becc446Smrg test -d "$prefix" || exit 1 4232becc446Smrg else 4242becc446Smrg case $prefix in 4252becc446Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4262becc446Smrg *) qprefix=$prefix;; 4272becc446Smrg esac 4282becc446Smrg prefixes="$prefixes '$qprefix'" 4292becc446Smrg fi 4302becc446Smrg fi 4312becc446Smrg prefix=$prefix/ 4328650bb69Smrg done 4338650bb69Smrg 4348650bb69Smrg if test -n "$prefixes"; then 4352becc446Smrg # Don't fail if two instances are running concurrently. 4362becc446Smrg (umask $mkdir_umask && 4372becc446Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4382becc446Smrg test -d "$dstdir" || exit 1 4392becc446Smrg obsolete_mkdir_used=true 4408650bb69Smrg fi 4418650bb69Smrg fi 4428650bb69Smrg fi 4438650bb69Smrg 4448650bb69Smrg if test -n "$dir_arg"; then 4458650bb69Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4468650bb69Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4478650bb69Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4488650bb69Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4498650bb69Smrg else 4508650bb69Smrg 4518650bb69Smrg # Make a couple of temp file names in the proper directory. 4523458e6c2Smrg dsttmp=${dstdirslash}_inst.$$_ 4533458e6c2Smrg rmtmp=${dstdirslash}_rm.$$_ 4548650bb69Smrg 4558650bb69Smrg # Trap to clean up those temp files at exit. 4568650bb69Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4578650bb69Smrg 4588650bb69Smrg # Copy the file name to the temp name. 4593458e6c2Smrg (umask $cp_umask && 4603458e6c2Smrg { test -z "$stripcmd" || { 4613458e6c2Smrg # Create $dsttmp read-write so that cp doesn't create it read-only, 4623458e6c2Smrg # which would cause strip to fail. 4633458e6c2Smrg if test -z "$doit"; then 4643458e6c2Smrg : >"$dsttmp" # No need to fork-exec 'touch'. 4653458e6c2Smrg else 4663458e6c2Smrg $doit touch "$dsttmp" 4673458e6c2Smrg fi 4683458e6c2Smrg } 4693458e6c2Smrg } && 4703458e6c2Smrg $doit_exec $cpprog "$src" "$dsttmp") && 4718650bb69Smrg 4728650bb69Smrg # and set any options; do chmod last to preserve setuid bits. 4738650bb69Smrg # 4748650bb69Smrg # If any of these fail, we abort the whole thing. If we want to 4758650bb69Smrg # ignore errors from any of these, just make sure not to ignore 4768650bb69Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4778650bb69Smrg # 4788650bb69Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4798650bb69Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4808650bb69Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4818650bb69Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4828650bb69Smrg 4838650bb69Smrg # If -C, don't bother to copy if it wouldn't change the file. 4848650bb69Smrg if $copy_on_change && 4852becc446Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4862becc446Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4872becc446Smrg set -f && 4888650bb69Smrg set X $old && old=:$2:$4:$5:$6 && 4898650bb69Smrg set X $new && new=:$2:$4:$5:$6 && 4902becc446Smrg set +f && 4918650bb69Smrg test "$old" = "$new" && 4928650bb69Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4938650bb69Smrg then 4948650bb69Smrg rm -f "$dsttmp" 4958650bb69Smrg else 4963458e6c2Smrg # If $backupsuffix is set, and the file being installed 4973458e6c2Smrg # already exists, attempt a backup. Don't worry if it fails, 4983458e6c2Smrg # e.g., if mv doesn't support -f. 4993458e6c2Smrg if test -n "$backupsuffix" && test -f "$dst"; then 5003458e6c2Smrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 5013458e6c2Smrg fi 5023458e6c2Smrg 5038650bb69Smrg # Rename the file to the real destination. 5048650bb69Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 5058650bb69Smrg 5068650bb69Smrg # The rename failed, perhaps because mv can't rename something else 5078650bb69Smrg # to itself, or perhaps because mv is so ancient that it does not 5088650bb69Smrg # support -f. 5098650bb69Smrg { 5102becc446Smrg # Now remove or move aside any old file at destination location. 5112becc446Smrg # We try this two ways since rm can't unlink itself on some 5122becc446Smrg # systems and the destination file might be busy for other 5132becc446Smrg # reasons. In this case, the final cleanup might fail but the new 5142becc446Smrg # file should still install successfully. 5152becc446Smrg { 5162becc446Smrg test ! -f "$dst" || 5173458e6c2Smrg $doit $rmcmd "$dst" 2>/dev/null || 5182becc446Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5193458e6c2Smrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 5202becc446Smrg } || 5212becc446Smrg { echo "$0: cannot unlink or rename $dst" >&2 5222becc446Smrg (exit 1); exit 1 5232becc446Smrg } 5242becc446Smrg } && 5252becc446Smrg 5262becc446Smrg # Now rename the file to the real destination. 5272becc446Smrg $doit $mvcmd "$dsttmp" "$dst" 5288650bb69Smrg } 5298650bb69Smrg fi || exit 1 5308650bb69Smrg 5318650bb69Smrg trap '' 0 5328650bb69Smrg fi 5338650bb69Smrgdone 5342c7c4e3dSmrg 5358650bb69Smrg# Local variables: 5363458e6c2Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 5378650bb69Smrg# time-stamp-start: "scriptversion=" 5388650bb69Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5393458e6c2Smrg# time-stamp-time-zone: "UTC0" 5408650bb69Smrg# time-stamp-end: "; # UTC" 5418650bb69Smrg# End: 542