install-sh revision c3d5982a
17da8b7e3Smrg#!/bin/sh 27da8b7e3Smrg# install - install a program, script, or datafile 37da8b7e3Smrg 4c3d5982aSmrgscriptversion=2011-11-20.07; # UTC 57da8b7e3Smrg 67da8b7e3Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 77da8b7e3Smrg# later released in X11R6 (xc/config/util/install.sh) with the 87da8b7e3Smrg# following copyright and license. 97da8b7e3Smrg# 107da8b7e3Smrg# Copyright (C) 1994 X Consortium 117da8b7e3Smrg# 127da8b7e3Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 137da8b7e3Smrg# of this software and associated documentation files (the "Software"), to 147da8b7e3Smrg# deal in the Software without restriction, including without limitation the 157da8b7e3Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 167da8b7e3Smrg# sell copies of the Software, and to permit persons to whom the Software is 177da8b7e3Smrg# furnished to do so, subject to the following conditions: 187da8b7e3Smrg# 197da8b7e3Smrg# The above copyright notice and this permission notice shall be included in 207da8b7e3Smrg# all copies or substantial portions of the Software. 217da8b7e3Smrg# 227da8b7e3Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 237da8b7e3Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 247da8b7e3Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 257da8b7e3Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 267da8b7e3Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 277da8b7e3Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 287da8b7e3Smrg# 297da8b7e3Smrg# Except as contained in this notice, the name of the X Consortium shall not 307da8b7e3Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 317da8b7e3Smrg# ings in this Software without prior written authorization from the X Consor- 327da8b7e3Smrg# tium. 337da8b7e3Smrg# 347da8b7e3Smrg# 357da8b7e3Smrg# FSF changes to this file are in the public domain. 367da8b7e3Smrg# 377da8b7e3Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38c3d5982aSmrg# 'make' implicit rules from creating a file called install from it 397da8b7e3Smrg# when there is no Makefile. 407da8b7e3Smrg# 417da8b7e3Smrg# This script is compatible with the BSD install script, but was written 42123e2cc7Smrg# from scratch. 43123e2cc7Smrg 44123e2cc7Smrgnl=' 45123e2cc7Smrg' 46123e2cc7SmrgIFS=" "" $nl" 477da8b7e3Smrg 487da8b7e3Smrg# set DOITPROG to echo to test this script 497da8b7e3Smrg 507da8b7e3Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51123e2cc7Smrgdoit=${DOITPROG-} 52123e2cc7Smrgif test -z "$doit"; then 53123e2cc7Smrg doit_exec=exec 54123e2cc7Smrgelse 55123e2cc7Smrg doit_exec=$doit 56123e2cc7Smrgfi 577da8b7e3Smrg 58123e2cc7Smrg# Put in absolute file names if you don't have them in your path; 59123e2cc7Smrg# or use environment vars. 60123e2cc7Smrg 61123e2cc7Smrgchgrpprog=${CHGRPPROG-chgrp} 62123e2cc7Smrgchmodprog=${CHMODPROG-chmod} 63123e2cc7Smrgchownprog=${CHOWNPROG-chown} 64123e2cc7Smrgcmpprog=${CMPPROG-cmp} 65123e2cc7Smrgcpprog=${CPPROG-cp} 66123e2cc7Smrgmkdirprog=${MKDIRPROG-mkdir} 67123e2cc7Smrgmvprog=${MVPROG-mv} 68123e2cc7Smrgrmprog=${RMPROG-rm} 69123e2cc7Smrgstripprog=${STRIPPROG-strip} 70123e2cc7Smrg 71123e2cc7Smrgposix_glob='?' 72123e2cc7Smrginitialize_posix_glob=' 73123e2cc7Smrg test "$posix_glob" != "?" || { 74123e2cc7Smrg if (set -f) 2>/dev/null; then 75123e2cc7Smrg posix_glob= 76123e2cc7Smrg else 77123e2cc7Smrg posix_glob=: 78123e2cc7Smrg fi 79123e2cc7Smrg } 80123e2cc7Smrg' 817da8b7e3Smrg 82123e2cc7Smrgposix_mkdir= 83123e2cc7Smrg 84123e2cc7Smrg# Desired mode of installed file. 85123e2cc7Smrgmode=0755 867da8b7e3Smrg 877da8b7e3Smrgchgrpcmd= 88123e2cc7Smrgchmodcmd=$chmodprog 89123e2cc7Smrgchowncmd= 90123e2cc7Smrgmvcmd=$mvprog 917da8b7e3Smrgrmcmd="$rmprog -f" 92123e2cc7Smrgstripcmd= 93123e2cc7Smrg 947da8b7e3Smrgsrc= 957da8b7e3Smrgdst= 967da8b7e3Smrgdir_arg= 97123e2cc7Smrgdst_arg= 98123e2cc7Smrg 99123e2cc7Smrgcopy_on_change=false 1007da8b7e3Smrgno_target_directory= 1017da8b7e3Smrg 102123e2cc7Smrgusage="\ 103123e2cc7SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1047da8b7e3Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1057da8b7e3Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1067da8b7e3Smrg or: $0 [OPTION]... -d DIRECTORIES... 1077da8b7e3Smrg 1087da8b7e3SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1097da8b7e3SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1107da8b7e3SmrgIn the 4th, create DIRECTORIES. 1117da8b7e3Smrg 1127da8b7e3SmrgOptions: 113123e2cc7Smrg --help display this help and exit. 114123e2cc7Smrg --version display version info and exit. 115123e2cc7Smrg 116123e2cc7Smrg -c (ignored) 117123e2cc7Smrg -C install only if different (preserve the last data modification time) 118123e2cc7Smrg -d create directories instead of installing files. 119123e2cc7Smrg -g GROUP $chgrpprog installed files to GROUP. 120123e2cc7Smrg -m MODE $chmodprog installed files to MODE. 121123e2cc7Smrg -o USER $chownprog installed files to USER. 122123e2cc7Smrg -s $stripprog installed files. 123123e2cc7Smrg -t DIRECTORY install into DIRECTORY. 124123e2cc7Smrg -T report an error if DSTFILE is a directory. 1257da8b7e3Smrg 1267da8b7e3SmrgEnvironment variables override the default commands: 127123e2cc7Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128123e2cc7Smrg RMPROG STRIPPROG 1297da8b7e3Smrg" 1307da8b7e3Smrg 131123e2cc7Smrgwhile test $# -ne 0; do 1327da8b7e3Smrg case $1 in 133123e2cc7Smrg -c) ;; 134123e2cc7Smrg 135123e2cc7Smrg -C) copy_on_change=true;; 1367da8b7e3Smrg 137123e2cc7Smrg -d) dir_arg=true;; 1387da8b7e3Smrg 1397da8b7e3Smrg -g) chgrpcmd="$chgrpprog $2" 140123e2cc7Smrg shift;; 1417da8b7e3Smrg 1427da8b7e3Smrg --help) echo "$usage"; exit $?;; 1437da8b7e3Smrg 144123e2cc7Smrg -m) mode=$2 145123e2cc7Smrg case $mode in 146123e2cc7Smrg *' '* | *' '* | *' 147123e2cc7Smrg'* | *'*'* | *'?'* | *'['*) 148123e2cc7Smrg echo "$0: invalid mode: $mode" >&2 149123e2cc7Smrg exit 1;; 150123e2cc7Smrg esac 151123e2cc7Smrg shift;; 1527da8b7e3Smrg 1537da8b7e3Smrg -o) chowncmd="$chownprog $2" 154123e2cc7Smrg shift;; 1557da8b7e3Smrg 156123e2cc7Smrg -s) stripcmd=$stripprog;; 1577da8b7e3Smrg 158123e2cc7Smrg -t) dst_arg=$2 159c3d5982aSmrg # Protect names problematic for 'test' and other utilities. 160c3d5982aSmrg case $dst_arg in 161c3d5982aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162c3d5982aSmrg esac 163123e2cc7Smrg shift;; 1647da8b7e3Smrg 165123e2cc7Smrg -T) no_target_directory=true;; 1667da8b7e3Smrg 1677da8b7e3Smrg --version) echo "$0 $scriptversion"; exit $?;; 1687da8b7e3Smrg 169123e2cc7Smrg --) shift 1707da8b7e3Smrg break;; 171123e2cc7Smrg 172123e2cc7Smrg -*) echo "$0: invalid option: $1" >&2 173123e2cc7Smrg exit 1;; 174123e2cc7Smrg 175123e2cc7Smrg *) break;; 1767da8b7e3Smrg esac 177123e2cc7Smrg shift 1787da8b7e3Smrgdone 1797da8b7e3Smrg 180123e2cc7Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181123e2cc7Smrg # When -d is used, all remaining arguments are directories to create. 182123e2cc7Smrg # When -t is used, the destination is already specified. 183123e2cc7Smrg # Otherwise, the last argument is the destination. Remove it from $@. 184123e2cc7Smrg for arg 185123e2cc7Smrg do 186123e2cc7Smrg if test -n "$dst_arg"; then 187123e2cc7Smrg # $@ is not empty: it contains at least $arg. 188123e2cc7Smrg set fnord "$@" "$dst_arg" 189123e2cc7Smrg shift # fnord 190123e2cc7Smrg fi 191123e2cc7Smrg shift # arg 192123e2cc7Smrg dst_arg=$arg 193c3d5982aSmrg # Protect names problematic for 'test' and other utilities. 194c3d5982aSmrg case $dst_arg in 195c3d5982aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196c3d5982aSmrg esac 197123e2cc7Smrg done 198123e2cc7Smrgfi 199123e2cc7Smrg 200123e2cc7Smrgif test $# -eq 0; then 2017da8b7e3Smrg if test -z "$dir_arg"; then 2027da8b7e3Smrg echo "$0: no input file specified." >&2 2037da8b7e3Smrg exit 1 2047da8b7e3Smrg fi 205c3d5982aSmrg # It's OK to call 'install-sh -d' without argument. 2067da8b7e3Smrg # This can happen when creating conditional directories. 2077da8b7e3Smrg exit 0 2087da8b7e3Smrgfi 2097da8b7e3Smrg 210123e2cc7Smrgif test -z "$dir_arg"; then 211c3d5982aSmrg do_exit='(exit $ret); exit $ret' 212c3d5982aSmrg trap "ret=129; $do_exit" 1 213c3d5982aSmrg trap "ret=130; $do_exit" 2 214c3d5982aSmrg trap "ret=141; $do_exit" 13 215c3d5982aSmrg trap "ret=143; $do_exit" 15 216123e2cc7Smrg 217123e2cc7Smrg # Set umask so as not to create temps with too-generous modes. 218123e2cc7Smrg # However, 'strip' requires both read and write access to temps. 219123e2cc7Smrg case $mode in 220123e2cc7Smrg # Optimize common cases. 221123e2cc7Smrg *644) cp_umask=133;; 222123e2cc7Smrg *755) cp_umask=22;; 223123e2cc7Smrg 224123e2cc7Smrg *[0-7]) 225123e2cc7Smrg if test -z "$stripcmd"; then 226123e2cc7Smrg u_plus_rw= 227123e2cc7Smrg else 228123e2cc7Smrg u_plus_rw='% 200' 229123e2cc7Smrg fi 230123e2cc7Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231123e2cc7Smrg *) 232123e2cc7Smrg if test -z "$stripcmd"; then 233123e2cc7Smrg u_plus_rw= 234123e2cc7Smrg else 235123e2cc7Smrg u_plus_rw=,u+rw 236123e2cc7Smrg fi 237123e2cc7Smrg cp_umask=$mode$u_plus_rw;; 238123e2cc7Smrg esac 239123e2cc7Smrgfi 240123e2cc7Smrg 2417da8b7e3Smrgfor src 2427da8b7e3Smrgdo 243c3d5982aSmrg # Protect names problematic for 'test' and other utilities. 2447da8b7e3Smrg case $src in 245c3d5982aSmrg -* | [=\(\)!]) src=./$src;; 2467da8b7e3Smrg esac 2477da8b7e3Smrg 2487da8b7e3Smrg if test -n "$dir_arg"; then 2497da8b7e3Smrg dst=$src 250123e2cc7Smrg dstdir=$dst 251123e2cc7Smrg test -d "$dstdir" 252123e2cc7Smrg dstdir_status=$? 2537da8b7e3Smrg else 254123e2cc7Smrg 2557da8b7e3Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2567da8b7e3Smrg # might cause directories to be created, which would be especially bad 2577da8b7e3Smrg # if $src (and thus $dsttmp) contains '*'. 2587da8b7e3Smrg if test ! -f "$src" && test ! -d "$src"; then 2597da8b7e3Smrg echo "$0: $src does not exist." >&2 2607da8b7e3Smrg exit 1 2617da8b7e3Smrg fi 2627da8b7e3Smrg 263123e2cc7Smrg if test -z "$dst_arg"; then 2647da8b7e3Smrg echo "$0: no destination specified." >&2 2657da8b7e3Smrg exit 1 2667da8b7e3Smrg fi 267123e2cc7Smrg dst=$dst_arg 2687da8b7e3Smrg 2697da8b7e3Smrg # If destination is a directory, append the input filename; won't work 2707da8b7e3Smrg # if double slashes aren't ignored. 2717da8b7e3Smrg if test -d "$dst"; then 2727da8b7e3Smrg if test -n "$no_target_directory"; then 273123e2cc7Smrg echo "$0: $dst_arg: Is a directory" >&2 2747da8b7e3Smrg exit 1 2757da8b7e3Smrg fi 276123e2cc7Smrg dstdir=$dst 277123e2cc7Smrg dst=$dstdir/`basename "$src"` 278123e2cc7Smrg dstdir_status=0 279123e2cc7Smrg else 280123e2cc7Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 281123e2cc7Smrg dstdir=` 282123e2cc7Smrg (dirname "$dst") 2>/dev/null || 283123e2cc7Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284123e2cc7Smrg X"$dst" : 'X\(//\)[^/]' \| \ 285123e2cc7Smrg X"$dst" : 'X\(//\)$' \| \ 286123e2cc7Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287123e2cc7Smrg echo X"$dst" | 288123e2cc7Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289123e2cc7Smrg s//\1/ 290123e2cc7Smrg q 291123e2cc7Smrg } 292123e2cc7Smrg /^X\(\/\/\)[^/].*/{ 293123e2cc7Smrg s//\1/ 294123e2cc7Smrg q 295123e2cc7Smrg } 296123e2cc7Smrg /^X\(\/\/\)$/{ 297123e2cc7Smrg s//\1/ 298123e2cc7Smrg q 299123e2cc7Smrg } 300123e2cc7Smrg /^X\(\/\).*/{ 301123e2cc7Smrg s//\1/ 302123e2cc7Smrg q 303123e2cc7Smrg } 304123e2cc7Smrg s/.*/./; q' 305123e2cc7Smrg ` 306123e2cc7Smrg 307123e2cc7Smrg test -d "$dstdir" 308123e2cc7Smrg dstdir_status=$? 3097da8b7e3Smrg fi 3107da8b7e3Smrg fi 3117da8b7e3Smrg 312123e2cc7Smrg obsolete_mkdir_used=false 313123e2cc7Smrg 314123e2cc7Smrg if test $dstdir_status != 0; then 315123e2cc7Smrg case $posix_mkdir in 316123e2cc7Smrg '') 317123e2cc7Smrg # Create intermediate dirs using mode 755 as modified by the umask. 318123e2cc7Smrg # This is like FreeBSD 'install' as of 1997-10-28. 319123e2cc7Smrg umask=`umask` 320123e2cc7Smrg case $stripcmd.$umask in 321123e2cc7Smrg # Optimize common cases. 322123e2cc7Smrg *[2367][2367]) mkdir_umask=$umask;; 323123e2cc7Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324123e2cc7Smrg 325123e2cc7Smrg *[0-7]) 326123e2cc7Smrg mkdir_umask=`expr $umask + 22 \ 327123e2cc7Smrg - $umask % 100 % 40 + $umask % 20 \ 328123e2cc7Smrg - $umask % 10 % 4 + $umask % 2 329123e2cc7Smrg `;; 330123e2cc7Smrg *) mkdir_umask=$umask,go-w;; 331123e2cc7Smrg esac 332123e2cc7Smrg 333123e2cc7Smrg # With -d, create the new directory with the user-specified mode. 334123e2cc7Smrg # Otherwise, rely on $mkdir_umask. 335123e2cc7Smrg if test -n "$dir_arg"; then 336123e2cc7Smrg mkdir_mode=-m$mode 337123e2cc7Smrg else 338123e2cc7Smrg mkdir_mode= 339123e2cc7Smrg fi 340123e2cc7Smrg 341123e2cc7Smrg posix_mkdir=false 342123e2cc7Smrg case $umask in 343123e2cc7Smrg *[123567][0-7][0-7]) 344123e2cc7Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 345123e2cc7Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346123e2cc7Smrg ;; 347123e2cc7Smrg *) 348123e2cc7Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349123e2cc7Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350123e2cc7Smrg 351123e2cc7Smrg if (umask $mkdir_umask && 352123e2cc7Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353123e2cc7Smrg then 354123e2cc7Smrg if test -z "$dir_arg" || { 355123e2cc7Smrg # Check for POSIX incompatibilities with -m. 356123e2cc7Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357c3d5982aSmrg # other-writable bit of parent directory when it shouldn't. 358123e2cc7Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359123e2cc7Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 360123e2cc7Smrg case $ls_ld_tmpdir in 361123e2cc7Smrg d????-?r-*) different_mode=700;; 362123e2cc7Smrg d????-?--*) different_mode=755;; 363123e2cc7Smrg *) false;; 364123e2cc7Smrg esac && 365123e2cc7Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366123e2cc7Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367123e2cc7Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368123e2cc7Smrg } 369123e2cc7Smrg } 370123e2cc7Smrg then posix_mkdir=: 371123e2cc7Smrg fi 372123e2cc7Smrg rmdir "$tmpdir/d" "$tmpdir" 373123e2cc7Smrg else 374123e2cc7Smrg # Remove any dirs left behind by ancient mkdir implementations. 375123e2cc7Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376123e2cc7Smrg fi 377123e2cc7Smrg trap '' 0;; 378123e2cc7Smrg esac;; 379123e2cc7Smrg esac 3807da8b7e3Smrg 381123e2cc7Smrg if 382123e2cc7Smrg $posix_mkdir && ( 383123e2cc7Smrg umask $mkdir_umask && 384123e2cc7Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385123e2cc7Smrg ) 386123e2cc7Smrg then : 387123e2cc7Smrg else 3887da8b7e3Smrg 389123e2cc7Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 390123e2cc7Smrg # or it failed possibly due to a race condition. Create the 391123e2cc7Smrg # directory the slow way, step by step, checking for races as we go. 3927da8b7e3Smrg 393123e2cc7Smrg case $dstdir in 394123e2cc7Smrg /*) prefix='/';; 395c3d5982aSmrg [-=\(\)!]*) prefix='./';; 396123e2cc7Smrg *) prefix='';; 397123e2cc7Smrg esac 3987da8b7e3Smrg 399123e2cc7Smrg eval "$initialize_posix_glob" 4007da8b7e3Smrg 401123e2cc7Smrg oIFS=$IFS 402123e2cc7Smrg IFS=/ 403123e2cc7Smrg $posix_glob set -f 404123e2cc7Smrg set fnord $dstdir 4057da8b7e3Smrg shift 406123e2cc7Smrg $posix_glob set +f 407123e2cc7Smrg IFS=$oIFS 408123e2cc7Smrg 409123e2cc7Smrg prefixes= 410123e2cc7Smrg 411123e2cc7Smrg for d 412123e2cc7Smrg do 413c3d5982aSmrg test X"$d" = X && continue 414123e2cc7Smrg 415123e2cc7Smrg prefix=$prefix$d 416123e2cc7Smrg if test -d "$prefix"; then 417123e2cc7Smrg prefixes= 418123e2cc7Smrg else 419123e2cc7Smrg if $posix_mkdir; then 420123e2cc7Smrg (umask=$mkdir_umask && 421123e2cc7Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422123e2cc7Smrg # Don't fail if two instances are running concurrently. 423123e2cc7Smrg test -d "$prefix" || exit 1 424123e2cc7Smrg else 425123e2cc7Smrg case $prefix in 426123e2cc7Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427123e2cc7Smrg *) qprefix=$prefix;; 428123e2cc7Smrg esac 429123e2cc7Smrg prefixes="$prefixes '$qprefix'" 430123e2cc7Smrg fi 431123e2cc7Smrg fi 432123e2cc7Smrg prefix=$prefix/ 433123e2cc7Smrg done 434123e2cc7Smrg 435123e2cc7Smrg if test -n "$prefixes"; then 436123e2cc7Smrg # Don't fail if two instances are running concurrently. 437123e2cc7Smrg (umask $mkdir_umask && 438123e2cc7Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 439123e2cc7Smrg test -d "$dstdir" || exit 1 440123e2cc7Smrg obsolete_mkdir_used=true 4417da8b7e3Smrg fi 442123e2cc7Smrg fi 4437da8b7e3Smrg fi 4447da8b7e3Smrg 4457da8b7e3Smrg if test -n "$dir_arg"; then 446123e2cc7Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447123e2cc7Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448123e2cc7Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449123e2cc7Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4507da8b7e3Smrg else 4517da8b7e3Smrg 4527da8b7e3Smrg # Make a couple of temp file names in the proper directory. 4537da8b7e3Smrg dsttmp=$dstdir/_inst.$$_ 4547da8b7e3Smrg rmtmp=$dstdir/_rm.$$_ 4557da8b7e3Smrg 4567da8b7e3Smrg # Trap to clean up those temp files at exit. 4577da8b7e3Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4587da8b7e3Smrg 4597da8b7e3Smrg # Copy the file name to the temp name. 460123e2cc7Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4617da8b7e3Smrg 4627da8b7e3Smrg # and set any options; do chmod last to preserve setuid bits. 4637da8b7e3Smrg # 4647da8b7e3Smrg # If any of these fail, we abort the whole thing. If we want to 4657da8b7e3Smrg # ignore errors from any of these, just make sure not to ignore 4667da8b7e3Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4677da8b7e3Smrg # 468123e2cc7Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469123e2cc7Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470123e2cc7Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471123e2cc7Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472123e2cc7Smrg 473123e2cc7Smrg # If -C, don't bother to copy if it wouldn't change the file. 474123e2cc7Smrg if $copy_on_change && 475123e2cc7Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476123e2cc7Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477123e2cc7Smrg 478123e2cc7Smrg eval "$initialize_posix_glob" && 479123e2cc7Smrg $posix_glob set -f && 480123e2cc7Smrg set X $old && old=:$2:$4:$5:$6 && 481123e2cc7Smrg set X $new && new=:$2:$4:$5:$6 && 482123e2cc7Smrg $posix_glob set +f && 483123e2cc7Smrg 484123e2cc7Smrg test "$old" = "$new" && 485123e2cc7Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486123e2cc7Smrg then 487123e2cc7Smrg rm -f "$dsttmp" 488123e2cc7Smrg else 489123e2cc7Smrg # Rename the file to the real destination. 490123e2cc7Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491123e2cc7Smrg 492123e2cc7Smrg # The rename failed, perhaps because mv can't rename something else 493123e2cc7Smrg # to itself, or perhaps because mv is so ancient that it does not 494123e2cc7Smrg # support -f. 495123e2cc7Smrg { 496123e2cc7Smrg # Now remove or move aside any old file at destination location. 497123e2cc7Smrg # We try this two ways since rm can't unlink itself on some 498123e2cc7Smrg # systems and the destination file might be busy for other 499123e2cc7Smrg # reasons. In this case, the final cleanup might fail but the new 500123e2cc7Smrg # file should still install successfully. 501123e2cc7Smrg { 502123e2cc7Smrg test ! -f "$dst" || 503123e2cc7Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 504123e2cc7Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505123e2cc7Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506123e2cc7Smrg } || 507123e2cc7Smrg { echo "$0: cannot unlink or rename $dst" >&2 508123e2cc7Smrg (exit 1); exit 1 509123e2cc7Smrg } 510123e2cc7Smrg } && 511123e2cc7Smrg 512123e2cc7Smrg # Now rename the file to the real destination. 513123e2cc7Smrg $doit $mvcmd "$dsttmp" "$dst" 514123e2cc7Smrg } 515123e2cc7Smrg fi || exit 1 516123e2cc7Smrg 517123e2cc7Smrg trap '' 0 518123e2cc7Smrg fi 5197da8b7e3Smrgdone 5207da8b7e3Smrg 5217da8b7e3Smrg# Local variables: 5227da8b7e3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5237da8b7e3Smrg# time-stamp-start: "scriptversion=" 5247da8b7e3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 525123e2cc7Smrg# time-stamp-time-zone: "UTC" 526123e2cc7Smrg# time-stamp-end: "; # UTC" 5277da8b7e3Smrg# End: 528