install-sh revision 0a6b08f8
1126a8a12Smrg#!/bin/sh 2126a8a12Smrg# install - install a program, script, or datafile 3126a8a12Smrg 40a6b08f8Smrgscriptversion=2011-11-20.07; # UTC 5126a8a12Smrg 6126a8a12Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7126a8a12Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8126a8a12Smrg# following copyright and license. 9126a8a12Smrg# 10126a8a12Smrg# Copyright (C) 1994 X Consortium 11126a8a12Smrg# 12126a8a12Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13126a8a12Smrg# of this software and associated documentation files (the "Software"), to 14126a8a12Smrg# deal in the Software without restriction, including without limitation the 15126a8a12Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16126a8a12Smrg# sell copies of the Software, and to permit persons to whom the Software is 17126a8a12Smrg# furnished to do so, subject to the following conditions: 18126a8a12Smrg# 19126a8a12Smrg# The above copyright notice and this permission notice shall be included in 20126a8a12Smrg# all copies or substantial portions of the Software. 21126a8a12Smrg# 22126a8a12Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23126a8a12Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24126a8a12Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25126a8a12Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26126a8a12Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27126a8a12Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28126a8a12Smrg# 29126a8a12Smrg# Except as contained in this notice, the name of the X Consortium shall not 30126a8a12Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31126a8a12Smrg# ings in this Software without prior written authorization from the X Consor- 32126a8a12Smrg# tium. 33126a8a12Smrg# 34126a8a12Smrg# 35126a8a12Smrg# FSF changes to this file are in the public domain. 36126a8a12Smrg# 37126a8a12Smrg# Calling this script install-sh is preferred over install.sh, to prevent 380a6b08f8Smrg# 'make' implicit rules from creating a file called install from it 39126a8a12Smrg# when there is no Makefile. 40126a8a12Smrg# 41126a8a12Smrg# This script is compatible with the BSD install script, but was written 42126a8a12Smrg# from scratch. 43126a8a12Smrg 44126a8a12Smrgnl=' 45126a8a12Smrg' 46126a8a12SmrgIFS=" "" $nl" 47126a8a12Smrg 48126a8a12Smrg# set DOITPROG to echo to test this script 49126a8a12Smrg 50126a8a12Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51d656433aSmrgdoit=${DOITPROG-} 52126a8a12Smrgif test -z "$doit"; then 53126a8a12Smrg doit_exec=exec 54126a8a12Smrgelse 55126a8a12Smrg doit_exec=$doit 56126a8a12Smrgfi 57126a8a12Smrg 58126a8a12Smrg# Put in absolute file names if you don't have them in your path; 59126a8a12Smrg# or use environment vars. 60126a8a12Smrg 61d656433aSmrgchgrpprog=${CHGRPPROG-chgrp} 62d656433aSmrgchmodprog=${CHMODPROG-chmod} 63d656433aSmrgchownprog=${CHOWNPROG-chown} 64d656433aSmrgcmpprog=${CMPPROG-cmp} 65d656433aSmrgcpprog=${CPPROG-cp} 66d656433aSmrgmkdirprog=${MKDIRPROG-mkdir} 67d656433aSmrgmvprog=${MVPROG-mv} 68d656433aSmrgrmprog=${RMPROG-rm} 69d656433aSmrgstripprog=${STRIPPROG-strip} 70d656433aSmrg 71d656433aSmrgposix_glob='?' 72d656433aSmrginitialize_posix_glob=' 73d656433aSmrg test "$posix_glob" != "?" || { 74d656433aSmrg if (set -f) 2>/dev/null; then 75d656433aSmrg posix_glob= 76d656433aSmrg else 77d656433aSmrg posix_glob=: 78d656433aSmrg fi 79d656433aSmrg } 80d656433aSmrg' 81126a8a12Smrg 82126a8a12Smrgposix_mkdir= 83126a8a12Smrg 84126a8a12Smrg# Desired mode of installed file. 85126a8a12Smrgmode=0755 86126a8a12Smrg 87d656433aSmrgchgrpcmd= 88126a8a12Smrgchmodcmd=$chmodprog 89126a8a12Smrgchowncmd= 90d656433aSmrgmvcmd=$mvprog 91126a8a12Smrgrmcmd="$rmprog -f" 92d656433aSmrgstripcmd= 93d656433aSmrg 94126a8a12Smrgsrc= 95126a8a12Smrgdst= 96126a8a12Smrgdir_arg= 97d656433aSmrgdst_arg= 98d656433aSmrg 99d656433aSmrgcopy_on_change=false 100126a8a12Smrgno_target_directory= 101126a8a12Smrg 102d656433aSmrgusage="\ 103d656433aSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104126a8a12Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105126a8a12Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106126a8a12Smrg or: $0 [OPTION]... -d DIRECTORIES... 107126a8a12Smrg 108126a8a12SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109126a8a12SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110126a8a12SmrgIn the 4th, create DIRECTORIES. 111126a8a12Smrg 112126a8a12SmrgOptions: 113d656433aSmrg --help display this help and exit. 114d656433aSmrg --version display version info and exit. 115d656433aSmrg 116d656433aSmrg -c (ignored) 117d656433aSmrg -C install only if different (preserve the last data modification time) 118d656433aSmrg -d create directories instead of installing files. 119d656433aSmrg -g GROUP $chgrpprog installed files to GROUP. 120d656433aSmrg -m MODE $chmodprog installed files to MODE. 121d656433aSmrg -o USER $chownprog installed files to USER. 122d656433aSmrg -s $stripprog installed files. 123d656433aSmrg -t DIRECTORY install into DIRECTORY. 124d656433aSmrg -T report an error if DSTFILE is a directory. 125126a8a12Smrg 126126a8a12SmrgEnvironment variables override the default commands: 127d656433aSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128d656433aSmrg RMPROG STRIPPROG 129126a8a12Smrg" 130126a8a12Smrg 131126a8a12Smrgwhile test $# -ne 0; do 132126a8a12Smrg case $1 in 133d656433aSmrg -c) ;; 134d656433aSmrg 135d656433aSmrg -C) copy_on_change=true;; 136126a8a12Smrg 137d656433aSmrg -d) dir_arg=true;; 138126a8a12Smrg 139126a8a12Smrg -g) chgrpcmd="$chgrpprog $2" 140d656433aSmrg shift;; 141126a8a12Smrg 142126a8a12Smrg --help) echo "$usage"; exit $?;; 143126a8a12Smrg 144126a8a12Smrg -m) mode=$2 145126a8a12Smrg case $mode in 146126a8a12Smrg *' '* | *' '* | *' 147126a8a12Smrg'* | *'*'* | *'?'* | *'['*) 148126a8a12Smrg echo "$0: invalid mode: $mode" >&2 149126a8a12Smrg exit 1;; 150126a8a12Smrg esac 151d656433aSmrg shift;; 152126a8a12Smrg 153126a8a12Smrg -o) chowncmd="$chownprog $2" 154d656433aSmrg shift;; 155126a8a12Smrg 156d656433aSmrg -s) stripcmd=$stripprog;; 157126a8a12Smrg 158d656433aSmrg -t) dst_arg=$2 1590a6b08f8Smrg # Protect names problematic for 'test' and other utilities. 1600a6b08f8Smrg case $dst_arg in 1610a6b08f8Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1620a6b08f8Smrg esac 163d656433aSmrg shift;; 164126a8a12Smrg 165d656433aSmrg -T) no_target_directory=true;; 166126a8a12Smrg 167126a8a12Smrg --version) echo "$0 $scriptversion"; exit $?;; 168126a8a12Smrg 169126a8a12Smrg --) shift 170126a8a12Smrg break;; 171126a8a12Smrg 172126a8a12Smrg -*) echo "$0: invalid option: $1" >&2 173126a8a12Smrg exit 1;; 174126a8a12Smrg 175126a8a12Smrg *) break;; 176126a8a12Smrg esac 177d656433aSmrg shift 178126a8a12Smrgdone 179126a8a12Smrg 180d656433aSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181126a8a12Smrg # When -d is used, all remaining arguments are directories to create. 182126a8a12Smrg # When -t is used, the destination is already specified. 183126a8a12Smrg # Otherwise, the last argument is the destination. Remove it from $@. 184126a8a12Smrg for arg 185126a8a12Smrg do 186d656433aSmrg if test -n "$dst_arg"; then 187126a8a12Smrg # $@ is not empty: it contains at least $arg. 188d656433aSmrg set fnord "$@" "$dst_arg" 189126a8a12Smrg shift # fnord 190126a8a12Smrg fi 191126a8a12Smrg shift # arg 192d656433aSmrg dst_arg=$arg 1930a6b08f8Smrg # Protect names problematic for 'test' and other utilities. 1940a6b08f8Smrg case $dst_arg in 1950a6b08f8Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1960a6b08f8Smrg esac 197126a8a12Smrg done 198126a8a12Smrgfi 199126a8a12Smrg 200126a8a12Smrgif test $# -eq 0; then 201126a8a12Smrg if test -z "$dir_arg"; then 202126a8a12Smrg echo "$0: no input file specified." >&2 203126a8a12Smrg exit 1 204126a8a12Smrg fi 2050a6b08f8Smrg # It's OK to call 'install-sh -d' without argument. 206126a8a12Smrg # This can happen when creating conditional directories. 207126a8a12Smrg exit 0 208126a8a12Smrgfi 209126a8a12Smrg 210126a8a12Smrgif test -z "$dir_arg"; then 2110a6b08f8Smrg do_exit='(exit $ret); exit $ret' 2120a6b08f8Smrg trap "ret=129; $do_exit" 1 2130a6b08f8Smrg trap "ret=130; $do_exit" 2 2140a6b08f8Smrg trap "ret=141; $do_exit" 13 2150a6b08f8Smrg trap "ret=143; $do_exit" 15 216126a8a12Smrg 217126a8a12Smrg # Set umask so as not to create temps with too-generous modes. 218126a8a12Smrg # However, 'strip' requires both read and write access to temps. 219126a8a12Smrg case $mode in 220126a8a12Smrg # Optimize common cases. 221126a8a12Smrg *644) cp_umask=133;; 222126a8a12Smrg *755) cp_umask=22;; 223126a8a12Smrg 224126a8a12Smrg *[0-7]) 225126a8a12Smrg if test -z "$stripcmd"; then 226126a8a12Smrg u_plus_rw= 227126a8a12Smrg else 228126a8a12Smrg u_plus_rw='% 200' 229126a8a12Smrg fi 230126a8a12Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231126a8a12Smrg *) 232126a8a12Smrg if test -z "$stripcmd"; then 233126a8a12Smrg u_plus_rw= 234126a8a12Smrg else 235126a8a12Smrg u_plus_rw=,u+rw 236126a8a12Smrg fi 237126a8a12Smrg cp_umask=$mode$u_plus_rw;; 238126a8a12Smrg esac 239126a8a12Smrgfi 240126a8a12Smrg 241126a8a12Smrgfor src 242126a8a12Smrgdo 2430a6b08f8Smrg # Protect names problematic for 'test' and other utilities. 244126a8a12Smrg case $src in 2450a6b08f8Smrg -* | [=\(\)!]) src=./$src;; 246126a8a12Smrg esac 247126a8a12Smrg 248126a8a12Smrg if test -n "$dir_arg"; then 249126a8a12Smrg dst=$src 250126a8a12Smrg dstdir=$dst 251126a8a12Smrg test -d "$dstdir" 252126a8a12Smrg dstdir_status=$? 253126a8a12Smrg else 254126a8a12Smrg 255126a8a12Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256126a8a12Smrg # might cause directories to be created, which would be especially bad 257126a8a12Smrg # if $src (and thus $dsttmp) contains '*'. 258126a8a12Smrg if test ! -f "$src" && test ! -d "$src"; then 259126a8a12Smrg echo "$0: $src does not exist." >&2 260126a8a12Smrg exit 1 261126a8a12Smrg fi 262126a8a12Smrg 263d656433aSmrg if test -z "$dst_arg"; then 264126a8a12Smrg echo "$0: no destination specified." >&2 265126a8a12Smrg exit 1 266126a8a12Smrg fi 267d656433aSmrg dst=$dst_arg 268126a8a12Smrg 269126a8a12Smrg # If destination is a directory, append the input filename; won't work 270126a8a12Smrg # if double slashes aren't ignored. 271126a8a12Smrg if test -d "$dst"; then 272126a8a12Smrg if test -n "$no_target_directory"; then 273d656433aSmrg echo "$0: $dst_arg: Is a directory" >&2 274126a8a12Smrg exit 1 275126a8a12Smrg fi 276126a8a12Smrg dstdir=$dst 277126a8a12Smrg dst=$dstdir/`basename "$src"` 278126a8a12Smrg dstdir_status=0 279126a8a12Smrg else 280126a8a12Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 281126a8a12Smrg dstdir=` 282126a8a12Smrg (dirname "$dst") 2>/dev/null || 283126a8a12Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284126a8a12Smrg X"$dst" : 'X\(//\)[^/]' \| \ 285126a8a12Smrg X"$dst" : 'X\(//\)$' \| \ 286126a8a12Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287126a8a12Smrg echo X"$dst" | 288126a8a12Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289126a8a12Smrg s//\1/ 290126a8a12Smrg q 291126a8a12Smrg } 292126a8a12Smrg /^X\(\/\/\)[^/].*/{ 293126a8a12Smrg s//\1/ 294126a8a12Smrg q 295126a8a12Smrg } 296126a8a12Smrg /^X\(\/\/\)$/{ 297126a8a12Smrg s//\1/ 298126a8a12Smrg q 299126a8a12Smrg } 300126a8a12Smrg /^X\(\/\).*/{ 301126a8a12Smrg s//\1/ 302126a8a12Smrg q 303126a8a12Smrg } 304126a8a12Smrg s/.*/./; q' 305126a8a12Smrg ` 306126a8a12Smrg 307126a8a12Smrg test -d "$dstdir" 308126a8a12Smrg dstdir_status=$? 309126a8a12Smrg fi 310126a8a12Smrg fi 311126a8a12Smrg 312126a8a12Smrg obsolete_mkdir_used=false 313126a8a12Smrg 314126a8a12Smrg if test $dstdir_status != 0; then 315126a8a12Smrg case $posix_mkdir in 316126a8a12Smrg '') 317126a8a12Smrg # Create intermediate dirs using mode 755 as modified by the umask. 318126a8a12Smrg # This is like FreeBSD 'install' as of 1997-10-28. 319126a8a12Smrg umask=`umask` 320126a8a12Smrg case $stripcmd.$umask in 321126a8a12Smrg # Optimize common cases. 322126a8a12Smrg *[2367][2367]) mkdir_umask=$umask;; 323126a8a12Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324126a8a12Smrg 325126a8a12Smrg *[0-7]) 326126a8a12Smrg mkdir_umask=`expr $umask + 22 \ 327126a8a12Smrg - $umask % 100 % 40 + $umask % 20 \ 328126a8a12Smrg - $umask % 10 % 4 + $umask % 2 329126a8a12Smrg `;; 330126a8a12Smrg *) mkdir_umask=$umask,go-w;; 331126a8a12Smrg esac 332126a8a12Smrg 333126a8a12Smrg # With -d, create the new directory with the user-specified mode. 334126a8a12Smrg # Otherwise, rely on $mkdir_umask. 335126a8a12Smrg if test -n "$dir_arg"; then 336126a8a12Smrg mkdir_mode=-m$mode 337126a8a12Smrg else 338126a8a12Smrg mkdir_mode= 339126a8a12Smrg fi 340126a8a12Smrg 341126a8a12Smrg posix_mkdir=false 342126a8a12Smrg case $umask in 343126a8a12Smrg *[123567][0-7][0-7]) 344126a8a12Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345126a8a12Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346126a8a12Smrg ;; 347126a8a12Smrg *) 348126a8a12Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349126a8a12Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350126a8a12Smrg 351126a8a12Smrg if (umask $mkdir_umask && 352126a8a12Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353126a8a12Smrg then 354126a8a12Smrg if test -z "$dir_arg" || { 355126a8a12Smrg # Check for POSIX incompatibilities with -m. 356126a8a12Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3570a6b08f8Smrg # other-writable bit of parent directory when it shouldn't. 358126a8a12Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359126a8a12Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360126a8a12Smrg case $ls_ld_tmpdir in 361126a8a12Smrg d????-?r-*) different_mode=700;; 362126a8a12Smrg d????-?--*) different_mode=755;; 363126a8a12Smrg *) false;; 364126a8a12Smrg esac && 365126a8a12Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366126a8a12Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367126a8a12Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368126a8a12Smrg } 369126a8a12Smrg } 370126a8a12Smrg then posix_mkdir=: 371126a8a12Smrg fi 372126a8a12Smrg rmdir "$tmpdir/d" "$tmpdir" 373126a8a12Smrg else 374126a8a12Smrg # Remove any dirs left behind by ancient mkdir implementations. 375126a8a12Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376126a8a12Smrg fi 377126a8a12Smrg trap '' 0;; 378126a8a12Smrg esac;; 379126a8a12Smrg esac 380126a8a12Smrg 381126a8a12Smrg if 382126a8a12Smrg $posix_mkdir && ( 383126a8a12Smrg umask $mkdir_umask && 384126a8a12Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385126a8a12Smrg ) 386126a8a12Smrg then : 387126a8a12Smrg else 388126a8a12Smrg 389126a8a12Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390126a8a12Smrg # or it failed possibly due to a race condition. Create the 391126a8a12Smrg # directory the slow way, step by step, checking for races as we go. 392126a8a12Smrg 393126a8a12Smrg case $dstdir in 394d656433aSmrg /*) prefix='/';; 3950a6b08f8Smrg [-=\(\)!]*) prefix='./';; 396d656433aSmrg *) prefix='';; 397126a8a12Smrg esac 398126a8a12Smrg 399d656433aSmrg eval "$initialize_posix_glob" 400126a8a12Smrg 401126a8a12Smrg oIFS=$IFS 402126a8a12Smrg IFS=/ 403d656433aSmrg $posix_glob set -f 404126a8a12Smrg set fnord $dstdir 405126a8a12Smrg shift 406d656433aSmrg $posix_glob set +f 407126a8a12Smrg IFS=$oIFS 408126a8a12Smrg 409126a8a12Smrg prefixes= 410126a8a12Smrg 411126a8a12Smrg for d 412126a8a12Smrg do 4130a6b08f8Smrg test X"$d" = X && continue 414126a8a12Smrg 415126a8a12Smrg prefix=$prefix$d 416126a8a12Smrg if test -d "$prefix"; then 417126a8a12Smrg prefixes= 418126a8a12Smrg else 419126a8a12Smrg if $posix_mkdir; then 420126a8a12Smrg (umask=$mkdir_umask && 421126a8a12Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422126a8a12Smrg # Don't fail if two instances are running concurrently. 423126a8a12Smrg test -d "$prefix" || exit 1 424126a8a12Smrg else 425126a8a12Smrg case $prefix in 426126a8a12Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427126a8a12Smrg *) qprefix=$prefix;; 428126a8a12Smrg esac 429126a8a12Smrg prefixes="$prefixes '$qprefix'" 430126a8a12Smrg fi 431126a8a12Smrg fi 432126a8a12Smrg prefix=$prefix/ 433126a8a12Smrg done 434126a8a12Smrg 435126a8a12Smrg if test -n "$prefixes"; then 436126a8a12Smrg # Don't fail if two instances are running concurrently. 437126a8a12Smrg (umask $mkdir_umask && 438126a8a12Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 439126a8a12Smrg test -d "$dstdir" || exit 1 440126a8a12Smrg obsolete_mkdir_used=true 441126a8a12Smrg fi 442126a8a12Smrg fi 443126a8a12Smrg fi 444126a8a12Smrg 445126a8a12Smrg if test -n "$dir_arg"; then 446126a8a12Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447126a8a12Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448126a8a12Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449126a8a12Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450126a8a12Smrg else 451126a8a12Smrg 452126a8a12Smrg # Make a couple of temp file names in the proper directory. 453126a8a12Smrg dsttmp=$dstdir/_inst.$$_ 454126a8a12Smrg rmtmp=$dstdir/_rm.$$_ 455126a8a12Smrg 456126a8a12Smrg # Trap to clean up those temp files at exit. 457126a8a12Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458126a8a12Smrg 459126a8a12Smrg # Copy the file name to the temp name. 460126a8a12Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461126a8a12Smrg 462126a8a12Smrg # and set any options; do chmod last to preserve setuid bits. 463126a8a12Smrg # 464126a8a12Smrg # If any of these fail, we abort the whole thing. If we want to 465126a8a12Smrg # ignore errors from any of these, just make sure not to ignore 466126a8a12Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 467126a8a12Smrg # 468d656433aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469d656433aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470d656433aSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471d656433aSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472d656433aSmrg 473d656433aSmrg # If -C, don't bother to copy if it wouldn't change the file. 474d656433aSmrg if $copy_on_change && 475d656433aSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476d656433aSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477d656433aSmrg 478d656433aSmrg eval "$initialize_posix_glob" && 479d656433aSmrg $posix_glob set -f && 480d656433aSmrg set X $old && old=:$2:$4:$5:$6 && 481d656433aSmrg set X $new && new=:$2:$4:$5:$6 && 482d656433aSmrg $posix_glob set +f && 483d656433aSmrg 484d656433aSmrg test "$old" = "$new" && 485d656433aSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486d656433aSmrg then 487d656433aSmrg rm -f "$dsttmp" 488d656433aSmrg else 489d656433aSmrg # Rename the file to the real destination. 490d656433aSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491d656433aSmrg 492d656433aSmrg # The rename failed, perhaps because mv can't rename something else 493d656433aSmrg # to itself, or perhaps because mv is so ancient that it does not 494d656433aSmrg # support -f. 495d656433aSmrg { 496d656433aSmrg # Now remove or move aside any old file at destination location. 497d656433aSmrg # We try this two ways since rm can't unlink itself on some 498d656433aSmrg # systems and the destination file might be busy for other 499d656433aSmrg # reasons. In this case, the final cleanup might fail but the new 500d656433aSmrg # file should still install successfully. 501d656433aSmrg { 502d656433aSmrg test ! -f "$dst" || 503d656433aSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 504d656433aSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505d656433aSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506d656433aSmrg } || 507d656433aSmrg { echo "$0: cannot unlink or rename $dst" >&2 508d656433aSmrg (exit 1); exit 1 509d656433aSmrg } 510d656433aSmrg } && 511d656433aSmrg 512d656433aSmrg # Now rename the file to the real destination. 513d656433aSmrg $doit $mvcmd "$dsttmp" "$dst" 514d656433aSmrg } 515d656433aSmrg fi || exit 1 516126a8a12Smrg 517126a8a12Smrg trap '' 0 518126a8a12Smrg fi 519126a8a12Smrgdone 520126a8a12Smrg 521126a8a12Smrg# Local variables: 522126a8a12Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 523126a8a12Smrg# time-stamp-start: "scriptversion=" 524126a8a12Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525d656433aSmrg# time-stamp-time-zone: "UTC" 526d656433aSmrg# time-stamp-end: "; # UTC" 527126a8a12Smrg# End: 528