install-sh revision 0ed7c580
10ed7c580Smrg#!/bin/sh 20ed7c580Smrg# install - install a program, script, or datafile 30ed7c580Smrg 40ed7c580Smrgscriptversion=2011-11-20.07; # UTC 50ed7c580Smrg 60ed7c580Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 70ed7c580Smrg# later released in X11R6 (xc/config/util/install.sh) with the 80ed7c580Smrg# following copyright and license. 90ed7c580Smrg# 100ed7c580Smrg# Copyright (C) 1994 X Consortium 110ed7c580Smrg# 120ed7c580Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 130ed7c580Smrg# of this software and associated documentation files (the "Software"), to 140ed7c580Smrg# deal in the Software without restriction, including without limitation the 150ed7c580Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 160ed7c580Smrg# sell copies of the Software, and to permit persons to whom the Software is 170ed7c580Smrg# furnished to do so, subject to the following conditions: 180ed7c580Smrg# 190ed7c580Smrg# The above copyright notice and this permission notice shall be included in 200ed7c580Smrg# all copies or substantial portions of the Software. 210ed7c580Smrg# 220ed7c580Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 230ed7c580Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 240ed7c580Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 250ed7c580Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 260ed7c580Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 270ed7c580Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 280ed7c580Smrg# 290ed7c580Smrg# Except as contained in this notice, the name of the X Consortium shall not 300ed7c580Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 310ed7c580Smrg# ings in this Software without prior written authorization from the X Consor- 320ed7c580Smrg# tium. 330ed7c580Smrg# 340ed7c580Smrg# 350ed7c580Smrg# FSF changes to this file are in the public domain. 360ed7c580Smrg# 370ed7c580Smrg# Calling this script install-sh is preferred over install.sh, to prevent 380ed7c580Smrg# 'make' implicit rules from creating a file called install from it 390ed7c580Smrg# when there is no Makefile. 400ed7c580Smrg# 410ed7c580Smrg# This script is compatible with the BSD install script, but was written 420ed7c580Smrg# from scratch. 430ed7c580Smrg 440ed7c580Smrgnl=' 450ed7c580Smrg' 460ed7c580SmrgIFS=" "" $nl" 470ed7c580Smrg 480ed7c580Smrg# set DOITPROG to echo to test this script 490ed7c580Smrg 500ed7c580Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 510ed7c580Smrgdoit=${DOITPROG-} 520ed7c580Smrgif test -z "$doit"; then 530ed7c580Smrg doit_exec=exec 540ed7c580Smrgelse 550ed7c580Smrg doit_exec=$doit 560ed7c580Smrgfi 570ed7c580Smrg 580ed7c580Smrg# Put in absolute file names if you don't have them in your path; 590ed7c580Smrg# or use environment vars. 600ed7c580Smrg 610ed7c580Smrgchgrpprog=${CHGRPPROG-chgrp} 620ed7c580Smrgchmodprog=${CHMODPROG-chmod} 630ed7c580Smrgchownprog=${CHOWNPROG-chown} 640ed7c580Smrgcmpprog=${CMPPROG-cmp} 650ed7c580Smrgcpprog=${CPPROG-cp} 660ed7c580Smrgmkdirprog=${MKDIRPROG-mkdir} 670ed7c580Smrgmvprog=${MVPROG-mv} 680ed7c580Smrgrmprog=${RMPROG-rm} 690ed7c580Smrgstripprog=${STRIPPROG-strip} 700ed7c580Smrg 710ed7c580Smrgposix_glob='?' 720ed7c580Smrginitialize_posix_glob=' 730ed7c580Smrg test "$posix_glob" != "?" || { 740ed7c580Smrg if (set -f) 2>/dev/null; then 750ed7c580Smrg posix_glob= 760ed7c580Smrg else 770ed7c580Smrg posix_glob=: 780ed7c580Smrg fi 790ed7c580Smrg } 800ed7c580Smrg' 810ed7c580Smrg 820ed7c580Smrgposix_mkdir= 830ed7c580Smrg 840ed7c580Smrg# Desired mode of installed file. 850ed7c580Smrgmode=0755 860ed7c580Smrg 870ed7c580Smrgchgrpcmd= 880ed7c580Smrgchmodcmd=$chmodprog 890ed7c580Smrgchowncmd= 900ed7c580Smrgmvcmd=$mvprog 910ed7c580Smrgrmcmd="$rmprog -f" 920ed7c580Smrgstripcmd= 930ed7c580Smrg 940ed7c580Smrgsrc= 950ed7c580Smrgdst= 960ed7c580Smrgdir_arg= 970ed7c580Smrgdst_arg= 980ed7c580Smrg 990ed7c580Smrgcopy_on_change=false 1000ed7c580Smrgno_target_directory= 1010ed7c580Smrg 1020ed7c580Smrgusage="\ 1030ed7c580SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1040ed7c580Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1050ed7c580Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1060ed7c580Smrg or: $0 [OPTION]... -d DIRECTORIES... 1070ed7c580Smrg 1080ed7c580SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1090ed7c580SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1100ed7c580SmrgIn the 4th, create DIRECTORIES. 1110ed7c580Smrg 1120ed7c580SmrgOptions: 1130ed7c580Smrg --help display this help and exit. 1140ed7c580Smrg --version display version info and exit. 1150ed7c580Smrg 1160ed7c580Smrg -c (ignored) 1170ed7c580Smrg -C install only if different (preserve the last data modification time) 1180ed7c580Smrg -d create directories instead of installing files. 1190ed7c580Smrg -g GROUP $chgrpprog installed files to GROUP. 1200ed7c580Smrg -m MODE $chmodprog installed files to MODE. 1210ed7c580Smrg -o USER $chownprog installed files to USER. 1220ed7c580Smrg -s $stripprog installed files. 1230ed7c580Smrg -t DIRECTORY install into DIRECTORY. 1240ed7c580Smrg -T report an error if DSTFILE is a directory. 1250ed7c580Smrg 1260ed7c580SmrgEnvironment variables override the default commands: 1270ed7c580Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 1280ed7c580Smrg RMPROG STRIPPROG 1290ed7c580Smrg" 1300ed7c580Smrg 1310ed7c580Smrgwhile test $# -ne 0; do 1320ed7c580Smrg case $1 in 1330ed7c580Smrg -c) ;; 1340ed7c580Smrg 1350ed7c580Smrg -C) copy_on_change=true;; 1360ed7c580Smrg 1370ed7c580Smrg -d) dir_arg=true;; 1380ed7c580Smrg 1390ed7c580Smrg -g) chgrpcmd="$chgrpprog $2" 1400ed7c580Smrg shift;; 1410ed7c580Smrg 1420ed7c580Smrg --help) echo "$usage"; exit $?;; 1430ed7c580Smrg 1440ed7c580Smrg -m) mode=$2 1450ed7c580Smrg case $mode in 1460ed7c580Smrg *' '* | *' '* | *' 1470ed7c580Smrg'* | *'*'* | *'?'* | *'['*) 1480ed7c580Smrg echo "$0: invalid mode: $mode" >&2 1490ed7c580Smrg exit 1;; 1500ed7c580Smrg esac 1510ed7c580Smrg shift;; 1520ed7c580Smrg 1530ed7c580Smrg -o) chowncmd="$chownprog $2" 1540ed7c580Smrg shift;; 1550ed7c580Smrg 1560ed7c580Smrg -s) stripcmd=$stripprog;; 1570ed7c580Smrg 1580ed7c580Smrg -t) dst_arg=$2 1590ed7c580Smrg # Protect names problematic for 'test' and other utilities. 1600ed7c580Smrg case $dst_arg in 1610ed7c580Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1620ed7c580Smrg esac 1630ed7c580Smrg shift;; 1640ed7c580Smrg 1650ed7c580Smrg -T) no_target_directory=true;; 1660ed7c580Smrg 1670ed7c580Smrg --version) echo "$0 $scriptversion"; exit $?;; 1680ed7c580Smrg 1690ed7c580Smrg --) shift 1700ed7c580Smrg break;; 1710ed7c580Smrg 1720ed7c580Smrg -*) echo "$0: invalid option: $1" >&2 1730ed7c580Smrg exit 1;; 1740ed7c580Smrg 1750ed7c580Smrg *) break;; 1760ed7c580Smrg esac 1770ed7c580Smrg shift 1780ed7c580Smrgdone 1790ed7c580Smrg 1800ed7c580Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1810ed7c580Smrg # When -d is used, all remaining arguments are directories to create. 1820ed7c580Smrg # When -t is used, the destination is already specified. 1830ed7c580Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1840ed7c580Smrg for arg 1850ed7c580Smrg do 1860ed7c580Smrg if test -n "$dst_arg"; then 1870ed7c580Smrg # $@ is not empty: it contains at least $arg. 1880ed7c580Smrg set fnord "$@" "$dst_arg" 1890ed7c580Smrg shift # fnord 1900ed7c580Smrg fi 1910ed7c580Smrg shift # arg 1920ed7c580Smrg dst_arg=$arg 1930ed7c580Smrg # Protect names problematic for 'test' and other utilities. 1940ed7c580Smrg case $dst_arg in 1950ed7c580Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 1960ed7c580Smrg esac 1970ed7c580Smrg done 1980ed7c580Smrgfi 1990ed7c580Smrg 2000ed7c580Smrgif test $# -eq 0; then 2010ed7c580Smrg if test -z "$dir_arg"; then 2020ed7c580Smrg echo "$0: no input file specified." >&2 2030ed7c580Smrg exit 1 2040ed7c580Smrg fi 2050ed7c580Smrg # It's OK to call 'install-sh -d' without argument. 2060ed7c580Smrg # This can happen when creating conditional directories. 2070ed7c580Smrg exit 0 2080ed7c580Smrgfi 2090ed7c580Smrg 2100ed7c580Smrgif test -z "$dir_arg"; then 2110ed7c580Smrg do_exit='(exit $ret); exit $ret' 2120ed7c580Smrg trap "ret=129; $do_exit" 1 2130ed7c580Smrg trap "ret=130; $do_exit" 2 2140ed7c580Smrg trap "ret=141; $do_exit" 13 2150ed7c580Smrg trap "ret=143; $do_exit" 15 2160ed7c580Smrg 2170ed7c580Smrg # Set umask so as not to create temps with too-generous modes. 2180ed7c580Smrg # However, 'strip' requires both read and write access to temps. 2190ed7c580Smrg case $mode in 2200ed7c580Smrg # Optimize common cases. 2210ed7c580Smrg *644) cp_umask=133;; 2220ed7c580Smrg *755) cp_umask=22;; 2230ed7c580Smrg 2240ed7c580Smrg *[0-7]) 2250ed7c580Smrg if test -z "$stripcmd"; then 2260ed7c580Smrg u_plus_rw= 2270ed7c580Smrg else 2280ed7c580Smrg u_plus_rw='% 200' 2290ed7c580Smrg fi 2300ed7c580Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2310ed7c580Smrg *) 2320ed7c580Smrg if test -z "$stripcmd"; then 2330ed7c580Smrg u_plus_rw= 2340ed7c580Smrg else 2350ed7c580Smrg u_plus_rw=,u+rw 2360ed7c580Smrg fi 2370ed7c580Smrg cp_umask=$mode$u_plus_rw;; 2380ed7c580Smrg esac 2390ed7c580Smrgfi 2400ed7c580Smrg 2410ed7c580Smrgfor src 2420ed7c580Smrgdo 2430ed7c580Smrg # Protect names problematic for 'test' and other utilities. 2440ed7c580Smrg case $src in 2450ed7c580Smrg -* | [=\(\)!]) src=./$src;; 2460ed7c580Smrg esac 2470ed7c580Smrg 2480ed7c580Smrg if test -n "$dir_arg"; then 2490ed7c580Smrg dst=$src 2500ed7c580Smrg dstdir=$dst 2510ed7c580Smrg test -d "$dstdir" 2520ed7c580Smrg dstdir_status=$? 2530ed7c580Smrg else 2540ed7c580Smrg 2550ed7c580Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2560ed7c580Smrg # might cause directories to be created, which would be especially bad 2570ed7c580Smrg # if $src (and thus $dsttmp) contains '*'. 2580ed7c580Smrg if test ! -f "$src" && test ! -d "$src"; then 2590ed7c580Smrg echo "$0: $src does not exist." >&2 2600ed7c580Smrg exit 1 2610ed7c580Smrg fi 2620ed7c580Smrg 2630ed7c580Smrg if test -z "$dst_arg"; then 2640ed7c580Smrg echo "$0: no destination specified." >&2 2650ed7c580Smrg exit 1 2660ed7c580Smrg fi 2670ed7c580Smrg dst=$dst_arg 2680ed7c580Smrg 2690ed7c580Smrg # If destination is a directory, append the input filename; won't work 2700ed7c580Smrg # if double slashes aren't ignored. 2710ed7c580Smrg if test -d "$dst"; then 2720ed7c580Smrg if test -n "$no_target_directory"; then 2730ed7c580Smrg echo "$0: $dst_arg: Is a directory" >&2 2740ed7c580Smrg exit 1 2750ed7c580Smrg fi 2760ed7c580Smrg dstdir=$dst 2770ed7c580Smrg dst=$dstdir/`basename "$src"` 2780ed7c580Smrg dstdir_status=0 2790ed7c580Smrg else 2800ed7c580Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2810ed7c580Smrg dstdir=` 2820ed7c580Smrg (dirname "$dst") 2>/dev/null || 2830ed7c580Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2840ed7c580Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2850ed7c580Smrg X"$dst" : 'X\(//\)$' \| \ 2860ed7c580Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2870ed7c580Smrg echo X"$dst" | 2880ed7c580Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2890ed7c580Smrg s//\1/ 2900ed7c580Smrg q 2910ed7c580Smrg } 2920ed7c580Smrg /^X\(\/\/\)[^/].*/{ 2930ed7c580Smrg s//\1/ 2940ed7c580Smrg q 2950ed7c580Smrg } 2960ed7c580Smrg /^X\(\/\/\)$/{ 2970ed7c580Smrg s//\1/ 2980ed7c580Smrg q 2990ed7c580Smrg } 3000ed7c580Smrg /^X\(\/\).*/{ 3010ed7c580Smrg s//\1/ 3020ed7c580Smrg q 3030ed7c580Smrg } 3040ed7c580Smrg s/.*/./; q' 3050ed7c580Smrg ` 3060ed7c580Smrg 3070ed7c580Smrg test -d "$dstdir" 3080ed7c580Smrg dstdir_status=$? 3090ed7c580Smrg fi 3100ed7c580Smrg fi 3110ed7c580Smrg 3120ed7c580Smrg obsolete_mkdir_used=false 3130ed7c580Smrg 3140ed7c580Smrg if test $dstdir_status != 0; then 3150ed7c580Smrg case $posix_mkdir in 3160ed7c580Smrg '') 3170ed7c580Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3180ed7c580Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3190ed7c580Smrg umask=`umask` 3200ed7c580Smrg case $stripcmd.$umask in 3210ed7c580Smrg # Optimize common cases. 3220ed7c580Smrg *[2367][2367]) mkdir_umask=$umask;; 3230ed7c580Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3240ed7c580Smrg 3250ed7c580Smrg *[0-7]) 3260ed7c580Smrg mkdir_umask=`expr $umask + 22 \ 3270ed7c580Smrg - $umask % 100 % 40 + $umask % 20 \ 3280ed7c580Smrg - $umask % 10 % 4 + $umask % 2 3290ed7c580Smrg `;; 3300ed7c580Smrg *) mkdir_umask=$umask,go-w;; 3310ed7c580Smrg esac 3320ed7c580Smrg 3330ed7c580Smrg # With -d, create the new directory with the user-specified mode. 3340ed7c580Smrg # Otherwise, rely on $mkdir_umask. 3350ed7c580Smrg if test -n "$dir_arg"; then 3360ed7c580Smrg mkdir_mode=-m$mode 3370ed7c580Smrg else 3380ed7c580Smrg mkdir_mode= 3390ed7c580Smrg fi 3400ed7c580Smrg 3410ed7c580Smrg posix_mkdir=false 3420ed7c580Smrg case $umask in 3430ed7c580Smrg *[123567][0-7][0-7]) 3440ed7c580Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3450ed7c580Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3460ed7c580Smrg ;; 3470ed7c580Smrg *) 3480ed7c580Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3490ed7c580Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3500ed7c580Smrg 3510ed7c580Smrg if (umask $mkdir_umask && 3520ed7c580Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3530ed7c580Smrg then 3540ed7c580Smrg if test -z "$dir_arg" || { 3550ed7c580Smrg # Check for POSIX incompatibilities with -m. 3560ed7c580Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3570ed7c580Smrg # other-writable bit of parent directory when it shouldn't. 3580ed7c580Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3590ed7c580Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3600ed7c580Smrg case $ls_ld_tmpdir in 3610ed7c580Smrg d????-?r-*) different_mode=700;; 3620ed7c580Smrg d????-?--*) different_mode=755;; 3630ed7c580Smrg *) false;; 3640ed7c580Smrg esac && 3650ed7c580Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3660ed7c580Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3670ed7c580Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3680ed7c580Smrg } 3690ed7c580Smrg } 3700ed7c580Smrg then posix_mkdir=: 3710ed7c580Smrg fi 3720ed7c580Smrg rmdir "$tmpdir/d" "$tmpdir" 3730ed7c580Smrg else 3740ed7c580Smrg # Remove any dirs left behind by ancient mkdir implementations. 3750ed7c580Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3760ed7c580Smrg fi 3770ed7c580Smrg trap '' 0;; 3780ed7c580Smrg esac;; 3790ed7c580Smrg esac 3800ed7c580Smrg 3810ed7c580Smrg if 3820ed7c580Smrg $posix_mkdir && ( 3830ed7c580Smrg umask $mkdir_umask && 3840ed7c580Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3850ed7c580Smrg ) 3860ed7c580Smrg then : 3870ed7c580Smrg else 3880ed7c580Smrg 3890ed7c580Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3900ed7c580Smrg # or it failed possibly due to a race condition. Create the 3910ed7c580Smrg # directory the slow way, step by step, checking for races as we go. 3920ed7c580Smrg 3930ed7c580Smrg case $dstdir in 3940ed7c580Smrg /*) prefix='/';; 3950ed7c580Smrg [-=\(\)!]*) prefix='./';; 3960ed7c580Smrg *) prefix='';; 3970ed7c580Smrg esac 3980ed7c580Smrg 3990ed7c580Smrg eval "$initialize_posix_glob" 4000ed7c580Smrg 4010ed7c580Smrg oIFS=$IFS 4020ed7c580Smrg IFS=/ 4030ed7c580Smrg $posix_glob set -f 4040ed7c580Smrg set fnord $dstdir 4050ed7c580Smrg shift 4060ed7c580Smrg $posix_glob set +f 4070ed7c580Smrg IFS=$oIFS 4080ed7c580Smrg 4090ed7c580Smrg prefixes= 4100ed7c580Smrg 4110ed7c580Smrg for d 4120ed7c580Smrg do 4130ed7c580Smrg test X"$d" = X && continue 4140ed7c580Smrg 4150ed7c580Smrg prefix=$prefix$d 4160ed7c580Smrg if test -d "$prefix"; then 4170ed7c580Smrg prefixes= 4180ed7c580Smrg else 4190ed7c580Smrg if $posix_mkdir; then 4200ed7c580Smrg (umask=$mkdir_umask && 4210ed7c580Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4220ed7c580Smrg # Don't fail if two instances are running concurrently. 4230ed7c580Smrg test -d "$prefix" || exit 1 4240ed7c580Smrg else 4250ed7c580Smrg case $prefix in 4260ed7c580Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4270ed7c580Smrg *) qprefix=$prefix;; 4280ed7c580Smrg esac 4290ed7c580Smrg prefixes="$prefixes '$qprefix'" 4300ed7c580Smrg fi 4310ed7c580Smrg fi 4320ed7c580Smrg prefix=$prefix/ 4330ed7c580Smrg done 4340ed7c580Smrg 4350ed7c580Smrg if test -n "$prefixes"; then 4360ed7c580Smrg # Don't fail if two instances are running concurrently. 4370ed7c580Smrg (umask $mkdir_umask && 4380ed7c580Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4390ed7c580Smrg test -d "$dstdir" || exit 1 4400ed7c580Smrg obsolete_mkdir_used=true 4410ed7c580Smrg fi 4420ed7c580Smrg fi 4430ed7c580Smrg fi 4440ed7c580Smrg 4450ed7c580Smrg if test -n "$dir_arg"; then 4460ed7c580Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4470ed7c580Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4480ed7c580Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4490ed7c580Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4500ed7c580Smrg else 4510ed7c580Smrg 4520ed7c580Smrg # Make a couple of temp file names in the proper directory. 4530ed7c580Smrg dsttmp=$dstdir/_inst.$$_ 4540ed7c580Smrg rmtmp=$dstdir/_rm.$$_ 4550ed7c580Smrg 4560ed7c580Smrg # Trap to clean up those temp files at exit. 4570ed7c580Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4580ed7c580Smrg 4590ed7c580Smrg # Copy the file name to the temp name. 4600ed7c580Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4610ed7c580Smrg 4620ed7c580Smrg # and set any options; do chmod last to preserve setuid bits. 4630ed7c580Smrg # 4640ed7c580Smrg # If any of these fail, we abort the whole thing. If we want to 4650ed7c580Smrg # ignore errors from any of these, just make sure not to ignore 4660ed7c580Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4670ed7c580Smrg # 4680ed7c580Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 4690ed7c580Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 4700ed7c580Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 4710ed7c580Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4720ed7c580Smrg 4730ed7c580Smrg # If -C, don't bother to copy if it wouldn't change the file. 4740ed7c580Smrg if $copy_on_change && 4750ed7c580Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 4760ed7c580Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 4770ed7c580Smrg 4780ed7c580Smrg eval "$initialize_posix_glob" && 4790ed7c580Smrg $posix_glob set -f && 4800ed7c580Smrg set X $old && old=:$2:$4:$5:$6 && 4810ed7c580Smrg set X $new && new=:$2:$4:$5:$6 && 4820ed7c580Smrg $posix_glob set +f && 4830ed7c580Smrg 4840ed7c580Smrg test "$old" = "$new" && 4850ed7c580Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 4860ed7c580Smrg then 4870ed7c580Smrg rm -f "$dsttmp" 4880ed7c580Smrg else 4890ed7c580Smrg # Rename the file to the real destination. 4900ed7c580Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 4910ed7c580Smrg 4920ed7c580Smrg # The rename failed, perhaps because mv can't rename something else 4930ed7c580Smrg # to itself, or perhaps because mv is so ancient that it does not 4940ed7c580Smrg # support -f. 4950ed7c580Smrg { 4960ed7c580Smrg # Now remove or move aside any old file at destination location. 4970ed7c580Smrg # We try this two ways since rm can't unlink itself on some 4980ed7c580Smrg # systems and the destination file might be busy for other 4990ed7c580Smrg # reasons. In this case, the final cleanup might fail but the new 5000ed7c580Smrg # file should still install successfully. 5010ed7c580Smrg { 5020ed7c580Smrg test ! -f "$dst" || 5030ed7c580Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 5040ed7c580Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 5050ed7c580Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 5060ed7c580Smrg } || 5070ed7c580Smrg { echo "$0: cannot unlink or rename $dst" >&2 5080ed7c580Smrg (exit 1); exit 1 5090ed7c580Smrg } 5100ed7c580Smrg } && 5110ed7c580Smrg 5120ed7c580Smrg # Now rename the file to the real destination. 5130ed7c580Smrg $doit $mvcmd "$dsttmp" "$dst" 5140ed7c580Smrg } 5150ed7c580Smrg fi || exit 1 5160ed7c580Smrg 5170ed7c580Smrg trap '' 0 5180ed7c580Smrg fi 5190ed7c580Smrgdone 5200ed7c580Smrg 5210ed7c580Smrg# Local variables: 5220ed7c580Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5230ed7c580Smrg# time-stamp-start: "scriptversion=" 5240ed7c580Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5250ed7c580Smrg# time-stamp-time-zone: "UTC" 5260ed7c580Smrg# time-stamp-end: "; # UTC" 5270ed7c580Smrg# End: 528