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