18585484eSchristos#!/bin/sh 28585484eSchristos# install - install a program, script, or datafile 38585484eSchristos 4*3e3909feSchristosscriptversion=2013-12-25.23; # UTC 58585484eSchristos 68585484eSchristos# This originates from X11R5 (mit/util/scripts/install.sh), which was 78585484eSchristos# later released in X11R6 (xc/config/util/install.sh) with the 88585484eSchristos# following copyright and license. 98585484eSchristos# 108585484eSchristos# Copyright (C) 1994 X Consortium 118585484eSchristos# 128585484eSchristos# Permission is hereby granted, free of charge, to any person obtaining a copy 138585484eSchristos# of this software and associated documentation files (the "Software"), to 148585484eSchristos# deal in the Software without restriction, including without limitation the 158585484eSchristos# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168585484eSchristos# sell copies of the Software, and to permit persons to whom the Software is 178585484eSchristos# furnished to do so, subject to the following conditions: 188585484eSchristos# 198585484eSchristos# The above copyright notice and this permission notice shall be included in 208585484eSchristos# all copies or substantial portions of the Software. 218585484eSchristos# 228585484eSchristos# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238585484eSchristos# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 248585484eSchristos# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 258585484eSchristos# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 268585484eSchristos# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 278585484eSchristos# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 288585484eSchristos# 298585484eSchristos# Except as contained in this notice, the name of the X Consortium shall not 308585484eSchristos# be used in advertising or otherwise to promote the sale, use or other deal- 318585484eSchristos# ings in this Software without prior written authorization from the X Consor- 328585484eSchristos# tium. 338585484eSchristos# 348585484eSchristos# 358585484eSchristos# FSF changes to this file are in the public domain. 368585484eSchristos# 378585484eSchristos# Calling this script install-sh is preferred over install.sh, to prevent 38*3e3909feSchristos# 'make' implicit rules from creating a file called install from it 398585484eSchristos# when there is no Makefile. 408585484eSchristos# 418585484eSchristos# This script is compatible with the BSD install script, but was written 428585484eSchristos# from scratch. 438585484eSchristos 44*3e3909feSchristostab=' ' 458585484eSchristosnl=' 468585484eSchristos' 47*3e3909feSchristosIFS=" $tab$nl" 488585484eSchristos 49*3e3909feSchristos# Set DOITPROG to "echo" to test this script. 508585484eSchristos 518585484eSchristosdoit=${DOITPROG-} 52*3e3909feSchristosdoit_exec=${doit:-exec} 538585484eSchristos 548585484eSchristos# Put in absolute file names if you don't have them in your path; 558585484eSchristos# or use environment vars. 568585484eSchristos 578585484eSchristoschgrpprog=${CHGRPPROG-chgrp} 588585484eSchristoschmodprog=${CHMODPROG-chmod} 598585484eSchristoschownprog=${CHOWNPROG-chown} 608585484eSchristoscmpprog=${CMPPROG-cmp} 618585484eSchristoscpprog=${CPPROG-cp} 628585484eSchristosmkdirprog=${MKDIRPROG-mkdir} 638585484eSchristosmvprog=${MVPROG-mv} 648585484eSchristosrmprog=${RMPROG-rm} 658585484eSchristosstripprog=${STRIPPROG-strip} 668585484eSchristos 678585484eSchristosposix_mkdir= 688585484eSchristos 698585484eSchristos# Desired mode of installed file. 708585484eSchristosmode=0755 718585484eSchristos 728585484eSchristoschgrpcmd= 738585484eSchristoschmodcmd=$chmodprog 748585484eSchristoschowncmd= 758585484eSchristosmvcmd=$mvprog 768585484eSchristosrmcmd="$rmprog -f" 778585484eSchristosstripcmd= 788585484eSchristos 798585484eSchristossrc= 808585484eSchristosdst= 818585484eSchristosdir_arg= 828585484eSchristosdst_arg= 838585484eSchristos 848585484eSchristoscopy_on_change=false 85*3e3909feSchristosis_target_a_directory=possibly 868585484eSchristos 878585484eSchristosusage="\ 888585484eSchristosUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 898585484eSchristos or: $0 [OPTION]... SRCFILES... DIRECTORY 908585484eSchristos or: $0 [OPTION]... -t DIRECTORY SRCFILES... 918585484eSchristos or: $0 [OPTION]... -d DIRECTORIES... 928585484eSchristos 938585484eSchristosIn the 1st form, copy SRCFILE to DSTFILE. 948585484eSchristosIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 958585484eSchristosIn the 4th, create DIRECTORIES. 968585484eSchristos 978585484eSchristosOptions: 988585484eSchristos --help display this help and exit. 998585484eSchristos --version display version info and exit. 1008585484eSchristos 1018585484eSchristos -c (ignored) 1028585484eSchristos -C install only if different (preserve the last data modification time) 1038585484eSchristos -d create directories instead of installing files. 1048585484eSchristos -g GROUP $chgrpprog installed files to GROUP. 1058585484eSchristos -m MODE $chmodprog installed files to MODE. 1068585484eSchristos -o USER $chownprog installed files to USER. 1078585484eSchristos -s $stripprog installed files. 1088585484eSchristos -t DIRECTORY install into DIRECTORY. 1098585484eSchristos -T report an error if DSTFILE is a directory. 1108585484eSchristos 1118585484eSchristosEnvironment variables override the default commands: 1128585484eSchristos CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1138585484eSchristos RMPROG STRIPPROG 1148585484eSchristos" 1158585484eSchristos 1168585484eSchristoswhile test $# -ne 0; do 1178585484eSchristos case $1 in 1188585484eSchristos -c) ;; 1198585484eSchristos 1208585484eSchristos -C) copy_on_change=true;; 1218585484eSchristos 1228585484eSchristos -d) dir_arg=true;; 1238585484eSchristos 1248585484eSchristos -g) chgrpcmd="$chgrpprog $2" 1258585484eSchristos shift;; 1268585484eSchristos 1278585484eSchristos --help) echo "$usage"; exit $?;; 1288585484eSchristos 1298585484eSchristos -m) mode=$2 1308585484eSchristos case $mode in 131*3e3909feSchristos *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) 1328585484eSchristos echo "$0: invalid mode: $mode" >&2 1338585484eSchristos exit 1;; 1348585484eSchristos esac 1358585484eSchristos shift;; 1368585484eSchristos 1378585484eSchristos -o) chowncmd="$chownprog $2" 1388585484eSchristos shift;; 1398585484eSchristos 1408585484eSchristos -s) stripcmd=$stripprog;; 1418585484eSchristos 142*3e3909feSchristos -t) 143*3e3909feSchristos is_target_a_directory=always 144*3e3909feSchristos dst_arg=$2 145*3e3909feSchristos # Protect names problematic for 'test' and other utilities. 146*3e3909feSchristos case $dst_arg in 147*3e3909feSchristos -* | [=\(\)!]) dst_arg=./$dst_arg;; 148*3e3909feSchristos esac 1498585484eSchristos shift;; 1508585484eSchristos 151*3e3909feSchristos -T) is_target_a_directory=never;; 1528585484eSchristos 1538585484eSchristos --version) echo "$0 $scriptversion"; exit $?;; 1548585484eSchristos 1558585484eSchristos --) shift 1568585484eSchristos break;; 1578585484eSchristos 1588585484eSchristos -*) echo "$0: invalid option: $1" >&2 1598585484eSchristos exit 1;; 1608585484eSchristos 1618585484eSchristos *) break;; 1628585484eSchristos esac 1638585484eSchristos shift 1648585484eSchristosdone 1658585484eSchristos 166*3e3909feSchristos# We allow the use of options -d and -T together, by making -d 167*3e3909feSchristos# take the precedence; this is for compatibility with GNU install. 168*3e3909feSchristos 169*3e3909feSchristosif test -n "$dir_arg"; then 170*3e3909feSchristos if test -n "$dst_arg"; then 171*3e3909feSchristos echo "$0: target directory not allowed when installing a directory." >&2 172*3e3909feSchristos exit 1 173*3e3909feSchristos fi 174*3e3909feSchristosfi 175*3e3909feSchristos 1768585484eSchristosif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1778585484eSchristos # When -d is used, all remaining arguments are directories to create. 1788585484eSchristos # When -t is used, the destination is already specified. 1798585484eSchristos # Otherwise, the last argument is the destination. Remove it from $@. 1808585484eSchristos for arg 1818585484eSchristos do 1828585484eSchristos if test -n "$dst_arg"; then 1838585484eSchristos # $@ is not empty: it contains at least $arg. 1848585484eSchristos set fnord "$@" "$dst_arg" 1858585484eSchristos shift # fnord 1868585484eSchristos fi 1878585484eSchristos shift # arg 1888585484eSchristos dst_arg=$arg 189*3e3909feSchristos # Protect names problematic for 'test' and other utilities. 190*3e3909feSchristos case $dst_arg in 191*3e3909feSchristos -* | [=\(\)!]) dst_arg=./$dst_arg;; 192*3e3909feSchristos esac 1938585484eSchristos done 1948585484eSchristosfi 1958585484eSchristos 1968585484eSchristosif test $# -eq 0; then 1978585484eSchristos if test -z "$dir_arg"; then 1988585484eSchristos echo "$0: no input file specified." >&2 1998585484eSchristos exit 1 2008585484eSchristos fi 201*3e3909feSchristos # It's OK to call 'install-sh -d' without argument. 2028585484eSchristos # This can happen when creating conditional directories. 2038585484eSchristos exit 0 2048585484eSchristosfi 2058585484eSchristos 2068585484eSchristosif test -z "$dir_arg"; then 207*3e3909feSchristos if test $# -gt 1 || test "$is_target_a_directory" = always; then 208*3e3909feSchristos if test ! -d "$dst_arg"; then 209*3e3909feSchristos echo "$0: $dst_arg: Is not a directory." >&2 210*3e3909feSchristos exit 1 211*3e3909feSchristos fi 212*3e3909feSchristos fi 213*3e3909feSchristosfi 214*3e3909feSchristos 215*3e3909feSchristosif test -z "$dir_arg"; then 216*3e3909feSchristos do_exit='(exit $ret); exit $ret' 217*3e3909feSchristos trap "ret=129; $do_exit" 1 218*3e3909feSchristos trap "ret=130; $do_exit" 2 219*3e3909feSchristos trap "ret=141; $do_exit" 13 220*3e3909feSchristos trap "ret=143; $do_exit" 15 2218585484eSchristos 2228585484eSchristos # Set umask so as not to create temps with too-generous modes. 2238585484eSchristos # However, 'strip' requires both read and write access to temps. 2248585484eSchristos case $mode in 2258585484eSchristos # Optimize common cases. 2268585484eSchristos *644) cp_umask=133;; 2278585484eSchristos *755) cp_umask=22;; 2288585484eSchristos 2298585484eSchristos *[0-7]) 2308585484eSchristos if test -z "$stripcmd"; then 2318585484eSchristos u_plus_rw= 2328585484eSchristos else 2338585484eSchristos u_plus_rw='% 200' 2348585484eSchristos fi 2358585484eSchristos cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2368585484eSchristos *) 2378585484eSchristos if test -z "$stripcmd"; then 2388585484eSchristos u_plus_rw= 2398585484eSchristos else 2408585484eSchristos u_plus_rw=,u+rw 2418585484eSchristos fi 2428585484eSchristos cp_umask=$mode$u_plus_rw;; 2438585484eSchristos esac 2448585484eSchristosfi 2458585484eSchristos 2468585484eSchristosfor src 2478585484eSchristosdo 248*3e3909feSchristos # Protect names problematic for 'test' and other utilities. 2498585484eSchristos case $src in 250*3e3909feSchristos -* | [=\(\)!]) src=./$src;; 2518585484eSchristos esac 2528585484eSchristos 2538585484eSchristos if test -n "$dir_arg"; then 2548585484eSchristos dst=$src 2558585484eSchristos dstdir=$dst 2568585484eSchristos test -d "$dstdir" 2578585484eSchristos dstdir_status=$? 2588585484eSchristos else 2598585484eSchristos 2608585484eSchristos # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2618585484eSchristos # might cause directories to be created, which would be especially bad 2628585484eSchristos # if $src (and thus $dsttmp) contains '*'. 2638585484eSchristos if test ! -f "$src" && test ! -d "$src"; then 2648585484eSchristos echo "$0: $src does not exist." >&2 2658585484eSchristos exit 1 2668585484eSchristos fi 2678585484eSchristos 2688585484eSchristos if test -z "$dst_arg"; then 2698585484eSchristos echo "$0: no destination specified." >&2 2708585484eSchristos exit 1 2718585484eSchristos fi 2728585484eSchristos dst=$dst_arg 2738585484eSchristos 2748585484eSchristos # If destination is a directory, append the input filename; won't work 2758585484eSchristos # if double slashes aren't ignored. 2768585484eSchristos if test -d "$dst"; then 277*3e3909feSchristos if test "$is_target_a_directory" = never; then 2788585484eSchristos echo "$0: $dst_arg: Is a directory" >&2 2798585484eSchristos exit 1 2808585484eSchristos fi 2818585484eSchristos dstdir=$dst 2828585484eSchristos dst=$dstdir/`basename "$src"` 2838585484eSchristos dstdir_status=0 2848585484eSchristos else 285*3e3909feSchristos dstdir=`dirname "$dst"` 2868585484eSchristos test -d "$dstdir" 2878585484eSchristos dstdir_status=$? 2888585484eSchristos fi 2898585484eSchristos fi 2908585484eSchristos 2918585484eSchristos obsolete_mkdir_used=false 2928585484eSchristos 2938585484eSchristos if test $dstdir_status != 0; then 2948585484eSchristos case $posix_mkdir in 2958585484eSchristos '') 2968585484eSchristos # Create intermediate dirs using mode 755 as modified by the umask. 2978585484eSchristos # This is like FreeBSD 'install' as of 1997-10-28. 2988585484eSchristos umask=`umask` 2998585484eSchristos case $stripcmd.$umask in 3008585484eSchristos # Optimize common cases. 3018585484eSchristos *[2367][2367]) mkdir_umask=$umask;; 3028585484eSchristos .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3038585484eSchristos 3048585484eSchristos *[0-7]) 3058585484eSchristos mkdir_umask=`expr $umask + 22 \ 3068585484eSchristos - $umask % 100 % 40 + $umask % 20 \ 3078585484eSchristos - $umask % 10 % 4 + $umask % 2 3088585484eSchristos `;; 3098585484eSchristos *) mkdir_umask=$umask,go-w;; 3108585484eSchristos esac 3118585484eSchristos 3128585484eSchristos # With -d, create the new directory with the user-specified mode. 3138585484eSchristos # Otherwise, rely on $mkdir_umask. 3148585484eSchristos if test -n "$dir_arg"; then 3158585484eSchristos mkdir_mode=-m$mode 3168585484eSchristos else 3178585484eSchristos mkdir_mode= 3188585484eSchristos fi 3198585484eSchristos 3208585484eSchristos posix_mkdir=false 3218585484eSchristos case $umask in 3228585484eSchristos *[123567][0-7][0-7]) 3238585484eSchristos # POSIX mkdir -p sets u+wx bits regardless of umask, which 3248585484eSchristos # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3258585484eSchristos ;; 3268585484eSchristos *) 3278585484eSchristos tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3288585484eSchristos trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3298585484eSchristos 3308585484eSchristos if (umask $mkdir_umask && 3318585484eSchristos exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3328585484eSchristos then 3338585484eSchristos if test -z "$dir_arg" || { 3348585484eSchristos # Check for POSIX incompatibilities with -m. 3358585484eSchristos # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 336*3e3909feSchristos # other-writable bit of parent directory when it shouldn't. 3378585484eSchristos # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3388585484eSchristos ls_ld_tmpdir=`ls -ld "$tmpdir"` 3398585484eSchristos case $ls_ld_tmpdir in 3408585484eSchristos d????-?r-*) different_mode=700;; 3418585484eSchristos d????-?--*) different_mode=755;; 3428585484eSchristos *) false;; 3438585484eSchristos esac && 3448585484eSchristos $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3458585484eSchristos ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3468585484eSchristos test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3478585484eSchristos } 3488585484eSchristos } 3498585484eSchristos then posix_mkdir=: 3508585484eSchristos fi 3518585484eSchristos rmdir "$tmpdir/d" "$tmpdir" 3528585484eSchristos else 3538585484eSchristos # Remove any dirs left behind by ancient mkdir implementations. 3548585484eSchristos rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3558585484eSchristos fi 3568585484eSchristos trap '' 0;; 3578585484eSchristos esac;; 3588585484eSchristos esac 3598585484eSchristos 3608585484eSchristos if 3618585484eSchristos $posix_mkdir && ( 3628585484eSchristos umask $mkdir_umask && 3638585484eSchristos $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3648585484eSchristos ) 3658585484eSchristos then : 3668585484eSchristos else 3678585484eSchristos 3688585484eSchristos # The umask is ridiculous, or mkdir does not conform to POSIX, 3698585484eSchristos # or it failed possibly due to a race condition. Create the 3708585484eSchristos # directory the slow way, step by step, checking for races as we go. 3718585484eSchristos 3728585484eSchristos case $dstdir in 3738585484eSchristos /*) prefix='/';; 374*3e3909feSchristos [-=\(\)!]*) prefix='./';; 3758585484eSchristos *) prefix='';; 3768585484eSchristos esac 3778585484eSchristos 3788585484eSchristos oIFS=$IFS 3798585484eSchristos IFS=/ 380*3e3909feSchristos set -f 3818585484eSchristos set fnord $dstdir 3828585484eSchristos shift 383*3e3909feSchristos set +f 3848585484eSchristos IFS=$oIFS 3858585484eSchristos 3868585484eSchristos prefixes= 3878585484eSchristos 3888585484eSchristos for d 3898585484eSchristos do 390*3e3909feSchristos test X"$d" = X && continue 3918585484eSchristos 3928585484eSchristos prefix=$prefix$d 3938585484eSchristos if test -d "$prefix"; then 3948585484eSchristos prefixes= 3958585484eSchristos else 3968585484eSchristos if $posix_mkdir; then 3978585484eSchristos (umask=$mkdir_umask && 3988585484eSchristos $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 3998585484eSchristos # Don't fail if two instances are running concurrently. 4008585484eSchristos test -d "$prefix" || exit 1 4018585484eSchristos else 4028585484eSchristos case $prefix in 4038585484eSchristos *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4048585484eSchristos *) qprefix=$prefix;; 4058585484eSchristos esac 4068585484eSchristos prefixes="$prefixes '$qprefix'" 4078585484eSchristos fi 4088585484eSchristos fi 4098585484eSchristos prefix=$prefix/ 4108585484eSchristos done 4118585484eSchristos 4128585484eSchristos if test -n "$prefixes"; then 4138585484eSchristos # Don't fail if two instances are running concurrently. 4148585484eSchristos (umask $mkdir_umask && 4158585484eSchristos eval "\$doit_exec \$mkdirprog $prefixes") || 4168585484eSchristos test -d "$dstdir" || exit 1 4178585484eSchristos obsolete_mkdir_used=true 4188585484eSchristos fi 4198585484eSchristos fi 4208585484eSchristos fi 4218585484eSchristos 4228585484eSchristos if test -n "$dir_arg"; then 4238585484eSchristos { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4248585484eSchristos { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4258585484eSchristos { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4268585484eSchristos test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4278585484eSchristos else 4288585484eSchristos 4298585484eSchristos # Make a couple of temp file names in the proper directory. 4308585484eSchristos dsttmp=$dstdir/_inst.$$_ 4318585484eSchristos rmtmp=$dstdir/_rm.$$_ 4328585484eSchristos 4338585484eSchristos # Trap to clean up those temp files at exit. 4348585484eSchristos trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4358585484eSchristos 4368585484eSchristos # Copy the file name to the temp name. 4378585484eSchristos (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4388585484eSchristos 4398585484eSchristos # and set any options; do chmod last to preserve setuid bits. 4408585484eSchristos # 4418585484eSchristos # If any of these fail, we abort the whole thing. If we want to 4428585484eSchristos # ignore errors from any of these, just make sure not to ignore 4438585484eSchristos # errors from the above "$doit $cpprog $src $dsttmp" command. 4448585484eSchristos # 4458585484eSchristos { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4468585484eSchristos { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4478585484eSchristos { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4488585484eSchristos { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4498585484eSchristos 4508585484eSchristos # If -C, don't bother to copy if it wouldn't change the file. 4518585484eSchristos if $copy_on_change && 4528585484eSchristos old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4538585484eSchristos new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 454*3e3909feSchristos set -f && 4558585484eSchristos set X $old && old=:$2:$4:$5:$6 && 4568585484eSchristos set X $new && new=:$2:$4:$5:$6 && 457*3e3909feSchristos set +f && 4588585484eSchristos test "$old" = "$new" && 4598585484eSchristos $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4608585484eSchristos then 4618585484eSchristos rm -f "$dsttmp" 4628585484eSchristos else 4638585484eSchristos # Rename the file to the real destination. 4648585484eSchristos $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4658585484eSchristos 4668585484eSchristos # The rename failed, perhaps because mv can't rename something else 4678585484eSchristos # to itself, or perhaps because mv is so ancient that it does not 4688585484eSchristos # support -f. 4698585484eSchristos { 4708585484eSchristos # Now remove or move aside any old file at destination location. 4718585484eSchristos # We try this two ways since rm can't unlink itself on some 4728585484eSchristos # systems and the destination file might be busy for other 4738585484eSchristos # reasons. In this case, the final cleanup might fail but the new 4748585484eSchristos # file should still install successfully. 4758585484eSchristos { 4768585484eSchristos test ! -f "$dst" || 4778585484eSchristos $doit $rmcmd -f "$dst" 2>/dev/null || 4788585484eSchristos { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4798585484eSchristos { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4808585484eSchristos } || 4818585484eSchristos { echo "$0: cannot unlink or rename $dst" >&2 4828585484eSchristos (exit 1); exit 1 4838585484eSchristos } 4848585484eSchristos } && 4858585484eSchristos 4868585484eSchristos # Now rename the file to the real destination. 4878585484eSchristos $doit $mvcmd "$dsttmp" "$dst" 4888585484eSchristos } 4898585484eSchristos fi || exit 1 4908585484eSchristos 4918585484eSchristos trap '' 0 4928585484eSchristos fi 4938585484eSchristosdone 4948585484eSchristos 4958585484eSchristos# Local variables: 4968585484eSchristos# eval: (add-hook 'write-file-hooks 'time-stamp) 4978585484eSchristos# time-stamp-start: "scriptversion=" 4988585484eSchristos# time-stamp-format: "%:y-%02m-%02d.%02H" 4998585484eSchristos# time-stamp-time-zone: "UTC" 5008585484eSchristos# time-stamp-end: "; # UTC" 5018585484eSchristos# End: 502