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