1bb068e1dSmrg#!/bin/sh 2bb068e1dSmrg# install - install a program, script, or datafile 3bb068e1dSmrg 4bb068e1dSmrgscriptversion=2020-11-14.01; # UTC 5bb068e1dSmrg 6bb068e1dSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7bb068e1dSmrg# later released in X11R6 (xc/config/util/install.sh) with the 8bb068e1dSmrg# following copyright and license. 9bb068e1dSmrg# 10bb068e1dSmrg# Copyright (C) 1994 X Consortium 11bb068e1dSmrg# 12bb068e1dSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13bb068e1dSmrg# of this software and associated documentation files (the "Software"), to 14bb068e1dSmrg# deal in the Software without restriction, including without limitation the 15bb068e1dSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16bb068e1dSmrg# sell copies of the Software, and to permit persons to whom the Software is 17bb068e1dSmrg# furnished to do so, subject to the following conditions: 18bb068e1dSmrg# 19bb068e1dSmrg# The above copyright notice and this permission notice shall be included in 20bb068e1dSmrg# all copies or substantial portions of the Software. 21bb068e1dSmrg# 22bb068e1dSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23bb068e1dSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24bb068e1dSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25bb068e1dSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26bb068e1dSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27bb068e1dSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28bb068e1dSmrg# 29bb068e1dSmrg# Except as contained in this notice, the name of the X Consortium shall not 30bb068e1dSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 31bb068e1dSmrg# ings in this Software without prior written authorization from the X Consor- 32bb068e1dSmrg# tium. 33bb068e1dSmrg# 34bb068e1dSmrg# 35bb068e1dSmrg# FSF changes to this file are in the public domain. 36bb068e1dSmrg# 37bb068e1dSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38bb068e1dSmrg# 'make' implicit rules from creating a file called install from it 39bb068e1dSmrg# when there is no Makefile. 40bb068e1dSmrg# 41bb068e1dSmrg# This script is compatible with the BSD install script, but was written 42bb068e1dSmrg# from scratch. 43bb068e1dSmrg 44bb068e1dSmrgtab=' ' 45bb068e1dSmrgnl=' 46bb068e1dSmrg' 47bb068e1dSmrgIFS=" $tab$nl" 48bb068e1dSmrg 49bb068e1dSmrg# Set DOITPROG to "echo" to test this script. 50bb068e1dSmrg 51bb068e1dSmrgdoit=${DOITPROG-} 52bb068e1dSmrgdoit_exec=${doit:-exec} 53bb068e1dSmrg 54bb068e1dSmrg# Put in absolute file names if you don't have them in your path; 55bb068e1dSmrg# or use environment vars. 56bb068e1dSmrg 57bb068e1dSmrgchgrpprog=${CHGRPPROG-chgrp} 58bb068e1dSmrgchmodprog=${CHMODPROG-chmod} 59bb068e1dSmrgchownprog=${CHOWNPROG-chown} 60bb068e1dSmrgcmpprog=${CMPPROG-cmp} 61bb068e1dSmrgcpprog=${CPPROG-cp} 62bb068e1dSmrgmkdirprog=${MKDIRPROG-mkdir} 63bb068e1dSmrgmvprog=${MVPROG-mv} 64bb068e1dSmrgrmprog=${RMPROG-rm} 65bb068e1dSmrgstripprog=${STRIPPROG-strip} 66bb068e1dSmrg 67bb068e1dSmrgposix_mkdir= 68bb068e1dSmrg 69bb068e1dSmrg# Desired mode of installed file. 70bb068e1dSmrgmode=0755 71bb068e1dSmrg 72bb068e1dSmrg# Create dirs (including intermediate dirs) using mode 755. 73bb068e1dSmrg# This is like GNU 'install' as of coreutils 8.32 (2020). 74bb068e1dSmrgmkdir_umask=22 75bb068e1dSmrg 76bb068e1dSmrgbackupsuffix= 77bb068e1dSmrgchgrpcmd= 78bb068e1dSmrgchmodcmd=$chmodprog 79bb068e1dSmrgchowncmd= 80bb068e1dSmrgmvcmd=$mvprog 81bb068e1dSmrgrmcmd="$rmprog -f" 82bb068e1dSmrgstripcmd= 83bb068e1dSmrg 84bb068e1dSmrgsrc= 85bb068e1dSmrgdst= 86bb068e1dSmrgdir_arg= 87bb068e1dSmrgdst_arg= 88bb068e1dSmrg 89bb068e1dSmrgcopy_on_change=false 90bb068e1dSmrgis_target_a_directory=possibly 91bb068e1dSmrg 92bb068e1dSmrgusage="\ 93bb068e1dSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 94bb068e1dSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 95bb068e1dSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 96bb068e1dSmrg or: $0 [OPTION]... -d DIRECTORIES... 97bb068e1dSmrg 98bb068e1dSmrgIn the 1st form, copy SRCFILE to DSTFILE. 99bb068e1dSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 100bb068e1dSmrgIn the 4th, create DIRECTORIES. 101bb068e1dSmrg 102bb068e1dSmrgOptions: 103bb068e1dSmrg --help display this help and exit. 104bb068e1dSmrg --version display version info and exit. 105bb068e1dSmrg 106bb068e1dSmrg -c (ignored) 107bb068e1dSmrg -C install only if different (preserve data modification time) 108bb068e1dSmrg -d create directories instead of installing files. 109bb068e1dSmrg -g GROUP $chgrpprog installed files to GROUP. 110bb068e1dSmrg -m MODE $chmodprog installed files to MODE. 111bb068e1dSmrg -o USER $chownprog installed files to USER. 112bb068e1dSmrg -p pass -p to $cpprog. 113bb068e1dSmrg -s $stripprog installed files. 114bb068e1dSmrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 115bb068e1dSmrg -t DIRECTORY install into DIRECTORY. 116bb068e1dSmrg -T report an error if DSTFILE is a directory. 117bb068e1dSmrg 118bb068e1dSmrgEnvironment variables override the default commands: 119bb068e1dSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 120bb068e1dSmrg RMPROG STRIPPROG 121bb068e1dSmrg 122bb068e1dSmrgBy default, rm is invoked with -f; when overridden with RMPROG, 123bb068e1dSmrgit's up to you to specify -f if you want it. 124bb068e1dSmrg 125bb068e1dSmrgIf -S is not specified, no backups are attempted. 126bb068e1dSmrg 127bb068e1dSmrgEmail bug reports to bug-automake@gnu.org. 128bb068e1dSmrgAutomake home page: https://www.gnu.org/software/automake/ 129bb068e1dSmrg" 130bb068e1dSmrg 131bb068e1dSmrgwhile test $# -ne 0; do 132bb068e1dSmrg case $1 in 133bb068e1dSmrg -c) ;; 134bb068e1dSmrg 135bb068e1dSmrg -C) copy_on_change=true;; 136bb068e1dSmrg 137bb068e1dSmrg -d) dir_arg=true;; 138bb068e1dSmrg 139bb068e1dSmrg -g) chgrpcmd="$chgrpprog $2" 140bb068e1dSmrg shift;; 141bb068e1dSmrg 142bb068e1dSmrg --help) echo "$usage"; exit $?;; 143bb068e1dSmrg 144bb068e1dSmrg -m) mode=$2 145bb068e1dSmrg case $mode in 146bb068e1dSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 147bb068e1dSmrg echo "$0: invalid mode: $mode" >&2 148bb068e1dSmrg exit 1;; 149bb068e1dSmrg esac 150bb068e1dSmrg shift;; 151bb068e1dSmrg 152bb068e1dSmrg -o) chowncmd="$chownprog $2" 153bb068e1dSmrg shift;; 154bb068e1dSmrg 155bb068e1dSmrg -p) cpprog="$cpprog -p";; 156bb068e1dSmrg 157bb068e1dSmrg -s) stripcmd=$stripprog;; 158bb068e1dSmrg 159bb068e1dSmrg -S) backupsuffix="$2" 160bb068e1dSmrg shift;; 161bb068e1dSmrg 162bb068e1dSmrg -t) 163bb068e1dSmrg is_target_a_directory=always 164bb068e1dSmrg dst_arg=$2 165bb068e1dSmrg # Protect names problematic for 'test' and other utilities. 166bb068e1dSmrg case $dst_arg in 167bb068e1dSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 168bb068e1dSmrg esac 169bb068e1dSmrg shift;; 170bb068e1dSmrg 171bb068e1dSmrg -T) is_target_a_directory=never;; 172bb068e1dSmrg 173bb068e1dSmrg --version) echo "$0 $scriptversion"; exit $?;; 174bb068e1dSmrg 175bb068e1dSmrg --) shift 176bb068e1dSmrg break;; 177bb068e1dSmrg 178bb068e1dSmrg -*) echo "$0: invalid option: $1" >&2 179bb068e1dSmrg exit 1;; 180bb068e1dSmrg 181bb068e1dSmrg *) break;; 182bb068e1dSmrg esac 183bb068e1dSmrg shift 184bb068e1dSmrgdone 185bb068e1dSmrg 186bb068e1dSmrg# We allow the use of options -d and -T together, by making -d 187bb068e1dSmrg# take the precedence; this is for compatibility with GNU install. 188bb068e1dSmrg 189bb068e1dSmrgif test -n "$dir_arg"; then 190bb068e1dSmrg if test -n "$dst_arg"; then 191bb068e1dSmrg echo "$0: target directory not allowed when installing a directory." >&2 192bb068e1dSmrg exit 1 193bb068e1dSmrg fi 194bb068e1dSmrgfi 195bb068e1dSmrg 196bb068e1dSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 197bb068e1dSmrg # When -d is used, all remaining arguments are directories to create. 198bb068e1dSmrg # When -t is used, the destination is already specified. 199bb068e1dSmrg # Otherwise, the last argument is the destination. Remove it from $@. 200bb068e1dSmrg for arg 201bb068e1dSmrg do 202bb068e1dSmrg if test -n "$dst_arg"; then 203bb068e1dSmrg # $@ is not empty: it contains at least $arg. 204bb068e1dSmrg set fnord "$@" "$dst_arg" 205bb068e1dSmrg shift # fnord 206bb068e1dSmrg fi 207bb068e1dSmrg shift # arg 208bb068e1dSmrg dst_arg=$arg 209bb068e1dSmrg # Protect names problematic for 'test' and other utilities. 210bb068e1dSmrg case $dst_arg in 211bb068e1dSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212bb068e1dSmrg esac 213bb068e1dSmrg done 214bb068e1dSmrgfi 215bb068e1dSmrg 216bb068e1dSmrgif test $# -eq 0; then 217bb068e1dSmrg if test -z "$dir_arg"; then 218bb068e1dSmrg echo "$0: no input file specified." >&2 219bb068e1dSmrg exit 1 220bb068e1dSmrg fi 221bb068e1dSmrg # It's OK to call 'install-sh -d' without argument. 222bb068e1dSmrg # This can happen when creating conditional directories. 223bb068e1dSmrg exit 0 224bb068e1dSmrgfi 225bb068e1dSmrg 226bb068e1dSmrgif test -z "$dir_arg"; then 227bb068e1dSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 228bb068e1dSmrg if test ! -d "$dst_arg"; then 229bb068e1dSmrg echo "$0: $dst_arg: Is not a directory." >&2 230bb068e1dSmrg exit 1 231bb068e1dSmrg fi 232bb068e1dSmrg fi 233bb068e1dSmrgfi 234bb068e1dSmrg 235bb068e1dSmrgif test -z "$dir_arg"; then 236bb068e1dSmrg do_exit='(exit $ret); exit $ret' 237bb068e1dSmrg trap "ret=129; $do_exit" 1 238bb068e1dSmrg trap "ret=130; $do_exit" 2 239bb068e1dSmrg trap "ret=141; $do_exit" 13 240bb068e1dSmrg trap "ret=143; $do_exit" 15 241bb068e1dSmrg 242bb068e1dSmrg # Set umask so as not to create temps with too-generous modes. 243bb068e1dSmrg # However, 'strip' requires both read and write access to temps. 244bb068e1dSmrg case $mode in 245bb068e1dSmrg # Optimize common cases. 246bb068e1dSmrg *644) cp_umask=133;; 247bb068e1dSmrg *755) cp_umask=22;; 248bb068e1dSmrg 249bb068e1dSmrg *[0-7]) 250bb068e1dSmrg if test -z "$stripcmd"; then 251bb068e1dSmrg u_plus_rw= 252bb068e1dSmrg else 253bb068e1dSmrg u_plus_rw='% 200' 254bb068e1dSmrg fi 255bb068e1dSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 256bb068e1dSmrg *) 257bb068e1dSmrg if test -z "$stripcmd"; then 258bb068e1dSmrg u_plus_rw= 259bb068e1dSmrg else 260bb068e1dSmrg u_plus_rw=,u+rw 261bb068e1dSmrg fi 262bb068e1dSmrg cp_umask=$mode$u_plus_rw;; 263bb068e1dSmrg esac 264bb068e1dSmrgfi 265bb068e1dSmrg 266bb068e1dSmrgfor src 267bb068e1dSmrgdo 268bb068e1dSmrg # Protect names problematic for 'test' and other utilities. 269bb068e1dSmrg case $src in 270bb068e1dSmrg -* | [=\(\)!]) src=./$src;; 271bb068e1dSmrg esac 272bb068e1dSmrg 273bb068e1dSmrg if test -n "$dir_arg"; then 274bb068e1dSmrg dst=$src 275bb068e1dSmrg dstdir=$dst 276bb068e1dSmrg test -d "$dstdir" 277bb068e1dSmrg dstdir_status=$? 278bb068e1dSmrg # Don't chown directories that already exist. 279bb068e1dSmrg if test $dstdir_status = 0; then 280bb068e1dSmrg chowncmd="" 281bb068e1dSmrg fi 282bb068e1dSmrg else 283bb068e1dSmrg 284bb068e1dSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 285bb068e1dSmrg # might cause directories to be created, which would be especially bad 286bb068e1dSmrg # if $src (and thus $dsttmp) contains '*'. 287bb068e1dSmrg if test ! -f "$src" && test ! -d "$src"; then 288bb068e1dSmrg echo "$0: $src does not exist." >&2 289bb068e1dSmrg exit 1 290bb068e1dSmrg fi 291bb068e1dSmrg 292bb068e1dSmrg if test -z "$dst_arg"; then 293bb068e1dSmrg echo "$0: no destination specified." >&2 294bb068e1dSmrg exit 1 295bb068e1dSmrg fi 296bb068e1dSmrg dst=$dst_arg 297bb068e1dSmrg 298bb068e1dSmrg # If destination is a directory, append the input filename. 299bb068e1dSmrg if test -d "$dst"; then 300bb068e1dSmrg if test "$is_target_a_directory" = never; then 301bb068e1dSmrg echo "$0: $dst_arg: Is a directory" >&2 302bb068e1dSmrg exit 1 303bb068e1dSmrg fi 304bb068e1dSmrg dstdir=$dst 305bb068e1dSmrg dstbase=`basename "$src"` 306bb068e1dSmrg case $dst in 307bb068e1dSmrg */) dst=$dst$dstbase;; 308bb068e1dSmrg *) dst=$dst/$dstbase;; 309bb068e1dSmrg esac 310bb068e1dSmrg dstdir_status=0 311bb068e1dSmrg else 312bb068e1dSmrg dstdir=`dirname "$dst"` 313bb068e1dSmrg test -d "$dstdir" 314bb068e1dSmrg dstdir_status=$? 315bb068e1dSmrg fi 316bb068e1dSmrg fi 317bb068e1dSmrg 318bb068e1dSmrg case $dstdir in 319bb068e1dSmrg */) dstdirslash=$dstdir;; 320bb068e1dSmrg *) dstdirslash=$dstdir/;; 321bb068e1dSmrg esac 322bb068e1dSmrg 323bb068e1dSmrg obsolete_mkdir_used=false 324bb068e1dSmrg 325bb068e1dSmrg if test $dstdir_status != 0; then 326bb068e1dSmrg case $posix_mkdir in 327bb068e1dSmrg '') 328bb068e1dSmrg # With -d, create the new directory with the user-specified mode. 329bb068e1dSmrg # Otherwise, rely on $mkdir_umask. 330bb068e1dSmrg if test -n "$dir_arg"; then 331bb068e1dSmrg mkdir_mode=-m$mode 332bb068e1dSmrg else 333bb068e1dSmrg mkdir_mode= 334bb068e1dSmrg fi 335bb068e1dSmrg 336bb068e1dSmrg posix_mkdir=false 337bb068e1dSmrg # The $RANDOM variable is not portable (e.g., dash). Use it 338bb068e1dSmrg # here however when possible just to lower collision chance. 339bb068e1dSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 340bb068e1dSmrg 341bb068e1dSmrg trap ' 342bb068e1dSmrg ret=$? 343bb068e1dSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 344bb068e1dSmrg exit $ret 345bb068e1dSmrg ' 0 346bb068e1dSmrg 347bb068e1dSmrg # Because "mkdir -p" follows existing symlinks and we likely work 348bb068e1dSmrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 349bb068e1dSmrg # directory is successfully created first before we actually test 350bb068e1dSmrg # 'mkdir -p'. 351bb068e1dSmrg if (umask $mkdir_umask && 352bb068e1dSmrg $mkdirprog $mkdir_mode "$tmpdir" && 353bb068e1dSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 354bb068e1dSmrg then 355bb068e1dSmrg if test -z "$dir_arg" || { 356bb068e1dSmrg # Check for POSIX incompatibilities with -m. 357bb068e1dSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 358bb068e1dSmrg # other-writable bit of parent directory when it shouldn't. 359bb068e1dSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 360bb068e1dSmrg test_tmpdir="$tmpdir/a" 361bb068e1dSmrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 362bb068e1dSmrg case $ls_ld_tmpdir in 363bb068e1dSmrg d????-?r-*) different_mode=700;; 364bb068e1dSmrg d????-?--*) different_mode=755;; 365bb068e1dSmrg *) false;; 366bb068e1dSmrg esac && 367bb068e1dSmrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 368bb068e1dSmrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 369bb068e1dSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 370bb068e1dSmrg } 371bb068e1dSmrg } 372bb068e1dSmrg then posix_mkdir=: 373bb068e1dSmrg fi 374bb068e1dSmrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 375bb068e1dSmrg else 376bb068e1dSmrg # Remove any dirs left behind by ancient mkdir implementations. 377bb068e1dSmrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 378bb068e1dSmrg fi 379bb068e1dSmrg trap '' 0;; 380bb068e1dSmrg esac 381bb068e1dSmrg 382bb068e1dSmrg if 383bb068e1dSmrg $posix_mkdir && ( 384bb068e1dSmrg umask $mkdir_umask && 385bb068e1dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 386bb068e1dSmrg ) 387bb068e1dSmrg then : 388bb068e1dSmrg else 389bb068e1dSmrg 390bb068e1dSmrg # mkdir does not conform to POSIX, 391bb068e1dSmrg # or it failed possibly due to a race condition. Create the 392bb068e1dSmrg # directory the slow way, step by step, checking for races as we go. 393bb068e1dSmrg 394bb068e1dSmrg case $dstdir in 395bb068e1dSmrg /*) prefix='/';; 396bb068e1dSmrg [-=\(\)!]*) prefix='./';; 397bb068e1dSmrg *) prefix='';; 398bb068e1dSmrg esac 399bb068e1dSmrg 400bb068e1dSmrg oIFS=$IFS 401bb068e1dSmrg IFS=/ 402bb068e1dSmrg set -f 403bb068e1dSmrg set fnord $dstdir 404bb068e1dSmrg shift 405bb068e1dSmrg set +f 406bb068e1dSmrg IFS=$oIFS 407bb068e1dSmrg 408bb068e1dSmrg prefixes= 409bb068e1dSmrg 410bb068e1dSmrg for d 411bb068e1dSmrg do 412bb068e1dSmrg test X"$d" = X && continue 413bb068e1dSmrg 414bb068e1dSmrg prefix=$prefix$d 415bb068e1dSmrg if test -d "$prefix"; then 416bb068e1dSmrg prefixes= 417bb068e1dSmrg else 418bb068e1dSmrg if $posix_mkdir; then 419bb068e1dSmrg (umask $mkdir_umask && 420bb068e1dSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 421bb068e1dSmrg # Don't fail if two instances are running concurrently. 422bb068e1dSmrg test -d "$prefix" || exit 1 423bb068e1dSmrg else 424bb068e1dSmrg case $prefix in 425bb068e1dSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 426bb068e1dSmrg *) qprefix=$prefix;; 427bb068e1dSmrg esac 428bb068e1dSmrg prefixes="$prefixes '$qprefix'" 429bb068e1dSmrg fi 430bb068e1dSmrg fi 431bb068e1dSmrg prefix=$prefix/ 432bb068e1dSmrg done 433bb068e1dSmrg 434bb068e1dSmrg if test -n "$prefixes"; then 435bb068e1dSmrg # Don't fail if two instances are running concurrently. 436bb068e1dSmrg (umask $mkdir_umask && 437bb068e1dSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 438bb068e1dSmrg test -d "$dstdir" || exit 1 439bb068e1dSmrg obsolete_mkdir_used=true 440bb068e1dSmrg fi 441bb068e1dSmrg fi 442bb068e1dSmrg fi 443bb068e1dSmrg 444bb068e1dSmrg if test -n "$dir_arg"; then 445bb068e1dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 446bb068e1dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 447bb068e1dSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 448bb068e1dSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 449bb068e1dSmrg else 450bb068e1dSmrg 451bb068e1dSmrg # Make a couple of temp file names in the proper directory. 452bb068e1dSmrg dsttmp=${dstdirslash}_inst.$$_ 453bb068e1dSmrg rmtmp=${dstdirslash}_rm.$$_ 454bb068e1dSmrg 455bb068e1dSmrg # Trap to clean up those temp files at exit. 456bb068e1dSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 457bb068e1dSmrg 458bb068e1dSmrg # Copy the file name to the temp name. 459bb068e1dSmrg (umask $cp_umask && 460bb068e1dSmrg { test -z "$stripcmd" || { 461bb068e1dSmrg # Create $dsttmp read-write so that cp doesn't create it read-only, 462bb068e1dSmrg # which would cause strip to fail. 463bb068e1dSmrg if test -z "$doit"; then 464bb068e1dSmrg : >"$dsttmp" # No need to fork-exec 'touch'. 465bb068e1dSmrg else 466bb068e1dSmrg $doit touch "$dsttmp" 467bb068e1dSmrg fi 468bb068e1dSmrg } 469bb068e1dSmrg } && 470bb068e1dSmrg $doit_exec $cpprog "$src" "$dsttmp") && 471bb068e1dSmrg 472bb068e1dSmrg # and set any options; do chmod last to preserve setuid bits. 473bb068e1dSmrg # 474bb068e1dSmrg # If any of these fail, we abort the whole thing. If we want to 475bb068e1dSmrg # ignore errors from any of these, just make sure not to ignore 476bb068e1dSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 477bb068e1dSmrg # 478bb068e1dSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 479bb068e1dSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 480bb068e1dSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 481bb068e1dSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 482bb068e1dSmrg 483bb068e1dSmrg # If -C, don't bother to copy if it wouldn't change the file. 484bb068e1dSmrg if $copy_on_change && 485bb068e1dSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 486bb068e1dSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 487bb068e1dSmrg set -f && 488bb068e1dSmrg set X $old && old=:$2:$4:$5:$6 && 489bb068e1dSmrg set X $new && new=:$2:$4:$5:$6 && 490bb068e1dSmrg set +f && 491bb068e1dSmrg test "$old" = "$new" && 492bb068e1dSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 493bb068e1dSmrg then 494bb068e1dSmrg rm -f "$dsttmp" 495bb068e1dSmrg else 496bb068e1dSmrg # If $backupsuffix is set, and the file being installed 497bb068e1dSmrg # already exists, attempt a backup. Don't worry if it fails, 498bb068e1dSmrg # e.g., if mv doesn't support -f. 499bb068e1dSmrg if test -n "$backupsuffix" && test -f "$dst"; then 500bb068e1dSmrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 501bb068e1dSmrg fi 502bb068e1dSmrg 503bb068e1dSmrg # Rename the file to the real destination. 504bb068e1dSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 505bb068e1dSmrg 506bb068e1dSmrg # The rename failed, perhaps because mv can't rename something else 507bb068e1dSmrg # to itself, or perhaps because mv is so ancient that it does not 508bb068e1dSmrg # support -f. 509bb068e1dSmrg { 510bb068e1dSmrg # Now remove or move aside any old file at destination location. 511bb068e1dSmrg # We try this two ways since rm can't unlink itself on some 512bb068e1dSmrg # systems and the destination file might be busy for other 513bb068e1dSmrg # reasons. In this case, the final cleanup might fail but the new 514bb068e1dSmrg # file should still install successfully. 515bb068e1dSmrg { 516bb068e1dSmrg test ! -f "$dst" || 517bb068e1dSmrg $doit $rmcmd "$dst" 2>/dev/null || 518bb068e1dSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 519bb068e1dSmrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 520bb068e1dSmrg } || 521bb068e1dSmrg { echo "$0: cannot unlink or rename $dst" >&2 522bb068e1dSmrg (exit 1); exit 1 523bb068e1dSmrg } 524bb068e1dSmrg } && 525bb068e1dSmrg 526bb068e1dSmrg # Now rename the file to the real destination. 527bb068e1dSmrg $doit $mvcmd "$dsttmp" "$dst" 528bb068e1dSmrg } 529bb068e1dSmrg fi || exit 1 530bb068e1dSmrg 531bb068e1dSmrg trap '' 0 532bb068e1dSmrg fi 533bb068e1dSmrgdone 534bb068e1dSmrg 535bb068e1dSmrg# Local variables: 536bb068e1dSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 537bb068e1dSmrg# time-stamp-start: "scriptversion=" 538bb068e1dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 539bb068e1dSmrg# time-stamp-time-zone: "UTC0" 540bb068e1dSmrg# time-stamp-end: "; # UTC" 541bb068e1dSmrg# End: 542