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