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