18b22bf3fSmrg#!/bin/sh 28b22bf3fSmrg# install - install a program, script, or datafile 38b22bf3fSmrg 414cde9d3Smrgscriptversion=2020-11-14.01; # UTC 58b22bf3fSmrg 68b22bf3fSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 78b22bf3fSmrg# later released in X11R6 (xc/config/util/install.sh) with the 88b22bf3fSmrg# following copyright and license. 98b22bf3fSmrg# 108b22bf3fSmrg# Copyright (C) 1994 X Consortium 118b22bf3fSmrg# 128b22bf3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 138b22bf3fSmrg# of this software and associated documentation files (the "Software"), to 148b22bf3fSmrg# deal in the Software without restriction, including without limitation the 158b22bf3fSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168b22bf3fSmrg# sell copies of the Software, and to permit persons to whom the Software is 178b22bf3fSmrg# furnished to do so, subject to the following conditions: 188b22bf3fSmrg# 198b22bf3fSmrg# The above copyright notice and this permission notice shall be included in 208b22bf3fSmrg# all copies or substantial portions of the Software. 218b22bf3fSmrg# 228b22bf3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238b22bf3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 248b22bf3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 258b22bf3fSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 268b22bf3fSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 278b22bf3fSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 288b22bf3fSmrg# 298b22bf3fSmrg# Except as contained in this notice, the name of the X Consortium shall not 308b22bf3fSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 318b22bf3fSmrg# ings in this Software without prior written authorization from the X Consor- 328b22bf3fSmrg# tium. 338b22bf3fSmrg# 348b22bf3fSmrg# 358b22bf3fSmrg# FSF changes to this file are in the public domain. 368b22bf3fSmrg# 378b22bf3fSmrg# Calling this script install-sh is preferred over install.sh, to prevent 38f126e068Smrg# 'make' implicit rules from creating a file called install from it 398b22bf3fSmrg# when there is no Makefile. 408b22bf3fSmrg# 418b22bf3fSmrg# This script is compatible with the BSD install script, but was written 428b22bf3fSmrg# from scratch. 438b22bf3fSmrg 44c74b14bdSmrgtab=' ' 458b22bf3fSmrgnl=' 468b22bf3fSmrg' 47c74b14bdSmrgIFS=" $tab$nl" 488b22bf3fSmrg 49c74b14bdSmrg# Set DOITPROG to "echo" to test this script. 508b22bf3fSmrg 5196a81b41Smrgdoit=${DOITPROG-} 52c74b14bdSmrgdoit_exec=${doit:-exec} 538b22bf3fSmrg 548b22bf3fSmrg# Put in absolute file names if you don't have them in your path; 558b22bf3fSmrg# or use environment vars. 568b22bf3fSmrg 5796a81b41Smrgchgrpprog=${CHGRPPROG-chgrp} 5896a81b41Smrgchmodprog=${CHMODPROG-chmod} 5996a81b41Smrgchownprog=${CHOWNPROG-chown} 6096a81b41Smrgcmpprog=${CMPPROG-cmp} 6196a81b41Smrgcpprog=${CPPROG-cp} 6296a81b41Smrgmkdirprog=${MKDIRPROG-mkdir} 6396a81b41Smrgmvprog=${MVPROG-mv} 6496a81b41Smrgrmprog=${RMPROG-rm} 6596a81b41Smrgstripprog=${STRIPPROG-strip} 6696a81b41Smrg 678b22bf3fSmrgposix_mkdir= 688b22bf3fSmrg 698b22bf3fSmrg# Desired mode of installed file. 708b22bf3fSmrgmode=0755 718b22bf3fSmrg 7214cde9d3Smrg# Create dirs (including intermediate dirs) using mode 755. 7314cde9d3Smrg# This is like GNU 'install' as of coreutils 8.32 (2020). 7414cde9d3Smrgmkdir_umask=22 7514cde9d3Smrg 7614cde9d3Smrgbackupsuffix= 7796a81b41Smrgchgrpcmd= 788b22bf3fSmrgchmodcmd=$chmodprog 798b22bf3fSmrgchowncmd= 8096a81b41Smrgmvcmd=$mvprog 818b22bf3fSmrgrmcmd="$rmprog -f" 8296a81b41Smrgstripcmd= 8396a81b41Smrg 848b22bf3fSmrgsrc= 858b22bf3fSmrgdst= 868b22bf3fSmrgdir_arg= 8796a81b41Smrgdst_arg= 8896a81b41Smrg 8996a81b41Smrgcopy_on_change=false 90c74b14bdSmrgis_target_a_directory=possibly 918b22bf3fSmrg 9296a81b41Smrgusage="\ 9396a81b41SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 948b22bf3fSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 958b22bf3fSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 968b22bf3fSmrg or: $0 [OPTION]... -d DIRECTORIES... 978b22bf3fSmrg 988b22bf3fSmrgIn the 1st form, copy SRCFILE to DSTFILE. 998b22bf3fSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1008b22bf3fSmrgIn the 4th, create DIRECTORIES. 1018b22bf3fSmrg 1028b22bf3fSmrgOptions: 10396a81b41Smrg --help display this help and exit. 10496a81b41Smrg --version display version info and exit. 10596a81b41Smrg 10696a81b41Smrg -c (ignored) 10714cde9d3Smrg -C install only if different (preserve data modification time) 10896a81b41Smrg -d create directories instead of installing files. 10996a81b41Smrg -g GROUP $chgrpprog installed files to GROUP. 11096a81b41Smrg -m MODE $chmodprog installed files to MODE. 11196a81b41Smrg -o USER $chownprog installed files to USER. 11214cde9d3Smrg -p pass -p to $cpprog. 11396a81b41Smrg -s $stripprog installed files. 11414cde9d3Smrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 11596a81b41Smrg -t DIRECTORY install into DIRECTORY. 11696a81b41Smrg -T report an error if DSTFILE is a directory. 1178b22bf3fSmrg 1188b22bf3fSmrgEnvironment variables override the default commands: 11996a81b41Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12096a81b41Smrg RMPROG STRIPPROG 12114cde9d3Smrg 12214cde9d3SmrgBy default, rm is invoked with -f; when overridden with RMPROG, 12314cde9d3Smrgit's up to you to specify -f if you want it. 12414cde9d3Smrg 12514cde9d3SmrgIf -S is not specified, no backups are attempted. 12614cde9d3Smrg 12714cde9d3SmrgEmail bug reports to bug-automake@gnu.org. 12814cde9d3SmrgAutomake home page: https://www.gnu.org/software/automake/ 1298b22bf3fSmrg" 1308b22bf3fSmrg 1318b22bf3fSmrgwhile test $# -ne 0; do 1328b22bf3fSmrg case $1 in 13396a81b41Smrg -c) ;; 13496a81b41Smrg 13596a81b41Smrg -C) copy_on_change=true;; 1368b22bf3fSmrg 13796a81b41Smrg -d) dir_arg=true;; 1388b22bf3fSmrg 1398b22bf3fSmrg -g) chgrpcmd="$chgrpprog $2" 140c74b14bdSmrg shift;; 1418b22bf3fSmrg 1428b22bf3fSmrg --help) echo "$usage"; exit $?;; 1438b22bf3fSmrg 1448b22bf3fSmrg -m) mode=$2 145c74b14bdSmrg case $mode in 146c74b14bdSmrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 147c74b14bdSmrg echo "$0: invalid mode: $mode" >&2 148c74b14bdSmrg exit 1;; 149c74b14bdSmrg esac 150c74b14bdSmrg shift;; 1518b22bf3fSmrg 1528b22bf3fSmrg -o) chowncmd="$chownprog $2" 153c74b14bdSmrg shift;; 1548b22bf3fSmrg 15514cde9d3Smrg -p) cpprog="$cpprog -p";; 15614cde9d3Smrg 15796a81b41Smrg -s) stripcmd=$stripprog;; 1588b22bf3fSmrg 15914cde9d3Smrg -S) backupsuffix="$2" 16014cde9d3Smrg shift;; 16114cde9d3Smrg 162c74b14bdSmrg -t) 163c74b14bdSmrg is_target_a_directory=always 164c74b14bdSmrg dst_arg=$2 165c74b14bdSmrg # Protect names problematic for 'test' and other utilities. 166c74b14bdSmrg case $dst_arg in 167c74b14bdSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 168c74b14bdSmrg esac 169c74b14bdSmrg shift;; 1708b22bf3fSmrg 171c74b14bdSmrg -T) is_target_a_directory=never;; 1728b22bf3fSmrg 1738b22bf3fSmrg --version) echo "$0 $scriptversion"; exit $?;; 1748b22bf3fSmrg 175c74b14bdSmrg --) shift 176c74b14bdSmrg break;; 1778b22bf3fSmrg 178c74b14bdSmrg -*) echo "$0: invalid option: $1" >&2 179c74b14bdSmrg exit 1;; 1808b22bf3fSmrg 1818b22bf3fSmrg *) break;; 1828b22bf3fSmrg esac 18396a81b41Smrg shift 1848b22bf3fSmrgdone 1858b22bf3fSmrg 186c74b14bdSmrg# We allow the use of options -d and -T together, by making -d 187c74b14bdSmrg# take the precedence; this is for compatibility with GNU install. 188c74b14bdSmrg 189c74b14bdSmrgif test -n "$dir_arg"; then 190c74b14bdSmrg if test -n "$dst_arg"; then 191c74b14bdSmrg echo "$0: target directory not allowed when installing a directory." >&2 192c74b14bdSmrg exit 1 193c74b14bdSmrg fi 194c74b14bdSmrgfi 195c74b14bdSmrg 19696a81b41Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1978b22bf3fSmrg # When -d is used, all remaining arguments are directories to create. 1988b22bf3fSmrg # When -t is used, the destination is already specified. 1998b22bf3fSmrg # Otherwise, the last argument is the destination. Remove it from $@. 2008b22bf3fSmrg for arg 2018b22bf3fSmrg do 20296a81b41Smrg if test -n "$dst_arg"; then 2038b22bf3fSmrg # $@ is not empty: it contains at least $arg. 20496a81b41Smrg set fnord "$@" "$dst_arg" 2058b22bf3fSmrg shift # fnord 2068b22bf3fSmrg fi 2078b22bf3fSmrg shift # arg 20896a81b41Smrg dst_arg=$arg 209f126e068Smrg # Protect names problematic for 'test' and other utilities. 210f126e068Smrg case $dst_arg in 211f126e068Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212f126e068Smrg esac 2138b22bf3fSmrg done 2148b22bf3fSmrgfi 2158b22bf3fSmrg 2168b22bf3fSmrgif test $# -eq 0; then 2178b22bf3fSmrg if test -z "$dir_arg"; then 2188b22bf3fSmrg echo "$0: no input file specified." >&2 2198b22bf3fSmrg exit 1 2208b22bf3fSmrg fi 221f126e068Smrg # It's OK to call 'install-sh -d' without argument. 2228b22bf3fSmrg # This can happen when creating conditional directories. 2238b22bf3fSmrg exit 0 2248b22bf3fSmrgfi 2258b22bf3fSmrg 226c74b14bdSmrgif test -z "$dir_arg"; then 227c74b14bdSmrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 228c74b14bdSmrg if test ! -d "$dst_arg"; then 229c74b14bdSmrg echo "$0: $dst_arg: Is not a directory." >&2 230c74b14bdSmrg exit 1 231c74b14bdSmrg fi 232c74b14bdSmrg fi 233c74b14bdSmrgfi 234c74b14bdSmrg 2358b22bf3fSmrgif test -z "$dir_arg"; then 236f126e068Smrg do_exit='(exit $ret); exit $ret' 237f126e068Smrg trap "ret=129; $do_exit" 1 238f126e068Smrg trap "ret=130; $do_exit" 2 239f126e068Smrg trap "ret=141; $do_exit" 13 240f126e068Smrg trap "ret=143; $do_exit" 15 2418b22bf3fSmrg 2428b22bf3fSmrg # Set umask so as not to create temps with too-generous modes. 2438b22bf3fSmrg # However, 'strip' requires both read and write access to temps. 2448b22bf3fSmrg case $mode in 2458b22bf3fSmrg # Optimize common cases. 2468b22bf3fSmrg *644) cp_umask=133;; 2478b22bf3fSmrg *755) cp_umask=22;; 2488b22bf3fSmrg 2498b22bf3fSmrg *[0-7]) 2508b22bf3fSmrg if test -z "$stripcmd"; then 251c74b14bdSmrg u_plus_rw= 2528b22bf3fSmrg else 253c74b14bdSmrg u_plus_rw='% 200' 2548b22bf3fSmrg fi 2558b22bf3fSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2568b22bf3fSmrg *) 2578b22bf3fSmrg if test -z "$stripcmd"; then 258c74b14bdSmrg u_plus_rw= 2598b22bf3fSmrg else 260c74b14bdSmrg u_plus_rw=,u+rw 2618b22bf3fSmrg fi 2628b22bf3fSmrg cp_umask=$mode$u_plus_rw;; 2638b22bf3fSmrg esac 2648b22bf3fSmrgfi 2658b22bf3fSmrg 2668b22bf3fSmrgfor src 2678b22bf3fSmrgdo 268f126e068Smrg # Protect names problematic for 'test' and other utilities. 2698b22bf3fSmrg case $src in 270f126e068Smrg -* | [=\(\)!]) src=./$src;; 2718b22bf3fSmrg esac 2728b22bf3fSmrg 2738b22bf3fSmrg if test -n "$dir_arg"; then 2748b22bf3fSmrg dst=$src 2758b22bf3fSmrg dstdir=$dst 2768b22bf3fSmrg test -d "$dstdir" 2778b22bf3fSmrg dstdir_status=$? 27814cde9d3Smrg # Don't chown directories that already exist. 27914cde9d3Smrg if test $dstdir_status = 0; then 28014cde9d3Smrg chowncmd="" 28114cde9d3Smrg fi 2828b22bf3fSmrg else 2838b22bf3fSmrg 2848b22bf3fSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2858b22bf3fSmrg # might cause directories to be created, which would be especially bad 2868b22bf3fSmrg # if $src (and thus $dsttmp) contains '*'. 2878b22bf3fSmrg if test ! -f "$src" && test ! -d "$src"; then 2888b22bf3fSmrg echo "$0: $src does not exist." >&2 2898b22bf3fSmrg exit 1 2908b22bf3fSmrg fi 2918b22bf3fSmrg 29296a81b41Smrg if test -z "$dst_arg"; then 2938b22bf3fSmrg echo "$0: no destination specified." >&2 2948b22bf3fSmrg exit 1 2958b22bf3fSmrg fi 29696a81b41Smrg dst=$dst_arg 2978b22bf3fSmrg 2989e1184feSmrg # If destination is a directory, append the input filename. 2998b22bf3fSmrg if test -d "$dst"; then 300c74b14bdSmrg if test "$is_target_a_directory" = never; then 301c74b14bdSmrg echo "$0: $dst_arg: Is a directory" >&2 302c74b14bdSmrg exit 1 3038b22bf3fSmrg fi 3048b22bf3fSmrg dstdir=$dst 3059e1184feSmrg dstbase=`basename "$src"` 3069e1184feSmrg case $dst in 3079e1184feSmrg */) dst=$dst$dstbase;; 3089e1184feSmrg *) dst=$dst/$dstbase;; 3099e1184feSmrg esac 3108b22bf3fSmrg dstdir_status=0 3118b22bf3fSmrg else 312c74b14bdSmrg dstdir=`dirname "$dst"` 3138b22bf3fSmrg test -d "$dstdir" 3148b22bf3fSmrg dstdir_status=$? 3158b22bf3fSmrg fi 3168b22bf3fSmrg fi 3178b22bf3fSmrg 3189e1184feSmrg case $dstdir in 3199e1184feSmrg */) dstdirslash=$dstdir;; 3209e1184feSmrg *) dstdirslash=$dstdir/;; 3219e1184feSmrg esac 3229e1184feSmrg 3238b22bf3fSmrg obsolete_mkdir_used=false 3248b22bf3fSmrg 3258b22bf3fSmrg if test $dstdir_status != 0; then 3268b22bf3fSmrg case $posix_mkdir in 3278b22bf3fSmrg '') 328c74b14bdSmrg # With -d, create the new directory with the user-specified mode. 329c74b14bdSmrg # Otherwise, rely on $mkdir_umask. 330c74b14bdSmrg if test -n "$dir_arg"; then 331c74b14bdSmrg mkdir_mode=-m$mode 332c74b14bdSmrg else 333c74b14bdSmrg mkdir_mode= 334c74b14bdSmrg fi 335c74b14bdSmrg 336c74b14bdSmrg posix_mkdir=false 33714cde9d3Smrg # The $RANDOM variable is not portable (e.g., dash). Use it 33814cde9d3Smrg # here however when possible just to lower collision chance. 33914cde9d3Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34014cde9d3Smrg 34114cde9d3Smrg trap ' 34214cde9d3Smrg ret=$? 34314cde9d3Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 34414cde9d3Smrg exit $ret 34514cde9d3Smrg ' 0 34614cde9d3Smrg 34714cde9d3Smrg # Because "mkdir -p" follows existing symlinks and we likely work 34814cde9d3Smrg # directly in world-writeable /tmp, make sure that the '$tmpdir' 34914cde9d3Smrg # directory is successfully created first before we actually test 35014cde9d3Smrg # 'mkdir -p'. 35114cde9d3Smrg if (umask $mkdir_umask && 35214cde9d3Smrg $mkdirprog $mkdir_mode "$tmpdir" && 35314cde9d3Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 35414cde9d3Smrg then 35514cde9d3Smrg if test -z "$dir_arg" || { 35614cde9d3Smrg # Check for POSIX incompatibilities with -m. 35714cde9d3Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35814cde9d3Smrg # other-writable bit of parent directory when it shouldn't. 35914cde9d3Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 36014cde9d3Smrg test_tmpdir="$tmpdir/a" 36114cde9d3Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 36214cde9d3Smrg case $ls_ld_tmpdir in 36314cde9d3Smrg d????-?r-*) different_mode=700;; 36414cde9d3Smrg d????-?--*) different_mode=755;; 36514cde9d3Smrg *) false;; 36614cde9d3Smrg esac && 36714cde9d3Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 36814cde9d3Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 36914cde9d3Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 37014cde9d3Smrg } 37114cde9d3Smrg } 37214cde9d3Smrg then posix_mkdir=: 37314cde9d3Smrg fi 37414cde9d3Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 37514cde9d3Smrg else 37614cde9d3Smrg # Remove any dirs left behind by ancient mkdir implementations. 37714cde9d3Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 37814cde9d3Smrg fi 37914cde9d3Smrg trap '' 0;; 3808b22bf3fSmrg esac 3818b22bf3fSmrg 3828b22bf3fSmrg if 3838b22bf3fSmrg $posix_mkdir && ( 384c74b14bdSmrg umask $mkdir_umask && 385c74b14bdSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3868b22bf3fSmrg ) 3878b22bf3fSmrg then : 3888b22bf3fSmrg else 3898b22bf3fSmrg 39014cde9d3Smrg # mkdir does not conform to POSIX, 3918b22bf3fSmrg # or it failed possibly due to a race condition. Create the 3928b22bf3fSmrg # directory the slow way, step by step, checking for races as we go. 3938b22bf3fSmrg 3948b22bf3fSmrg case $dstdir in 395c74b14bdSmrg /*) prefix='/';; 396c74b14bdSmrg [-=\(\)!]*) prefix='./';; 397c74b14bdSmrg *) prefix='';; 3988b22bf3fSmrg esac 3998b22bf3fSmrg 4008b22bf3fSmrg oIFS=$IFS 4018b22bf3fSmrg IFS=/ 402c74b14bdSmrg set -f 4038b22bf3fSmrg set fnord $dstdir 4048b22bf3fSmrg shift 405c74b14bdSmrg set +f 4068b22bf3fSmrg IFS=$oIFS 4078b22bf3fSmrg 4088b22bf3fSmrg prefixes= 4098b22bf3fSmrg 4108b22bf3fSmrg for d 4118b22bf3fSmrg do 412c74b14bdSmrg test X"$d" = X && continue 413c74b14bdSmrg 414c74b14bdSmrg prefix=$prefix$d 415c74b14bdSmrg if test -d "$prefix"; then 416c74b14bdSmrg prefixes= 417c74b14bdSmrg else 418c74b14bdSmrg if $posix_mkdir; then 41914cde9d3Smrg (umask $mkdir_umask && 420c74b14bdSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 421c74b14bdSmrg # Don't fail if two instances are running concurrently. 422c74b14bdSmrg test -d "$prefix" || exit 1 423c74b14bdSmrg else 424c74b14bdSmrg case $prefix in 425c74b14bdSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 426c74b14bdSmrg *) qprefix=$prefix;; 427c74b14bdSmrg esac 428c74b14bdSmrg prefixes="$prefixes '$qprefix'" 429c74b14bdSmrg fi 430c74b14bdSmrg fi 431c74b14bdSmrg prefix=$prefix/ 4328b22bf3fSmrg done 4338b22bf3fSmrg 4348b22bf3fSmrg if test -n "$prefixes"; then 435c74b14bdSmrg # Don't fail if two instances are running concurrently. 436c74b14bdSmrg (umask $mkdir_umask && 437c74b14bdSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 438c74b14bdSmrg test -d "$dstdir" || exit 1 439c74b14bdSmrg obsolete_mkdir_used=true 4408b22bf3fSmrg fi 4418b22bf3fSmrg fi 4428b22bf3fSmrg fi 4438b22bf3fSmrg 4448b22bf3fSmrg if test -n "$dir_arg"; then 4458b22bf3fSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4468b22bf3fSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4478b22bf3fSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4488b22bf3fSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4498b22bf3fSmrg else 4508b22bf3fSmrg 4518b22bf3fSmrg # Make a couple of temp file names in the proper directory. 4529e1184feSmrg dsttmp=${dstdirslash}_inst.$$_ 4539e1184feSmrg rmtmp=${dstdirslash}_rm.$$_ 4548b22bf3fSmrg 4558b22bf3fSmrg # Trap to clean up those temp files at exit. 4568b22bf3fSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4578b22bf3fSmrg 4588b22bf3fSmrg # Copy the file name to the temp name. 45914cde9d3Smrg (umask $cp_umask && 46014cde9d3Smrg { test -z "$stripcmd" || { 46114cde9d3Smrg # Create $dsttmp read-write so that cp doesn't create it read-only, 46214cde9d3Smrg # which would cause strip to fail. 46314cde9d3Smrg if test -z "$doit"; then 46414cde9d3Smrg : >"$dsttmp" # No need to fork-exec 'touch'. 46514cde9d3Smrg else 46614cde9d3Smrg $doit touch "$dsttmp" 46714cde9d3Smrg fi 46814cde9d3Smrg } 46914cde9d3Smrg } && 47014cde9d3Smrg $doit_exec $cpprog "$src" "$dsttmp") && 4718b22bf3fSmrg 4728b22bf3fSmrg # and set any options; do chmod last to preserve setuid bits. 4738b22bf3fSmrg # 4748b22bf3fSmrg # If any of these fail, we abort the whole thing. If we want to 4758b22bf3fSmrg # ignore errors from any of these, just make sure not to ignore 4768b22bf3fSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4778b22bf3fSmrg # 47896a81b41Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 47996a81b41Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 48096a81b41Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 48196a81b41Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 48296a81b41Smrg 48396a81b41Smrg # If -C, don't bother to copy if it wouldn't change the file. 48496a81b41Smrg if $copy_on_change && 485c74b14bdSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 486c74b14bdSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 487c74b14bdSmrg set -f && 48896a81b41Smrg set X $old && old=:$2:$4:$5:$6 && 48996a81b41Smrg set X $new && new=:$2:$4:$5:$6 && 490c74b14bdSmrg set +f && 49196a81b41Smrg test "$old" = "$new" && 49296a81b41Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 49396a81b41Smrg then 49496a81b41Smrg rm -f "$dsttmp" 49596a81b41Smrg else 49614cde9d3Smrg # If $backupsuffix is set, and the file being installed 49714cde9d3Smrg # already exists, attempt a backup. Don't worry if it fails, 49814cde9d3Smrg # e.g., if mv doesn't support -f. 49914cde9d3Smrg if test -n "$backupsuffix" && test -f "$dst"; then 50014cde9d3Smrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 50114cde9d3Smrg fi 50214cde9d3Smrg 50396a81b41Smrg # Rename the file to the real destination. 50496a81b41Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 50596a81b41Smrg 50696a81b41Smrg # The rename failed, perhaps because mv can't rename something else 50796a81b41Smrg # to itself, or perhaps because mv is so ancient that it does not 50896a81b41Smrg # support -f. 50996a81b41Smrg { 510c74b14bdSmrg # Now remove or move aside any old file at destination location. 511c74b14bdSmrg # We try this two ways since rm can't unlink itself on some 512c74b14bdSmrg # systems and the destination file might be busy for other 513c74b14bdSmrg # reasons. In this case, the final cleanup might fail but the new 514c74b14bdSmrg # file should still install successfully. 515c74b14bdSmrg { 516c74b14bdSmrg test ! -f "$dst" || 51714cde9d3Smrg $doit $rmcmd "$dst" 2>/dev/null || 518c74b14bdSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 51914cde9d3Smrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 520c74b14bdSmrg } || 521c74b14bdSmrg { echo "$0: cannot unlink or rename $dst" >&2 522c74b14bdSmrg (exit 1); exit 1 523c74b14bdSmrg } 524c74b14bdSmrg } && 525c74b14bdSmrg 526c74b14bdSmrg # Now rename the file to the real destination. 527c74b14bdSmrg $doit $mvcmd "$dsttmp" "$dst" 52896a81b41Smrg } 52996a81b41Smrg fi || exit 1 5308b22bf3fSmrg 5318b22bf3fSmrg trap '' 0 5328b22bf3fSmrg fi 5338b22bf3fSmrgdone 5348b22bf3fSmrg 5358b22bf3fSmrg# Local variables: 5369e1184feSmrg# eval: (add-hook 'before-save-hook 'time-stamp) 5378b22bf3fSmrg# time-stamp-start: "scriptversion=" 5388b22bf3fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5399e1184feSmrg# time-stamp-time-zone: "UTC0" 54096a81b41Smrg# time-stamp-end: "; # UTC" 5418b22bf3fSmrg# End: 542