install-sh revision fc27e79c
1659607e0Smrg#!/bin/sh 2659607e0Smrg# install - install a program, script, or datafile 3659607e0Smrg 4fc27e79cSmrgscriptversion=2006-12-25.00 5659607e0Smrg 6659607e0Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 7659607e0Smrg# later released in X11R6 (xc/config/util/install.sh) with the 8659607e0Smrg# following copyright and license. 9659607e0Smrg# 10659607e0Smrg# Copyright (C) 1994 X Consortium 11659607e0Smrg# 12659607e0Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 13659607e0Smrg# of this software and associated documentation files (the "Software"), to 14659607e0Smrg# deal in the Software without restriction, including without limitation the 15659607e0Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16659607e0Smrg# sell copies of the Software, and to permit persons to whom the Software is 17659607e0Smrg# furnished to do so, subject to the following conditions: 18659607e0Smrg# 19659607e0Smrg# The above copyright notice and this permission notice shall be included in 20659607e0Smrg# all copies or substantial portions of the Software. 21659607e0Smrg# 22659607e0Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23659607e0Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24659607e0Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25659607e0Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26659607e0Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27659607e0Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28659607e0Smrg# 29659607e0Smrg# Except as contained in this notice, the name of the X Consortium shall not 30659607e0Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 31659607e0Smrg# ings in this Software without prior written authorization from the X Consor- 32659607e0Smrg# tium. 33659607e0Smrg# 34659607e0Smrg# 35659607e0Smrg# FSF changes to this file are in the public domain. 36659607e0Smrg# 37659607e0Smrg# Calling this script install-sh is preferred over install.sh, to prevent 38659607e0Smrg# `make' implicit rules from creating a file called install from it 39659607e0Smrg# when there is no Makefile. 40659607e0Smrg# 41659607e0Smrg# This script is compatible with the BSD install script, but was written 42659607e0Smrg# from scratch. 43659607e0Smrg 44659607e0Smrgnl=' 45659607e0Smrg' 46659607e0SmrgIFS=" "" $nl" 47659607e0Smrg 48659607e0Smrg# set DOITPROG to echo to test this script 49659607e0Smrg 50659607e0Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51fc27e79cSmrgdoit=${DOITPROG-} 52659607e0Smrgif test -z "$doit"; then 53659607e0Smrg doit_exec=exec 54659607e0Smrgelse 55659607e0Smrg doit_exec=$doit 56659607e0Smrgfi 57659607e0Smrg 58659607e0Smrg# Put in absolute file names if you don't have them in your path; 59659607e0Smrg# or use environment vars. 60659607e0Smrg 61fc27e79cSmrgchgrpprog=${CHGRPPROG-chgrp} 62fc27e79cSmrgchmodprog=${CHMODPROG-chmod} 63fc27e79cSmrgchownprog=${CHOWNPROG-chown} 64fc27e79cSmrgcmpprog=${CMPPROG-cmp} 65fc27e79cSmrgcpprog=${CPPROG-cp} 66fc27e79cSmrgmkdirprog=${MKDIRPROG-mkdir} 67fc27e79cSmrgmvprog=${MVPROG-mv} 68fc27e79cSmrgrmprog=${RMPROG-rm} 69fc27e79cSmrgstripprog=${STRIPPROG-strip} 70fc27e79cSmrg 71fc27e79cSmrgposix_glob='?' 72fc27e79cSmrginitialize_posix_glob=' 73fc27e79cSmrg test "$posix_glob" != "?" || { 74fc27e79cSmrg if (set -f) 2>/dev/null; then 75fc27e79cSmrg posix_glob= 76fc27e79cSmrg else 77fc27e79cSmrg posix_glob=: 78fc27e79cSmrg fi 79fc27e79cSmrg } 80fc27e79cSmrg' 81659607e0Smrg 82659607e0Smrgposix_mkdir= 83659607e0Smrg 84659607e0Smrg# Desired mode of installed file. 85659607e0Smrgmode=0755 86659607e0Smrg 87fc27e79cSmrgchgrpcmd= 88659607e0Smrgchmodcmd=$chmodprog 89659607e0Smrgchowncmd= 90fc27e79cSmrgmvcmd=$mvprog 91659607e0Smrgrmcmd="$rmprog -f" 92fc27e79cSmrgstripcmd= 93fc27e79cSmrg 94659607e0Smrgsrc= 95659607e0Smrgdst= 96659607e0Smrgdir_arg= 97fc27e79cSmrgdst_arg= 98fc27e79cSmrg 99fc27e79cSmrgcopy_on_change=false 100659607e0Smrgno_target_directory= 101659607e0Smrg 102fc27e79cSmrgusage="\ 103fc27e79cSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104659607e0Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 105659607e0Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106659607e0Smrg or: $0 [OPTION]... -d DIRECTORIES... 107659607e0Smrg 108659607e0SmrgIn the 1st form, copy SRCFILE to DSTFILE. 109659607e0SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110659607e0SmrgIn the 4th, create DIRECTORIES. 111659607e0Smrg 112659607e0SmrgOptions: 113fc27e79cSmrg --help display this help and exit. 114fc27e79cSmrg --version display version info and exit. 115fc27e79cSmrg 116fc27e79cSmrg -c (ignored) 117fc27e79cSmrg -C install only if different (preserve the last data modification time) 118fc27e79cSmrg -d create directories instead of installing files. 119fc27e79cSmrg -g GROUP $chgrpprog installed files to GROUP. 120fc27e79cSmrg -m MODE $chmodprog installed files to MODE. 121fc27e79cSmrg -o USER $chownprog installed files to USER. 122fc27e79cSmrg -s $stripprog installed files. 123fc27e79cSmrg -t DIRECTORY install into DIRECTORY. 124fc27e79cSmrg -T report an error if DSTFILE is a directory. 125659607e0Smrg 126659607e0SmrgEnvironment variables override the default commands: 127fc27e79cSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128fc27e79cSmrg RMPROG STRIPPROG 129659607e0Smrg" 130659607e0Smrg 131659607e0Smrgwhile test $# -ne 0; do 132659607e0Smrg case $1 in 133fc27e79cSmrg -c) ;; 134fc27e79cSmrg 135fc27e79cSmrg -C) copy_on_change=true;; 136659607e0Smrg 137fc27e79cSmrg -d) dir_arg=true;; 138659607e0Smrg 139659607e0Smrg -g) chgrpcmd="$chgrpprog $2" 140fc27e79cSmrg shift;; 141659607e0Smrg 142659607e0Smrg --help) echo "$usage"; exit $?;; 143659607e0Smrg 144659607e0Smrg -m) mode=$2 145659607e0Smrg case $mode in 146659607e0Smrg *' '* | *' '* | *' 147659607e0Smrg'* | *'*'* | *'?'* | *'['*) 148659607e0Smrg echo "$0: invalid mode: $mode" >&2 149659607e0Smrg exit 1;; 150659607e0Smrg esac 151fc27e79cSmrg shift;; 152659607e0Smrg 153659607e0Smrg -o) chowncmd="$chownprog $2" 154fc27e79cSmrg shift;; 155659607e0Smrg 156fc27e79cSmrg -s) stripcmd=$stripprog;; 157659607e0Smrg 158fc27e79cSmrg -t) dst_arg=$2 159fc27e79cSmrg shift;; 160659607e0Smrg 161fc27e79cSmrg -T) no_target_directory=true;; 162659607e0Smrg 163659607e0Smrg --version) echo "$0 $scriptversion"; exit $?;; 164659607e0Smrg 165659607e0Smrg --) shift 166659607e0Smrg break;; 167659607e0Smrg 168659607e0Smrg -*) echo "$0: invalid option: $1" >&2 169659607e0Smrg exit 1;; 170659607e0Smrg 171659607e0Smrg *) break;; 172659607e0Smrg esac 173fc27e79cSmrg shift 174659607e0Smrgdone 175659607e0Smrg 176fc27e79cSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 177659607e0Smrg # When -d is used, all remaining arguments are directories to create. 178659607e0Smrg # When -t is used, the destination is already specified. 179659607e0Smrg # Otherwise, the last argument is the destination. Remove it from $@. 180659607e0Smrg for arg 181659607e0Smrg do 182fc27e79cSmrg if test -n "$dst_arg"; then 183659607e0Smrg # $@ is not empty: it contains at least $arg. 184fc27e79cSmrg set fnord "$@" "$dst_arg" 185659607e0Smrg shift # fnord 186659607e0Smrg fi 187659607e0Smrg shift # arg 188fc27e79cSmrg dst_arg=$arg 189659607e0Smrg done 190659607e0Smrgfi 191659607e0Smrg 192659607e0Smrgif test $# -eq 0; then 193659607e0Smrg if test -z "$dir_arg"; then 194659607e0Smrg echo "$0: no input file specified." >&2 195659607e0Smrg exit 1 196659607e0Smrg fi 197659607e0Smrg # It's OK to call `install-sh -d' without argument. 198659607e0Smrg # This can happen when creating conditional directories. 199659607e0Smrg exit 0 200659607e0Smrgfi 201659607e0Smrg 202659607e0Smrgif test -z "$dir_arg"; then 203659607e0Smrg trap '(exit $?); exit' 1 2 13 15 204659607e0Smrg 205659607e0Smrg # Set umask so as not to create temps with too-generous modes. 206659607e0Smrg # However, 'strip' requires both read and write access to temps. 207659607e0Smrg case $mode in 208659607e0Smrg # Optimize common cases. 209659607e0Smrg *644) cp_umask=133;; 210659607e0Smrg *755) cp_umask=22;; 211659607e0Smrg 212659607e0Smrg *[0-7]) 213659607e0Smrg if test -z "$stripcmd"; then 214659607e0Smrg u_plus_rw= 215659607e0Smrg else 216659607e0Smrg u_plus_rw='% 200' 217659607e0Smrg fi 218659607e0Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 219659607e0Smrg *) 220659607e0Smrg if test -z "$stripcmd"; then 221659607e0Smrg u_plus_rw= 222659607e0Smrg else 223659607e0Smrg u_plus_rw=,u+rw 224659607e0Smrg fi 225659607e0Smrg cp_umask=$mode$u_plus_rw;; 226659607e0Smrg esac 227659607e0Smrgfi 228659607e0Smrg 229659607e0Smrgfor src 230659607e0Smrgdo 231659607e0Smrg # Protect names starting with `-'. 232659607e0Smrg case $src in 233fc27e79cSmrg -*) src=./$src;; 234659607e0Smrg esac 235659607e0Smrg 236659607e0Smrg if test -n "$dir_arg"; then 237659607e0Smrg dst=$src 238659607e0Smrg dstdir=$dst 239659607e0Smrg test -d "$dstdir" 240659607e0Smrg dstdir_status=$? 241659607e0Smrg else 242659607e0Smrg 243659607e0Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 244659607e0Smrg # might cause directories to be created, which would be especially bad 245659607e0Smrg # if $src (and thus $dsttmp) contains '*'. 246659607e0Smrg if test ! -f "$src" && test ! -d "$src"; then 247659607e0Smrg echo "$0: $src does not exist." >&2 248659607e0Smrg exit 1 249659607e0Smrg fi 250659607e0Smrg 251fc27e79cSmrg if test -z "$dst_arg"; then 252659607e0Smrg echo "$0: no destination specified." >&2 253659607e0Smrg exit 1 254659607e0Smrg fi 255659607e0Smrg 256fc27e79cSmrg dst=$dst_arg 257659607e0Smrg # Protect names starting with `-'. 258659607e0Smrg case $dst in 259fc27e79cSmrg -*) dst=./$dst;; 260659607e0Smrg esac 261659607e0Smrg 262659607e0Smrg # If destination is a directory, append the input filename; won't work 263659607e0Smrg # if double slashes aren't ignored. 264659607e0Smrg if test -d "$dst"; then 265659607e0Smrg if test -n "$no_target_directory"; then 266fc27e79cSmrg echo "$0: $dst_arg: Is a directory" >&2 267659607e0Smrg exit 1 268659607e0Smrg fi 269659607e0Smrg dstdir=$dst 270659607e0Smrg dst=$dstdir/`basename "$src"` 271659607e0Smrg dstdir_status=0 272659607e0Smrg else 273659607e0Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 274659607e0Smrg dstdir=` 275659607e0Smrg (dirname "$dst") 2>/dev/null || 276659607e0Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 277659607e0Smrg X"$dst" : 'X\(//\)[^/]' \| \ 278659607e0Smrg X"$dst" : 'X\(//\)$' \| \ 279659607e0Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 280659607e0Smrg echo X"$dst" | 281659607e0Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 282659607e0Smrg s//\1/ 283659607e0Smrg q 284659607e0Smrg } 285659607e0Smrg /^X\(\/\/\)[^/].*/{ 286659607e0Smrg s//\1/ 287659607e0Smrg q 288659607e0Smrg } 289659607e0Smrg /^X\(\/\/\)$/{ 290659607e0Smrg s//\1/ 291659607e0Smrg q 292659607e0Smrg } 293659607e0Smrg /^X\(\/\).*/{ 294659607e0Smrg s//\1/ 295659607e0Smrg q 296659607e0Smrg } 297659607e0Smrg s/.*/./; q' 298659607e0Smrg ` 299659607e0Smrg 300659607e0Smrg test -d "$dstdir" 301659607e0Smrg dstdir_status=$? 302659607e0Smrg fi 303659607e0Smrg fi 304659607e0Smrg 305659607e0Smrg obsolete_mkdir_used=false 306659607e0Smrg 307659607e0Smrg if test $dstdir_status != 0; then 308659607e0Smrg case $posix_mkdir in 309659607e0Smrg '') 310659607e0Smrg # Create intermediate dirs using mode 755 as modified by the umask. 311659607e0Smrg # This is like FreeBSD 'install' as of 1997-10-28. 312659607e0Smrg umask=`umask` 313659607e0Smrg case $stripcmd.$umask in 314659607e0Smrg # Optimize common cases. 315659607e0Smrg *[2367][2367]) mkdir_umask=$umask;; 316659607e0Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 317659607e0Smrg 318659607e0Smrg *[0-7]) 319659607e0Smrg mkdir_umask=`expr $umask + 22 \ 320659607e0Smrg - $umask % 100 % 40 + $umask % 20 \ 321659607e0Smrg - $umask % 10 % 4 + $umask % 2 322659607e0Smrg `;; 323659607e0Smrg *) mkdir_umask=$umask,go-w;; 324659607e0Smrg esac 325659607e0Smrg 326659607e0Smrg # With -d, create the new directory with the user-specified mode. 327659607e0Smrg # Otherwise, rely on $mkdir_umask. 328659607e0Smrg if test -n "$dir_arg"; then 329659607e0Smrg mkdir_mode=-m$mode 330659607e0Smrg else 331659607e0Smrg mkdir_mode= 332659607e0Smrg fi 333659607e0Smrg 334659607e0Smrg posix_mkdir=false 335659607e0Smrg case $umask in 336659607e0Smrg *[123567][0-7][0-7]) 337659607e0Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 338659607e0Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 339659607e0Smrg ;; 340659607e0Smrg *) 341659607e0Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 342659607e0Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 343659607e0Smrg 344659607e0Smrg if (umask $mkdir_umask && 345659607e0Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 346659607e0Smrg then 347659607e0Smrg if test -z "$dir_arg" || { 348659607e0Smrg # Check for POSIX incompatibilities with -m. 349659607e0Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 350659607e0Smrg # other-writeable bit of parent directory when it shouldn't. 351659607e0Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 352659607e0Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 353659607e0Smrg case $ls_ld_tmpdir in 354659607e0Smrg d????-?r-*) different_mode=700;; 355659607e0Smrg d????-?--*) different_mode=755;; 356659607e0Smrg *) false;; 357659607e0Smrg esac && 358659607e0Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 359659607e0Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 360659607e0Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 361659607e0Smrg } 362659607e0Smrg } 363659607e0Smrg then posix_mkdir=: 364659607e0Smrg fi 365659607e0Smrg rmdir "$tmpdir/d" "$tmpdir" 366659607e0Smrg else 367659607e0Smrg # Remove any dirs left behind by ancient mkdir implementations. 368659607e0Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 369659607e0Smrg fi 370659607e0Smrg trap '' 0;; 371659607e0Smrg esac;; 372659607e0Smrg esac 373659607e0Smrg 374659607e0Smrg if 375659607e0Smrg $posix_mkdir && ( 376659607e0Smrg umask $mkdir_umask && 377659607e0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 378659607e0Smrg ) 379659607e0Smrg then : 380659607e0Smrg else 381659607e0Smrg 382659607e0Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 383659607e0Smrg # or it failed possibly due to a race condition. Create the 384659607e0Smrg # directory the slow way, step by step, checking for races as we go. 385659607e0Smrg 386659607e0Smrg case $dstdir in 387fc27e79cSmrg /*) prefix='/';; 388fc27e79cSmrg -*) prefix='./';; 389fc27e79cSmrg *) prefix='';; 390659607e0Smrg esac 391659607e0Smrg 392fc27e79cSmrg eval "$initialize_posix_glob" 393659607e0Smrg 394659607e0Smrg oIFS=$IFS 395659607e0Smrg IFS=/ 396fc27e79cSmrg $posix_glob set -f 397659607e0Smrg set fnord $dstdir 398659607e0Smrg shift 399fc27e79cSmrg $posix_glob set +f 400659607e0Smrg IFS=$oIFS 401659607e0Smrg 402659607e0Smrg prefixes= 403659607e0Smrg 404659607e0Smrg for d 405659607e0Smrg do 406659607e0Smrg test -z "$d" && continue 407659607e0Smrg 408659607e0Smrg prefix=$prefix$d 409659607e0Smrg if test -d "$prefix"; then 410659607e0Smrg prefixes= 411659607e0Smrg else 412659607e0Smrg if $posix_mkdir; then 413659607e0Smrg (umask=$mkdir_umask && 414659607e0Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 415659607e0Smrg # Don't fail if two instances are running concurrently. 416659607e0Smrg test -d "$prefix" || exit 1 417659607e0Smrg else 418659607e0Smrg case $prefix in 419659607e0Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 420659607e0Smrg *) qprefix=$prefix;; 421659607e0Smrg esac 422659607e0Smrg prefixes="$prefixes '$qprefix'" 423659607e0Smrg fi 424659607e0Smrg fi 425659607e0Smrg prefix=$prefix/ 426659607e0Smrg done 427659607e0Smrg 428659607e0Smrg if test -n "$prefixes"; then 429659607e0Smrg # Don't fail if two instances are running concurrently. 430659607e0Smrg (umask $mkdir_umask && 431659607e0Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 432659607e0Smrg test -d "$dstdir" || exit 1 433659607e0Smrg obsolete_mkdir_used=true 434659607e0Smrg fi 435659607e0Smrg fi 436659607e0Smrg fi 437659607e0Smrg 438659607e0Smrg if test -n "$dir_arg"; then 439659607e0Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 440659607e0Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 441659607e0Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 442659607e0Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 443659607e0Smrg else 444659607e0Smrg 445659607e0Smrg # Make a couple of temp file names in the proper directory. 446659607e0Smrg dsttmp=$dstdir/_inst.$$_ 447659607e0Smrg rmtmp=$dstdir/_rm.$$_ 448659607e0Smrg 449659607e0Smrg # Trap to clean up those temp files at exit. 450659607e0Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 451659607e0Smrg 452659607e0Smrg # Copy the file name to the temp name. 453659607e0Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 454659607e0Smrg 455659607e0Smrg # and set any options; do chmod last to preserve setuid bits. 456659607e0Smrg # 457659607e0Smrg # If any of these fail, we abort the whole thing. If we want to 458659607e0Smrg # ignore errors from any of these, just make sure not to ignore 459659607e0Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 460659607e0Smrg # 461fc27e79cSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 462fc27e79cSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 463fc27e79cSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 464fc27e79cSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 465fc27e79cSmrg 466fc27e79cSmrg # If -C, don't bother to copy if it wouldn't change the file. 467fc27e79cSmrg if $copy_on_change && 468fc27e79cSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 469fc27e79cSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 470fc27e79cSmrg 471fc27e79cSmrg eval "$initialize_posix_glob" && 472fc27e79cSmrg $posix_glob set -f && 473fc27e79cSmrg set X $old && old=:$2:$4:$5:$6 && 474fc27e79cSmrg set X $new && new=:$2:$4:$5:$6 && 475fc27e79cSmrg $posix_glob set +f && 476fc27e79cSmrg 477fc27e79cSmrg test "$old" = "$new" && 478fc27e79cSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 479fc27e79cSmrg then 480fc27e79cSmrg rm -f "$dsttmp" 481fc27e79cSmrg else 482fc27e79cSmrg # Rename the file to the real destination. 483fc27e79cSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 484fc27e79cSmrg 485fc27e79cSmrg # The rename failed, perhaps because mv can't rename something else 486fc27e79cSmrg # to itself, or perhaps because mv is so ancient that it does not 487fc27e79cSmrg # support -f. 488fc27e79cSmrg { 489fc27e79cSmrg # Now remove or move aside any old file at destination location. 490fc27e79cSmrg # We try this two ways since rm can't unlink itself on some 491fc27e79cSmrg # systems and the destination file might be busy for other 492fc27e79cSmrg # reasons. In this case, the final cleanup might fail but the new 493fc27e79cSmrg # file should still install successfully. 494fc27e79cSmrg { 495fc27e79cSmrg test ! -f "$dst" || 496fc27e79cSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 497fc27e79cSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 498fc27e79cSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 499fc27e79cSmrg } || 500fc27e79cSmrg { echo "$0: cannot unlink or rename $dst" >&2 501fc27e79cSmrg (exit 1); exit 1 502fc27e79cSmrg } 503fc27e79cSmrg } && 504fc27e79cSmrg 505fc27e79cSmrg # Now rename the file to the real destination. 506fc27e79cSmrg $doit $mvcmd "$dsttmp" "$dst" 507fc27e79cSmrg } 508fc27e79cSmrg fi || exit 1 509659607e0Smrg 510659607e0Smrg trap '' 0 511659607e0Smrg fi 512659607e0Smrgdone 513659607e0Smrg 514659607e0Smrg# Local variables: 515659607e0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 516659607e0Smrg# time-stamp-start: "scriptversion=" 517659607e0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 518659607e0Smrg# time-stamp-end: "$" 519659607e0Smrg# End: 520