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