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