install-sh revision 4e411241
18c9fbc29Smrg#!/bin/sh 28c9fbc29Smrg# install - install a program, script, or datafile 38c9fbc29Smrg 44e411241Smrgscriptversion=2009-04-28.21; # UTC 58c9fbc29Smrg 68c9fbc29Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 78c9fbc29Smrg# later released in X11R6 (xc/config/util/install.sh) with the 88c9fbc29Smrg# following copyright and license. 98c9fbc29Smrg# 108c9fbc29Smrg# Copyright (C) 1994 X Consortium 118c9fbc29Smrg# 128c9fbc29Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 138c9fbc29Smrg# of this software and associated documentation files (the "Software"), to 148c9fbc29Smrg# deal in the Software without restriction, including without limitation the 158c9fbc29Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168c9fbc29Smrg# sell copies of the Software, and to permit persons to whom the Software is 178c9fbc29Smrg# furnished to do so, subject to the following conditions: 188c9fbc29Smrg# 198c9fbc29Smrg# The above copyright notice and this permission notice shall be included in 208c9fbc29Smrg# all copies or substantial portions of the Software. 218c9fbc29Smrg# 228c9fbc29Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238c9fbc29Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 248c9fbc29Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 258c9fbc29Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 268c9fbc29Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 278c9fbc29Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 288c9fbc29Smrg# 298c9fbc29Smrg# Except as contained in this notice, the name of the X Consortium shall not 308c9fbc29Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 318c9fbc29Smrg# ings in this Software without prior written authorization from the X Consor- 328c9fbc29Smrg# tium. 338c9fbc29Smrg# 348c9fbc29Smrg# 358c9fbc29Smrg# FSF changes to this file are in the public domain. 368c9fbc29Smrg# 378c9fbc29Smrg# Calling this script install-sh is preferred over install.sh, to prevent 388c9fbc29Smrg# `make' implicit rules from creating a file called install from it 398c9fbc29Smrg# when there is no Makefile. 408c9fbc29Smrg# 418c9fbc29Smrg# This script is compatible with the BSD install script, but was written 428c9fbc29Smrg# from scratch. 438c9fbc29Smrg 448c9fbc29Smrgnl=' 458c9fbc29Smrg' 468c9fbc29SmrgIFS=" "" $nl" 478c9fbc29Smrg 488c9fbc29Smrg# set DOITPROG to echo to test this script 498c9fbc29Smrg 508c9fbc29Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 514e411241Smrgdoit=${DOITPROG-} 528c9fbc29Smrgif test -z "$doit"; then 538c9fbc29Smrg doit_exec=exec 548c9fbc29Smrgelse 558c9fbc29Smrg doit_exec=$doit 568c9fbc29Smrgfi 578c9fbc29Smrg 588c9fbc29Smrg# Put in absolute file names if you don't have them in your path; 598c9fbc29Smrg# or use environment vars. 608c9fbc29Smrg 614e411241Smrgchgrpprog=${CHGRPPROG-chgrp} 624e411241Smrgchmodprog=${CHMODPROG-chmod} 634e411241Smrgchownprog=${CHOWNPROG-chown} 644e411241Smrgcmpprog=${CMPPROG-cmp} 654e411241Smrgcpprog=${CPPROG-cp} 664e411241Smrgmkdirprog=${MKDIRPROG-mkdir} 674e411241Smrgmvprog=${MVPROG-mv} 684e411241Smrgrmprog=${RMPROG-rm} 694e411241Smrgstripprog=${STRIPPROG-strip} 704e411241Smrg 714e411241Smrgposix_glob='?' 724e411241Smrginitialize_posix_glob=' 734e411241Smrg test "$posix_glob" != "?" || { 744e411241Smrg if (set -f) 2>/dev/null; then 754e411241Smrg posix_glob= 764e411241Smrg else 774e411241Smrg posix_glob=: 784e411241Smrg fi 794e411241Smrg } 804e411241Smrg' 818c9fbc29Smrg 828c9fbc29Smrgposix_mkdir= 838c9fbc29Smrg 848c9fbc29Smrg# Desired mode of installed file. 858c9fbc29Smrgmode=0755 868c9fbc29Smrg 874e411241Smrgchgrpcmd= 888c9fbc29Smrgchmodcmd=$chmodprog 898c9fbc29Smrgchowncmd= 904e411241Smrgmvcmd=$mvprog 918c9fbc29Smrgrmcmd="$rmprog -f" 924e411241Smrgstripcmd= 934e411241Smrg 948c9fbc29Smrgsrc= 958c9fbc29Smrgdst= 968c9fbc29Smrgdir_arg= 974e411241Smrgdst_arg= 984e411241Smrg 994e411241Smrgcopy_on_change=false 1008c9fbc29Smrgno_target_directory= 1018c9fbc29Smrg 1024e411241Smrgusage="\ 1034e411241SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1048c9fbc29Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1058c9fbc29Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1068c9fbc29Smrg or: $0 [OPTION]... -d DIRECTORIES... 1078c9fbc29Smrg 1088c9fbc29SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1098c9fbc29SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1108c9fbc29SmrgIn the 4th, create DIRECTORIES. 1118c9fbc29Smrg 1128c9fbc29SmrgOptions: 1134e411241Smrg --help display this help and exit. 1144e411241Smrg --version display version info and exit. 1154e411241Smrg 1164e411241Smrg -c (ignored) 1174e411241Smrg -C install only if different (preserve the last data modification time) 1184e411241Smrg -d create directories instead of installing files. 1194e411241Smrg -g GROUP $chgrpprog installed files to GROUP. 1204e411241Smrg -m MODE $chmodprog installed files to MODE. 1214e411241Smrg -o USER $chownprog installed files to USER. 1224e411241Smrg -s $stripprog installed files. 1234e411241Smrg -t DIRECTORY install into DIRECTORY. 1244e411241Smrg -T report an error if DSTFILE is a directory. 1258c9fbc29Smrg 1268c9fbc29SmrgEnvironment variables override the default commands: 1274e411241Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1284e411241Smrg RMPROG STRIPPROG 1298c9fbc29Smrg" 1308c9fbc29Smrg 1318c9fbc29Smrgwhile test $# -ne 0; do 1328c9fbc29Smrg case $1 in 1334e411241Smrg -c) ;; 1344e411241Smrg 1354e411241Smrg -C) copy_on_change=true;; 1368c9fbc29Smrg 1374e411241Smrg -d) dir_arg=true;; 1388c9fbc29Smrg 1398c9fbc29Smrg -g) chgrpcmd="$chgrpprog $2" 1404e411241Smrg shift;; 1418c9fbc29Smrg 1428c9fbc29Smrg --help) echo "$usage"; exit $?;; 1438c9fbc29Smrg 1448c9fbc29Smrg -m) mode=$2 1458c9fbc29Smrg case $mode in 1468c9fbc29Smrg *' '* | *' '* | *' 1478c9fbc29Smrg'* | *'*'* | *'?'* | *'['*) 1488c9fbc29Smrg echo "$0: invalid mode: $mode" >&2 1498c9fbc29Smrg exit 1;; 1508c9fbc29Smrg esac 1514e411241Smrg shift;; 1528c9fbc29Smrg 1538c9fbc29Smrg -o) chowncmd="$chownprog $2" 1544e411241Smrg shift;; 1558c9fbc29Smrg 1564e411241Smrg -s) stripcmd=$stripprog;; 1578c9fbc29Smrg 1584e411241Smrg -t) dst_arg=$2 1594e411241Smrg shift;; 1608c9fbc29Smrg 1614e411241Smrg -T) no_target_directory=true;; 1628c9fbc29Smrg 1638c9fbc29Smrg --version) echo "$0 $scriptversion"; exit $?;; 1648c9fbc29Smrg 1658c9fbc29Smrg --) shift 1668c9fbc29Smrg break;; 1678c9fbc29Smrg 1688c9fbc29Smrg -*) echo "$0: invalid option: $1" >&2 1698c9fbc29Smrg exit 1;; 1708c9fbc29Smrg 1718c9fbc29Smrg *) break;; 1728c9fbc29Smrg esac 1734e411241Smrg shift 1748c9fbc29Smrgdone 1758c9fbc29Smrg 1764e411241Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1778c9fbc29Smrg # When -d is used, all remaining arguments are directories to create. 1788c9fbc29Smrg # When -t is used, the destination is already specified. 1798c9fbc29Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1808c9fbc29Smrg for arg 1818c9fbc29Smrg do 1824e411241Smrg if test -n "$dst_arg"; then 1838c9fbc29Smrg # $@ is not empty: it contains at least $arg. 1844e411241Smrg set fnord "$@" "$dst_arg" 1858c9fbc29Smrg shift # fnord 1868c9fbc29Smrg fi 1878c9fbc29Smrg shift # arg 1884e411241Smrg dst_arg=$arg 1898c9fbc29Smrg done 1908c9fbc29Smrgfi 1918c9fbc29Smrg 1928c9fbc29Smrgif test $# -eq 0; then 1938c9fbc29Smrg if test -z "$dir_arg"; then 1948c9fbc29Smrg echo "$0: no input file specified." >&2 1958c9fbc29Smrg exit 1 1968c9fbc29Smrg fi 1978c9fbc29Smrg # It's OK to call `install-sh -d' without argument. 1988c9fbc29Smrg # This can happen when creating conditional directories. 1998c9fbc29Smrg exit 0 2008c9fbc29Smrgfi 2018c9fbc29Smrg 2028c9fbc29Smrgif test -z "$dir_arg"; then 2038c9fbc29Smrg trap '(exit $?); exit' 1 2 13 15 2048c9fbc29Smrg 2058c9fbc29Smrg # Set umask so as not to create temps with too-generous modes. 2068c9fbc29Smrg # However, 'strip' requires both read and write access to temps. 2078c9fbc29Smrg case $mode in 2088c9fbc29Smrg # Optimize common cases. 2098c9fbc29Smrg *644) cp_umask=133;; 2108c9fbc29Smrg *755) cp_umask=22;; 2118c9fbc29Smrg 2128c9fbc29Smrg *[0-7]) 2138c9fbc29Smrg if test -z "$stripcmd"; then 2148c9fbc29Smrg u_plus_rw= 2158c9fbc29Smrg else 2168c9fbc29Smrg u_plus_rw='% 200' 2178c9fbc29Smrg fi 2188c9fbc29Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2198c9fbc29Smrg *) 2208c9fbc29Smrg if test -z "$stripcmd"; then 2218c9fbc29Smrg u_plus_rw= 2228c9fbc29Smrg else 2238c9fbc29Smrg u_plus_rw=,u+rw 2248c9fbc29Smrg fi 2258c9fbc29Smrg cp_umask=$mode$u_plus_rw;; 2268c9fbc29Smrg esac 2278c9fbc29Smrgfi 2288c9fbc29Smrg 2298c9fbc29Smrgfor src 2308c9fbc29Smrgdo 2318c9fbc29Smrg # Protect names starting with `-'. 2328c9fbc29Smrg case $src in 2334e411241Smrg -*) src=./$src;; 2348c9fbc29Smrg esac 2358c9fbc29Smrg 2368c9fbc29Smrg if test -n "$dir_arg"; then 2378c9fbc29Smrg dst=$src 2388c9fbc29Smrg dstdir=$dst 2398c9fbc29Smrg test -d "$dstdir" 2408c9fbc29Smrg dstdir_status=$? 2418c9fbc29Smrg else 2428c9fbc29Smrg 2438c9fbc29Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2448c9fbc29Smrg # might cause directories to be created, which would be especially bad 2458c9fbc29Smrg # if $src (and thus $dsttmp) contains '*'. 2468c9fbc29Smrg if test ! -f "$src" && test ! -d "$src"; then 2478c9fbc29Smrg echo "$0: $src does not exist." >&2 2488c9fbc29Smrg exit 1 2498c9fbc29Smrg fi 2508c9fbc29Smrg 2514e411241Smrg if test -z "$dst_arg"; then 2528c9fbc29Smrg echo "$0: no destination specified." >&2 2538c9fbc29Smrg exit 1 2548c9fbc29Smrg fi 2558c9fbc29Smrg 2564e411241Smrg dst=$dst_arg 2578c9fbc29Smrg # Protect names starting with `-'. 2588c9fbc29Smrg case $dst in 2594e411241Smrg -*) dst=./$dst;; 2608c9fbc29Smrg esac 2618c9fbc29Smrg 2628c9fbc29Smrg # If destination is a directory, append the input filename; won't work 2638c9fbc29Smrg # if double slashes aren't ignored. 2648c9fbc29Smrg if test -d "$dst"; then 2658c9fbc29Smrg if test -n "$no_target_directory"; then 2664e411241Smrg echo "$0: $dst_arg: Is a directory" >&2 2678c9fbc29Smrg exit 1 2688c9fbc29Smrg fi 2698c9fbc29Smrg dstdir=$dst 2708c9fbc29Smrg dst=$dstdir/`basename "$src"` 2718c9fbc29Smrg dstdir_status=0 2728c9fbc29Smrg else 2738c9fbc29Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2748c9fbc29Smrg dstdir=` 2758c9fbc29Smrg (dirname "$dst") 2>/dev/null || 2768c9fbc29Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2778c9fbc29Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2788c9fbc29Smrg X"$dst" : 'X\(//\)$' \| \ 2798c9fbc29Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2808c9fbc29Smrg echo X"$dst" | 2818c9fbc29Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2828c9fbc29Smrg s//\1/ 2838c9fbc29Smrg q 2848c9fbc29Smrg } 2858c9fbc29Smrg /^X\(\/\/\)[^/].*/{ 2868c9fbc29Smrg s//\1/ 2878c9fbc29Smrg q 2888c9fbc29Smrg } 2898c9fbc29Smrg /^X\(\/\/\)$/{ 2908c9fbc29Smrg s//\1/ 2918c9fbc29Smrg q 2928c9fbc29Smrg } 2938c9fbc29Smrg /^X\(\/\).*/{ 2948c9fbc29Smrg s//\1/ 2958c9fbc29Smrg q 2968c9fbc29Smrg } 2978c9fbc29Smrg s/.*/./; q' 2988c9fbc29Smrg ` 2998c9fbc29Smrg 3008c9fbc29Smrg test -d "$dstdir" 3018c9fbc29Smrg dstdir_status=$? 3028c9fbc29Smrg fi 3038c9fbc29Smrg fi 3048c9fbc29Smrg 3058c9fbc29Smrg obsolete_mkdir_used=false 3068c9fbc29Smrg 3078c9fbc29Smrg if test $dstdir_status != 0; then 3088c9fbc29Smrg case $posix_mkdir in 3098c9fbc29Smrg '') 3108c9fbc29Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3118c9fbc29Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3128c9fbc29Smrg umask=`umask` 3138c9fbc29Smrg case $stripcmd.$umask in 3148c9fbc29Smrg # Optimize common cases. 3158c9fbc29Smrg *[2367][2367]) mkdir_umask=$umask;; 3168c9fbc29Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3178c9fbc29Smrg 3188c9fbc29Smrg *[0-7]) 3198c9fbc29Smrg mkdir_umask=`expr $umask + 22 \ 3208c9fbc29Smrg - $umask % 100 % 40 + $umask % 20 \ 3218c9fbc29Smrg - $umask % 10 % 4 + $umask % 2 3228c9fbc29Smrg `;; 3238c9fbc29Smrg *) mkdir_umask=$umask,go-w;; 3248c9fbc29Smrg esac 3258c9fbc29Smrg 3268c9fbc29Smrg # With -d, create the new directory with the user-specified mode. 3278c9fbc29Smrg # Otherwise, rely on $mkdir_umask. 3288c9fbc29Smrg if test -n "$dir_arg"; then 3298c9fbc29Smrg mkdir_mode=-m$mode 3308c9fbc29Smrg else 3318c9fbc29Smrg mkdir_mode= 3328c9fbc29Smrg fi 3338c9fbc29Smrg 3348c9fbc29Smrg posix_mkdir=false 3358c9fbc29Smrg case $umask in 3368c9fbc29Smrg *[123567][0-7][0-7]) 3378c9fbc29Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3388c9fbc29Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3398c9fbc29Smrg ;; 3408c9fbc29Smrg *) 3418c9fbc29Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3428c9fbc29Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3438c9fbc29Smrg 3448c9fbc29Smrg if (umask $mkdir_umask && 3458c9fbc29Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3468c9fbc29Smrg then 3478c9fbc29Smrg if test -z "$dir_arg" || { 3488c9fbc29Smrg # Check for POSIX incompatibilities with -m. 3498c9fbc29Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3508c9fbc29Smrg # other-writeable bit of parent directory when it shouldn't. 3518c9fbc29Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3528c9fbc29Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3538c9fbc29Smrg case $ls_ld_tmpdir in 3548c9fbc29Smrg d????-?r-*) different_mode=700;; 3558c9fbc29Smrg d????-?--*) different_mode=755;; 3568c9fbc29Smrg *) false;; 3578c9fbc29Smrg esac && 3588c9fbc29Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3598c9fbc29Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3608c9fbc29Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3618c9fbc29Smrg } 3628c9fbc29Smrg } 3638c9fbc29Smrg then posix_mkdir=: 3648c9fbc29Smrg fi 3658c9fbc29Smrg rmdir "$tmpdir/d" "$tmpdir" 3668c9fbc29Smrg else 3678c9fbc29Smrg # Remove any dirs left behind by ancient mkdir implementations. 3688c9fbc29Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3698c9fbc29Smrg fi 3708c9fbc29Smrg trap '' 0;; 3718c9fbc29Smrg esac;; 3728c9fbc29Smrg esac 3738c9fbc29Smrg 3748c9fbc29Smrg if 3758c9fbc29Smrg $posix_mkdir && ( 3768c9fbc29Smrg umask $mkdir_umask && 3778c9fbc29Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3788c9fbc29Smrg ) 3798c9fbc29Smrg then : 3808c9fbc29Smrg else 3818c9fbc29Smrg 3828c9fbc29Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3838c9fbc29Smrg # or it failed possibly due to a race condition. Create the 3848c9fbc29Smrg # directory the slow way, step by step, checking for races as we go. 3858c9fbc29Smrg 3868c9fbc29Smrg case $dstdir in 3874e411241Smrg /*) prefix='/';; 3884e411241Smrg -*) prefix='./';; 3894e411241Smrg *) prefix='';; 3908c9fbc29Smrg esac 3918c9fbc29Smrg 3924e411241Smrg eval "$initialize_posix_glob" 3938c9fbc29Smrg 3948c9fbc29Smrg oIFS=$IFS 3958c9fbc29Smrg IFS=/ 3964e411241Smrg $posix_glob set -f 3978c9fbc29Smrg set fnord $dstdir 3988c9fbc29Smrg shift 3994e411241Smrg $posix_glob set +f 4008c9fbc29Smrg IFS=$oIFS 4018c9fbc29Smrg 4028c9fbc29Smrg prefixes= 4038c9fbc29Smrg 4048c9fbc29Smrg for d 4058c9fbc29Smrg do 4068c9fbc29Smrg test -z "$d" && continue 4078c9fbc29Smrg 4088c9fbc29Smrg prefix=$prefix$d 4098c9fbc29Smrg if test -d "$prefix"; then 4108c9fbc29Smrg prefixes= 4118c9fbc29Smrg else 4128c9fbc29Smrg if $posix_mkdir; then 4138c9fbc29Smrg (umask=$mkdir_umask && 4148c9fbc29Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4158c9fbc29Smrg # Don't fail if two instances are running concurrently. 4168c9fbc29Smrg test -d "$prefix" || exit 1 4178c9fbc29Smrg else 4188c9fbc29Smrg case $prefix in 4198c9fbc29Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4208c9fbc29Smrg *) qprefix=$prefix;; 4218c9fbc29Smrg esac 4228c9fbc29Smrg prefixes="$prefixes '$qprefix'" 4238c9fbc29Smrg fi 4248c9fbc29Smrg fi 4258c9fbc29Smrg prefix=$prefix/ 4268c9fbc29Smrg done 4278c9fbc29Smrg 4288c9fbc29Smrg if test -n "$prefixes"; then 4298c9fbc29Smrg # Don't fail if two instances are running concurrently. 4308c9fbc29Smrg (umask $mkdir_umask && 4318c9fbc29Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4328c9fbc29Smrg test -d "$dstdir" || exit 1 4338c9fbc29Smrg obsolete_mkdir_used=true 4348c9fbc29Smrg fi 4358c9fbc29Smrg fi 4368c9fbc29Smrg fi 4378c9fbc29Smrg 4388c9fbc29Smrg if test -n "$dir_arg"; then 4398c9fbc29Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4408c9fbc29Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4418c9fbc29Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4428c9fbc29Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4438c9fbc29Smrg else 4448c9fbc29Smrg 4458c9fbc29Smrg # Make a couple of temp file names in the proper directory. 4468c9fbc29Smrg dsttmp=$dstdir/_inst.$$_ 4478c9fbc29Smrg rmtmp=$dstdir/_rm.$$_ 4488c9fbc29Smrg 4498c9fbc29Smrg # Trap to clean up those temp files at exit. 4508c9fbc29Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4518c9fbc29Smrg 4528c9fbc29Smrg # Copy the file name to the temp name. 4538c9fbc29Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4548c9fbc29Smrg 4558c9fbc29Smrg # and set any options; do chmod last to preserve setuid bits. 4568c9fbc29Smrg # 4578c9fbc29Smrg # If any of these fail, we abort the whole thing. If we want to 4588c9fbc29Smrg # ignore errors from any of these, just make sure not to ignore 4598c9fbc29Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4608c9fbc29Smrg # 4614e411241Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4624e411241Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4634e411241Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4644e411241Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4654e411241Smrg 4664e411241Smrg # If -C, don't bother to copy if it wouldn't change the file. 4674e411241Smrg if $copy_on_change && 4684e411241Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4694e411241Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4704e411241Smrg 4714e411241Smrg eval "$initialize_posix_glob" && 4724e411241Smrg $posix_glob set -f && 4734e411241Smrg set X $old && old=:$2:$4:$5:$6 && 4744e411241Smrg set X $new && new=:$2:$4:$5:$6 && 4754e411241Smrg $posix_glob set +f && 4764e411241Smrg 4774e411241Smrg test "$old" = "$new" && 4784e411241Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4794e411241Smrg then 4804e411241Smrg rm -f "$dsttmp" 4814e411241Smrg else 4824e411241Smrg # Rename the file to the real destination. 4834e411241Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4844e411241Smrg 4854e411241Smrg # The rename failed, perhaps because mv can't rename something else 4864e411241Smrg # to itself, or perhaps because mv is so ancient that it does not 4874e411241Smrg # support -f. 4884e411241Smrg { 4894e411241Smrg # Now remove or move aside any old file at destination location. 4904e411241Smrg # We try this two ways since rm can't unlink itself on some 4914e411241Smrg # systems and the destination file might be busy for other 4924e411241Smrg # reasons. In this case, the final cleanup might fail but the new 4934e411241Smrg # file should still install successfully. 4944e411241Smrg { 4954e411241Smrg test ! -f "$dst" || 4964e411241Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 4974e411241Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 4984e411241Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 4994e411241Smrg } || 5004e411241Smrg { echo "$0: cannot unlink or rename $dst" >&2 5014e411241Smrg (exit 1); exit 1 5024e411241Smrg } 5034e411241Smrg } && 5044e411241Smrg 5054e411241Smrg # Now rename the file to the real destination. 5064e411241Smrg $doit $mvcmd "$dsttmp" "$dst" 5074e411241Smrg } 5084e411241Smrg fi || exit 1 5098c9fbc29Smrg 5108c9fbc29Smrg trap '' 0 5118c9fbc29Smrg fi 5128c9fbc29Smrgdone 5138c9fbc29Smrg 5148c9fbc29Smrg# Local variables: 5158c9fbc29Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5168c9fbc29Smrg# time-stamp-start: "scriptversion=" 5178c9fbc29Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5184e411241Smrg# time-stamp-time-zone: "UTC" 5194e411241Smrg# time-stamp-end: "; # UTC" 5208c9fbc29Smrg# End: 521