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