1597410b8Schristos#!/bin/sh 2597410b8Schristos# install - install a program, script, or datafile 3597410b8Schristos 4*9d210927Schristosscriptversion=2013-12-25.23; # UTC 5597410b8Schristos 6597410b8Schristos# This originates from X11R5 (mit/util/scripts/install.sh), which was 7597410b8Schristos# later released in X11R6 (xc/config/util/install.sh) with the 8597410b8Schristos# following copyright and license. 9597410b8Schristos# 10597410b8Schristos# Copyright (C) 1994 X Consortium 11597410b8Schristos# 12597410b8Schristos# Permission is hereby granted, free of charge, to any person obtaining a copy 13597410b8Schristos# of this software and associated documentation files (the "Software"), to 14597410b8Schristos# deal in the Software without restriction, including without limitation the 15597410b8Schristos# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16597410b8Schristos# sell copies of the Software, and to permit persons to whom the Software is 17597410b8Schristos# furnished to do so, subject to the following conditions: 18597410b8Schristos# 19597410b8Schristos# The above copyright notice and this permission notice shall be included in 20597410b8Schristos# all copies or substantial portions of the Software. 21597410b8Schristos# 22597410b8Schristos# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23597410b8Schristos# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24597410b8Schristos# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25597410b8Schristos# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26597410b8Schristos# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27597410b8Schristos# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28597410b8Schristos# 29597410b8Schristos# Except as contained in this notice, the name of the X Consortium shall not 30597410b8Schristos# be used in advertising or otherwise to promote the sale, use or other deal- 31597410b8Schristos# ings in this Software without prior written authorization from the X Consor- 32597410b8Schristos# tium. 33597410b8Schristos# 34597410b8Schristos# 35597410b8Schristos# FSF changes to this file are in the public domain. 36597410b8Schristos# 37597410b8Schristos# Calling this script install-sh is preferred over install.sh, to prevent 38*9d210927Schristos# 'make' implicit rules from creating a file called install from it 39597410b8Schristos# when there is no Makefile. 40597410b8Schristos# 41597410b8Schristos# This script is compatible with the BSD install script, but was written 42597410b8Schristos# from scratch. 43597410b8Schristos 44*9d210927Schristostab=' ' 45597410b8Schristosnl=' 46597410b8Schristos' 47*9d210927SchristosIFS=" $tab$nl" 48597410b8Schristos 49*9d210927Schristos# Set DOITPROG to "echo" to test this script. 50597410b8Schristos 51597410b8Schristosdoit=${DOITPROG-} 52*9d210927Schristosdoit_exec=${doit:-exec} 53597410b8Schristos 54597410b8Schristos# Put in absolute file names if you don't have them in your path; 55597410b8Schristos# or use environment vars. 56597410b8Schristos 57597410b8Schristoschgrpprog=${CHGRPPROG-chgrp} 58597410b8Schristoschmodprog=${CHMODPROG-chmod} 59597410b8Schristoschownprog=${CHOWNPROG-chown} 60597410b8Schristoscmpprog=${CMPPROG-cmp} 61597410b8Schristoscpprog=${CPPROG-cp} 62597410b8Schristosmkdirprog=${MKDIRPROG-mkdir} 63597410b8Schristosmvprog=${MVPROG-mv} 64597410b8Schristosrmprog=${RMPROG-rm} 65597410b8Schristosstripprog=${STRIPPROG-strip} 66597410b8Schristos 67597410b8Schristosposix_mkdir= 68597410b8Schristos 69597410b8Schristos# Desired mode of installed file. 70597410b8Schristosmode=0755 71597410b8Schristos 72597410b8Schristoschgrpcmd= 73597410b8Schristoschmodcmd=$chmodprog 74597410b8Schristoschowncmd= 75597410b8Schristosmvcmd=$mvprog 76597410b8Schristosrmcmd="$rmprog -f" 77597410b8Schristosstripcmd= 78597410b8Schristos 79597410b8Schristossrc= 80597410b8Schristosdst= 81597410b8Schristosdir_arg= 82597410b8Schristosdst_arg= 83597410b8Schristos 84597410b8Schristoscopy_on_change=false 85*9d210927Schristosis_target_a_directory=possibly 86597410b8Schristos 87597410b8Schristosusage="\ 88597410b8SchristosUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 89597410b8Schristos or: $0 [OPTION]... SRCFILES... DIRECTORY 90597410b8Schristos or: $0 [OPTION]... -t DIRECTORY SRCFILES... 91597410b8Schristos or: $0 [OPTION]... -d DIRECTORIES... 92597410b8Schristos 93597410b8SchristosIn the 1st form, copy SRCFILE to DSTFILE. 94597410b8SchristosIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 95597410b8SchristosIn the 4th, create DIRECTORIES. 96597410b8Schristos 97597410b8SchristosOptions: 98597410b8Schristos --help display this help and exit. 99597410b8Schristos --version display version info and exit. 100597410b8Schristos 101597410b8Schristos -c (ignored) 102597410b8Schristos -C install only if different (preserve the last data modification time) 103597410b8Schristos -d create directories instead of installing files. 104597410b8Schristos -g GROUP $chgrpprog installed files to GROUP. 105597410b8Schristos -m MODE $chmodprog installed files to MODE. 106597410b8Schristos -o USER $chownprog installed files to USER. 107597410b8Schristos -s $stripprog installed files. 108597410b8Schristos -t DIRECTORY install into DIRECTORY. 109597410b8Schristos -T report an error if DSTFILE is a directory. 110597410b8Schristos 111597410b8SchristosEnvironment variables override the default commands: 112597410b8Schristos CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 113597410b8Schristos RMPROG STRIPPROG 114597410b8Schristos" 115597410b8Schristos 116597410b8Schristoswhile test $# -ne 0; do 117597410b8Schristos case $1 in 118597410b8Schristos -c) ;; 119597410b8Schristos 120597410b8Schristos -C) copy_on_change=true;; 121597410b8Schristos 122597410b8Schristos -d) dir_arg=true;; 123597410b8Schristos 124597410b8Schristos -g) chgrpcmd="$chgrpprog $2" 125597410b8Schristos shift;; 126597410b8Schristos 127597410b8Schristos --help) echo "$usage"; exit $?;; 128597410b8Schristos 129597410b8Schristos -m) mode=$2 130597410b8Schristos case $mode in 131*9d210927Schristos *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 132597410b8Schristos echo "$0: invalid mode: $mode" >&2 133597410b8Schristos exit 1;; 134597410b8Schristos esac 135597410b8Schristos shift;; 136597410b8Schristos 137597410b8Schristos -o) chowncmd="$chownprog $2" 138597410b8Schristos shift;; 139597410b8Schristos 140597410b8Schristos -s) stripcmd=$stripprog;; 141597410b8Schristos 142*9d210927Schristos -t) 143*9d210927Schristos is_target_a_directory=always 144*9d210927Schristos dst_arg=$2 145*9d210927Schristos # Protect names problematic for 'test' and other utilities. 146*9d210927Schristos case $dst_arg in 147*9d210927Schristos -* | [=\(\)!]) dst_arg=./$dst_arg;; 148*9d210927Schristos esac 149597410b8Schristos shift;; 150597410b8Schristos 151*9d210927Schristos -T) is_target_a_directory=never;; 152597410b8Schristos 153597410b8Schristos --version) echo "$0 $scriptversion"; exit $?;; 154597410b8Schristos 155597410b8Schristos --) shift 156597410b8Schristos break;; 157597410b8Schristos 158597410b8Schristos -*) echo "$0: invalid option: $1" >&2 159597410b8Schristos exit 1;; 160597410b8Schristos 161597410b8Schristos *) break;; 162597410b8Schristos esac 163597410b8Schristos shift 164597410b8Schristosdone 165597410b8Schristos 166*9d210927Schristos# We allow the use of options -d and -T together, by making -d 167*9d210927Schristos# take the precedence; this is for compatibility with GNU install. 168*9d210927Schristos 169*9d210927Schristosif test -n "$dir_arg"; then 170*9d210927Schristos if test -n "$dst_arg"; then 171*9d210927Schristos echo "$0: target directory not allowed when installing a directory." >&2 172*9d210927Schristos exit 1 173*9d210927Schristos fi 174*9d210927Schristosfi 175*9d210927Schristos 176597410b8Schristosif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 177597410b8Schristos # When -d is used, all remaining arguments are directories to create. 178597410b8Schristos # When -t is used, the destination is already specified. 179597410b8Schristos # Otherwise, the last argument is the destination. Remove it from $@. 180597410b8Schristos for arg 181597410b8Schristos do 182597410b8Schristos if test -n "$dst_arg"; then 183597410b8Schristos # $@ is not empty: it contains at least $arg. 184597410b8Schristos set fnord "$@" "$dst_arg" 185597410b8Schristos shift # fnord 186597410b8Schristos fi 187597410b8Schristos shift # arg 188597410b8Schristos dst_arg=$arg 189*9d210927Schristos # Protect names problematic for 'test' and other utilities. 190*9d210927Schristos case $dst_arg in 191*9d210927Schristos -* | [=\(\)!]) dst_arg=./$dst_arg;; 192*9d210927Schristos esac 193597410b8Schristos done 194597410b8Schristosfi 195597410b8Schristos 196597410b8Schristosif test $# -eq 0; then 197597410b8Schristos if test -z "$dir_arg"; then 198597410b8Schristos echo "$0: no input file specified." >&2 199597410b8Schristos exit 1 200597410b8Schristos fi 201*9d210927Schristos # It's OK to call 'install-sh -d' without argument. 202597410b8Schristos # This can happen when creating conditional directories. 203597410b8Schristos exit 0 204597410b8Schristosfi 205597410b8Schristos 206597410b8Schristosif test -z "$dir_arg"; then 207*9d210927Schristos if test $# -gt 1 || test "$is_target_a_directory" = always; then 208*9d210927Schristos if test ! -d "$dst_arg"; then 209*9d210927Schristos echo "$0: $dst_arg: Is not a directory." >&2 210*9d210927Schristos exit 1 211*9d210927Schristos fi 212*9d210927Schristos fi 213*9d210927Schristosfi 214*9d210927Schristos 215*9d210927Schristosif test -z "$dir_arg"; then 216*9d210927Schristos do_exit='(exit $ret); exit $ret' 217*9d210927Schristos trap "ret=129; $do_exit" 1 218*9d210927Schristos trap "ret=130; $do_exit" 2 219*9d210927Schristos trap "ret=141; $do_exit" 13 220*9d210927Schristos trap "ret=143; $do_exit" 15 221597410b8Schristos 222597410b8Schristos # Set umask so as not to create temps with too-generous modes. 223597410b8Schristos # However, 'strip' requires both read and write access to temps. 224597410b8Schristos case $mode in 225597410b8Schristos # Optimize common cases. 226597410b8Schristos *644) cp_umask=133;; 227597410b8Schristos *755) cp_umask=22;; 228597410b8Schristos 229597410b8Schristos *[0-7]) 230597410b8Schristos if test -z "$stripcmd"; then 231597410b8Schristos u_plus_rw= 232597410b8Schristos else 233597410b8Schristos u_plus_rw='% 200' 234597410b8Schristos fi 235597410b8Schristos cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 236597410b8Schristos *) 237597410b8Schristos if test -z "$stripcmd"; then 238597410b8Schristos u_plus_rw= 239597410b8Schristos else 240597410b8Schristos u_plus_rw=,u+rw 241597410b8Schristos fi 242597410b8Schristos cp_umask=$mode$u_plus_rw;; 243597410b8Schristos esac 244597410b8Schristosfi 245597410b8Schristos 246597410b8Schristosfor src 247597410b8Schristosdo 248*9d210927Schristos # Protect names problematic for 'test' and other utilities. 249597410b8Schristos case $src in 250*9d210927Schristos -* | [=\(\)!]) src=./$src;; 251597410b8Schristos esac 252597410b8Schristos 253597410b8Schristos if test -n "$dir_arg"; then 254597410b8Schristos dst=$src 255597410b8Schristos dstdir=$dst 256597410b8Schristos test -d "$dstdir" 257597410b8Schristos dstdir_status=$? 258597410b8Schristos else 259597410b8Schristos 260597410b8Schristos # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 261597410b8Schristos # might cause directories to be created, which would be especially bad 262597410b8Schristos # if $src (and thus $dsttmp) contains '*'. 263597410b8Schristos if test ! -f "$src" && test ! -d "$src"; then 264597410b8Schristos echo "$0: $src does not exist." >&2 265597410b8Schristos exit 1 266597410b8Schristos fi 267597410b8Schristos 268597410b8Schristos if test -z "$dst_arg"; then 269597410b8Schristos echo "$0: no destination specified." >&2 270597410b8Schristos exit 1 271597410b8Schristos fi 272597410b8Schristos dst=$dst_arg 273597410b8Schristos 274597410b8Schristos # If destination is a directory, append the input filename; won't work 275597410b8Schristos # if double slashes aren't ignored. 276597410b8Schristos if test -d "$dst"; then 277*9d210927Schristos if test "$is_target_a_directory" = never; then 278597410b8Schristos echo "$0: $dst_arg: Is a directory" >&2 279597410b8Schristos exit 1 280597410b8Schristos fi 281597410b8Schristos dstdir=$dst 282597410b8Schristos dst=$dstdir/`basename "$src"` 283597410b8Schristos dstdir_status=0 284597410b8Schristos else 285*9d210927Schristos dstdir=`dirname "$dst"` 286597410b8Schristos test -d "$dstdir" 287597410b8Schristos dstdir_status=$? 288597410b8Schristos fi 289597410b8Schristos fi 290597410b8Schristos 291597410b8Schristos obsolete_mkdir_used=false 292597410b8Schristos 293597410b8Schristos if test $dstdir_status != 0; then 294597410b8Schristos case $posix_mkdir in 295597410b8Schristos '') 296597410b8Schristos # Create intermediate dirs using mode 755 as modified by the umask. 297597410b8Schristos # This is like FreeBSD 'install' as of 1997-10-28. 298597410b8Schristos umask=`umask` 299597410b8Schristos case $stripcmd.$umask in 300597410b8Schristos # Optimize common cases. 301597410b8Schristos *[2367][2367]) mkdir_umask=$umask;; 302597410b8Schristos .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 303597410b8Schristos 304597410b8Schristos *[0-7]) 305597410b8Schristos mkdir_umask=`expr $umask + 22 \ 306597410b8Schristos - $umask % 100 % 40 + $umask % 20 \ 307597410b8Schristos - $umask % 10 % 4 + $umask % 2 308597410b8Schristos `;; 309597410b8Schristos *) mkdir_umask=$umask,go-w;; 310597410b8Schristos esac 311597410b8Schristos 312597410b8Schristos # With -d, create the new directory with the user-specified mode. 313597410b8Schristos # Otherwise, rely on $mkdir_umask. 314597410b8Schristos if test -n "$dir_arg"; then 315597410b8Schristos mkdir_mode=-m$mode 316597410b8Schristos else 317597410b8Schristos mkdir_mode= 318597410b8Schristos fi 319597410b8Schristos 320597410b8Schristos posix_mkdir=false 321597410b8Schristos case $umask in 322597410b8Schristos *[123567][0-7][0-7]) 323597410b8Schristos # POSIX mkdir -p sets u+wx bits regardless of umask, which 324597410b8Schristos # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 325597410b8Schristos ;; 326597410b8Schristos *) 327597410b8Schristos tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 328597410b8Schristos trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 329597410b8Schristos 330597410b8Schristos if (umask $mkdir_umask && 331597410b8Schristos exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 332597410b8Schristos then 333597410b8Schristos if test -z "$dir_arg" || { 334597410b8Schristos # Check for POSIX incompatibilities with -m. 335597410b8Schristos # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336*9d210927Schristos # other-writable bit of parent directory when it shouldn't. 337597410b8Schristos # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 338597410b8Schristos ls_ld_tmpdir=`ls -ld "$tmpdir"` 339597410b8Schristos case $ls_ld_tmpdir in 340597410b8Schristos d????-?r-*) different_mode=700;; 341597410b8Schristos d????-?--*) different_mode=755;; 342597410b8Schristos *) false;; 343597410b8Schristos esac && 344597410b8Schristos $mkdirprog -m$different_mode -p -- "$tmpdir" && { 345597410b8Schristos ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 346597410b8Schristos test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 347597410b8Schristos } 348597410b8Schristos } 349597410b8Schristos then posix_mkdir=: 350597410b8Schristos fi 351597410b8Schristos rmdir "$tmpdir/d" "$tmpdir" 352597410b8Schristos else 353597410b8Schristos # Remove any dirs left behind by ancient mkdir implementations. 354597410b8Schristos rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 355597410b8Schristos fi 356597410b8Schristos trap '' 0;; 357597410b8Schristos esac;; 358597410b8Schristos esac 359597410b8Schristos 360597410b8Schristos if 361597410b8Schristos $posix_mkdir && ( 362597410b8Schristos umask $mkdir_umask && 363597410b8Schristos $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 364597410b8Schristos ) 365597410b8Schristos then : 366597410b8Schristos else 367597410b8Schristos 368597410b8Schristos # The umask is ridiculous, or mkdir does not conform to POSIX, 369597410b8Schristos # or it failed possibly due to a race condition. Create the 370597410b8Schristos # directory the slow way, step by step, checking for races as we go. 371597410b8Schristos 372597410b8Schristos case $dstdir in 373597410b8Schristos /*) prefix='/';; 374*9d210927Schristos [-=\(\)!]*) prefix='./';; 375597410b8Schristos *) prefix='';; 376597410b8Schristos esac 377597410b8Schristos 378597410b8Schristos oIFS=$IFS 379597410b8Schristos IFS=/ 380*9d210927Schristos set -f 381597410b8Schristos set fnord $dstdir 382597410b8Schristos shift 383*9d210927Schristos set +f 384597410b8Schristos IFS=$oIFS 385597410b8Schristos 386597410b8Schristos prefixes= 387597410b8Schristos 388597410b8Schristos for d 389597410b8Schristos do 390*9d210927Schristos test X"$d" = X && continue 391597410b8Schristos 392597410b8Schristos prefix=$prefix$d 393597410b8Schristos if test -d "$prefix"; then 394597410b8Schristos prefixes= 395597410b8Schristos else 396597410b8Schristos if $posix_mkdir; then 397597410b8Schristos (umask=$mkdir_umask && 398597410b8Schristos $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 399597410b8Schristos # Don't fail if two instances are running concurrently. 400597410b8Schristos test -d "$prefix" || exit 1 401597410b8Schristos else 402597410b8Schristos case $prefix in 403597410b8Schristos *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 404597410b8Schristos *) qprefix=$prefix;; 405597410b8Schristos esac 406597410b8Schristos prefixes="$prefixes '$qprefix'" 407597410b8Schristos fi 408597410b8Schristos fi 409597410b8Schristos prefix=$prefix/ 410597410b8Schristos done 411597410b8Schristos 412597410b8Schristos if test -n "$prefixes"; then 413597410b8Schristos # Don't fail if two instances are running concurrently. 414597410b8Schristos (umask $mkdir_umask && 415597410b8Schristos eval "\$doit_exec \$mkdirprog $prefixes") || 416597410b8Schristos test -d "$dstdir" || exit 1 417597410b8Schristos obsolete_mkdir_used=true 418597410b8Schristos fi 419597410b8Schristos fi 420597410b8Schristos fi 421597410b8Schristos 422597410b8Schristos if test -n "$dir_arg"; then 423597410b8Schristos { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 424597410b8Schristos { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 425597410b8Schristos { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 426597410b8Schristos test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 427597410b8Schristos else 428597410b8Schristos 429597410b8Schristos # Make a couple of temp file names in the proper directory. 430597410b8Schristos dsttmp=$dstdir/_inst.$$_ 431597410b8Schristos rmtmp=$dstdir/_rm.$$_ 432597410b8Schristos 433597410b8Schristos # Trap to clean up those temp files at exit. 434597410b8Schristos trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 435597410b8Schristos 436597410b8Schristos # Copy the file name to the temp name. 437597410b8Schristos (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 438597410b8Schristos 439597410b8Schristos # and set any options; do chmod last to preserve setuid bits. 440597410b8Schristos # 441597410b8Schristos # If any of these fail, we abort the whole thing. If we want to 442597410b8Schristos # ignore errors from any of these, just make sure not to ignore 443597410b8Schristos # errors from the above "$doit $cpprog $src $dsttmp" command. 444597410b8Schristos # 445597410b8Schristos { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 446597410b8Schristos { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 447597410b8Schristos { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 448597410b8Schristos { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 449597410b8Schristos 450597410b8Schristos # If -C, don't bother to copy if it wouldn't change the file. 451597410b8Schristos if $copy_on_change && 452597410b8Schristos old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 453597410b8Schristos new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454*9d210927Schristos set -f && 455597410b8Schristos set X $old && old=:$2:$4:$5:$6 && 456597410b8Schristos set X $new && new=:$2:$4:$5:$6 && 457*9d210927Schristos set +f && 458597410b8Schristos test "$old" = "$new" && 459597410b8Schristos $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 460597410b8Schristos then 461597410b8Schristos rm -f "$dsttmp" 462597410b8Schristos else 463597410b8Schristos # Rename the file to the real destination. 464597410b8Schristos $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 465597410b8Schristos 466597410b8Schristos # The rename failed, perhaps because mv can't rename something else 467597410b8Schristos # to itself, or perhaps because mv is so ancient that it does not 468597410b8Schristos # support -f. 469597410b8Schristos { 470597410b8Schristos # Now remove or move aside any old file at destination location. 471597410b8Schristos # We try this two ways since rm can't unlink itself on some 472597410b8Schristos # systems and the destination file might be busy for other 473597410b8Schristos # reasons. In this case, the final cleanup might fail but the new 474597410b8Schristos # file should still install successfully. 475597410b8Schristos { 476597410b8Schristos test ! -f "$dst" || 477597410b8Schristos $doit $rmcmd -f "$dst" 2>/dev/null || 478597410b8Schristos { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 479597410b8Schristos { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 480597410b8Schristos } || 481597410b8Schristos { echo "$0: cannot unlink or rename $dst" >&2 482597410b8Schristos (exit 1); exit 1 483597410b8Schristos } 484597410b8Schristos } && 485597410b8Schristos 486597410b8Schristos # Now rename the file to the real destination. 487597410b8Schristos $doit $mvcmd "$dsttmp" "$dst" 488597410b8Schristos } 489597410b8Schristos fi || exit 1 490597410b8Schristos 491597410b8Schristos trap '' 0 492597410b8Schristos fi 493597410b8Schristosdone 494597410b8Schristos 495597410b8Schristos# Local variables: 496597410b8Schristos# eval: (add-hook 'write-file-hooks 'time-stamp) 497597410b8Schristos# time-stamp-start: "scriptversion=" 498597410b8Schristos# time-stamp-format: "%:y-%02m-%02d.%02H" 499597410b8Schristos# time-stamp-time-zone: "UTC" 500597410b8Schristos# time-stamp-end: "; # UTC" 501597410b8Schristos# End: 502