install-sh revision 6cf5427a
10cc6efb6Smrg#!/bin/sh 20cc6efb6Smrg# install - install a program, script, or datafile 36cf5427aSmrg 46cf5427aSmrgscriptversion=2009-04-28.21; # UTC 56cf5427aSmrg 60cc6efb6Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 70cc6efb6Smrg# later released in X11R6 (xc/config/util/install.sh) with the 80cc6efb6Smrg# following copyright and license. 90cc6efb6Smrg# 100cc6efb6Smrg# Copyright (C) 1994 X Consortium 110cc6efb6Smrg# 120cc6efb6Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 130cc6efb6Smrg# of this software and associated documentation files (the "Software"), to 140cc6efb6Smrg# deal in the Software without restriction, including without limitation the 150cc6efb6Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 160cc6efb6Smrg# sell copies of the Software, and to permit persons to whom the Software is 170cc6efb6Smrg# furnished to do so, subject to the following conditions: 180cc6efb6Smrg# 190cc6efb6Smrg# The above copyright notice and this permission notice shall be included in 200cc6efb6Smrg# all copies or substantial portions of the Software. 210cc6efb6Smrg# 220cc6efb6Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 230cc6efb6Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 240cc6efb6Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 250cc6efb6Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 260cc6efb6Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 270cc6efb6Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 280cc6efb6Smrg# 290cc6efb6Smrg# Except as contained in this notice, the name of the X Consortium shall not 300cc6efb6Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 310cc6efb6Smrg# ings in this Software without prior written authorization from the X Consor- 320cc6efb6Smrg# tium. 330cc6efb6Smrg# 340cc6efb6Smrg# 350cc6efb6Smrg# FSF changes to this file are in the public domain. 360cc6efb6Smrg# 370cc6efb6Smrg# Calling this script install-sh is preferred over install.sh, to prevent 380cc6efb6Smrg# `make' implicit rules from creating a file called install from it 390cc6efb6Smrg# when there is no Makefile. 400cc6efb6Smrg# 410cc6efb6Smrg# This script is compatible with the BSD install script, but was written 426cf5427aSmrg# from scratch. 430cc6efb6Smrg 446cf5427aSmrgnl=' 456cf5427aSmrg' 466cf5427aSmrgIFS=" "" $nl" 470cc6efb6Smrg 480cc6efb6Smrg# set DOITPROG to echo to test this script 490cc6efb6Smrg 500cc6efb6Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 516cf5427aSmrgdoit=${DOITPROG-} 526cf5427aSmrgif test -z "$doit"; then 536cf5427aSmrg doit_exec=exec 540cc6efb6Smrgelse 556cf5427aSmrg doit_exec=$doit 560cc6efb6Smrgfi 570cc6efb6Smrg 586cf5427aSmrg# Put in absolute file names if you don't have them in your path; 596cf5427aSmrg# or use environment vars. 606cf5427aSmrg 616cf5427aSmrgchgrpprog=${CHGRPPROG-chgrp} 626cf5427aSmrgchmodprog=${CHMODPROG-chmod} 636cf5427aSmrgchownprog=${CHOWNPROG-chown} 646cf5427aSmrgcmpprog=${CMPPROG-cmp} 656cf5427aSmrgcpprog=${CPPROG-cp} 666cf5427aSmrgmkdirprog=${MKDIRPROG-mkdir} 676cf5427aSmrgmvprog=${MVPROG-mv} 686cf5427aSmrgrmprog=${RMPROG-rm} 696cf5427aSmrgstripprog=${STRIPPROG-strip} 706cf5427aSmrg 716cf5427aSmrgposix_glob='?' 726cf5427aSmrginitialize_posix_glob=' 736cf5427aSmrg test "$posix_glob" != "?" || { 746cf5427aSmrg if (set -f) 2>/dev/null; then 756cf5427aSmrg posix_glob= 766cf5427aSmrg else 776cf5427aSmrg posix_glob=: 786cf5427aSmrg fi 796cf5427aSmrg } 806cf5427aSmrg' 816cf5427aSmrg 826cf5427aSmrgposix_mkdir= 836cf5427aSmrg 846cf5427aSmrg# Desired mode of installed file. 856cf5427aSmrgmode=0755 866cf5427aSmrg 876cf5427aSmrgchgrpcmd= 886cf5427aSmrgchmodcmd=$chmodprog 896cf5427aSmrgchowncmd= 906cf5427aSmrgmvcmd=$mvprog 916cf5427aSmrgrmcmd="$rmprog -f" 926cf5427aSmrgstripcmd= 930cc6efb6Smrg 946cf5427aSmrgsrc= 956cf5427aSmrgdst= 966cf5427aSmrgdir_arg= 976cf5427aSmrgdst_arg= 980cc6efb6Smrg 996cf5427aSmrgcopy_on_change=false 1006cf5427aSmrgno_target_directory= 1010cc6efb6Smrg 1026cf5427aSmrgusage="\ 1036cf5427aSmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1046cf5427aSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1056cf5427aSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1066cf5427aSmrg or: $0 [OPTION]... -d DIRECTORIES... 1070cc6efb6Smrg 1086cf5427aSmrgIn the 1st form, copy SRCFILE to DSTFILE. 1096cf5427aSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1106cf5427aSmrgIn the 4th, create DIRECTORIES. 1110cc6efb6Smrg 1126cf5427aSmrgOptions: 1136cf5427aSmrg --help display this help and exit. 1146cf5427aSmrg --version display version info and exit. 1150cc6efb6Smrg 1166cf5427aSmrg -c (ignored) 1176cf5427aSmrg -C install only if different (preserve the last data modification time) 1186cf5427aSmrg -d create directories instead of installing files. 1196cf5427aSmrg -g GROUP $chgrpprog installed files to GROUP. 1206cf5427aSmrg -m MODE $chmodprog installed files to MODE. 1216cf5427aSmrg -o USER $chownprog installed files to USER. 1226cf5427aSmrg -s $stripprog installed files. 1236cf5427aSmrg -t DIRECTORY install into DIRECTORY. 1246cf5427aSmrg -T report an error if DSTFILE is a directory. 1250cc6efb6Smrg 1266cf5427aSmrgEnvironment variables override the default commands: 1276cf5427aSmrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1286cf5427aSmrg RMPROG STRIPPROG 1296cf5427aSmrg" 1300cc6efb6Smrg 1316cf5427aSmrgwhile test $# -ne 0; do 1326cf5427aSmrg case $1 in 1336cf5427aSmrg -c) ;; 1340cc6efb6Smrg 1356cf5427aSmrg -C) copy_on_change=true;; 1360cc6efb6Smrg 1376cf5427aSmrg -d) dir_arg=true;; 1380cc6efb6Smrg 1396cf5427aSmrg -g) chgrpcmd="$chgrpprog $2" 1406cf5427aSmrg shift;; 1410cc6efb6Smrg 1426cf5427aSmrg --help) echo "$usage"; exit $?;; 1430cc6efb6Smrg 1446cf5427aSmrg -m) mode=$2 1456cf5427aSmrg case $mode in 1466cf5427aSmrg *' '* | *' '* | *' 1476cf5427aSmrg'* | *'*'* | *'?'* | *'['*) 1486cf5427aSmrg echo "$0: invalid mode: $mode" >&2 1496cf5427aSmrg exit 1;; 1506cf5427aSmrg esac 1516cf5427aSmrg shift;; 1520cc6efb6Smrg 1536cf5427aSmrg -o) chowncmd="$chownprog $2" 1546cf5427aSmrg shift;; 1550cc6efb6Smrg 1566cf5427aSmrg -s) stripcmd=$stripprog;; 1570cc6efb6Smrg 1586cf5427aSmrg -t) dst_arg=$2 1596cf5427aSmrg shift;; 1600cc6efb6Smrg 1616cf5427aSmrg -T) no_target_directory=true;; 1620cc6efb6Smrg 1636cf5427aSmrg --version) echo "$0 $scriptversion"; exit $?;; 1640cc6efb6Smrg 1656cf5427aSmrg --) shift 1666cf5427aSmrg break;; 1670cc6efb6Smrg 1686cf5427aSmrg -*) echo "$0: invalid option: $1" >&2 1696cf5427aSmrg exit 1;; 1700cc6efb6Smrg 1716cf5427aSmrg *) break;; 1726cf5427aSmrg esac 1736cf5427aSmrg shift 1746cf5427aSmrgdone 1750cc6efb6Smrg 1766cf5427aSmrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1776cf5427aSmrg # When -d is used, all remaining arguments are directories to create. 1786cf5427aSmrg # When -t is used, the destination is already specified. 1796cf5427aSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1806cf5427aSmrg for arg 1816cf5427aSmrg do 1826cf5427aSmrg if test -n "$dst_arg"; then 1836cf5427aSmrg # $@ is not empty: it contains at least $arg. 1846cf5427aSmrg set fnord "$@" "$dst_arg" 1856cf5427aSmrg shift # fnord 1866cf5427aSmrg fi 1876cf5427aSmrg shift # arg 1886cf5427aSmrg dst_arg=$arg 1896cf5427aSmrg done 1906cf5427aSmrgfi 1910cc6efb6Smrg 1926cf5427aSmrgif test $# -eq 0; then 1936cf5427aSmrg if test -z "$dir_arg"; then 1946cf5427aSmrg echo "$0: no input file specified." >&2 1956cf5427aSmrg exit 1 1966cf5427aSmrg fi 1976cf5427aSmrg # It's OK to call `install-sh -d' without argument. 1986cf5427aSmrg # This can happen when creating conditional directories. 1996cf5427aSmrg exit 0 2006cf5427aSmrgfi 2010cc6efb6Smrg 2026cf5427aSmrgif test -z "$dir_arg"; then 2036cf5427aSmrg trap '(exit $?); exit' 1 2 13 15 2046cf5427aSmrg 2056cf5427aSmrg # Set umask so as not to create temps with too-generous modes. 2066cf5427aSmrg # However, 'strip' requires both read and write access to temps. 2076cf5427aSmrg case $mode in 2086cf5427aSmrg # Optimize common cases. 2096cf5427aSmrg *644) cp_umask=133;; 2106cf5427aSmrg *755) cp_umask=22;; 2116cf5427aSmrg 2126cf5427aSmrg *[0-7]) 2136cf5427aSmrg if test -z "$stripcmd"; then 2146cf5427aSmrg u_plus_rw= 2156cf5427aSmrg else 2166cf5427aSmrg u_plus_rw='% 200' 2176cf5427aSmrg fi 2186cf5427aSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2196cf5427aSmrg *) 2206cf5427aSmrg if test -z "$stripcmd"; then 2216cf5427aSmrg u_plus_rw= 2226cf5427aSmrg else 2236cf5427aSmrg u_plus_rw=,u+rw 2246cf5427aSmrg fi 2256cf5427aSmrg cp_umask=$mode$u_plus_rw;; 2266cf5427aSmrg esac 2276cf5427aSmrgfi 2280cc6efb6Smrg 2296cf5427aSmrgfor src 2306cf5427aSmrgdo 2316cf5427aSmrg # Protect names starting with `-'. 2326cf5427aSmrg case $src in 2336cf5427aSmrg -*) src=./$src;; 2346cf5427aSmrg esac 2356cf5427aSmrg 2366cf5427aSmrg if test -n "$dir_arg"; then 2376cf5427aSmrg dst=$src 2386cf5427aSmrg dstdir=$dst 2396cf5427aSmrg test -d "$dstdir" 2406cf5427aSmrg dstdir_status=$? 2416cf5427aSmrg else 2426cf5427aSmrg 2436cf5427aSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2446cf5427aSmrg # might cause directories to be created, which would be especially bad 2456cf5427aSmrg # if $src (and thus $dsttmp) contains '*'. 2466cf5427aSmrg if test ! -f "$src" && test ! -d "$src"; then 2476cf5427aSmrg echo "$0: $src does not exist." >&2 2486cf5427aSmrg exit 1 2496cf5427aSmrg fi 2506cf5427aSmrg 2516cf5427aSmrg if test -z "$dst_arg"; then 2526cf5427aSmrg echo "$0: no destination specified." >&2 2536cf5427aSmrg exit 1 2546cf5427aSmrg fi 2556cf5427aSmrg 2566cf5427aSmrg dst=$dst_arg 2576cf5427aSmrg # Protect names starting with `-'. 2586cf5427aSmrg case $dst in 2596cf5427aSmrg -*) dst=./$dst;; 2606cf5427aSmrg esac 2610cc6efb6Smrg 2626cf5427aSmrg # If destination is a directory, append the input filename; won't work 2636cf5427aSmrg # if double slashes aren't ignored. 2646cf5427aSmrg if test -d "$dst"; then 2656cf5427aSmrg if test -n "$no_target_directory"; then 2666cf5427aSmrg echo "$0: $dst_arg: Is a directory" >&2 2676cf5427aSmrg exit 1 2686cf5427aSmrg fi 2696cf5427aSmrg dstdir=$dst 2706cf5427aSmrg dst=$dstdir/`basename "$src"` 2716cf5427aSmrg dstdir_status=0 2726cf5427aSmrg else 2736cf5427aSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2746cf5427aSmrg dstdir=` 2756cf5427aSmrg (dirname "$dst") 2>/dev/null || 2766cf5427aSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2776cf5427aSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2786cf5427aSmrg X"$dst" : 'X\(//\)$' \| \ 2796cf5427aSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2806cf5427aSmrg echo X"$dst" | 2816cf5427aSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2826cf5427aSmrg s//\1/ 2836cf5427aSmrg q 2846cf5427aSmrg } 2856cf5427aSmrg /^X\(\/\/\)[^/].*/{ 2866cf5427aSmrg s//\1/ 2876cf5427aSmrg q 2886cf5427aSmrg } 2896cf5427aSmrg /^X\(\/\/\)$/{ 2906cf5427aSmrg s//\1/ 2916cf5427aSmrg q 2926cf5427aSmrg } 2936cf5427aSmrg /^X\(\/\).*/{ 2946cf5427aSmrg s//\1/ 2956cf5427aSmrg q 2966cf5427aSmrg } 2976cf5427aSmrg s/.*/./; q' 2986cf5427aSmrg ` 2996cf5427aSmrg 3006cf5427aSmrg test -d "$dstdir" 3016cf5427aSmrg dstdir_status=$? 3026cf5427aSmrg fi 3036cf5427aSmrg fi 3046cf5427aSmrg 3056cf5427aSmrg obsolete_mkdir_used=false 3066cf5427aSmrg 3076cf5427aSmrg if test $dstdir_status != 0; then 3086cf5427aSmrg case $posix_mkdir in 3096cf5427aSmrg '') 3106cf5427aSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3116cf5427aSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3126cf5427aSmrg umask=`umask` 3136cf5427aSmrg case $stripcmd.$umask in 3146cf5427aSmrg # Optimize common cases. 3156cf5427aSmrg *[2367][2367]) mkdir_umask=$umask;; 3166cf5427aSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3176cf5427aSmrg 3186cf5427aSmrg *[0-7]) 3196cf5427aSmrg mkdir_umask=`expr $umask + 22 \ 3206cf5427aSmrg - $umask % 100 % 40 + $umask % 20 \ 3216cf5427aSmrg - $umask % 10 % 4 + $umask % 2 3226cf5427aSmrg `;; 3236cf5427aSmrg *) mkdir_umask=$umask,go-w;; 3246cf5427aSmrg esac 3256cf5427aSmrg 3266cf5427aSmrg # With -d, create the new directory with the user-specified mode. 3276cf5427aSmrg # Otherwise, rely on $mkdir_umask. 3286cf5427aSmrg if test -n "$dir_arg"; then 3296cf5427aSmrg mkdir_mode=-m$mode 3300cc6efb6Smrg else 3316cf5427aSmrg mkdir_mode= 3320cc6efb6Smrg fi 3330cc6efb6Smrg 3346cf5427aSmrg posix_mkdir=false 3356cf5427aSmrg case $umask in 3366cf5427aSmrg *[123567][0-7][0-7]) 3376cf5427aSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3386cf5427aSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3396cf5427aSmrg ;; 3406cf5427aSmrg *) 3416cf5427aSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3426cf5427aSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3436cf5427aSmrg 3446cf5427aSmrg if (umask $mkdir_umask && 3456cf5427aSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3466cf5427aSmrg then 3476cf5427aSmrg if test -z "$dir_arg" || { 3486cf5427aSmrg # Check for POSIX incompatibilities with -m. 3496cf5427aSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3506cf5427aSmrg # other-writeable bit of parent directory when it shouldn't. 3516cf5427aSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3526cf5427aSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3536cf5427aSmrg case $ls_ld_tmpdir in 3546cf5427aSmrg d????-?r-*) different_mode=700;; 3556cf5427aSmrg d????-?--*) different_mode=755;; 3566cf5427aSmrg *) false;; 3576cf5427aSmrg esac && 3586cf5427aSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3596cf5427aSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3606cf5427aSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3616cf5427aSmrg } 3626cf5427aSmrg } 3636cf5427aSmrg then posix_mkdir=: 3646cf5427aSmrg fi 3656cf5427aSmrg rmdir "$tmpdir/d" "$tmpdir" 3666cf5427aSmrg else 3676cf5427aSmrg # Remove any dirs left behind by ancient mkdir implementations. 3686cf5427aSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3696cf5427aSmrg fi 3706cf5427aSmrg trap '' 0;; 3716cf5427aSmrg esac;; 3726cf5427aSmrg esac 3730cc6efb6Smrg 3746cf5427aSmrg if 3756cf5427aSmrg $posix_mkdir && ( 3766cf5427aSmrg umask $mkdir_umask && 3776cf5427aSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3786cf5427aSmrg ) 3796cf5427aSmrg then : 3806cf5427aSmrg else 3816cf5427aSmrg 3826cf5427aSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3836cf5427aSmrg # or it failed possibly due to a race condition. Create the 3846cf5427aSmrg # directory the slow way, step by step, checking for races as we go. 3856cf5427aSmrg 3866cf5427aSmrg case $dstdir in 3876cf5427aSmrg /*) prefix='/';; 3886cf5427aSmrg -*) prefix='./';; 3896cf5427aSmrg *) prefix='';; 3906cf5427aSmrg esac 3916cf5427aSmrg 3926cf5427aSmrg eval "$initialize_posix_glob" 3936cf5427aSmrg 3946cf5427aSmrg oIFS=$IFS 3956cf5427aSmrg IFS=/ 3966cf5427aSmrg $posix_glob set -f 3976cf5427aSmrg set fnord $dstdir 3986cf5427aSmrg shift 3996cf5427aSmrg $posix_glob set +f 4006cf5427aSmrg IFS=$oIFS 4016cf5427aSmrg 4026cf5427aSmrg prefixes= 4036cf5427aSmrg 4046cf5427aSmrg for d 4056cf5427aSmrg do 4066cf5427aSmrg test -z "$d" && continue 4076cf5427aSmrg 4086cf5427aSmrg prefix=$prefix$d 4096cf5427aSmrg if test -d "$prefix"; then 4106cf5427aSmrg prefixes= 4116cf5427aSmrg else 4126cf5427aSmrg if $posix_mkdir; then 4136cf5427aSmrg (umask=$mkdir_umask && 4146cf5427aSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4156cf5427aSmrg # Don't fail if two instances are running concurrently. 4166cf5427aSmrg test -d "$prefix" || exit 1 4176cf5427aSmrg else 4186cf5427aSmrg case $prefix in 4196cf5427aSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4206cf5427aSmrg *) qprefix=$prefix;; 4216cf5427aSmrg esac 4226cf5427aSmrg prefixes="$prefixes '$qprefix'" 4236cf5427aSmrg fi 4246cf5427aSmrg fi 4256cf5427aSmrg prefix=$prefix/ 4266cf5427aSmrg done 4276cf5427aSmrg 4286cf5427aSmrg if test -n "$prefixes"; then 4296cf5427aSmrg # Don't fail if two instances are running concurrently. 4306cf5427aSmrg (umask $mkdir_umask && 4316cf5427aSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4326cf5427aSmrg test -d "$dstdir" || exit 1 4336cf5427aSmrg obsolete_mkdir_used=true 4346cf5427aSmrg fi 4356cf5427aSmrg fi 4366cf5427aSmrg fi 4376cf5427aSmrg 4386cf5427aSmrg if test -n "$dir_arg"; then 4396cf5427aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4406cf5427aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4416cf5427aSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4426cf5427aSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4436cf5427aSmrg else 4446cf5427aSmrg 4456cf5427aSmrg # Make a couple of temp file names in the proper directory. 4466cf5427aSmrg dsttmp=$dstdir/_inst.$$_ 4476cf5427aSmrg rmtmp=$dstdir/_rm.$$_ 4486cf5427aSmrg 4496cf5427aSmrg # Trap to clean up those temp files at exit. 4506cf5427aSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4516cf5427aSmrg 4526cf5427aSmrg # Copy the file name to the temp name. 4536cf5427aSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4546cf5427aSmrg 4556cf5427aSmrg # and set any options; do chmod last to preserve setuid bits. 4566cf5427aSmrg # 4576cf5427aSmrg # If any of these fail, we abort the whole thing. If we want to 4586cf5427aSmrg # ignore errors from any of these, just make sure not to ignore 4596cf5427aSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4606cf5427aSmrg # 4616cf5427aSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4626cf5427aSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4636cf5427aSmrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4646cf5427aSmrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4656cf5427aSmrg 4666cf5427aSmrg # If -C, don't bother to copy if it wouldn't change the file. 4676cf5427aSmrg if $copy_on_change && 4686cf5427aSmrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4696cf5427aSmrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4706cf5427aSmrg 4716cf5427aSmrg eval "$initialize_posix_glob" && 4726cf5427aSmrg $posix_glob set -f && 4736cf5427aSmrg set X $old && old=:$2:$4:$5:$6 && 4746cf5427aSmrg set X $new && new=:$2:$4:$5:$6 && 4756cf5427aSmrg $posix_glob set +f && 4766cf5427aSmrg 4776cf5427aSmrg test "$old" = "$new" && 4786cf5427aSmrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4796cf5427aSmrg then 4806cf5427aSmrg rm -f "$dsttmp" 4816cf5427aSmrg else 4826cf5427aSmrg # Rename the file to the real destination. 4836cf5427aSmrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4846cf5427aSmrg 4856cf5427aSmrg # The rename failed, perhaps because mv can't rename something else 4866cf5427aSmrg # to itself, or perhaps because mv is so ancient that it does not 4876cf5427aSmrg # support -f. 4886cf5427aSmrg { 4896cf5427aSmrg # Now remove or move aside any old file at destination location. 4906cf5427aSmrg # We try this two ways since rm can't unlink itself on some 4916cf5427aSmrg # systems and the destination file might be busy for other 4926cf5427aSmrg # reasons. In this case, the final cleanup might fail but the new 4936cf5427aSmrg # file should still install successfully. 4946cf5427aSmrg { 4956cf5427aSmrg test ! -f "$dst" || 4966cf5427aSmrg $doit $rmcmd -f "$dst" 2>/dev/null || 4976cf5427aSmrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4986cf5427aSmrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4996cf5427aSmrg } || 5006cf5427aSmrg { echo "$0: cannot unlink or rename $dst" >&2 5016cf5427aSmrg (exit 1); exit 1 5026cf5427aSmrg } 5036cf5427aSmrg } && 5046cf5427aSmrg 5056cf5427aSmrg # Now rename the file to the real destination. 5066cf5427aSmrg $doit $mvcmd "$dsttmp" "$dst" 5076cf5427aSmrg } 5086cf5427aSmrg fi || exit 1 5096cf5427aSmrg 5106cf5427aSmrg trap '' 0 5116cf5427aSmrg fi 5126cf5427aSmrgdone 5130cc6efb6Smrg 5146cf5427aSmrg# Local variables: 5156cf5427aSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5166cf5427aSmrg# time-stamp-start: "scriptversion=" 5176cf5427aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5186cf5427aSmrg# time-stamp-time-zone: "UTC" 5196cf5427aSmrg# time-stamp-end: "; # UTC" 5206cf5427aSmrg# End: 521