install-sh revision bf2eeab3
114c0a534Smrg#!/bin/sh 214c0a534Smrg# install - install a program, script, or datafile 314c0a534Smrg 4bf2eeab3Smrgscriptversion=2009-04-28.21; # UTC 514c0a534Smrg 614c0a534Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 714c0a534Smrg# later released in X11R6 (xc/config/util/install.sh) with the 814c0a534Smrg# following copyright and license. 914c0a534Smrg# 1014c0a534Smrg# Copyright (C) 1994 X Consortium 1114c0a534Smrg# 1214c0a534Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1314c0a534Smrg# of this software and associated documentation files (the "Software"), to 1414c0a534Smrg# deal in the Software without restriction, including without limitation the 1514c0a534Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1614c0a534Smrg# sell copies of the Software, and to permit persons to whom the Software is 1714c0a534Smrg# furnished to do so, subject to the following conditions: 1814c0a534Smrg# 1914c0a534Smrg# The above copyright notice and this permission notice shall be included in 2014c0a534Smrg# all copies or substantial portions of the Software. 2114c0a534Smrg# 2214c0a534Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2314c0a534Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2414c0a534Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2514c0a534Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2614c0a534Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2714c0a534Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2814c0a534Smrg# 2914c0a534Smrg# Except as contained in this notice, the name of the X Consortium shall not 3014c0a534Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3114c0a534Smrg# ings in this Software without prior written authorization from the X Consor- 3214c0a534Smrg# tium. 3314c0a534Smrg# 3414c0a534Smrg# 3514c0a534Smrg# FSF changes to this file are in the public domain. 3614c0a534Smrg# 3714c0a534Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3814c0a534Smrg# `make' implicit rules from creating a file called install from it 3914c0a534Smrg# when there is no Makefile. 4014c0a534Smrg# 4114c0a534Smrg# This script is compatible with the BSD install script, but was written 42bf2eeab3Smrg# from scratch. 43bf2eeab3Smrg 44bf2eeab3Smrgnl=' 45bf2eeab3Smrg' 46bf2eeab3SmrgIFS=" "" $nl" 4714c0a534Smrg 4814c0a534Smrg# set DOITPROG to echo to test this script 4914c0a534Smrg 5014c0a534Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51bf2eeab3Smrgdoit=${DOITPROG-} 52bf2eeab3Smrgif test -z "$doit"; then 53bf2eeab3Smrg doit_exec=exec 54bf2eeab3Smrgelse 55bf2eeab3Smrg doit_exec=$doit 56bf2eeab3Smrgfi 5714c0a534Smrg 58bf2eeab3Smrg# Put in absolute file names if you don't have them in your path; 59bf2eeab3Smrg# or use environment vars. 60bf2eeab3Smrg 61bf2eeab3Smrgchgrpprog=${CHGRPPROG-chgrp} 62bf2eeab3Smrgchmodprog=${CHMODPROG-chmod} 63bf2eeab3Smrgchownprog=${CHOWNPROG-chown} 64bf2eeab3Smrgcmpprog=${CMPPROG-cmp} 65bf2eeab3Smrgcpprog=${CPPROG-cp} 66bf2eeab3Smrgmkdirprog=${MKDIRPROG-mkdir} 67bf2eeab3Smrgmvprog=${MVPROG-mv} 68bf2eeab3Smrgrmprog=${RMPROG-rm} 69bf2eeab3Smrgstripprog=${STRIPPROG-strip} 70bf2eeab3Smrg 71bf2eeab3Smrgposix_glob='?' 72bf2eeab3Smrginitialize_posix_glob=' 73bf2eeab3Smrg test "$posix_glob" != "?" || { 74bf2eeab3Smrg if (set -f) 2>/dev/null; then 75bf2eeab3Smrg posix_glob= 76bf2eeab3Smrg else 77bf2eeab3Smrg posix_glob=: 78bf2eeab3Smrg fi 79bf2eeab3Smrg } 80bf2eeab3Smrg' 8114c0a534Smrg 82bf2eeab3Smrgposix_mkdir= 83bf2eeab3Smrg 84bf2eeab3Smrg# Desired mode of installed file. 85bf2eeab3Smrgmode=0755 8614c0a534Smrg 8714c0a534Smrgchgrpcmd= 88bf2eeab3Smrgchmodcmd=$chmodprog 89bf2eeab3Smrgchowncmd= 90bf2eeab3Smrgmvcmd=$mvprog 9114c0a534Smrgrmcmd="$rmprog -f" 92bf2eeab3Smrgstripcmd= 93bf2eeab3Smrg 9414c0a534Smrgsrc= 9514c0a534Smrgdst= 9614c0a534Smrgdir_arg= 97bf2eeab3Smrgdst_arg= 98bf2eeab3Smrg 99bf2eeab3Smrgcopy_on_change=false 10014c0a534Smrgno_target_directory= 10114c0a534Smrg 102bf2eeab3Smrgusage="\ 103bf2eeab3SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10414c0a534Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10514c0a534Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10614c0a534Smrg or: $0 [OPTION]... -d DIRECTORIES... 10714c0a534Smrg 10814c0a534SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10914c0a534SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11014c0a534SmrgIn the 4th, create DIRECTORIES. 11114c0a534Smrg 11214c0a534SmrgOptions: 113bf2eeab3Smrg --help display this help and exit. 114bf2eeab3Smrg --version display version info and exit. 115bf2eeab3Smrg 116bf2eeab3Smrg -c (ignored) 117bf2eeab3Smrg -C install only if different (preserve the last data modification time) 118bf2eeab3Smrg -d create directories instead of installing files. 119bf2eeab3Smrg -g GROUP $chgrpprog installed files to GROUP. 120bf2eeab3Smrg -m MODE $chmodprog installed files to MODE. 121bf2eeab3Smrg -o USER $chownprog installed files to USER. 122bf2eeab3Smrg -s $stripprog installed files. 123bf2eeab3Smrg -t DIRECTORY install into DIRECTORY. 124bf2eeab3Smrg -T report an error if DSTFILE is a directory. 12514c0a534Smrg 12614c0a534SmrgEnvironment variables override the default commands: 127bf2eeab3Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128bf2eeab3Smrg RMPROG STRIPPROG 12914c0a534Smrg" 13014c0a534Smrg 131bf2eeab3Smrgwhile test $# -ne 0; do 13214c0a534Smrg case $1 in 133bf2eeab3Smrg -c) ;; 134bf2eeab3Smrg 135bf2eeab3Smrg -C) copy_on_change=true;; 13614c0a534Smrg 137bf2eeab3Smrg -d) dir_arg=true;; 13814c0a534Smrg 13914c0a534Smrg -g) chgrpcmd="$chgrpprog $2" 140bf2eeab3Smrg shift;; 14114c0a534Smrg 14214c0a534Smrg --help) echo "$usage"; exit $?;; 14314c0a534Smrg 144bf2eeab3Smrg -m) mode=$2 145bf2eeab3Smrg case $mode in 146bf2eeab3Smrg *' '* | *' '* | *' 147bf2eeab3Smrg'* | *'*'* | *'?'* | *'['*) 148bf2eeab3Smrg echo "$0: invalid mode: $mode" >&2 149bf2eeab3Smrg exit 1;; 150bf2eeab3Smrg esac 151bf2eeab3Smrg shift;; 15214c0a534Smrg 15314c0a534Smrg -o) chowncmd="$chownprog $2" 154bf2eeab3Smrg shift;; 15514c0a534Smrg 156bf2eeab3Smrg -s) stripcmd=$stripprog;; 15714c0a534Smrg 158bf2eeab3Smrg -t) dst_arg=$2 159bf2eeab3Smrg shift;; 16014c0a534Smrg 161bf2eeab3Smrg -T) no_target_directory=true;; 16214c0a534Smrg 16314c0a534Smrg --version) echo "$0 $scriptversion"; exit $?;; 16414c0a534Smrg 165bf2eeab3Smrg --) shift 16614c0a534Smrg break;; 167bf2eeab3Smrg 168bf2eeab3Smrg -*) echo "$0: invalid option: $1" >&2 169bf2eeab3Smrg exit 1;; 170bf2eeab3Smrg 171bf2eeab3Smrg *) break;; 17214c0a534Smrg esac 173bf2eeab3Smrg shift 17414c0a534Smrgdone 17514c0a534Smrg 176bf2eeab3Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 177bf2eeab3Smrg # When -d is used, all remaining arguments are directories to create. 178bf2eeab3Smrg # When -t is used, the destination is already specified. 179bf2eeab3Smrg # Otherwise, the last argument is the destination. Remove it from $@. 180bf2eeab3Smrg for arg 181bf2eeab3Smrg do 182bf2eeab3Smrg if test -n "$dst_arg"; then 183bf2eeab3Smrg # $@ is not empty: it contains at least $arg. 184bf2eeab3Smrg set fnord "$@" "$dst_arg" 185bf2eeab3Smrg shift # fnord 186bf2eeab3Smrg fi 187bf2eeab3Smrg shift # arg 188bf2eeab3Smrg dst_arg=$arg 189bf2eeab3Smrg done 190bf2eeab3Smrgfi 191bf2eeab3Smrg 192bf2eeab3Smrgif test $# -eq 0; then 19314c0a534Smrg if test -z "$dir_arg"; then 19414c0a534Smrg echo "$0: no input file specified." >&2 19514c0a534Smrg exit 1 19614c0a534Smrg fi 19714c0a534Smrg # It's OK to call `install-sh -d' without argument. 19814c0a534Smrg # This can happen when creating conditional directories. 19914c0a534Smrg exit 0 20014c0a534Smrgfi 20114c0a534Smrg 202bf2eeab3Smrgif test -z "$dir_arg"; then 203bf2eeab3Smrg trap '(exit $?); exit' 1 2 13 15 204bf2eeab3Smrg 205bf2eeab3Smrg # Set umask so as not to create temps with too-generous modes. 206bf2eeab3Smrg # However, 'strip' requires both read and write access to temps. 207bf2eeab3Smrg case $mode in 208bf2eeab3Smrg # Optimize common cases. 209bf2eeab3Smrg *644) cp_umask=133;; 210bf2eeab3Smrg *755) cp_umask=22;; 211bf2eeab3Smrg 212bf2eeab3Smrg *[0-7]) 213bf2eeab3Smrg if test -z "$stripcmd"; then 214bf2eeab3Smrg u_plus_rw= 215bf2eeab3Smrg else 216bf2eeab3Smrg u_plus_rw='% 200' 217bf2eeab3Smrg fi 218bf2eeab3Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 219bf2eeab3Smrg *) 220bf2eeab3Smrg if test -z "$stripcmd"; then 221bf2eeab3Smrg u_plus_rw= 222bf2eeab3Smrg else 223bf2eeab3Smrg u_plus_rw=,u+rw 224bf2eeab3Smrg fi 225bf2eeab3Smrg cp_umask=$mode$u_plus_rw;; 226bf2eeab3Smrg esac 227bf2eeab3Smrgfi 228bf2eeab3Smrg 22914c0a534Smrgfor src 23014c0a534Smrgdo 23114c0a534Smrg # Protect names starting with `-'. 23214c0a534Smrg case $src in 233bf2eeab3Smrg -*) src=./$src;; 23414c0a534Smrg esac 23514c0a534Smrg 23614c0a534Smrg if test -n "$dir_arg"; then 23714c0a534Smrg dst=$src 238bf2eeab3Smrg dstdir=$dst 239bf2eeab3Smrg test -d "$dstdir" 240bf2eeab3Smrg dstdir_status=$? 24114c0a534Smrg else 242bf2eeab3Smrg 24314c0a534Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 24414c0a534Smrg # might cause directories to be created, which would be especially bad 24514c0a534Smrg # if $src (and thus $dsttmp) contains '*'. 24614c0a534Smrg if test ! -f "$src" && test ! -d "$src"; then 24714c0a534Smrg echo "$0: $src does not exist." >&2 24814c0a534Smrg exit 1 24914c0a534Smrg fi 25014c0a534Smrg 251bf2eeab3Smrg if test -z "$dst_arg"; then 25214c0a534Smrg echo "$0: no destination specified." >&2 25314c0a534Smrg exit 1 25414c0a534Smrg fi 25514c0a534Smrg 256bf2eeab3Smrg dst=$dst_arg 25714c0a534Smrg # Protect names starting with `-'. 25814c0a534Smrg case $dst in 259bf2eeab3Smrg -*) dst=./$dst;; 26014c0a534Smrg esac 26114c0a534Smrg 26214c0a534Smrg # If destination is a directory, append the input filename; won't work 26314c0a534Smrg # if double slashes aren't ignored. 26414c0a534Smrg if test -d "$dst"; then 26514c0a534Smrg if test -n "$no_target_directory"; then 266bf2eeab3Smrg echo "$0: $dst_arg: Is a directory" >&2 26714c0a534Smrg exit 1 26814c0a534Smrg fi 269bf2eeab3Smrg dstdir=$dst 270bf2eeab3Smrg dst=$dstdir/`basename "$src"` 271bf2eeab3Smrg dstdir_status=0 272bf2eeab3Smrg else 273bf2eeab3Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 274bf2eeab3Smrg dstdir=` 275bf2eeab3Smrg (dirname "$dst") 2>/dev/null || 276bf2eeab3Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 277bf2eeab3Smrg X"$dst" : 'X\(//\)[^/]' \| \ 278bf2eeab3Smrg X"$dst" : 'X\(//\)$' \| \ 279bf2eeab3Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 280bf2eeab3Smrg echo X"$dst" | 281bf2eeab3Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 282bf2eeab3Smrg s//\1/ 283bf2eeab3Smrg q 284bf2eeab3Smrg } 285bf2eeab3Smrg /^X\(\/\/\)[^/].*/{ 286bf2eeab3Smrg s//\1/ 287bf2eeab3Smrg q 288bf2eeab3Smrg } 289bf2eeab3Smrg /^X\(\/\/\)$/{ 290bf2eeab3Smrg s//\1/ 291bf2eeab3Smrg q 292bf2eeab3Smrg } 293bf2eeab3Smrg /^X\(\/\).*/{ 294bf2eeab3Smrg s//\1/ 295bf2eeab3Smrg q 296bf2eeab3Smrg } 297bf2eeab3Smrg s/.*/./; q' 298bf2eeab3Smrg ` 299bf2eeab3Smrg 300bf2eeab3Smrg test -d "$dstdir" 301bf2eeab3Smrg dstdir_status=$? 30214c0a534Smrg fi 30314c0a534Smrg fi 30414c0a534Smrg 305bf2eeab3Smrg obsolete_mkdir_used=false 306bf2eeab3Smrg 307bf2eeab3Smrg if test $dstdir_status != 0; then 308bf2eeab3Smrg case $posix_mkdir in 309bf2eeab3Smrg '') 310bf2eeab3Smrg # Create intermediate dirs using mode 755 as modified by the umask. 311bf2eeab3Smrg # This is like FreeBSD 'install' as of 1997-10-28. 312bf2eeab3Smrg umask=`umask` 313bf2eeab3Smrg case $stripcmd.$umask in 314bf2eeab3Smrg # Optimize common cases. 315bf2eeab3Smrg *[2367][2367]) mkdir_umask=$umask;; 316bf2eeab3Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 317bf2eeab3Smrg 318bf2eeab3Smrg *[0-7]) 319bf2eeab3Smrg mkdir_umask=`expr $umask + 22 \ 320bf2eeab3Smrg - $umask % 100 % 40 + $umask % 20 \ 321bf2eeab3Smrg - $umask % 10 % 4 + $umask % 2 322bf2eeab3Smrg `;; 323bf2eeab3Smrg *) mkdir_umask=$umask,go-w;; 324bf2eeab3Smrg esac 325bf2eeab3Smrg 326bf2eeab3Smrg # With -d, create the new directory with the user-specified mode. 327bf2eeab3Smrg # Otherwise, rely on $mkdir_umask. 328bf2eeab3Smrg if test -n "$dir_arg"; then 329bf2eeab3Smrg mkdir_mode=-m$mode 330bf2eeab3Smrg else 331bf2eeab3Smrg mkdir_mode= 332bf2eeab3Smrg fi 333bf2eeab3Smrg 334bf2eeab3Smrg posix_mkdir=false 335bf2eeab3Smrg case $umask in 336bf2eeab3Smrg *[123567][0-7][0-7]) 337bf2eeab3Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 338bf2eeab3Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 339bf2eeab3Smrg ;; 340bf2eeab3Smrg *) 341bf2eeab3Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 342bf2eeab3Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 343bf2eeab3Smrg 344bf2eeab3Smrg if (umask $mkdir_umask && 345bf2eeab3Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 346bf2eeab3Smrg then 347bf2eeab3Smrg if test -z "$dir_arg" || { 348bf2eeab3Smrg # Check for POSIX incompatibilities with -m. 349bf2eeab3Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 350bf2eeab3Smrg # other-writeable bit of parent directory when it shouldn't. 351bf2eeab3Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 352bf2eeab3Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 353bf2eeab3Smrg case $ls_ld_tmpdir in 354bf2eeab3Smrg d????-?r-*) different_mode=700;; 355bf2eeab3Smrg d????-?--*) different_mode=755;; 356bf2eeab3Smrg *) false;; 357bf2eeab3Smrg esac && 358bf2eeab3Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 359bf2eeab3Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 360bf2eeab3Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 361bf2eeab3Smrg } 362bf2eeab3Smrg } 363bf2eeab3Smrg then posix_mkdir=: 364bf2eeab3Smrg fi 365bf2eeab3Smrg rmdir "$tmpdir/d" "$tmpdir" 366bf2eeab3Smrg else 367bf2eeab3Smrg # Remove any dirs left behind by ancient mkdir implementations. 368bf2eeab3Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 369bf2eeab3Smrg fi 370bf2eeab3Smrg trap '' 0;; 371bf2eeab3Smrg esac;; 372bf2eeab3Smrg esac 37314c0a534Smrg 374bf2eeab3Smrg if 375bf2eeab3Smrg $posix_mkdir && ( 376bf2eeab3Smrg umask $mkdir_umask && 377bf2eeab3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 378bf2eeab3Smrg ) 379bf2eeab3Smrg then : 380bf2eeab3Smrg else 38114c0a534Smrg 382bf2eeab3Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 383bf2eeab3Smrg # or it failed possibly due to a race condition. Create the 384bf2eeab3Smrg # directory the slow way, step by step, checking for races as we go. 38514c0a534Smrg 386bf2eeab3Smrg case $dstdir in 387bf2eeab3Smrg /*) prefix='/';; 388bf2eeab3Smrg -*) prefix='./';; 389bf2eeab3Smrg *) prefix='';; 390bf2eeab3Smrg esac 39114c0a534Smrg 392bf2eeab3Smrg eval "$initialize_posix_glob" 39314c0a534Smrg 394bf2eeab3Smrg oIFS=$IFS 395bf2eeab3Smrg IFS=/ 396bf2eeab3Smrg $posix_glob set -f 397bf2eeab3Smrg set fnord $dstdir 39814c0a534Smrg shift 399bf2eeab3Smrg $posix_glob set +f 400bf2eeab3Smrg IFS=$oIFS 401bf2eeab3Smrg 402bf2eeab3Smrg prefixes= 403bf2eeab3Smrg 404bf2eeab3Smrg for d 405bf2eeab3Smrg do 406bf2eeab3Smrg test -z "$d" && continue 407bf2eeab3Smrg 408bf2eeab3Smrg prefix=$prefix$d 409bf2eeab3Smrg if test -d "$prefix"; then 410bf2eeab3Smrg prefixes= 411bf2eeab3Smrg else 412bf2eeab3Smrg if $posix_mkdir; then 413bf2eeab3Smrg (umask=$mkdir_umask && 414bf2eeab3Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 415bf2eeab3Smrg # Don't fail if two instances are running concurrently. 416bf2eeab3Smrg test -d "$prefix" || exit 1 417bf2eeab3Smrg else 418bf2eeab3Smrg case $prefix in 419bf2eeab3Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 420bf2eeab3Smrg *) qprefix=$prefix;; 421bf2eeab3Smrg esac 422bf2eeab3Smrg prefixes="$prefixes '$qprefix'" 423bf2eeab3Smrg fi 424bf2eeab3Smrg fi 425bf2eeab3Smrg prefix=$prefix/ 426bf2eeab3Smrg done 427bf2eeab3Smrg 428bf2eeab3Smrg if test -n "$prefixes"; then 429bf2eeab3Smrg # Don't fail if two instances are running concurrently. 430bf2eeab3Smrg (umask $mkdir_umask && 431bf2eeab3Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 432bf2eeab3Smrg test -d "$dstdir" || exit 1 433bf2eeab3Smrg obsolete_mkdir_used=true 43414c0a534Smrg fi 435bf2eeab3Smrg fi 43614c0a534Smrg fi 43714c0a534Smrg 43814c0a534Smrg if test -n "$dir_arg"; then 439bf2eeab3Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 440bf2eeab3Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 441bf2eeab3Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 442bf2eeab3Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44314c0a534Smrg else 44414c0a534Smrg 44514c0a534Smrg # Make a couple of temp file names in the proper directory. 44614c0a534Smrg dsttmp=$dstdir/_inst.$$_ 44714c0a534Smrg rmtmp=$dstdir/_rm.$$_ 44814c0a534Smrg 44914c0a534Smrg # Trap to clean up those temp files at exit. 45014c0a534Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45114c0a534Smrg 45214c0a534Smrg # Copy the file name to the temp name. 453bf2eeab3Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45414c0a534Smrg 45514c0a534Smrg # and set any options; do chmod last to preserve setuid bits. 45614c0a534Smrg # 45714c0a534Smrg # If any of these fail, we abort the whole thing. If we want to 45814c0a534Smrg # ignore errors from any of these, just make sure not to ignore 45914c0a534Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46014c0a534Smrg # 461bf2eeab3Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 462bf2eeab3Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 463bf2eeab3Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 464bf2eeab3Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 465bf2eeab3Smrg 466bf2eeab3Smrg # If -C, don't bother to copy if it wouldn't change the file. 467bf2eeab3Smrg if $copy_on_change && 468bf2eeab3Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 469bf2eeab3Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 470bf2eeab3Smrg 471bf2eeab3Smrg eval "$initialize_posix_glob" && 472bf2eeab3Smrg $posix_glob set -f && 473bf2eeab3Smrg set X $old && old=:$2:$4:$5:$6 && 474bf2eeab3Smrg set X $new && new=:$2:$4:$5:$6 && 475bf2eeab3Smrg $posix_glob set +f && 476bf2eeab3Smrg 477bf2eeab3Smrg test "$old" = "$new" && 478bf2eeab3Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 479bf2eeab3Smrg then 480bf2eeab3Smrg rm -f "$dsttmp" 481bf2eeab3Smrg else 482bf2eeab3Smrg # Rename the file to the real destination. 483bf2eeab3Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 484bf2eeab3Smrg 485bf2eeab3Smrg # The rename failed, perhaps because mv can't rename something else 486bf2eeab3Smrg # to itself, or perhaps because mv is so ancient that it does not 487bf2eeab3Smrg # support -f. 488bf2eeab3Smrg { 489bf2eeab3Smrg # Now remove or move aside any old file at destination location. 490bf2eeab3Smrg # We try this two ways since rm can't unlink itself on some 491bf2eeab3Smrg # systems and the destination file might be busy for other 492bf2eeab3Smrg # reasons. In this case, the final cleanup might fail but the new 493bf2eeab3Smrg # file should still install successfully. 494bf2eeab3Smrg { 495bf2eeab3Smrg test ! -f "$dst" || 496bf2eeab3Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 497bf2eeab3Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 498bf2eeab3Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 499bf2eeab3Smrg } || 500bf2eeab3Smrg { echo "$0: cannot unlink or rename $dst" >&2 501bf2eeab3Smrg (exit 1); exit 1 502bf2eeab3Smrg } 503bf2eeab3Smrg } && 504bf2eeab3Smrg 505bf2eeab3Smrg # Now rename the file to the real destination. 506bf2eeab3Smrg $doit $mvcmd "$dsttmp" "$dst" 507bf2eeab3Smrg } 508bf2eeab3Smrg fi || exit 1 509bf2eeab3Smrg 510bf2eeab3Smrg trap '' 0 511bf2eeab3Smrg fi 51214c0a534Smrgdone 51314c0a534Smrg 51414c0a534Smrg# Local variables: 51514c0a534Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 51614c0a534Smrg# time-stamp-start: "scriptversion=" 51714c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 518bf2eeab3Smrg# time-stamp-time-zone: "UTC" 519bf2eeab3Smrg# time-stamp-end: "; # UTC" 52014c0a534Smrg# End: 521