1bd1da9d7Smrg#!/bin/sh 2bd1da9d7Smrg# install - install a program, script, or datafile 3bd1da9d7Smrg 46ad5a0e2Smrgscriptversion=2020-11-14.01; # UTC 5bd1da9d7Smrg 6bd1da9d7Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7bd1da9d7Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8bd1da9d7Smrg# following copyright and license. 9bd1da9d7Smrg# 10bd1da9d7Smrg# Copyright (C) 1994 X Consortium 11bd1da9d7Smrg# 12bd1da9d7Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13bd1da9d7Smrg# of this software and associated documentation files (the "Software"), to 14bd1da9d7Smrg# deal in the Software without restriction, including without limitation the 15bd1da9d7Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16bd1da9d7Smrg# sell copies of the Software, and to permit persons to whom the Software is 17bd1da9d7Smrg# furnished to do so, subject to the following conditions: 18bd1da9d7Smrg# 19bd1da9d7Smrg# The above copyright notice and this permission notice shall be included in 20bd1da9d7Smrg# all copies or substantial portions of the Software. 21bd1da9d7Smrg# 22bd1da9d7Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23bd1da9d7Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24bd1da9d7Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25bd1da9d7Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26bd1da9d7Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27bd1da9d7Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28bd1da9d7Smrg# 29bd1da9d7Smrg# Except as contained in this notice, the name of the X Consortium shall not 30bd1da9d7Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31bd1da9d7Smrg# ings in this Software without prior written authorization from the X Consor- 32bd1da9d7Smrg# tium. 33bd1da9d7Smrg# 34bd1da9d7Smrg# 35bd1da9d7Smrg# FSF changes to this file are in the public domain. 36bd1da9d7Smrg# 37bd1da9d7Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38899129b3Smrg# 'make' implicit rules from creating a file called install from it 39bd1da9d7Smrg# when there is no Makefile. 40bd1da9d7Smrg# 41bd1da9d7Smrg# This script is compatible with the BSD install script, but was written 425bcb6992Smrg# from scratch. 435bcb6992Smrg 44e6d2e958Smrgtab=' ' 455bcb6992Smrgnl=' 465bcb6992Smrg' 47e6d2e958SmrgIFS=" $tab$nl" 48bd1da9d7Smrg 49e6d2e958Smrg# Set DOITPROG to "echo" to test this script. 50bd1da9d7Smrg 515bcb6992Smrgdoit=${DOITPROG-} 52e6d2e958Smrgdoit_exec=${doit:-exec} 53bd1da9d7Smrg 545bcb6992Smrg# Put in absolute file names if you don't have them in your path; 555bcb6992Smrg# or use environment vars. 565bcb6992Smrg 575bcb6992Smrgchgrpprog=${CHGRPPROG-chgrp} 585bcb6992Smrgchmodprog=${CHMODPROG-chmod} 595bcb6992Smrgchownprog=${CHOWNPROG-chown} 605bcb6992Smrgcmpprog=${CMPPROG-cmp} 615bcb6992Smrgcpprog=${CPPROG-cp} 625bcb6992Smrgmkdirprog=${MKDIRPROG-mkdir} 635bcb6992Smrgmvprog=${MVPROG-mv} 645bcb6992Smrgrmprog=${RMPROG-rm} 655bcb6992Smrgstripprog=${STRIPPROG-strip} 665bcb6992Smrg 675bcb6992Smrgposix_mkdir= 685bcb6992Smrg 695bcb6992Smrg# Desired mode of installed file. 705bcb6992Smrgmode=0755 71bd1da9d7Smrg 726ad5a0e2Smrg# Create dirs (including intermediate dirs) using mode 755. 736ad5a0e2Smrg# This is like GNU 'install' as of coreutils 8.32 (2020). 746ad5a0e2Smrgmkdir_umask=22 756ad5a0e2Smrg 766ad5a0e2Smrgbackupsuffix= 77bd1da9d7Smrgchgrpcmd= 785bcb6992Smrgchmodcmd=$chmodprog 795bcb6992Smrgchowncmd= 805bcb6992Smrgmvcmd=$mvprog 81bd1da9d7Smrgrmcmd="$rmprog -f" 825bcb6992Smrgstripcmd= 835bcb6992Smrg 84bd1da9d7Smrgsrc= 85bd1da9d7Smrgdst= 86bd1da9d7Smrgdir_arg= 875bcb6992Smrgdst_arg= 885bcb6992Smrg 895bcb6992Smrgcopy_on_change=false 90e6d2e958Smrgis_target_a_directory=possibly 91bd1da9d7Smrg 925bcb6992Smrgusage="\ 935bcb6992SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 94bd1da9d7Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 95bd1da9d7Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 96bd1da9d7Smrg or: $0 [OPTION]... -d DIRECTORIES... 97bd1da9d7Smrg 98bd1da9d7SmrgIn the 1st form, copy SRCFILE to DSTFILE. 99bd1da9d7SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 100bd1da9d7SmrgIn the 4th, create DIRECTORIES. 101bd1da9d7Smrg 102bd1da9d7SmrgOptions: 1035bcb6992Smrg --help display this help and exit. 1045bcb6992Smrg --version display version info and exit. 1055bcb6992Smrg 1065bcb6992Smrg -c (ignored) 1076ad5a0e2Smrg -C install only if different (preserve data modification time) 1085bcb6992Smrg -d create directories instead of installing files. 1095bcb6992Smrg -g GROUP $chgrpprog installed files to GROUP. 1105bcb6992Smrg -m MODE $chmodprog installed files to MODE. 1115bcb6992Smrg -o USER $chownprog installed files to USER. 1126ad5a0e2Smrg -p pass -p to $cpprog. 1135bcb6992Smrg -s $stripprog installed files. 1146ad5a0e2Smrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 1155bcb6992Smrg -t DIRECTORY install into DIRECTORY. 1165bcb6992Smrg -T report an error if DSTFILE is a directory. 117bd1da9d7Smrg 118bd1da9d7SmrgEnvironment variables override the default commands: 1195bcb6992Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1205bcb6992Smrg RMPROG STRIPPROG 1216ad5a0e2Smrg 1226ad5a0e2SmrgBy default, rm is invoked with -f; when overridden with RMPROG, 1236ad5a0e2Smrgit's up to you to specify -f if you want it. 1246ad5a0e2Smrg 1256ad5a0e2SmrgIf -S is not specified, no backups are attempted. 1266ad5a0e2Smrg 1276ad5a0e2SmrgEmail bug reports to bug-automake@gnu.org. 1286ad5a0e2SmrgAutomake home page: https://www.gnu.org/software/automake/ 129bd1da9d7Smrg" 130bd1da9d7Smrg 1315bcb6992Smrgwhile test $# -ne 0; do 132bd1da9d7Smrg case $1 in 1335bcb6992Smrg -c) ;; 1345bcb6992Smrg 1355bcb6992Smrg -C) copy_on_change=true;; 136bd1da9d7Smrg 1375bcb6992Smrg -d) dir_arg=true;; 138bd1da9d7Smrg 139bd1da9d7Smrg -g) chgrpcmd="$chgrpprog $2" 140e6d2e958Smrg shift;; 141bd1da9d7Smrg 142bd1da9d7Smrg --help) echo "$usage"; exit $?;; 143bd1da9d7Smrg 1445bcb6992Smrg -m) mode=$2 145e6d2e958Smrg case $mode in 146e6d2e958Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 147e6d2e958Smrg echo "$0: invalid mode: $mode" >&2 148e6d2e958Smrg exit 1;; 149e6d2e958Smrg esac 150e6d2e958Smrg shift;; 151bd1da9d7Smrg 152bd1da9d7Smrg -o) chowncmd="$chownprog $2" 153e6d2e958Smrg shift;; 154bd1da9d7Smrg 1556ad5a0e2Smrg -p) cpprog="$cpprog -p";; 1566ad5a0e2Smrg 1575bcb6992Smrg -s) stripcmd=$stripprog;; 158bd1da9d7Smrg 1596ad5a0e2Smrg -S) backupsuffix="$2" 1606ad5a0e2Smrg shift;; 1616ad5a0e2Smrg 162e6d2e958Smrg -t) 163e6d2e958Smrg is_target_a_directory=always 164e6d2e958Smrg dst_arg=$2 165e6d2e958Smrg # Protect names problematic for 'test' and other utilities. 166e6d2e958Smrg case $dst_arg in 167e6d2e958Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 168e6d2e958Smrg esac 169e6d2e958Smrg shift;; 170bd1da9d7Smrg 171e6d2e958Smrg -T) is_target_a_directory=never;; 172bd1da9d7Smrg 173bd1da9d7Smrg --version) echo "$0 $scriptversion"; exit $?;; 174bd1da9d7Smrg 175e6d2e958Smrg --) shift 176e6d2e958Smrg break;; 1775bcb6992Smrg 178e6d2e958Smrg -*) echo "$0: invalid option: $1" >&2 179e6d2e958Smrg exit 1;; 1805bcb6992Smrg 1815bcb6992Smrg *) break;; 182bd1da9d7Smrg esac 1835bcb6992Smrg shift 184bd1da9d7Smrgdone 185bd1da9d7Smrg 186e6d2e958Smrg# We allow the use of options -d and -T together, by making -d 187e6d2e958Smrg# take the precedence; this is for compatibility with GNU install. 188e6d2e958Smrg 189e6d2e958Smrgif test -n "$dir_arg"; then 190e6d2e958Smrg if test -n "$dst_arg"; then 191e6d2e958Smrg echo "$0: target directory not allowed when installing a directory." >&2 192e6d2e958Smrg exit 1 193e6d2e958Smrg fi 194e6d2e958Smrgfi 195e6d2e958Smrg 1965bcb6992Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1975bcb6992Smrg # When -d is used, all remaining arguments are directories to create. 1985bcb6992Smrg # When -t is used, the destination is already specified. 1995bcb6992Smrg # Otherwise, the last argument is the destination. Remove it from $@. 2005bcb6992Smrg for arg 2015bcb6992Smrg do 2025bcb6992Smrg if test -n "$dst_arg"; then 2035bcb6992Smrg # $@ is not empty: it contains at least $arg. 2045bcb6992Smrg set fnord "$@" "$dst_arg" 2055bcb6992Smrg shift # fnord 2065bcb6992Smrg fi 2075bcb6992Smrg shift # arg 2085bcb6992Smrg dst_arg=$arg 209899129b3Smrg # Protect names problematic for 'test' and other utilities. 210899129b3Smrg case $dst_arg in 211899129b3Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212899129b3Smrg esac 2135bcb6992Smrg done 2145bcb6992Smrgfi 2155bcb6992Smrg 2165bcb6992Smrgif test $# -eq 0; then 217bd1da9d7Smrg if test -z "$dir_arg"; then 218bd1da9d7Smrg echo "$0: no input file specified." >&2 219bd1da9d7Smrg exit 1 220bd1da9d7Smrg fi 221899129b3Smrg # It's OK to call 'install-sh -d' without argument. 222bd1da9d7Smrg # This can happen when creating conditional directories. 223bd1da9d7Smrg exit 0 224bd1da9d7Smrgfi 225bd1da9d7Smrg 226e6d2e958Smrgif test -z "$dir_arg"; then 227e6d2e958Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 228e6d2e958Smrg if test ! -d "$dst_arg"; then 229e6d2e958Smrg echo "$0: $dst_arg: Is not a directory." >&2 230e6d2e958Smrg exit 1 231e6d2e958Smrg fi 232e6d2e958Smrg fi 233e6d2e958Smrgfi 234e6d2e958Smrg 2355bcb6992Smrgif test -z "$dir_arg"; then 236899129b3Smrg do_exit='(exit $ret); exit $ret' 237899129b3Smrg trap "ret=129; $do_exit" 1 238899129b3Smrg trap "ret=130; $do_exit" 2 239899129b3Smrg trap "ret=141; $do_exit" 13 240899129b3Smrg trap "ret=143; $do_exit" 15 2415bcb6992Smrg 2425bcb6992Smrg # Set umask so as not to create temps with too-generous modes. 2435bcb6992Smrg # However, 'strip' requires both read and write access to temps. 2445bcb6992Smrg case $mode in 2455bcb6992Smrg # Optimize common cases. 2465bcb6992Smrg *644) cp_umask=133;; 2475bcb6992Smrg *755) cp_umask=22;; 2485bcb6992Smrg 2495bcb6992Smrg *[0-7]) 2505bcb6992Smrg if test -z "$stripcmd"; then 251e6d2e958Smrg u_plus_rw= 2525bcb6992Smrg else 253e6d2e958Smrg u_plus_rw='% 200' 2545bcb6992Smrg fi 2555bcb6992Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2565bcb6992Smrg *) 2575bcb6992Smrg if test -z "$stripcmd"; then 258e6d2e958Smrg u_plus_rw= 2595bcb6992Smrg else 260e6d2e958Smrg u_plus_rw=,u+rw 2615bcb6992Smrg fi 2625bcb6992Smrg cp_umask=$mode$u_plus_rw;; 2635bcb6992Smrg esac 2645bcb6992Smrgfi 2655bcb6992Smrg 266bd1da9d7Smrgfor src 267bd1da9d7Smrgdo 268899129b3Smrg # Protect names problematic for 'test' and other utilities. 269bd1da9d7Smrg case $src in 270899129b3Smrg -* | [=\(\)!]) src=./$src;; 271bd1da9d7Smrg esac 272bd1da9d7Smrg 273bd1da9d7Smrg if test -n "$dir_arg"; then 274bd1da9d7Smrg dst=$src 2755bcb6992Smrg dstdir=$dst 2765bcb6992Smrg test -d "$dstdir" 2775bcb6992Smrg dstdir_status=$? 2786ad5a0e2Smrg # Don't chown directories that already exist. 2796ad5a0e2Smrg if test $dstdir_status = 0; then 2806ad5a0e2Smrg chowncmd="" 2816ad5a0e2Smrg fi 282bd1da9d7Smrg else 2835bcb6992Smrg 284bd1da9d7Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 285bd1da9d7Smrg # might cause directories to be created, which would be especially bad 286bd1da9d7Smrg # if $src (and thus $dsttmp) contains '*'. 287bd1da9d7Smrg if test ! -f "$src" && test ! -d "$src"; then 288bd1da9d7Smrg echo "$0: $src does not exist." >&2 289bd1da9d7Smrg exit 1 290bd1da9d7Smrg fi 291bd1da9d7Smrg 2925bcb6992Smrg if test -z "$dst_arg"; then 293bd1da9d7Smrg echo "$0: no destination specified." >&2 294bd1da9d7Smrg exit 1 295bd1da9d7Smrg fi 2965bcb6992Smrg dst=$dst_arg 297bd1da9d7Smrg 2986ad5a0e2Smrg # If destination is a directory, append the input filename. 299bd1da9d7Smrg if test -d "$dst"; then 300e6d2e958Smrg if test "$is_target_a_directory" = never; then 301e6d2e958Smrg echo "$0: $dst_arg: Is a directory" >&2 302e6d2e958Smrg exit 1 303bd1da9d7Smrg fi 3045bcb6992Smrg dstdir=$dst 3056ad5a0e2Smrg dstbase=`basename "$src"` 3066ad5a0e2Smrg case $dst in 3076ad5a0e2Smrg */) dst=$dst$dstbase;; 3086ad5a0e2Smrg *) dst=$dst/$dstbase;; 3096ad5a0e2Smrg esac 3105bcb6992Smrg dstdir_status=0 3115bcb6992Smrg else 312e6d2e958Smrg dstdir=`dirname "$dst"` 3135bcb6992Smrg test -d "$dstdir" 3145bcb6992Smrg dstdir_status=$? 315bd1da9d7Smrg fi 316bd1da9d7Smrg fi 317bd1da9d7Smrg 3186ad5a0e2Smrg case $dstdir in 3196ad5a0e2Smrg */) dstdirslash=$dstdir;; 3206ad5a0e2Smrg *) dstdirslash=$dstdir/;; 3216ad5a0e2Smrg esac 3226ad5a0e2Smrg 3235bcb6992Smrg obsolete_mkdir_used=false 3245bcb6992Smrg 3255bcb6992Smrg if test $dstdir_status != 0; then 3265bcb6992Smrg case $posix_mkdir in 3275bcb6992Smrg '') 328e6d2e958Smrg # With -d, create the new directory with the user-specified mode. 329e6d2e958Smrg # Otherwise, rely on $mkdir_umask. 330e6d2e958Smrg if test -n "$dir_arg"; then 331e6d2e958Smrg mkdir_mode=-m$mode 332e6d2e958Smrg else 333e6d2e958Smrg mkdir_mode= 334e6d2e958Smrg fi 335e6d2e958Smrg 336e6d2e958Smrg posix_mkdir=false 3376ad5a0e2Smrg # The $RANDOM variable is not portable (e.g., dash). Use it 3386ad5a0e2Smrg # here however when possible just to lower collision chance. 3396ad5a0e2Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3406ad5a0e2Smrg 3416ad5a0e2Smrg trap ' 3426ad5a0e2Smrg ret=$? 3436ad5a0e2Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 3446ad5a0e2Smrg exit $ret 3456ad5a0e2Smrg ' 0 3466ad5a0e2Smrg 3476ad5a0e2Smrg # Because "mkdir -p" follows existing symlinks and we likely work 3486ad5a0e2Smrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 3496ad5a0e2Smrg # directory is successfully created first before we actually test 3506ad5a0e2Smrg # 'mkdir -p'. 3516ad5a0e2Smrg if (umask $mkdir_umask && 3526ad5a0e2Smrg $mkdirprog $mkdir_mode "$tmpdir" && 3536ad5a0e2Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 3546ad5a0e2Smrg then 3556ad5a0e2Smrg if test -z "$dir_arg" || { 3566ad5a0e2Smrg # Check for POSIX incompatibilities with -m. 3576ad5a0e2Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3586ad5a0e2Smrg # other-writable bit of parent directory when it shouldn't. 3596ad5a0e2Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3606ad5a0e2Smrg test_tmpdir="$tmpdir/a" 3616ad5a0e2Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 3626ad5a0e2Smrg case $ls_ld_tmpdir in 3636ad5a0e2Smrg d????-?r-*) different_mode=700;; 3646ad5a0e2Smrg d????-?--*) different_mode=755;; 3656ad5a0e2Smrg *) false;; 3666ad5a0e2Smrg esac && 3676ad5a0e2Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 3686ad5a0e2Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 3696ad5a0e2Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3706ad5a0e2Smrg } 3716ad5a0e2Smrg } 3726ad5a0e2Smrg then posix_mkdir=: 3736ad5a0e2Smrg fi 3746ad5a0e2Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 3756ad5a0e2Smrg else 3766ad5a0e2Smrg # Remove any dirs left behind by ancient mkdir implementations. 3776ad5a0e2Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 3786ad5a0e2Smrg fi 3796ad5a0e2Smrg trap '' 0;; 3805bcb6992Smrg esac 381bd1da9d7Smrg 3825bcb6992Smrg if 3835bcb6992Smrg $posix_mkdir && ( 384e6d2e958Smrg umask $mkdir_umask && 385e6d2e958Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3865bcb6992Smrg ) 3875bcb6992Smrg then : 3885bcb6992Smrg else 389bd1da9d7Smrg 3906ad5a0e2Smrg # mkdir does not conform to POSIX, 3915bcb6992Smrg # or it failed possibly due to a race condition. Create the 3925bcb6992Smrg # directory the slow way, step by step, checking for races as we go. 393bd1da9d7Smrg 3945bcb6992Smrg case $dstdir in 395e6d2e958Smrg /*) prefix='/';; 396e6d2e958Smrg [-=\(\)!]*) prefix='./';; 397e6d2e958Smrg *) prefix='';; 3985bcb6992Smrg esac 399bd1da9d7Smrg 4005bcb6992Smrg oIFS=$IFS 4015bcb6992Smrg IFS=/ 402e6d2e958Smrg set -f 4035bcb6992Smrg set fnord $dstdir 404bd1da9d7Smrg shift 405e6d2e958Smrg set +f 4065bcb6992Smrg IFS=$oIFS 4075bcb6992Smrg 4085bcb6992Smrg prefixes= 4095bcb6992Smrg 4105bcb6992Smrg for d 4115bcb6992Smrg do 412e6d2e958Smrg test X"$d" = X && continue 413e6d2e958Smrg 414e6d2e958Smrg prefix=$prefix$d 415e6d2e958Smrg if test -d "$prefix"; then 416e6d2e958Smrg prefixes= 417e6d2e958Smrg else 418e6d2e958Smrg if $posix_mkdir; then 4196ad5a0e2Smrg (umask $mkdir_umask && 420e6d2e958Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 421e6d2e958Smrg # Don't fail if two instances are running concurrently. 422e6d2e958Smrg test -d "$prefix" || exit 1 423e6d2e958Smrg else 424e6d2e958Smrg case $prefix in 425e6d2e958Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 426e6d2e958Smrg *) qprefix=$prefix;; 427e6d2e958Smrg esac 428e6d2e958Smrg prefixes="$prefixes '$qprefix'" 429e6d2e958Smrg fi 430e6d2e958Smrg fi 431e6d2e958Smrg prefix=$prefix/ 4325bcb6992Smrg done 4335bcb6992Smrg 4345bcb6992Smrg if test -n "$prefixes"; then 435e6d2e958Smrg # Don't fail if two instances are running concurrently. 436e6d2e958Smrg (umask $mkdir_umask && 437e6d2e958Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 438e6d2e958Smrg test -d "$dstdir" || exit 1 439e6d2e958Smrg obsolete_mkdir_used=true 440bd1da9d7Smrg fi 4415bcb6992Smrg fi 442bd1da9d7Smrg fi 443bd1da9d7Smrg 444bd1da9d7Smrg if test -n "$dir_arg"; then 4455bcb6992Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4465bcb6992Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4475bcb6992Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4485bcb6992Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 449bd1da9d7Smrg else 450bd1da9d7Smrg 451bd1da9d7Smrg # Make a couple of temp file names in the proper directory. 4526ad5a0e2Smrg dsttmp=${dstdirslash}_inst.$$_ 4536ad5a0e2Smrg rmtmp=${dstdirslash}_rm.$$_ 454bd1da9d7Smrg 455bd1da9d7Smrg # Trap to clean up those temp files at exit. 456bd1da9d7Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 457bd1da9d7Smrg 458bd1da9d7Smrg # Copy the file name to the temp name. 4596ad5a0e2Smrg (umask $cp_umask && 4606ad5a0e2Smrg { test -z "$stripcmd" || { 4616ad5a0e2Smrg # Create $dsttmp read-write so that cp doesn't create it read-only, 4626ad5a0e2Smrg # which would cause strip to fail. 4636ad5a0e2Smrg if test -z "$doit"; then 4646ad5a0e2Smrg : >"$dsttmp" # No need to fork-exec 'touch'. 4656ad5a0e2Smrg else 4666ad5a0e2Smrg $doit touch "$dsttmp" 4676ad5a0e2Smrg fi 4686ad5a0e2Smrg } 4696ad5a0e2Smrg } && 4706ad5a0e2Smrg $doit_exec $cpprog "$src" "$dsttmp") && 471bd1da9d7Smrg 472bd1da9d7Smrg # and set any options; do chmod last to preserve setuid bits. 473bd1da9d7Smrg # 474bd1da9d7Smrg # If any of these fail, we abort the whole thing. If we want to 475bd1da9d7Smrg # ignore errors from any of these, just make sure not to ignore 476bd1da9d7Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 477bd1da9d7Smrg # 4785bcb6992Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4795bcb6992Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4805bcb6992Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4815bcb6992Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4825bcb6992Smrg 4835bcb6992Smrg # If -C, don't bother to copy if it wouldn't change the file. 4845bcb6992Smrg if $copy_on_change && 485e6d2e958Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 486e6d2e958Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 487e6d2e958Smrg set -f && 4885bcb6992Smrg set X $old && old=:$2:$4:$5:$6 && 4895bcb6992Smrg set X $new && new=:$2:$4:$5:$6 && 490e6d2e958Smrg set +f && 4915bcb6992Smrg test "$old" = "$new" && 4925bcb6992Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4935bcb6992Smrg then 4945bcb6992Smrg rm -f "$dsttmp" 4955bcb6992Smrg else 4966ad5a0e2Smrg # If $backupsuffix is set, and the file being installed 4976ad5a0e2Smrg # already exists, attempt a backup. Don't worry if it fails, 4986ad5a0e2Smrg # e.g., if mv doesn't support -f. 4996ad5a0e2Smrg if test -n "$backupsuffix" && test -f "$dst"; then 5006ad5a0e2Smrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 5016ad5a0e2Smrg fi 5026ad5a0e2Smrg 5035bcb6992Smrg # Rename the file to the real destination. 5045bcb6992Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 5055bcb6992Smrg 5065bcb6992Smrg # The rename failed, perhaps because mv can't rename something else 5075bcb6992Smrg # to itself, or perhaps because mv is so ancient that it does not 5085bcb6992Smrg # support -f. 5095bcb6992Smrg { 510e6d2e958Smrg # Now remove or move aside any old file at destination location. 511e6d2e958Smrg # We try this two ways since rm can't unlink itself on some 512e6d2e958Smrg # systems and the destination file might be busy for other 513e6d2e958Smrg # reasons. In this case, the final cleanup might fail but the new 514e6d2e958Smrg # file should still install successfully. 515e6d2e958Smrg { 516e6d2e958Smrg test ! -f "$dst" || 5176ad5a0e2Smrg $doit $rmcmd "$dst" 2>/dev/null || 518e6d2e958Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5196ad5a0e2Smrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 520e6d2e958Smrg } || 521e6d2e958Smrg { echo "$0: cannot unlink or rename $dst" >&2 522e6d2e958Smrg (exit 1); exit 1 523e6d2e958Smrg } 524e6d2e958Smrg } && 525e6d2e958Smrg 526e6d2e958Smrg # Now rename the file to the real destination. 527e6d2e958Smrg $doit $mvcmd "$dsttmp" "$dst" 5285bcb6992Smrg } 5295bcb6992Smrg fi || exit 1 5305bcb6992Smrg 5315bcb6992Smrg trap '' 0 5325bcb6992Smrg fi 533bd1da9d7Smrgdone 534bd1da9d7Smrg 535bd1da9d7Smrg# Local variables: 5366ad5a0e2Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 537bd1da9d7Smrg# time-stamp-start: "scriptversion=" 538bd1da9d7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5396ad5a0e2Smrg# time-stamp-time-zone: "UTC0" 5405bcb6992Smrg# time-stamp-end: "; # UTC" 541bd1da9d7Smrg# End: 542