19f606849Smrg#!/bin/sh 29f606849Smrg# install - install a program, script, or datafile 39f606849Smrg 4dc088bc7Smrgscriptversion=2024-06-19.01; # UTC 59f606849Smrg 69f606849Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 79f606849Smrg# later released in X11R6 (xc/config/util/install.sh) with the 89f606849Smrg# following copyright and license. 99f606849Smrg# 109f606849Smrg# Copyright (C) 1994 X Consortium 119f606849Smrg# 129f606849Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 139f606849Smrg# of this software and associated documentation files (the "Software"), to 149f606849Smrg# deal in the Software without restriction, including without limitation the 159f606849Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 169f606849Smrg# sell copies of the Software, and to permit persons to whom the Software is 179f606849Smrg# furnished to do so, subject to the following conditions: 189f606849Smrg# 199f606849Smrg# The above copyright notice and this permission notice shall be included in 209f606849Smrg# all copies or substantial portions of the Software. 219f606849Smrg# 229f606849Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239f606849Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 249f606849Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259f606849Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 269f606849Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 279f606849Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 289f606849Smrg# 299f606849Smrg# Except as contained in this notice, the name of the X Consortium shall not 309f606849Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 319f606849Smrg# ings in this Software without prior written authorization from the X Consor- 329f606849Smrg# tium. 339f606849Smrg# 349f606849Smrg# 359f606849Smrg# FSF changes to this file are in the public domain. 369f606849Smrg# 379f606849Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38cdbfa18aSmrg# 'make' implicit rules from creating a file called install from it 399f606849Smrg# when there is no Makefile. 409f606849Smrg# 419f606849Smrg# This script is compatible with the BSD install script, but was written 429f606849Smrg# from scratch. 439f606849Smrg 44949d0342Smrgtab=' ' 459f606849Smrgnl=' 469f606849Smrg' 47949d0342SmrgIFS=" $tab$nl" 489f606849Smrg 49949d0342Smrg# Set DOITPROG to "echo" to test this script. 509f606849Smrg 51fba89afeSmrgdoit=${DOITPROG-} 52949d0342Smrgdoit_exec=${doit:-exec} 539f606849Smrg 549f606849Smrg# Put in absolute file names if you don't have them in your path; 559f606849Smrg# or use environment vars. 569f606849Smrg 57fba89afeSmrgchgrpprog=${CHGRPPROG-chgrp} 58fba89afeSmrgchmodprog=${CHMODPROG-chmod} 59fba89afeSmrgchownprog=${CHOWNPROG-chown} 60fba89afeSmrgcmpprog=${CMPPROG-cmp} 61fba89afeSmrgcpprog=${CPPROG-cp} 62fba89afeSmrgmkdirprog=${MKDIRPROG-mkdir} 63fba89afeSmrgmvprog=${MVPROG-mv} 64fba89afeSmrgrmprog=${RMPROG-rm} 65fba89afeSmrgstripprog=${STRIPPROG-strip} 66fba89afeSmrg 679f606849Smrgposix_mkdir= 689f606849Smrg 699f606849Smrg# Desired mode of installed file. 709f606849Smrgmode=0755 719f606849Smrg 72949d0342Smrg# Create dirs (including intermediate dirs) using mode 755. 73949d0342Smrg# This is like GNU 'install' as of coreutils 8.32 (2020). 74949d0342Smrgmkdir_umask=22 75949d0342Smrg 76949d0342Smrgbackupsuffix= 77fba89afeSmrgchgrpcmd= 789f606849Smrgchmodcmd=$chmodprog 799f606849Smrgchowncmd= 80fba89afeSmrgmvcmd=$mvprog 819f606849Smrgrmcmd="$rmprog -f" 82fba89afeSmrgstripcmd= 83fba89afeSmrg 849f606849Smrgsrc= 859f606849Smrgdst= 869f606849Smrgdir_arg= 87fba89afeSmrgdst_arg= 88fba89afeSmrg 89fba89afeSmrgcopy_on_change=false 90949d0342Smrgis_target_a_directory=possibly 919f606849Smrg 92fba89afeSmrgusage="\ 93fba89afeSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 949f606849Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 959f606849Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 969f606849Smrg or: $0 [OPTION]... -d DIRECTORIES... 979f606849Smrg 989f606849SmrgIn the 1st form, copy SRCFILE to DSTFILE. 999f606849SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1009f606849SmrgIn the 4th, create DIRECTORIES. 1019f606849Smrg 1029f606849SmrgOptions: 103fba89afeSmrg --help display this help and exit. 104fba89afeSmrg --version display version info and exit. 105fba89afeSmrg 106fba89afeSmrg -c (ignored) 107949d0342Smrg -C install only if different (preserve data modification time) 108fba89afeSmrg -d create directories instead of installing files. 109fba89afeSmrg -g GROUP $chgrpprog installed files to GROUP. 110fba89afeSmrg -m MODE $chmodprog installed files to MODE. 111fba89afeSmrg -o USER $chownprog installed files to USER. 112949d0342Smrg -p pass -p to $cpprog. 113fba89afeSmrg -s $stripprog installed files. 114949d0342Smrg -S SUFFIX attempt to back up existing files, with suffix SUFFIX. 115fba89afeSmrg -t DIRECTORY install into DIRECTORY. 116fba89afeSmrg -T report an error if DSTFILE is a directory. 1179f606849Smrg 1189f606849SmrgEnvironment variables override the default commands: 119fba89afeSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 120fba89afeSmrg RMPROG STRIPPROG 121949d0342Smrg 122949d0342SmrgBy default, rm is invoked with -f; when overridden with RMPROG, 123949d0342Smrgit's up to you to specify -f if you want it. 124949d0342Smrg 125949d0342SmrgIf -S is not specified, no backups are attempted. 126949d0342Smrg 127dc088bc7SmrgReport bugs to <bug-automake@gnu.org>. 128dc088bc7SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>. 129dc088bc7SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>." 1309f606849Smrg 1319f606849Smrgwhile test $# -ne 0; do 1329f606849Smrg case $1 in 133fba89afeSmrg -c) ;; 134fba89afeSmrg 135fba89afeSmrg -C) copy_on_change=true;; 1369f606849Smrg 137fba89afeSmrg -d) dir_arg=true;; 1389f606849Smrg 1399f606849Smrg -g) chgrpcmd="$chgrpprog $2" 140949d0342Smrg shift;; 1419f606849Smrg 1429f606849Smrg --help) echo "$usage"; exit $?;; 1439f606849Smrg 1449f606849Smrg -m) mode=$2 145949d0342Smrg case $mode in 146949d0342Smrg *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 147949d0342Smrg echo "$0: invalid mode: $mode" >&2 148949d0342Smrg exit 1;; 149949d0342Smrg esac 150949d0342Smrg shift;; 1519f606849Smrg 1529f606849Smrg -o) chowncmd="$chownprog $2" 153949d0342Smrg shift;; 154949d0342Smrg 155949d0342Smrg -p) cpprog="$cpprog -p";; 1569f606849Smrg 157fba89afeSmrg -s) stripcmd=$stripprog;; 1589f606849Smrg 159949d0342Smrg -S) backupsuffix="$2" 160949d0342Smrg shift;; 1619f606849Smrg 162949d0342Smrg -t) 163949d0342Smrg is_target_a_directory=always 164949d0342Smrg dst_arg=$2 165949d0342Smrg # Protect names problematic for 'test' and other utilities. 166949d0342Smrg case $dst_arg in 167949d0342Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 168949d0342Smrg esac 169949d0342Smrg shift;; 170949d0342Smrg 171949d0342Smrg -T) is_target_a_directory=never;; 1729f606849Smrg 173dc088bc7Smrg --version) echo "$0 (GNU Automake) $scriptversion"; exit $?;; 1749f606849Smrg 175949d0342Smrg --) shift 176949d0342Smrg break;; 1779f606849Smrg 178949d0342Smrg -*) echo "$0: invalid option: $1" >&2 179949d0342Smrg exit 1;; 1809f606849Smrg 1819f606849Smrg *) break;; 1829f606849Smrg esac 183fba89afeSmrg shift 1849f606849Smrgdone 1859f606849Smrg 186949d0342Smrg# We allow the use of options -d and -T together, by making -d 187949d0342Smrg# take the precedence; this is for compatibility with GNU install. 188949d0342Smrg 189949d0342Smrgif test -n "$dir_arg"; then 190949d0342Smrg if test -n "$dst_arg"; then 191949d0342Smrg echo "$0: target directory not allowed when installing a directory." >&2 192949d0342Smrg exit 1 193949d0342Smrg fi 194949d0342Smrgfi 195949d0342Smrg 196fba89afeSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1979f606849Smrg # When -d is used, all remaining arguments are directories to create. 1989f606849Smrg # When -t is used, the destination is already specified. 1999f606849Smrg # Otherwise, the last argument is the destination. Remove it from $@. 2009f606849Smrg for arg 2019f606849Smrg do 202fba89afeSmrg if test -n "$dst_arg"; then 2039f606849Smrg # $@ is not empty: it contains at least $arg. 204fba89afeSmrg set fnord "$@" "$dst_arg" 2059f606849Smrg shift # fnord 2069f606849Smrg fi 2079f606849Smrg shift # arg 208fba89afeSmrg dst_arg=$arg 209cdbfa18aSmrg # Protect names problematic for 'test' and other utilities. 210cdbfa18aSmrg case $dst_arg in 211cdbfa18aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 212cdbfa18aSmrg esac 2139f606849Smrg done 2149f606849Smrgfi 2159f606849Smrg 2169f606849Smrgif test $# -eq 0; then 2179f606849Smrg if test -z "$dir_arg"; then 2189f606849Smrg echo "$0: no input file specified." >&2 2199f606849Smrg exit 1 2209f606849Smrg fi 221cdbfa18aSmrg # It's OK to call 'install-sh -d' without argument. 2229f606849Smrg # This can happen when creating conditional directories. 2239f606849Smrg exit 0 2249f606849Smrgfi 2259f606849Smrg 226949d0342Smrgif test -z "$dir_arg"; then 227949d0342Smrg if test $# -gt 1 || test "$is_target_a_directory" = always; then 228949d0342Smrg if test ! -d "$dst_arg"; then 229949d0342Smrg echo "$0: $dst_arg: Is not a directory." >&2 230949d0342Smrg exit 1 231949d0342Smrg fi 232949d0342Smrg fi 233949d0342Smrgfi 234949d0342Smrg 2359f606849Smrgif test -z "$dir_arg"; then 236cdbfa18aSmrg do_exit='(exit $ret); exit $ret' 237cdbfa18aSmrg trap "ret=129; $do_exit" 1 238cdbfa18aSmrg trap "ret=130; $do_exit" 2 239cdbfa18aSmrg trap "ret=141; $do_exit" 13 240cdbfa18aSmrg trap "ret=143; $do_exit" 15 2419f606849Smrg 2429f606849Smrg # Set umask so as not to create temps with too-generous modes. 2439f606849Smrg # However, 'strip' requires both read and write access to temps. 2449f606849Smrg case $mode in 2459f606849Smrg # Optimize common cases. 2469f606849Smrg *644) cp_umask=133;; 2479f606849Smrg *755) cp_umask=22;; 2489f606849Smrg 2499f606849Smrg *[0-7]) 2509f606849Smrg if test -z "$stripcmd"; then 251949d0342Smrg u_plus_rw= 2529f606849Smrg else 253949d0342Smrg u_plus_rw='% 200' 2549f606849Smrg fi 2559f606849Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2569f606849Smrg *) 2579f606849Smrg if test -z "$stripcmd"; then 258949d0342Smrg u_plus_rw= 2599f606849Smrg else 260949d0342Smrg u_plus_rw=,u+rw 2619f606849Smrg fi 2629f606849Smrg cp_umask=$mode$u_plus_rw;; 2639f606849Smrg esac 2649f606849Smrgfi 2659f606849Smrg 2669f606849Smrgfor src 2679f606849Smrgdo 268cdbfa18aSmrg # Protect names problematic for 'test' and other utilities. 2699f606849Smrg case $src in 270cdbfa18aSmrg -* | [=\(\)!]) src=./$src;; 2719f606849Smrg esac 2729f606849Smrg 2739f606849Smrg if test -n "$dir_arg"; then 2749f606849Smrg dst=$src 2759f606849Smrg dstdir=$dst 2769f606849Smrg test -d "$dstdir" 2779f606849Smrg dstdir_status=$? 278949d0342Smrg # Don't chown directories that already exist. 279949d0342Smrg if test $dstdir_status = 0; then 280949d0342Smrg chowncmd="" 281949d0342Smrg fi 2829f606849Smrg else 2839f606849Smrg 2849f606849Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2859f606849Smrg # might cause directories to be created, which would be especially bad 2869f606849Smrg # if $src (and thus $dsttmp) contains '*'. 2879f606849Smrg if test ! -f "$src" && test ! -d "$src"; then 2889f606849Smrg echo "$0: $src does not exist." >&2 2899f606849Smrg exit 1 2909f606849Smrg fi 2919f606849Smrg 292fba89afeSmrg if test -z "$dst_arg"; then 2939f606849Smrg echo "$0: no destination specified." >&2 2949f606849Smrg exit 1 2959f606849Smrg fi 296fba89afeSmrg dst=$dst_arg 2979f606849Smrg 298949d0342Smrg # If destination is a directory, append the input filename. 2999f606849Smrg if test -d "$dst"; then 300949d0342Smrg if test "$is_target_a_directory" = never; then 301949d0342Smrg echo "$0: $dst_arg: Is a directory" >&2 302949d0342Smrg exit 1 3039f606849Smrg fi 3049f606849Smrg dstdir=$dst 305949d0342Smrg dstbase=`basename "$src"` 306949d0342Smrg case $dst in 307949d0342Smrg */) dst=$dst$dstbase;; 308949d0342Smrg *) dst=$dst/$dstbase;; 309949d0342Smrg esac 3109f606849Smrg dstdir_status=0 3119f606849Smrg else 312949d0342Smrg dstdir=`dirname "$dst"` 3139f606849Smrg test -d "$dstdir" 3149f606849Smrg dstdir_status=$? 3159f606849Smrg fi 3169f606849Smrg fi 3179f606849Smrg 318949d0342Smrg case $dstdir in 319949d0342Smrg */) dstdirslash=$dstdir;; 320949d0342Smrg *) dstdirslash=$dstdir/;; 321949d0342Smrg esac 322949d0342Smrg 3239f606849Smrg obsolete_mkdir_used=false 3249f606849Smrg 3259f606849Smrg if test $dstdir_status != 0; then 3269f606849Smrg case $posix_mkdir in 3279f606849Smrg '') 328949d0342Smrg # With -d, create the new directory with the user-specified mode. 329949d0342Smrg # Otherwise, rely on $mkdir_umask. 330949d0342Smrg if test -n "$dir_arg"; then 331949d0342Smrg mkdir_mode=-m$mode 332949d0342Smrg else 333949d0342Smrg mkdir_mode= 334949d0342Smrg fi 335949d0342Smrg 336949d0342Smrg posix_mkdir=false 337949d0342Smrg # The $RANDOM variable is not portable (e.g., dash). Use it 338949d0342Smrg # here however when possible just to lower collision chance. 339949d0342Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 340949d0342Smrg 341949d0342Smrg trap ' 342949d0342Smrg ret=$? 343949d0342Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null 344949d0342Smrg exit $ret 345949d0342Smrg ' 0 346949d0342Smrg 347949d0342Smrg # Because "mkdir -p" follows existing symlinks and we likely work 348dc088bc7Smrg # directly in world-writable /tmp, make sure that the '$tmpdir' 349949d0342Smrg # directory is successfully created first before we actually test 350949d0342Smrg # 'mkdir -p'. 351949d0342Smrg if (umask $mkdir_umask && 352949d0342Smrg $mkdirprog $mkdir_mode "$tmpdir" && 353949d0342Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 354949d0342Smrg then 355949d0342Smrg if test -z "$dir_arg" || { 356dc088bc7Smrg # Check for POSIX incompatibility with -m. 357949d0342Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 358949d0342Smrg # other-writable bit of parent directory when it shouldn't. 359949d0342Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 360949d0342Smrg test_tmpdir="$tmpdir/a" 361949d0342Smrg ls_ld_tmpdir=`ls -ld "$test_tmpdir"` 362949d0342Smrg case $ls_ld_tmpdir in 363949d0342Smrg d????-?r-*) different_mode=700;; 364949d0342Smrg d????-?--*) different_mode=755;; 365949d0342Smrg *) false;; 366949d0342Smrg esac && 367949d0342Smrg $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { 368949d0342Smrg ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` 369949d0342Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 370949d0342Smrg } 371949d0342Smrg } 372949d0342Smrg then posix_mkdir=: 373949d0342Smrg fi 374949d0342Smrg rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 3759f606849Smrg else 376949d0342Smrg # Remove any dirs left behind by ancient mkdir implementations. 377949d0342Smrg rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null 3789f606849Smrg fi 379949d0342Smrg trap '' 0;; 3809f606849Smrg esac 3819f606849Smrg 3829f606849Smrg if 3839f606849Smrg $posix_mkdir && ( 384949d0342Smrg umask $mkdir_umask && 385949d0342Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3869f606849Smrg ) 3879f606849Smrg then : 3889f606849Smrg else 3899f606849Smrg 390949d0342Smrg # mkdir does not conform to POSIX, 3919f606849Smrg # or it failed possibly due to a race condition. Create the 3929f606849Smrg # directory the slow way, step by step, checking for races as we go. 3939f606849Smrg 3949f606849Smrg case $dstdir in 395949d0342Smrg /*) prefix='/';; 396949d0342Smrg [-=\(\)!]*) prefix='./';; 397949d0342Smrg *) prefix='';; 3989f606849Smrg esac 3999f606849Smrg 4009f606849Smrg oIFS=$IFS 4019f606849Smrg IFS=/ 402949d0342Smrg set -f 4039f606849Smrg set fnord $dstdir 4049f606849Smrg shift 405949d0342Smrg set +f 4069f606849Smrg IFS=$oIFS 4079f606849Smrg 4089f606849Smrg prefixes= 4099f606849Smrg 4109f606849Smrg for d 4119f606849Smrg do 412949d0342Smrg test X"$d" = X && continue 413949d0342Smrg 414949d0342Smrg prefix=$prefix$d 415949d0342Smrg if test -d "$prefix"; then 416949d0342Smrg prefixes= 417949d0342Smrg else 418949d0342Smrg if $posix_mkdir; then 419949d0342Smrg (umask $mkdir_umask && 420949d0342Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 421949d0342Smrg # Don't fail if two instances are running concurrently. 422949d0342Smrg test -d "$prefix" || exit 1 423949d0342Smrg else 424949d0342Smrg case $prefix in 425949d0342Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 426949d0342Smrg *) qprefix=$prefix;; 427949d0342Smrg esac 428949d0342Smrg prefixes="$prefixes '$qprefix'" 429949d0342Smrg fi 430949d0342Smrg fi 431949d0342Smrg prefix=$prefix/ 4329f606849Smrg done 4339f606849Smrg 4349f606849Smrg if test -n "$prefixes"; then 435949d0342Smrg # Don't fail if two instances are running concurrently. 436949d0342Smrg (umask $mkdir_umask && 437949d0342Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 438949d0342Smrg test -d "$dstdir" || exit 1 439949d0342Smrg obsolete_mkdir_used=true 4409f606849Smrg fi 4419f606849Smrg fi 4429f606849Smrg fi 4439f606849Smrg 4449f606849Smrg if test -n "$dir_arg"; then 4459f606849Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4469f606849Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4479f606849Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4489f606849Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4499f606849Smrg else 4509f606849Smrg 4519f606849Smrg # Make a couple of temp file names in the proper directory. 452949d0342Smrg dsttmp=${dstdirslash}_inst.$$_ 453949d0342Smrg rmtmp=${dstdirslash}_rm.$$_ 4549f606849Smrg 4559f606849Smrg # Trap to clean up those temp files at exit. 4569f606849Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4579f606849Smrg 4589f606849Smrg # Copy the file name to the temp name. 459949d0342Smrg (umask $cp_umask && 460949d0342Smrg { test -z "$stripcmd" || { 461949d0342Smrg # Create $dsttmp read-write so that cp doesn't create it read-only, 462949d0342Smrg # which would cause strip to fail. 463949d0342Smrg if test -z "$doit"; then 464949d0342Smrg : >"$dsttmp" # No need to fork-exec 'touch'. 465949d0342Smrg else 466949d0342Smrg $doit touch "$dsttmp" 467949d0342Smrg fi 468949d0342Smrg } 469949d0342Smrg } && 470949d0342Smrg $doit_exec $cpprog "$src" "$dsttmp") && 4719f606849Smrg 4729f606849Smrg # and set any options; do chmod last to preserve setuid bits. 4739f606849Smrg # 4749f606849Smrg # If any of these fail, we abort the whole thing. If we want to 4759f606849Smrg # ignore errors from any of these, just make sure not to ignore 4769f606849Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4779f606849Smrg # 478fba89afeSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 479fba89afeSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 480fba89afeSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 481fba89afeSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 482fba89afeSmrg 483fba89afeSmrg # If -C, don't bother to copy if it wouldn't change the file. 484fba89afeSmrg if $copy_on_change && 485949d0342Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 486949d0342Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 487949d0342Smrg set -f && 488fba89afeSmrg set X $old && old=:$2:$4:$5:$6 && 489fba89afeSmrg set X $new && new=:$2:$4:$5:$6 && 490949d0342Smrg set +f && 491fba89afeSmrg test "$old" = "$new" && 492fba89afeSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 493fba89afeSmrg then 494fba89afeSmrg rm -f "$dsttmp" 495fba89afeSmrg else 496949d0342Smrg # If $backupsuffix is set, and the file being installed 497949d0342Smrg # already exists, attempt a backup. Don't worry if it fails, 498949d0342Smrg # e.g., if mv doesn't support -f. 499949d0342Smrg if test -n "$backupsuffix" && test -f "$dst"; then 500949d0342Smrg $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null 501949d0342Smrg fi 502949d0342Smrg 503fba89afeSmrg # Rename the file to the real destination. 504fba89afeSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 505fba89afeSmrg 506fba89afeSmrg # The rename failed, perhaps because mv can't rename something else 507fba89afeSmrg # to itself, or perhaps because mv is so ancient that it does not 508fba89afeSmrg # support -f. 509fba89afeSmrg { 510949d0342Smrg # Now remove or move aside any old file at destination location. 511949d0342Smrg # We try this two ways since rm can't unlink itself on some 512949d0342Smrg # systems and the destination file might be busy for other 513949d0342Smrg # reasons. In this case, the final cleanup might fail but the new 514949d0342Smrg # file should still install successfully. 515949d0342Smrg { 516949d0342Smrg test ! -f "$dst" || 517949d0342Smrg $doit $rmcmd "$dst" 2>/dev/null || 518949d0342Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 519949d0342Smrg { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } 520949d0342Smrg } || 521949d0342Smrg { echo "$0: cannot unlink or rename $dst" >&2 522949d0342Smrg (exit 1); exit 1 523949d0342Smrg } 524949d0342Smrg } && 525949d0342Smrg 526949d0342Smrg # Now rename the file to the real destination. 527949d0342Smrg $doit $mvcmd "$dsttmp" "$dst" 528fba89afeSmrg } 529fba89afeSmrg fi || exit 1 5309f606849Smrg 5319f606849Smrg trap '' 0 5329f606849Smrg fi 5339f606849Smrgdone 5349f606849Smrg 5359f606849Smrg# Local variables: 536949d0342Smrg# eval: (add-hook 'before-save-hook 'time-stamp) 5379f606849Smrg# time-stamp-start: "scriptversion=" 5389f606849Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 539949d0342Smrg# time-stamp-time-zone: "UTC0" 540fba89afeSmrg# time-stamp-end: "; # UTC" 5419f606849Smrg# End: 542