install-sh revision 3e6c936a
14456fccdSmrg#!/bin/sh 24456fccdSmrg# install - install a program, script, or datafile 34456fccdSmrg 43e6c936aSmrgscriptversion=2011-11-20.07; # UTC 54456fccdSmrg 64456fccdSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 74456fccdSmrg# later released in X11R6 (xc/config/util/install.sh) with the 84456fccdSmrg# following copyright and license. 94456fccdSmrg# 104456fccdSmrg# Copyright (C) 1994 X Consortium 114456fccdSmrg# 124456fccdSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 134456fccdSmrg# of this software and associated documentation files (the "Software"), to 144456fccdSmrg# deal in the Software without restriction, including without limitation the 154456fccdSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 164456fccdSmrg# sell copies of the Software, and to permit persons to whom the Software is 174456fccdSmrg# furnished to do so, subject to the following conditions: 184456fccdSmrg# 194456fccdSmrg# The above copyright notice and this permission notice shall be included in 204456fccdSmrg# all copies or substantial portions of the Software. 214456fccdSmrg# 224456fccdSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 234456fccdSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 244456fccdSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 254456fccdSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 264456fccdSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 274456fccdSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 284456fccdSmrg# 294456fccdSmrg# Except as contained in this notice, the name of the X Consortium shall not 304456fccdSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 314456fccdSmrg# ings in this Software without prior written authorization from the X Consor- 324456fccdSmrg# tium. 334456fccdSmrg# 344456fccdSmrg# 354456fccdSmrg# FSF changes to this file are in the public domain. 364456fccdSmrg# 374456fccdSmrg# Calling this script install-sh is preferred over install.sh, to prevent 383e6c936aSmrg# 'make' implicit rules from creating a file called install from it 394456fccdSmrg# when there is no Makefile. 404456fccdSmrg# 414456fccdSmrg# This script is compatible with the BSD install script, but was written 4242d69509Smrg# from scratch. 4342d69509Smrg 4442d69509Smrgnl=' 4542d69509Smrg' 4642d69509SmrgIFS=" "" $nl" 474456fccdSmrg 484456fccdSmrg# set DOITPROG to echo to test this script 494456fccdSmrg 504456fccdSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5142d69509Smrgdoit=${DOITPROG-} 5242d69509Smrgif test -z "$doit"; then 5342d69509Smrg doit_exec=exec 5442d69509Smrgelse 5542d69509Smrg doit_exec=$doit 5642d69509Smrgfi 574456fccdSmrg 5842d69509Smrg# Put in absolute file names if you don't have them in your path; 5942d69509Smrg# or use environment vars. 6042d69509Smrg 6142d69509Smrgchgrpprog=${CHGRPPROG-chgrp} 6242d69509Smrgchmodprog=${CHMODPROG-chmod} 6342d69509Smrgchownprog=${CHOWNPROG-chown} 6442d69509Smrgcmpprog=${CMPPROG-cmp} 6542d69509Smrgcpprog=${CPPROG-cp} 6642d69509Smrgmkdirprog=${MKDIRPROG-mkdir} 6742d69509Smrgmvprog=${MVPROG-mv} 6842d69509Smrgrmprog=${RMPROG-rm} 6942d69509Smrgstripprog=${STRIPPROG-strip} 7042d69509Smrg 7142d69509Smrgposix_glob='?' 7242d69509Smrginitialize_posix_glob=' 7342d69509Smrg test "$posix_glob" != "?" || { 7442d69509Smrg if (set -f) 2>/dev/null; then 7542d69509Smrg posix_glob= 7642d69509Smrg else 7742d69509Smrg posix_glob=: 7842d69509Smrg fi 7942d69509Smrg } 8042d69509Smrg' 814456fccdSmrg 8242d69509Smrgposix_mkdir= 8342d69509Smrg 8442d69509Smrg# Desired mode of installed file. 8542d69509Smrgmode=0755 864456fccdSmrg 874456fccdSmrgchgrpcmd= 8842d69509Smrgchmodcmd=$chmodprog 8942d69509Smrgchowncmd= 9042d69509Smrgmvcmd=$mvprog 914456fccdSmrgrmcmd="$rmprog -f" 9242d69509Smrgstripcmd= 9342d69509Smrg 944456fccdSmrgsrc= 954456fccdSmrgdst= 964456fccdSmrgdir_arg= 9742d69509Smrgdst_arg= 9842d69509Smrg 9942d69509Smrgcopy_on_change=false 1004456fccdSmrgno_target_directory= 1014456fccdSmrg 10242d69509Smrgusage="\ 10342d69509SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1044456fccdSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1054456fccdSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1064456fccdSmrg or: $0 [OPTION]... -d DIRECTORIES... 1074456fccdSmrg 1084456fccdSmrgIn the 1st form, copy SRCFILE to DSTFILE. 1094456fccdSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1104456fccdSmrgIn the 4th, create DIRECTORIES. 1114456fccdSmrg 1124456fccdSmrgOptions: 11342d69509Smrg --help display this help and exit. 11442d69509Smrg --version display version info and exit. 11542d69509Smrg 11642d69509Smrg -c (ignored) 11742d69509Smrg -C install only if different (preserve the last data modification time) 11842d69509Smrg -d create directories instead of installing files. 11942d69509Smrg -g GROUP $chgrpprog installed files to GROUP. 12042d69509Smrg -m MODE $chmodprog installed files to MODE. 12142d69509Smrg -o USER $chownprog installed files to USER. 12242d69509Smrg -s $stripprog installed files. 12342d69509Smrg -t DIRECTORY install into DIRECTORY. 12442d69509Smrg -T report an error if DSTFILE is a directory. 1254456fccdSmrg 1264456fccdSmrgEnvironment variables override the default commands: 12742d69509Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12842d69509Smrg RMPROG STRIPPROG 1294456fccdSmrg" 1304456fccdSmrg 13142d69509Smrgwhile test $# -ne 0; do 1324456fccdSmrg case $1 in 13342d69509Smrg -c) ;; 13442d69509Smrg 13542d69509Smrg -C) copy_on_change=true;; 1364456fccdSmrg 13742d69509Smrg -d) dir_arg=true;; 1384456fccdSmrg 1394456fccdSmrg -g) chgrpcmd="$chgrpprog $2" 14042d69509Smrg shift;; 1414456fccdSmrg 1424456fccdSmrg --help) echo "$usage"; exit $?;; 1434456fccdSmrg 14442d69509Smrg -m) mode=$2 14542d69509Smrg case $mode in 14642d69509Smrg *' '* | *' '* | *' 14742d69509Smrg'* | *'*'* | *'?'* | *'['*) 14842d69509Smrg echo "$0: invalid mode: $mode" >&2 14942d69509Smrg exit 1;; 15042d69509Smrg esac 15142d69509Smrg shift;; 1524456fccdSmrg 1534456fccdSmrg -o) chowncmd="$chownprog $2" 15442d69509Smrg shift;; 1554456fccdSmrg 15642d69509Smrg -s) stripcmd=$stripprog;; 1574456fccdSmrg 15842d69509Smrg -t) dst_arg=$2 1593e6c936aSmrg # Protect names problematic for 'test' and other utilities. 1603e6c936aSmrg case $dst_arg in 1613e6c936aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1623e6c936aSmrg esac 16342d69509Smrg shift;; 1644456fccdSmrg 16542d69509Smrg -T) no_target_directory=true;; 1664456fccdSmrg 1674456fccdSmrg --version) echo "$0 $scriptversion"; exit $?;; 1684456fccdSmrg 16942d69509Smrg --) shift 1704456fccdSmrg break;; 17142d69509Smrg 17242d69509Smrg -*) echo "$0: invalid option: $1" >&2 17342d69509Smrg exit 1;; 17442d69509Smrg 17542d69509Smrg *) break;; 1764456fccdSmrg esac 17742d69509Smrg shift 1784456fccdSmrgdone 1794456fccdSmrg 18042d69509Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 18142d69509Smrg # When -d is used, all remaining arguments are directories to create. 18242d69509Smrg # When -t is used, the destination is already specified. 18342d69509Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18442d69509Smrg for arg 18542d69509Smrg do 18642d69509Smrg if test -n "$dst_arg"; then 18742d69509Smrg # $@ is not empty: it contains at least $arg. 18842d69509Smrg set fnord "$@" "$dst_arg" 18942d69509Smrg shift # fnord 19042d69509Smrg fi 19142d69509Smrg shift # arg 19242d69509Smrg dst_arg=$arg 1933e6c936aSmrg # Protect names problematic for 'test' and other utilities. 1943e6c936aSmrg case $dst_arg in 1953e6c936aSmrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1963e6c936aSmrg esac 19742d69509Smrg done 19842d69509Smrgfi 19942d69509Smrg 20042d69509Smrgif test $# -eq 0; then 2014456fccdSmrg if test -z "$dir_arg"; then 2024456fccdSmrg echo "$0: no input file specified." >&2 2034456fccdSmrg exit 1 2044456fccdSmrg fi 2053e6c936aSmrg # It's OK to call 'install-sh -d' without argument. 2064456fccdSmrg # This can happen when creating conditional directories. 2074456fccdSmrg exit 0 2084456fccdSmrgfi 2094456fccdSmrg 21042d69509Smrgif test -z "$dir_arg"; then 2113e6c936aSmrg do_exit='(exit $ret); exit $ret' 2123e6c936aSmrg trap "ret=129; $do_exit" 1 2133e6c936aSmrg trap "ret=130; $do_exit" 2 2143e6c936aSmrg trap "ret=141; $do_exit" 13 2153e6c936aSmrg trap "ret=143; $do_exit" 15 21642d69509Smrg 21742d69509Smrg # Set umask so as not to create temps with too-generous modes. 21842d69509Smrg # However, 'strip' requires both read and write access to temps. 21942d69509Smrg case $mode in 22042d69509Smrg # Optimize common cases. 22142d69509Smrg *644) cp_umask=133;; 22242d69509Smrg *755) cp_umask=22;; 22342d69509Smrg 22442d69509Smrg *[0-7]) 22542d69509Smrg if test -z "$stripcmd"; then 22642d69509Smrg u_plus_rw= 22742d69509Smrg else 22842d69509Smrg u_plus_rw='% 200' 22942d69509Smrg fi 23042d69509Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23142d69509Smrg *) 23242d69509Smrg if test -z "$stripcmd"; then 23342d69509Smrg u_plus_rw= 23442d69509Smrg else 23542d69509Smrg u_plus_rw=,u+rw 23642d69509Smrg fi 23742d69509Smrg cp_umask=$mode$u_plus_rw;; 23842d69509Smrg esac 23942d69509Smrgfi 24042d69509Smrg 2414456fccdSmrgfor src 2424456fccdSmrgdo 2433e6c936aSmrg # Protect names problematic for 'test' and other utilities. 2444456fccdSmrg case $src in 2453e6c936aSmrg -* | [=\(\)!]) src=./$src;; 2464456fccdSmrg esac 2474456fccdSmrg 2484456fccdSmrg if test -n "$dir_arg"; then 2494456fccdSmrg dst=$src 25042d69509Smrg dstdir=$dst 25142d69509Smrg test -d "$dstdir" 25242d69509Smrg dstdir_status=$? 2534456fccdSmrg else 25442d69509Smrg 2554456fccdSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2564456fccdSmrg # might cause directories to be created, which would be especially bad 2574456fccdSmrg # if $src (and thus $dsttmp) contains '*'. 2584456fccdSmrg if test ! -f "$src" && test ! -d "$src"; then 2594456fccdSmrg echo "$0: $src does not exist." >&2 2604456fccdSmrg exit 1 2614456fccdSmrg fi 2624456fccdSmrg 26342d69509Smrg if test -z "$dst_arg"; then 2644456fccdSmrg echo "$0: no destination specified." >&2 2654456fccdSmrg exit 1 2664456fccdSmrg fi 26742d69509Smrg dst=$dst_arg 2684456fccdSmrg 2694456fccdSmrg # If destination is a directory, append the input filename; won't work 2704456fccdSmrg # if double slashes aren't ignored. 2714456fccdSmrg if test -d "$dst"; then 2724456fccdSmrg if test -n "$no_target_directory"; then 27342d69509Smrg echo "$0: $dst_arg: Is a directory" >&2 2744456fccdSmrg exit 1 2754456fccdSmrg fi 27642d69509Smrg dstdir=$dst 27742d69509Smrg dst=$dstdir/`basename "$src"` 27842d69509Smrg dstdir_status=0 27942d69509Smrg else 28042d69509Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 28142d69509Smrg dstdir=` 28242d69509Smrg (dirname "$dst") 2>/dev/null || 28342d69509Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 28442d69509Smrg X"$dst" : 'X\(//\)[^/]' \| \ 28542d69509Smrg X"$dst" : 'X\(//\)$' \| \ 28642d69509Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28742d69509Smrg echo X"$dst" | 28842d69509Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28942d69509Smrg s//\1/ 29042d69509Smrg q 29142d69509Smrg } 29242d69509Smrg /^X\(\/\/\)[^/].*/{ 29342d69509Smrg s//\1/ 29442d69509Smrg q 29542d69509Smrg } 29642d69509Smrg /^X\(\/\/\)$/{ 29742d69509Smrg s//\1/ 29842d69509Smrg q 29942d69509Smrg } 30042d69509Smrg /^X\(\/\).*/{ 30142d69509Smrg s//\1/ 30242d69509Smrg q 30342d69509Smrg } 30442d69509Smrg s/.*/./; q' 30542d69509Smrg ` 30642d69509Smrg 30742d69509Smrg test -d "$dstdir" 30842d69509Smrg dstdir_status=$? 3094456fccdSmrg fi 3104456fccdSmrg fi 3114456fccdSmrg 31242d69509Smrg obsolete_mkdir_used=false 31342d69509Smrg 31442d69509Smrg if test $dstdir_status != 0; then 31542d69509Smrg case $posix_mkdir in 31642d69509Smrg '') 31742d69509Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31842d69509Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31942d69509Smrg umask=`umask` 32042d69509Smrg case $stripcmd.$umask in 32142d69509Smrg # Optimize common cases. 32242d69509Smrg *[2367][2367]) mkdir_umask=$umask;; 32342d69509Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 32442d69509Smrg 32542d69509Smrg *[0-7]) 32642d69509Smrg mkdir_umask=`expr $umask + 22 \ 32742d69509Smrg - $umask % 100 % 40 + $umask % 20 \ 32842d69509Smrg - $umask % 10 % 4 + $umask % 2 32942d69509Smrg `;; 33042d69509Smrg *) mkdir_umask=$umask,go-w;; 33142d69509Smrg esac 33242d69509Smrg 33342d69509Smrg # With -d, create the new directory with the user-specified mode. 33442d69509Smrg # Otherwise, rely on $mkdir_umask. 33542d69509Smrg if test -n "$dir_arg"; then 33642d69509Smrg mkdir_mode=-m$mode 33742d69509Smrg else 33842d69509Smrg mkdir_mode= 33942d69509Smrg fi 34042d69509Smrg 34142d69509Smrg posix_mkdir=false 34242d69509Smrg case $umask in 34342d69509Smrg *[123567][0-7][0-7]) 34442d69509Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 34542d69509Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 34642d69509Smrg ;; 34742d69509Smrg *) 34842d69509Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34942d69509Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 35042d69509Smrg 35142d69509Smrg if (umask $mkdir_umask && 35242d69509Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 35342d69509Smrg then 35442d69509Smrg if test -z "$dir_arg" || { 35542d69509Smrg # Check for POSIX incompatibilities with -m. 35642d69509Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3573e6c936aSmrg # other-writable bit of parent directory when it shouldn't. 35842d69509Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35942d69509Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 36042d69509Smrg case $ls_ld_tmpdir in 36142d69509Smrg d????-?r-*) different_mode=700;; 36242d69509Smrg d????-?--*) different_mode=755;; 36342d69509Smrg *) false;; 36442d69509Smrg esac && 36542d69509Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 36642d69509Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36742d69509Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36842d69509Smrg } 36942d69509Smrg } 37042d69509Smrg then posix_mkdir=: 37142d69509Smrg fi 37242d69509Smrg rmdir "$tmpdir/d" "$tmpdir" 37342d69509Smrg else 37442d69509Smrg # Remove any dirs left behind by ancient mkdir implementations. 37542d69509Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 37642d69509Smrg fi 37742d69509Smrg trap '' 0;; 37842d69509Smrg esac;; 37942d69509Smrg esac 3804456fccdSmrg 38142d69509Smrg if 38242d69509Smrg $posix_mkdir && ( 38342d69509Smrg umask $mkdir_umask && 38442d69509Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38542d69509Smrg ) 38642d69509Smrg then : 38742d69509Smrg else 3884456fccdSmrg 38942d69509Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 39042d69509Smrg # or it failed possibly due to a race condition. Create the 39142d69509Smrg # directory the slow way, step by step, checking for races as we go. 3924456fccdSmrg 39342d69509Smrg case $dstdir in 39442d69509Smrg /*) prefix='/';; 3953e6c936aSmrg [-=\(\)!]*) prefix='./';; 39642d69509Smrg *) prefix='';; 39742d69509Smrg esac 3984456fccdSmrg 39942d69509Smrg eval "$initialize_posix_glob" 4004456fccdSmrg 40142d69509Smrg oIFS=$IFS 40242d69509Smrg IFS=/ 40342d69509Smrg $posix_glob set -f 40442d69509Smrg set fnord $dstdir 4054456fccdSmrg shift 40642d69509Smrg $posix_glob set +f 40742d69509Smrg IFS=$oIFS 40842d69509Smrg 40942d69509Smrg prefixes= 41042d69509Smrg 41142d69509Smrg for d 41242d69509Smrg do 4133e6c936aSmrg test X"$d" = X && continue 41442d69509Smrg 41542d69509Smrg prefix=$prefix$d 41642d69509Smrg if test -d "$prefix"; then 41742d69509Smrg prefixes= 41842d69509Smrg else 41942d69509Smrg if $posix_mkdir; then 42042d69509Smrg (umask=$mkdir_umask && 42142d69509Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42242d69509Smrg # Don't fail if two instances are running concurrently. 42342d69509Smrg test -d "$prefix" || exit 1 42442d69509Smrg else 42542d69509Smrg case $prefix in 42642d69509Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42742d69509Smrg *) qprefix=$prefix;; 42842d69509Smrg esac 42942d69509Smrg prefixes="$prefixes '$qprefix'" 43042d69509Smrg fi 43142d69509Smrg fi 43242d69509Smrg prefix=$prefix/ 43342d69509Smrg done 43442d69509Smrg 43542d69509Smrg if test -n "$prefixes"; then 43642d69509Smrg # Don't fail if two instances are running concurrently. 43742d69509Smrg (umask $mkdir_umask && 43842d69509Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43942d69509Smrg test -d "$dstdir" || exit 1 44042d69509Smrg obsolete_mkdir_used=true 4414456fccdSmrg fi 44242d69509Smrg fi 4434456fccdSmrg fi 4444456fccdSmrg 4454456fccdSmrg if test -n "$dir_arg"; then 44642d69509Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44742d69509Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44842d69509Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44942d69509Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4504456fccdSmrg else 4514456fccdSmrg 4524456fccdSmrg # Make a couple of temp file names in the proper directory. 4534456fccdSmrg dsttmp=$dstdir/_inst.$$_ 4544456fccdSmrg rmtmp=$dstdir/_rm.$$_ 4554456fccdSmrg 4564456fccdSmrg # Trap to clean up those temp files at exit. 4574456fccdSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4584456fccdSmrg 4594456fccdSmrg # Copy the file name to the temp name. 46042d69509Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4614456fccdSmrg 4624456fccdSmrg # and set any options; do chmod last to preserve setuid bits. 4634456fccdSmrg # 4644456fccdSmrg # If any of these fail, we abort the whole thing. If we want to 4654456fccdSmrg # ignore errors from any of these, just make sure not to ignore 4664456fccdSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4674456fccdSmrg # 46842d69509Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46942d69509Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 47042d69509Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 47142d69509Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 47242d69509Smrg 47342d69509Smrg # If -C, don't bother to copy if it wouldn't change the file. 47442d69509Smrg if $copy_on_change && 47542d69509Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 47642d69509Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47742d69509Smrg 47842d69509Smrg eval "$initialize_posix_glob" && 47942d69509Smrg $posix_glob set -f && 48042d69509Smrg set X $old && old=:$2:$4:$5:$6 && 48142d69509Smrg set X $new && new=:$2:$4:$5:$6 && 48242d69509Smrg $posix_glob set +f && 48342d69509Smrg 48442d69509Smrg test "$old" = "$new" && 48542d69509Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 48642d69509Smrg then 48742d69509Smrg rm -f "$dsttmp" 48842d69509Smrg else 48942d69509Smrg # Rename the file to the real destination. 49042d69509Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 49142d69509Smrg 49242d69509Smrg # The rename failed, perhaps because mv can't rename something else 49342d69509Smrg # to itself, or perhaps because mv is so ancient that it does not 49442d69509Smrg # support -f. 49542d69509Smrg { 49642d69509Smrg # Now remove or move aside any old file at destination location. 49742d69509Smrg # We try this two ways since rm can't unlink itself on some 49842d69509Smrg # systems and the destination file might be busy for other 49942d69509Smrg # reasons. In this case, the final cleanup might fail but the new 50042d69509Smrg # file should still install successfully. 50142d69509Smrg { 50242d69509Smrg test ! -f "$dst" || 50342d69509Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 50442d69509Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 50542d69509Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 50642d69509Smrg } || 50742d69509Smrg { echo "$0: cannot unlink or rename $dst" >&2 50842d69509Smrg (exit 1); exit 1 50942d69509Smrg } 51042d69509Smrg } && 51142d69509Smrg 51242d69509Smrg # Now rename the file to the real destination. 51342d69509Smrg $doit $mvcmd "$dsttmp" "$dst" 51442d69509Smrg } 51542d69509Smrg fi || exit 1 51642d69509Smrg 51742d69509Smrg trap '' 0 51842d69509Smrg fi 5194456fccdSmrgdone 5204456fccdSmrg 5214456fccdSmrg# Local variables: 5224456fccdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5234456fccdSmrg# time-stamp-start: "scriptversion=" 5244456fccdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52542d69509Smrg# time-stamp-time-zone: "UTC" 52642d69509Smrg# time-stamp-end: "; # UTC" 5274456fccdSmrg# End: 528