install-sh revision e1e1713c
17a84e134Smrg#!/bin/sh 27a84e134Smrg# install - install a program, script, or datafile 37a84e134Smrg 4e1e1713cSmrgscriptversion=2009-04-28.21; # UTC 57a84e134Smrg 67a84e134Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 77a84e134Smrg# later released in X11R6 (xc/config/util/install.sh) with the 87a84e134Smrg# following copyright and license. 97a84e134Smrg# 107a84e134Smrg# Copyright (C) 1994 X Consortium 117a84e134Smrg# 127a84e134Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 137a84e134Smrg# of this software and associated documentation files (the "Software"), to 147a84e134Smrg# deal in the Software without restriction, including without limitation the 157a84e134Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 167a84e134Smrg# sell copies of the Software, and to permit persons to whom the Software is 177a84e134Smrg# furnished to do so, subject to the following conditions: 187a84e134Smrg# 197a84e134Smrg# The above copyright notice and this permission notice shall be included in 207a84e134Smrg# all copies or substantial portions of the Software. 217a84e134Smrg# 227a84e134Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 237a84e134Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 247a84e134Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 257a84e134Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 267a84e134Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 277a84e134Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 287a84e134Smrg# 297a84e134Smrg# Except as contained in this notice, the name of the X Consortium shall not 307a84e134Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 317a84e134Smrg# ings in this Software without prior written authorization from the X Consor- 327a84e134Smrg# tium. 337a84e134Smrg# 347a84e134Smrg# 357a84e134Smrg# FSF changes to this file are in the public domain. 367a84e134Smrg# 377a84e134Smrg# Calling this script install-sh is preferred over install.sh, to prevent 387a84e134Smrg# `make' implicit rules from creating a file called install from it 397a84e134Smrg# when there is no Makefile. 407a84e134Smrg# 417a84e134Smrg# This script is compatible with the BSD install script, but was written 427a84e134Smrg# from scratch. 437a84e134Smrg 447a84e134Smrgnl=' 457a84e134Smrg' 467a84e134SmrgIFS=" "" $nl" 477a84e134Smrg 487a84e134Smrg# set DOITPROG to echo to test this script 497a84e134Smrg 507a84e134Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51ab902922Smrgdoit=${DOITPROG-} 527a84e134Smrgif test -z "$doit"; then 537a84e134Smrg doit_exec=exec 547a84e134Smrgelse 557a84e134Smrg doit_exec=$doit 567a84e134Smrgfi 577a84e134Smrg 587a84e134Smrg# Put in absolute file names if you don't have them in your path; 597a84e134Smrg# or use environment vars. 607a84e134Smrg 61ab902922Smrgchgrpprog=${CHGRPPROG-chgrp} 62ab902922Smrgchmodprog=${CHMODPROG-chmod} 63ab902922Smrgchownprog=${CHOWNPROG-chown} 64ab902922Smrgcmpprog=${CMPPROG-cmp} 65ab902922Smrgcpprog=${CPPROG-cp} 66ab902922Smrgmkdirprog=${MKDIRPROG-mkdir} 67ab902922Smrgmvprog=${MVPROG-mv} 68ab902922Smrgrmprog=${RMPROG-rm} 69ab902922Smrgstripprog=${STRIPPROG-strip} 70ab902922Smrg 71ab902922Smrgposix_glob='?' 72ab902922Smrginitialize_posix_glob=' 73ab902922Smrg test "$posix_glob" != "?" || { 74ab902922Smrg if (set -f) 2>/dev/null; then 75ab902922Smrg posix_glob= 76ab902922Smrg else 77ab902922Smrg posix_glob=: 78ab902922Smrg fi 79ab902922Smrg } 80ab902922Smrg' 817a84e134Smrg 827a84e134Smrgposix_mkdir= 837a84e134Smrg 847a84e134Smrg# Desired mode of installed file. 857a84e134Smrgmode=0755 867a84e134Smrg 87ab902922Smrgchgrpcmd= 887a84e134Smrgchmodcmd=$chmodprog 897a84e134Smrgchowncmd= 90ab902922Smrgmvcmd=$mvprog 917a84e134Smrgrmcmd="$rmprog -f" 92ab902922Smrgstripcmd= 93ab902922Smrg 947a84e134Smrgsrc= 957a84e134Smrgdst= 967a84e134Smrgdir_arg= 97ab902922Smrgdst_arg= 98ab902922Smrg 99ab902922Smrgcopy_on_change=false 1007a84e134Smrgno_target_directory= 1017a84e134Smrg 102ab902922Smrgusage="\ 103ab902922SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1047a84e134Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1057a84e134Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1067a84e134Smrg or: $0 [OPTION]... -d DIRECTORIES... 1077a84e134Smrg 1087a84e134SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1097a84e134SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1107a84e134SmrgIn the 4th, create DIRECTORIES. 1117a84e134Smrg 1127a84e134SmrgOptions: 113ab902922Smrg --help display this help and exit. 114ab902922Smrg --version display version info and exit. 115ab902922Smrg 116ab902922Smrg -c (ignored) 117ab902922Smrg -C install only if different (preserve the last data modification time) 118ab902922Smrg -d create directories instead of installing files. 119ab902922Smrg -g GROUP $chgrpprog installed files to GROUP. 120ab902922Smrg -m MODE $chmodprog installed files to MODE. 121ab902922Smrg -o USER $chownprog installed files to USER. 122ab902922Smrg -s $stripprog installed files. 123ab902922Smrg -t DIRECTORY install into DIRECTORY. 124ab902922Smrg -T report an error if DSTFILE is a directory. 1257a84e134Smrg 1267a84e134SmrgEnvironment variables override the default commands: 127ab902922Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128ab902922Smrg RMPROG STRIPPROG 1297a84e134Smrg" 1307a84e134Smrg 1317a84e134Smrgwhile test $# -ne 0; do 1327a84e134Smrg case $1 in 133ab902922Smrg -c) ;; 134ab902922Smrg 135ab902922Smrg -C) copy_on_change=true;; 1367a84e134Smrg 137ab902922Smrg -d) dir_arg=true;; 1387a84e134Smrg 1397a84e134Smrg -g) chgrpcmd="$chgrpprog $2" 140ab902922Smrg shift;; 1417a84e134Smrg 1427a84e134Smrg --help) echo "$usage"; exit $?;; 1437a84e134Smrg 1447a84e134Smrg -m) mode=$2 1457a84e134Smrg case $mode in 1467a84e134Smrg *' '* | *' '* | *' 1477a84e134Smrg'* | *'*'* | *'?'* | *'['*) 1487a84e134Smrg echo "$0: invalid mode: $mode" >&2 1497a84e134Smrg exit 1;; 1507a84e134Smrg esac 151ab902922Smrg shift;; 1527a84e134Smrg 1537a84e134Smrg -o) chowncmd="$chownprog $2" 154ab902922Smrg shift;; 1557a84e134Smrg 156ab902922Smrg -s) stripcmd=$stripprog;; 1577a84e134Smrg 158ab902922Smrg -t) dst_arg=$2 159ab902922Smrg shift;; 1607a84e134Smrg 161ab902922Smrg -T) no_target_directory=true;; 1627a84e134Smrg 1637a84e134Smrg --version) echo "$0 $scriptversion"; exit $?;; 1647a84e134Smrg 1657a84e134Smrg --) shift 1667a84e134Smrg break;; 1677a84e134Smrg 1687a84e134Smrg -*) echo "$0: invalid option: $1" >&2 1697a84e134Smrg exit 1;; 1707a84e134Smrg 1717a84e134Smrg *) break;; 1727a84e134Smrg esac 173ab902922Smrg shift 1747a84e134Smrgdone 1757a84e134Smrg 176ab902922Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1777a84e134Smrg # When -d is used, all remaining arguments are directories to create. 1787a84e134Smrg # When -t is used, the destination is already specified. 1797a84e134Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1807a84e134Smrg for arg 1817a84e134Smrg do 182ab902922Smrg if test -n "$dst_arg"; then 1837a84e134Smrg # $@ is not empty: it contains at least $arg. 184ab902922Smrg set fnord "$@" "$dst_arg" 1857a84e134Smrg shift # fnord 1867a84e134Smrg fi 1877a84e134Smrg shift # arg 188ab902922Smrg dst_arg=$arg 1897a84e134Smrg done 1907a84e134Smrgfi 1917a84e134Smrg 1927a84e134Smrgif test $# -eq 0; then 1937a84e134Smrg if test -z "$dir_arg"; then 1947a84e134Smrg echo "$0: no input file specified." >&2 1957a84e134Smrg exit 1 1967a84e134Smrg fi 1977a84e134Smrg # It's OK to call `install-sh -d' without argument. 1987a84e134Smrg # This can happen when creating conditional directories. 1997a84e134Smrg exit 0 2007a84e134Smrgfi 2017a84e134Smrg 2027a84e134Smrgif test -z "$dir_arg"; then 2037a84e134Smrg trap '(exit $?); exit' 1 2 13 15 2047a84e134Smrg 2057a84e134Smrg # Set umask so as not to create temps with too-generous modes. 2067a84e134Smrg # However, 'strip' requires both read and write access to temps. 2077a84e134Smrg case $mode in 2087a84e134Smrg # Optimize common cases. 2097a84e134Smrg *644) cp_umask=133;; 2107a84e134Smrg *755) cp_umask=22;; 2117a84e134Smrg 2127a84e134Smrg *[0-7]) 2137a84e134Smrg if test -z "$stripcmd"; then 2147a84e134Smrg u_plus_rw= 2157a84e134Smrg else 2167a84e134Smrg u_plus_rw='% 200' 2177a84e134Smrg fi 2187a84e134Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2197a84e134Smrg *) 2207a84e134Smrg if test -z "$stripcmd"; then 2217a84e134Smrg u_plus_rw= 2227a84e134Smrg else 2237a84e134Smrg u_plus_rw=,u+rw 2247a84e134Smrg fi 2257a84e134Smrg cp_umask=$mode$u_plus_rw;; 2267a84e134Smrg esac 2277a84e134Smrgfi 2287a84e134Smrg 2297a84e134Smrgfor src 2307a84e134Smrgdo 2317a84e134Smrg # Protect names starting with `-'. 2327a84e134Smrg case $src in 233ab902922Smrg -*) src=./$src;; 2347a84e134Smrg esac 2357a84e134Smrg 2367a84e134Smrg if test -n "$dir_arg"; then 2377a84e134Smrg dst=$src 2387a84e134Smrg dstdir=$dst 2397a84e134Smrg test -d "$dstdir" 2407a84e134Smrg dstdir_status=$? 2417a84e134Smrg else 2427a84e134Smrg 2437a84e134Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2447a84e134Smrg # might cause directories to be created, which would be especially bad 2457a84e134Smrg # if $src (and thus $dsttmp) contains '*'. 2467a84e134Smrg if test ! -f "$src" && test ! -d "$src"; then 2477a84e134Smrg echo "$0: $src does not exist." >&2 2487a84e134Smrg exit 1 2497a84e134Smrg fi 2507a84e134Smrg 251ab902922Smrg if test -z "$dst_arg"; then 2527a84e134Smrg echo "$0: no destination specified." >&2 2537a84e134Smrg exit 1 2547a84e134Smrg fi 2557a84e134Smrg 256ab902922Smrg dst=$dst_arg 2577a84e134Smrg # Protect names starting with `-'. 2587a84e134Smrg case $dst in 259ab902922Smrg -*) dst=./$dst;; 2607a84e134Smrg esac 2617a84e134Smrg 2627a84e134Smrg # If destination is a directory, append the input filename; won't work 2637a84e134Smrg # if double slashes aren't ignored. 2647a84e134Smrg if test -d "$dst"; then 2657a84e134Smrg if test -n "$no_target_directory"; then 266ab902922Smrg echo "$0: $dst_arg: Is a directory" >&2 2677a84e134Smrg exit 1 2687a84e134Smrg fi 2697a84e134Smrg dstdir=$dst 2707a84e134Smrg dst=$dstdir/`basename "$src"` 2717a84e134Smrg dstdir_status=0 2727a84e134Smrg else 2737a84e134Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2747a84e134Smrg dstdir=` 2757a84e134Smrg (dirname "$dst") 2>/dev/null || 2767a84e134Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2777a84e134Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2787a84e134Smrg X"$dst" : 'X\(//\)$' \| \ 2797a84e134Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2807a84e134Smrg echo X"$dst" | 2817a84e134Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2827a84e134Smrg s//\1/ 2837a84e134Smrg q 2847a84e134Smrg } 2857a84e134Smrg /^X\(\/\/\)[^/].*/{ 2867a84e134Smrg s//\1/ 2877a84e134Smrg q 2887a84e134Smrg } 2897a84e134Smrg /^X\(\/\/\)$/{ 2907a84e134Smrg s//\1/ 2917a84e134Smrg q 2927a84e134Smrg } 2937a84e134Smrg /^X\(\/\).*/{ 2947a84e134Smrg s//\1/ 2957a84e134Smrg q 2967a84e134Smrg } 2977a84e134Smrg s/.*/./; q' 2987a84e134Smrg ` 2997a84e134Smrg 3007a84e134Smrg test -d "$dstdir" 3017a84e134Smrg dstdir_status=$? 3027a84e134Smrg fi 3037a84e134Smrg fi 3047a84e134Smrg 3057a84e134Smrg obsolete_mkdir_used=false 3067a84e134Smrg 3077a84e134Smrg if test $dstdir_status != 0; then 3087a84e134Smrg case $posix_mkdir in 3097a84e134Smrg '') 3107a84e134Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3117a84e134Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3127a84e134Smrg umask=`umask` 3137a84e134Smrg case $stripcmd.$umask in 3147a84e134Smrg # Optimize common cases. 3157a84e134Smrg *[2367][2367]) mkdir_umask=$umask;; 3167a84e134Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3177a84e134Smrg 3187a84e134Smrg *[0-7]) 3197a84e134Smrg mkdir_umask=`expr $umask + 22 \ 3207a84e134Smrg - $umask % 100 % 40 + $umask % 20 \ 3217a84e134Smrg - $umask % 10 % 4 + $umask % 2 3227a84e134Smrg `;; 3237a84e134Smrg *) mkdir_umask=$umask,go-w;; 3247a84e134Smrg esac 3257a84e134Smrg 3267a84e134Smrg # With -d, create the new directory with the user-specified mode. 3277a84e134Smrg # Otherwise, rely on $mkdir_umask. 3287a84e134Smrg if test -n "$dir_arg"; then 3297a84e134Smrg mkdir_mode=-m$mode 3307a84e134Smrg else 3317a84e134Smrg mkdir_mode= 3327a84e134Smrg fi 3337a84e134Smrg 3347a84e134Smrg posix_mkdir=false 3357a84e134Smrg case $umask in 3367a84e134Smrg *[123567][0-7][0-7]) 3377a84e134Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3387a84e134Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3397a84e134Smrg ;; 3407a84e134Smrg *) 3417a84e134Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3427a84e134Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3437a84e134Smrg 3447a84e134Smrg if (umask $mkdir_umask && 3457a84e134Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3467a84e134Smrg then 3477a84e134Smrg if test -z "$dir_arg" || { 3487a84e134Smrg # Check for POSIX incompatibilities with -m. 3497a84e134Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3507a84e134Smrg # other-writeable bit of parent directory when it shouldn't. 3517a84e134Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3527a84e134Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3537a84e134Smrg case $ls_ld_tmpdir in 3547a84e134Smrg d????-?r-*) different_mode=700;; 3557a84e134Smrg d????-?--*) different_mode=755;; 3567a84e134Smrg *) false;; 3577a84e134Smrg esac && 3587a84e134Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3597a84e134Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3607a84e134Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3617a84e134Smrg } 3627a84e134Smrg } 3637a84e134Smrg then posix_mkdir=: 3647a84e134Smrg fi 3657a84e134Smrg rmdir "$tmpdir/d" "$tmpdir" 3667a84e134Smrg else 3677a84e134Smrg # Remove any dirs left behind by ancient mkdir implementations. 3687a84e134Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3697a84e134Smrg fi 3707a84e134Smrg trap '' 0;; 3717a84e134Smrg esac;; 3727a84e134Smrg esac 3737a84e134Smrg 3747a84e134Smrg if 3757a84e134Smrg $posix_mkdir && ( 3767a84e134Smrg umask $mkdir_umask && 3777a84e134Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3787a84e134Smrg ) 3797a84e134Smrg then : 3807a84e134Smrg else 3817a84e134Smrg 3827a84e134Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3837a84e134Smrg # or it failed possibly due to a race condition. Create the 3847a84e134Smrg # directory the slow way, step by step, checking for races as we go. 3857a84e134Smrg 3867a84e134Smrg case $dstdir in 387ab902922Smrg /*) prefix='/';; 388ab902922Smrg -*) prefix='./';; 389ab902922Smrg *) prefix='';; 3907a84e134Smrg esac 3917a84e134Smrg 392ab902922Smrg eval "$initialize_posix_glob" 3937a84e134Smrg 3947a84e134Smrg oIFS=$IFS 3957a84e134Smrg IFS=/ 396ab902922Smrg $posix_glob set -f 3977a84e134Smrg set fnord $dstdir 3987a84e134Smrg shift 399ab902922Smrg $posix_glob set +f 4007a84e134Smrg IFS=$oIFS 4017a84e134Smrg 4027a84e134Smrg prefixes= 4037a84e134Smrg 4047a84e134Smrg for d 4057a84e134Smrg do 4067a84e134Smrg test -z "$d" && continue 4077a84e134Smrg 4087a84e134Smrg prefix=$prefix$d 4097a84e134Smrg if test -d "$prefix"; then 4107a84e134Smrg prefixes= 4117a84e134Smrg else 4127a84e134Smrg if $posix_mkdir; then 4137a84e134Smrg (umask=$mkdir_umask && 4147a84e134Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4157a84e134Smrg # Don't fail if two instances are running concurrently. 4167a84e134Smrg test -d "$prefix" || exit 1 4177a84e134Smrg else 4187a84e134Smrg case $prefix in 4197a84e134Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4207a84e134Smrg *) qprefix=$prefix;; 4217a84e134Smrg esac 4227a84e134Smrg prefixes="$prefixes '$qprefix'" 4237a84e134Smrg fi 4247a84e134Smrg fi 4257a84e134Smrg prefix=$prefix/ 4267a84e134Smrg done 4277a84e134Smrg 4287a84e134Smrg if test -n "$prefixes"; then 4297a84e134Smrg # Don't fail if two instances are running concurrently. 4307a84e134Smrg (umask $mkdir_umask && 4317a84e134Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4327a84e134Smrg test -d "$dstdir" || exit 1 4337a84e134Smrg obsolete_mkdir_used=true 4347a84e134Smrg fi 4357a84e134Smrg fi 4367a84e134Smrg fi 4377a84e134Smrg 4387a84e134Smrg if test -n "$dir_arg"; then 4397a84e134Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4407a84e134Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4417a84e134Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4427a84e134Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4437a84e134Smrg else 4447a84e134Smrg 4457a84e134Smrg # Make a couple of temp file names in the proper directory. 4467a84e134Smrg dsttmp=$dstdir/_inst.$$_ 4477a84e134Smrg rmtmp=$dstdir/_rm.$$_ 4487a84e134Smrg 4497a84e134Smrg # Trap to clean up those temp files at exit. 4507a84e134Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4517a84e134Smrg 4527a84e134Smrg # Copy the file name to the temp name. 4537a84e134Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4547a84e134Smrg 4557a84e134Smrg # and set any options; do chmod last to preserve setuid bits. 4567a84e134Smrg # 4577a84e134Smrg # If any of these fail, we abort the whole thing. If we want to 4587a84e134Smrg # ignore errors from any of these, just make sure not to ignore 4597a84e134Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4607a84e134Smrg # 461ab902922Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 462ab902922Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 463ab902922Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 464ab902922Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 465ab902922Smrg 466ab902922Smrg # If -C, don't bother to copy if it wouldn't change the file. 467ab902922Smrg if $copy_on_change && 468ab902922Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 469ab902922Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 470ab902922Smrg 471ab902922Smrg eval "$initialize_posix_glob" && 472ab902922Smrg $posix_glob set -f && 473ab902922Smrg set X $old && old=:$2:$4:$5:$6 && 474ab902922Smrg set X $new && new=:$2:$4:$5:$6 && 475ab902922Smrg $posix_glob set +f && 476ab902922Smrg 477ab902922Smrg test "$old" = "$new" && 478ab902922Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 479ab902922Smrg then 480ab902922Smrg rm -f "$dsttmp" 481ab902922Smrg else 482ab902922Smrg # Rename the file to the real destination. 483ab902922Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 484ab902922Smrg 485ab902922Smrg # The rename failed, perhaps because mv can't rename something else 486ab902922Smrg # to itself, or perhaps because mv is so ancient that it does not 487ab902922Smrg # support -f. 488ab902922Smrg { 489ab902922Smrg # Now remove or move aside any old file at destination location. 490ab902922Smrg # We try this two ways since rm can't unlink itself on some 491ab902922Smrg # systems and the destination file might be busy for other 492ab902922Smrg # reasons. In this case, the final cleanup might fail but the new 493ab902922Smrg # file should still install successfully. 494ab902922Smrg { 495ab902922Smrg test ! -f "$dst" || 496ab902922Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 497ab902922Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 498ab902922Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 499ab902922Smrg } || 500ab902922Smrg { echo "$0: cannot unlink or rename $dst" >&2 501ab902922Smrg (exit 1); exit 1 502ab902922Smrg } 503ab902922Smrg } && 504ab902922Smrg 505ab902922Smrg # Now rename the file to the real destination. 506ab902922Smrg $doit $mvcmd "$dsttmp" "$dst" 507ab902922Smrg } 508ab902922Smrg fi || exit 1 5097a84e134Smrg 5107a84e134Smrg trap '' 0 5117a84e134Smrg fi 5127a84e134Smrgdone 5137a84e134Smrg 5147a84e134Smrg# Local variables: 5157a84e134Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5167a84e134Smrg# time-stamp-start: "scriptversion=" 5177a84e134Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 518e1e1713cSmrg# time-stamp-time-zone: "UTC" 519e1e1713cSmrg# time-stamp-end: "; # UTC" 5207a84e134Smrg# End: 521