install-sh revision 3a72f200
19027f4a0Smrg#!/bin/sh 29027f4a0Smrg# install - install a program, script, or datafile 39027f4a0Smrg 43a72f200Smrgscriptversion=2009-04-28.21; # UTC 59027f4a0Smrg 69027f4a0Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 79027f4a0Smrg# later released in X11R6 (xc/config/util/install.sh) with the 89027f4a0Smrg# following copyright and license. 99027f4a0Smrg# 109027f4a0Smrg# Copyright (C) 1994 X Consortium 119027f4a0Smrg# 129027f4a0Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 139027f4a0Smrg# of this software and associated documentation files (the "Software"), to 149027f4a0Smrg# deal in the Software without restriction, including without limitation the 159027f4a0Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 169027f4a0Smrg# sell copies of the Software, and to permit persons to whom the Software is 179027f4a0Smrg# furnished to do so, subject to the following conditions: 189027f4a0Smrg# 199027f4a0Smrg# The above copyright notice and this permission notice shall be included in 209027f4a0Smrg# all copies or substantial portions of the Software. 219027f4a0Smrg# 229027f4a0Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239027f4a0Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 249027f4a0Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259027f4a0Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 269027f4a0Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 279027f4a0Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 289027f4a0Smrg# 299027f4a0Smrg# Except as contained in this notice, the name of the X Consortium shall not 309027f4a0Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 319027f4a0Smrg# ings in this Software without prior written authorization from the X Consor- 329027f4a0Smrg# tium. 339027f4a0Smrg# 349027f4a0Smrg# 359027f4a0Smrg# FSF changes to this file are in the public domain. 369027f4a0Smrg# 379027f4a0Smrg# Calling this script install-sh is preferred over install.sh, to prevent 389027f4a0Smrg# `make' implicit rules from creating a file called install from it 399027f4a0Smrg# when there is no Makefile. 409027f4a0Smrg# 419027f4a0Smrg# This script is compatible with the BSD install script, but was written 423a72f200Smrg# from scratch. 433a72f200Smrg 443a72f200Smrgnl=' 453a72f200Smrg' 463a72f200SmrgIFS=" "" $nl" 479027f4a0Smrg 489027f4a0Smrg# set DOITPROG to echo to test this script 499027f4a0Smrg 509027f4a0Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 513a72f200Smrgdoit=${DOITPROG-} 523a72f200Smrgif test -z "$doit"; then 533a72f200Smrg doit_exec=exec 543a72f200Smrgelse 553a72f200Smrg doit_exec=$doit 563a72f200Smrgfi 579027f4a0Smrg 583a72f200Smrg# Put in absolute file names if you don't have them in your path; 593a72f200Smrg# or use environment vars. 603a72f200Smrg 613a72f200Smrgchgrpprog=${CHGRPPROG-chgrp} 623a72f200Smrgchmodprog=${CHMODPROG-chmod} 633a72f200Smrgchownprog=${CHOWNPROG-chown} 643a72f200Smrgcmpprog=${CMPPROG-cmp} 653a72f200Smrgcpprog=${CPPROG-cp} 663a72f200Smrgmkdirprog=${MKDIRPROG-mkdir} 673a72f200Smrgmvprog=${MVPROG-mv} 683a72f200Smrgrmprog=${RMPROG-rm} 693a72f200Smrgstripprog=${STRIPPROG-strip} 703a72f200Smrg 713a72f200Smrgposix_glob='?' 723a72f200Smrginitialize_posix_glob=' 733a72f200Smrg test "$posix_glob" != "?" || { 743a72f200Smrg if (set -f) 2>/dev/null; then 753a72f200Smrg posix_glob= 763a72f200Smrg else 773a72f200Smrg posix_glob=: 783a72f200Smrg fi 793a72f200Smrg } 803a72f200Smrg' 819027f4a0Smrg 823a72f200Smrgposix_mkdir= 833a72f200Smrg 843a72f200Smrg# Desired mode of installed file. 853a72f200Smrgmode=0755 869027f4a0Smrg 879027f4a0Smrgchgrpcmd= 883a72f200Smrgchmodcmd=$chmodprog 893a72f200Smrgchowncmd= 903a72f200Smrgmvcmd=$mvprog 919027f4a0Smrgrmcmd="$rmprog -f" 923a72f200Smrgstripcmd= 933a72f200Smrg 949027f4a0Smrgsrc= 959027f4a0Smrgdst= 969027f4a0Smrgdir_arg= 973a72f200Smrgdst_arg= 983a72f200Smrg 993a72f200Smrgcopy_on_change=false 1009027f4a0Smrgno_target_directory= 1019027f4a0Smrg 1023a72f200Smrgusage="\ 1033a72f200SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1049027f4a0Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1059027f4a0Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1069027f4a0Smrg or: $0 [OPTION]... -d DIRECTORIES... 1079027f4a0Smrg 1089027f4a0SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1099027f4a0SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1109027f4a0SmrgIn the 4th, create DIRECTORIES. 1119027f4a0Smrg 1129027f4a0SmrgOptions: 1133a72f200Smrg --help display this help and exit. 1143a72f200Smrg --version display version info and exit. 1153a72f200Smrg 1163a72f200Smrg -c (ignored) 1173a72f200Smrg -C install only if different (preserve the last data modification time) 1183a72f200Smrg -d create directories instead of installing files. 1193a72f200Smrg -g GROUP $chgrpprog installed files to GROUP. 1203a72f200Smrg -m MODE $chmodprog installed files to MODE. 1213a72f200Smrg -o USER $chownprog installed files to USER. 1223a72f200Smrg -s $stripprog installed files. 1233a72f200Smrg -t DIRECTORY install into DIRECTORY. 1243a72f200Smrg -T report an error if DSTFILE is a directory. 1259027f4a0Smrg 1269027f4a0SmrgEnvironment variables override the default commands: 1273a72f200Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1283a72f200Smrg RMPROG STRIPPROG 1299027f4a0Smrg" 1309027f4a0Smrg 1313a72f200Smrgwhile test $# -ne 0; do 1329027f4a0Smrg case $1 in 1333a72f200Smrg -c) ;; 1343a72f200Smrg 1353a72f200Smrg -C) copy_on_change=true;; 1369027f4a0Smrg 1373a72f200Smrg -d) dir_arg=true;; 1389027f4a0Smrg 1399027f4a0Smrg -g) chgrpcmd="$chgrpprog $2" 1403a72f200Smrg shift;; 1419027f4a0Smrg 1429027f4a0Smrg --help) echo "$usage"; exit $?;; 1439027f4a0Smrg 1443a72f200Smrg -m) mode=$2 1453a72f200Smrg case $mode in 1463a72f200Smrg *' '* | *' '* | *' 1473a72f200Smrg'* | *'*'* | *'?'* | *'['*) 1483a72f200Smrg echo "$0: invalid mode: $mode" >&2 1493a72f200Smrg exit 1;; 1503a72f200Smrg esac 1513a72f200Smrg shift;; 1529027f4a0Smrg 1539027f4a0Smrg -o) chowncmd="$chownprog $2" 1543a72f200Smrg shift;; 1559027f4a0Smrg 1563a72f200Smrg -s) stripcmd=$stripprog;; 1579027f4a0Smrg 1583a72f200Smrg -t) dst_arg=$2 1593a72f200Smrg shift;; 1609027f4a0Smrg 1613a72f200Smrg -T) no_target_directory=true;; 1629027f4a0Smrg 1639027f4a0Smrg --version) echo "$0 $scriptversion"; exit $?;; 1649027f4a0Smrg 1653a72f200Smrg --) shift 1669027f4a0Smrg break;; 1673a72f200Smrg 1683a72f200Smrg -*) echo "$0: invalid option: $1" >&2 1693a72f200Smrg exit 1;; 1703a72f200Smrg 1713a72f200Smrg *) break;; 1729027f4a0Smrg esac 1733a72f200Smrg shift 1749027f4a0Smrgdone 1759027f4a0Smrg 1763a72f200Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1773a72f200Smrg # When -d is used, all remaining arguments are directories to create. 1783a72f200Smrg # When -t is used, the destination is already specified. 1793a72f200Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1803a72f200Smrg for arg 1813a72f200Smrg do 1823a72f200Smrg if test -n "$dst_arg"; then 1833a72f200Smrg # $@ is not empty: it contains at least $arg. 1843a72f200Smrg set fnord "$@" "$dst_arg" 1853a72f200Smrg shift # fnord 1863a72f200Smrg fi 1873a72f200Smrg shift # arg 1883a72f200Smrg dst_arg=$arg 1893a72f200Smrg done 1903a72f200Smrgfi 1913a72f200Smrg 1923a72f200Smrgif test $# -eq 0; then 1939027f4a0Smrg if test -z "$dir_arg"; then 1949027f4a0Smrg echo "$0: no input file specified." >&2 1959027f4a0Smrg exit 1 1969027f4a0Smrg fi 1979027f4a0Smrg # It's OK to call `install-sh -d' without argument. 1989027f4a0Smrg # This can happen when creating conditional directories. 1999027f4a0Smrg exit 0 2009027f4a0Smrgfi 2019027f4a0Smrg 2023a72f200Smrgif test -z "$dir_arg"; then 2033a72f200Smrg trap '(exit $?); exit' 1 2 13 15 2043a72f200Smrg 2053a72f200Smrg # Set umask so as not to create temps with too-generous modes. 2063a72f200Smrg # However, 'strip' requires both read and write access to temps. 2073a72f200Smrg case $mode in 2083a72f200Smrg # Optimize common cases. 2093a72f200Smrg *644) cp_umask=133;; 2103a72f200Smrg *755) cp_umask=22;; 2113a72f200Smrg 2123a72f200Smrg *[0-7]) 2133a72f200Smrg if test -z "$stripcmd"; then 2143a72f200Smrg u_plus_rw= 2153a72f200Smrg else 2163a72f200Smrg u_plus_rw='% 200' 2173a72f200Smrg fi 2183a72f200Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2193a72f200Smrg *) 2203a72f200Smrg if test -z "$stripcmd"; then 2213a72f200Smrg u_plus_rw= 2223a72f200Smrg else 2233a72f200Smrg u_plus_rw=,u+rw 2243a72f200Smrg fi 2253a72f200Smrg cp_umask=$mode$u_plus_rw;; 2263a72f200Smrg esac 2273a72f200Smrgfi 2283a72f200Smrg 2299027f4a0Smrgfor src 2309027f4a0Smrgdo 2319027f4a0Smrg # Protect names starting with `-'. 2329027f4a0Smrg case $src in 2333a72f200Smrg -*) src=./$src;; 2349027f4a0Smrg esac 2359027f4a0Smrg 2369027f4a0Smrg if test -n "$dir_arg"; then 2379027f4a0Smrg dst=$src 2383a72f200Smrg dstdir=$dst 2393a72f200Smrg test -d "$dstdir" 2403a72f200Smrg dstdir_status=$? 2419027f4a0Smrg else 2423a72f200Smrg 2439027f4a0Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2449027f4a0Smrg # might cause directories to be created, which would be especially bad 2459027f4a0Smrg # if $src (and thus $dsttmp) contains '*'. 2469027f4a0Smrg if test ! -f "$src" && test ! -d "$src"; then 2479027f4a0Smrg echo "$0: $src does not exist." >&2 2489027f4a0Smrg exit 1 2499027f4a0Smrg fi 2509027f4a0Smrg 2513a72f200Smrg if test -z "$dst_arg"; then 2529027f4a0Smrg echo "$0: no destination specified." >&2 2539027f4a0Smrg exit 1 2549027f4a0Smrg fi 2559027f4a0Smrg 2563a72f200Smrg dst=$dst_arg 2579027f4a0Smrg # Protect names starting with `-'. 2589027f4a0Smrg case $dst in 2593a72f200Smrg -*) dst=./$dst;; 2609027f4a0Smrg esac 2619027f4a0Smrg 2629027f4a0Smrg # If destination is a directory, append the input filename; won't work 2639027f4a0Smrg # if double slashes aren't ignored. 2649027f4a0Smrg if test -d "$dst"; then 2659027f4a0Smrg if test -n "$no_target_directory"; then 2663a72f200Smrg echo "$0: $dst_arg: Is a directory" >&2 2679027f4a0Smrg exit 1 2689027f4a0Smrg fi 2693a72f200Smrg dstdir=$dst 2703a72f200Smrg dst=$dstdir/`basename "$src"` 2713a72f200Smrg dstdir_status=0 2723a72f200Smrg else 2733a72f200Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2743a72f200Smrg dstdir=` 2753a72f200Smrg (dirname "$dst") 2>/dev/null || 2763a72f200Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2773a72f200Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2783a72f200Smrg X"$dst" : 'X\(//\)$' \| \ 2793a72f200Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2803a72f200Smrg echo X"$dst" | 2813a72f200Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2823a72f200Smrg s//\1/ 2833a72f200Smrg q 2843a72f200Smrg } 2853a72f200Smrg /^X\(\/\/\)[^/].*/{ 2863a72f200Smrg s//\1/ 2873a72f200Smrg q 2883a72f200Smrg } 2893a72f200Smrg /^X\(\/\/\)$/{ 2903a72f200Smrg s//\1/ 2913a72f200Smrg q 2923a72f200Smrg } 2933a72f200Smrg /^X\(\/\).*/{ 2943a72f200Smrg s//\1/ 2953a72f200Smrg q 2963a72f200Smrg } 2973a72f200Smrg s/.*/./; q' 2983a72f200Smrg ` 2993a72f200Smrg 3003a72f200Smrg test -d "$dstdir" 3013a72f200Smrg dstdir_status=$? 3029027f4a0Smrg fi 3039027f4a0Smrg fi 3049027f4a0Smrg 3053a72f200Smrg obsolete_mkdir_used=false 3063a72f200Smrg 3073a72f200Smrg if test $dstdir_status != 0; then 3083a72f200Smrg case $posix_mkdir in 3093a72f200Smrg '') 3103a72f200Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3113a72f200Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3123a72f200Smrg umask=`umask` 3133a72f200Smrg case $stripcmd.$umask in 3143a72f200Smrg # Optimize common cases. 3153a72f200Smrg *[2367][2367]) mkdir_umask=$umask;; 3163a72f200Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3173a72f200Smrg 3183a72f200Smrg *[0-7]) 3193a72f200Smrg mkdir_umask=`expr $umask + 22 \ 3203a72f200Smrg - $umask % 100 % 40 + $umask % 20 \ 3213a72f200Smrg - $umask % 10 % 4 + $umask % 2 3223a72f200Smrg `;; 3233a72f200Smrg *) mkdir_umask=$umask,go-w;; 3243a72f200Smrg esac 3253a72f200Smrg 3263a72f200Smrg # With -d, create the new directory with the user-specified mode. 3273a72f200Smrg # Otherwise, rely on $mkdir_umask. 3283a72f200Smrg if test -n "$dir_arg"; then 3293a72f200Smrg mkdir_mode=-m$mode 3303a72f200Smrg else 3313a72f200Smrg mkdir_mode= 3323a72f200Smrg fi 3333a72f200Smrg 3343a72f200Smrg posix_mkdir=false 3353a72f200Smrg case $umask in 3363a72f200Smrg *[123567][0-7][0-7]) 3373a72f200Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3383a72f200Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3393a72f200Smrg ;; 3403a72f200Smrg *) 3413a72f200Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3423a72f200Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3433a72f200Smrg 3443a72f200Smrg if (umask $mkdir_umask && 3453a72f200Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3463a72f200Smrg then 3473a72f200Smrg if test -z "$dir_arg" || { 3483a72f200Smrg # Check for POSIX incompatibilities with -m. 3493a72f200Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3503a72f200Smrg # other-writeable bit of parent directory when it shouldn't. 3513a72f200Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3523a72f200Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3533a72f200Smrg case $ls_ld_tmpdir in 3543a72f200Smrg d????-?r-*) different_mode=700;; 3553a72f200Smrg d????-?--*) different_mode=755;; 3563a72f200Smrg *) false;; 3573a72f200Smrg esac && 3583a72f200Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3593a72f200Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3603a72f200Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3613a72f200Smrg } 3623a72f200Smrg } 3633a72f200Smrg then posix_mkdir=: 3643a72f200Smrg fi 3653a72f200Smrg rmdir "$tmpdir/d" "$tmpdir" 3663a72f200Smrg else 3673a72f200Smrg # Remove any dirs left behind by ancient mkdir implementations. 3683a72f200Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3693a72f200Smrg fi 3703a72f200Smrg trap '' 0;; 3713a72f200Smrg esac;; 3723a72f200Smrg esac 3739027f4a0Smrg 3743a72f200Smrg if 3753a72f200Smrg $posix_mkdir && ( 3763a72f200Smrg umask $mkdir_umask && 3773a72f200Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3783a72f200Smrg ) 3793a72f200Smrg then : 3803a72f200Smrg else 3819027f4a0Smrg 3823a72f200Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3833a72f200Smrg # or it failed possibly due to a race condition. Create the 3843a72f200Smrg # directory the slow way, step by step, checking for races as we go. 3859027f4a0Smrg 3863a72f200Smrg case $dstdir in 3873a72f200Smrg /*) prefix='/';; 3883a72f200Smrg -*) prefix='./';; 3893a72f200Smrg *) prefix='';; 3903a72f200Smrg esac 3919027f4a0Smrg 3923a72f200Smrg eval "$initialize_posix_glob" 3939027f4a0Smrg 3943a72f200Smrg oIFS=$IFS 3953a72f200Smrg IFS=/ 3963a72f200Smrg $posix_glob set -f 3973a72f200Smrg set fnord $dstdir 3989027f4a0Smrg shift 3993a72f200Smrg $posix_glob set +f 4003a72f200Smrg IFS=$oIFS 4013a72f200Smrg 4023a72f200Smrg prefixes= 4033a72f200Smrg 4043a72f200Smrg for d 4053a72f200Smrg do 4063a72f200Smrg test -z "$d" && continue 4073a72f200Smrg 4083a72f200Smrg prefix=$prefix$d 4093a72f200Smrg if test -d "$prefix"; then 4103a72f200Smrg prefixes= 4113a72f200Smrg else 4123a72f200Smrg if $posix_mkdir; then 4133a72f200Smrg (umask=$mkdir_umask && 4143a72f200Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4153a72f200Smrg # Don't fail if two instances are running concurrently. 4163a72f200Smrg test -d "$prefix" || exit 1 4173a72f200Smrg else 4183a72f200Smrg case $prefix in 4193a72f200Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4203a72f200Smrg *) qprefix=$prefix;; 4213a72f200Smrg esac 4223a72f200Smrg prefixes="$prefixes '$qprefix'" 4233a72f200Smrg fi 4243a72f200Smrg fi 4253a72f200Smrg prefix=$prefix/ 4263a72f200Smrg done 4273a72f200Smrg 4283a72f200Smrg if test -n "$prefixes"; then 4293a72f200Smrg # Don't fail if two instances are running concurrently. 4303a72f200Smrg (umask $mkdir_umask && 4313a72f200Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4323a72f200Smrg test -d "$dstdir" || exit 1 4333a72f200Smrg obsolete_mkdir_used=true 4349027f4a0Smrg fi 4353a72f200Smrg fi 4369027f4a0Smrg fi 4379027f4a0Smrg 4389027f4a0Smrg if test -n "$dir_arg"; then 4393a72f200Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4403a72f200Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4413a72f200Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4423a72f200Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4439027f4a0Smrg else 4449027f4a0Smrg 4459027f4a0Smrg # Make a couple of temp file names in the proper directory. 4469027f4a0Smrg dsttmp=$dstdir/_inst.$$_ 4479027f4a0Smrg rmtmp=$dstdir/_rm.$$_ 4489027f4a0Smrg 4499027f4a0Smrg # Trap to clean up those temp files at exit. 4509027f4a0Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4519027f4a0Smrg 4529027f4a0Smrg # Copy the file name to the temp name. 4533a72f200Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4549027f4a0Smrg 4559027f4a0Smrg # and set any options; do chmod last to preserve setuid bits. 4569027f4a0Smrg # 4579027f4a0Smrg # If any of these fail, we abort the whole thing. If we want to 4589027f4a0Smrg # ignore errors from any of these, just make sure not to ignore 4599027f4a0Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4609027f4a0Smrg # 4613a72f200Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4623a72f200Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4633a72f200Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4643a72f200Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4653a72f200Smrg 4663a72f200Smrg # If -C, don't bother to copy if it wouldn't change the file. 4673a72f200Smrg if $copy_on_change && 4683a72f200Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4693a72f200Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4703a72f200Smrg 4713a72f200Smrg eval "$initialize_posix_glob" && 4723a72f200Smrg $posix_glob set -f && 4733a72f200Smrg set X $old && old=:$2:$4:$5:$6 && 4743a72f200Smrg set X $new && new=:$2:$4:$5:$6 && 4753a72f200Smrg $posix_glob set +f && 4763a72f200Smrg 4773a72f200Smrg test "$old" = "$new" && 4783a72f200Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4793a72f200Smrg then 4803a72f200Smrg rm -f "$dsttmp" 4813a72f200Smrg else 4823a72f200Smrg # Rename the file to the real destination. 4833a72f200Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4843a72f200Smrg 4853a72f200Smrg # The rename failed, perhaps because mv can't rename something else 4863a72f200Smrg # to itself, or perhaps because mv is so ancient that it does not 4873a72f200Smrg # support -f. 4883a72f200Smrg { 4893a72f200Smrg # Now remove or move aside any old file at destination location. 4903a72f200Smrg # We try this two ways since rm can't unlink itself on some 4913a72f200Smrg # systems and the destination file might be busy for other 4923a72f200Smrg # reasons. In this case, the final cleanup might fail but the new 4933a72f200Smrg # file should still install successfully. 4943a72f200Smrg { 4953a72f200Smrg test ! -f "$dst" || 4963a72f200Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4973a72f200Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4983a72f200Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4993a72f200Smrg } || 5003a72f200Smrg { echo "$0: cannot unlink or rename $dst" >&2 5013a72f200Smrg (exit 1); exit 1 5023a72f200Smrg } 5033a72f200Smrg } && 5043a72f200Smrg 5053a72f200Smrg # Now rename the file to the real destination. 5063a72f200Smrg $doit $mvcmd "$dsttmp" "$dst" 5073a72f200Smrg } 5083a72f200Smrg fi || exit 1 5093a72f200Smrg 5103a72f200Smrg trap '' 0 5113a72f200Smrg fi 5129027f4a0Smrgdone 5139027f4a0Smrg 5149027f4a0Smrg# Local variables: 5159027f4a0Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5169027f4a0Smrg# time-stamp-start: "scriptversion=" 5179027f4a0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5183a72f200Smrg# time-stamp-time-zone: "UTC" 5193a72f200Smrg# time-stamp-end: "; # UTC" 5209027f4a0Smrg# End: 521