install-sh revision 405c8079
18ae04fa6Smrg#!/bin/sh 28ae04fa6Smrg# install - install a program, script, or datafile 38ae04fa6Smrg 4405c8079Smrgscriptversion=2011-01-19.21; # UTC 58ae04fa6Smrg 68ae04fa6Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 78ae04fa6Smrg# later released in X11R6 (xc/config/util/install.sh) with the 88ae04fa6Smrg# following copyright and license. 98ae04fa6Smrg# 108ae04fa6Smrg# Copyright (C) 1994 X Consortium 118ae04fa6Smrg# 128ae04fa6Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 138ae04fa6Smrg# of this software and associated documentation files (the "Software"), to 148ae04fa6Smrg# deal in the Software without restriction, including without limitation the 158ae04fa6Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168ae04fa6Smrg# sell copies of the Software, and to permit persons to whom the Software is 178ae04fa6Smrg# furnished to do so, subject to the following conditions: 188ae04fa6Smrg# 198ae04fa6Smrg# The above copyright notice and this permission notice shall be included in 208ae04fa6Smrg# all copies or substantial portions of the Software. 218ae04fa6Smrg# 228ae04fa6Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 238ae04fa6Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 248ae04fa6Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 258ae04fa6Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 268ae04fa6Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 278ae04fa6Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 288ae04fa6Smrg# 298ae04fa6Smrg# Except as contained in this notice, the name of the X Consortium shall not 308ae04fa6Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 318ae04fa6Smrg# ings in this Software without prior written authorization from the X Consor- 328ae04fa6Smrg# tium. 338ae04fa6Smrg# 348ae04fa6Smrg# 358ae04fa6Smrg# FSF changes to this file are in the public domain. 368ae04fa6Smrg# 378ae04fa6Smrg# Calling this script install-sh is preferred over install.sh, to prevent 388ae04fa6Smrg# `make' implicit rules from creating a file called install from it 398ae04fa6Smrg# when there is no Makefile. 408ae04fa6Smrg# 418ae04fa6Smrg# This script is compatible with the BSD install script, but was written 428ae04fa6Smrg# from scratch. 438ae04fa6Smrg 448ae04fa6Smrgnl=' 458ae04fa6Smrg' 468ae04fa6SmrgIFS=" "" $nl" 478ae04fa6Smrg 488ae04fa6Smrg# set DOITPROG to echo to test this script 498ae04fa6Smrg 508ae04fa6Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5144af7230Smrgdoit=${DOITPROG-} 528ae04fa6Smrgif test -z "$doit"; then 538ae04fa6Smrg doit_exec=exec 548ae04fa6Smrgelse 558ae04fa6Smrg doit_exec=$doit 568ae04fa6Smrgfi 578ae04fa6Smrg 588ae04fa6Smrg# Put in absolute file names if you don't have them in your path; 598ae04fa6Smrg# or use environment vars. 608ae04fa6Smrg 6144af7230Smrgchgrpprog=${CHGRPPROG-chgrp} 6244af7230Smrgchmodprog=${CHMODPROG-chmod} 6344af7230Smrgchownprog=${CHOWNPROG-chown} 6444af7230Smrgcmpprog=${CMPPROG-cmp} 6544af7230Smrgcpprog=${CPPROG-cp} 6644af7230Smrgmkdirprog=${MKDIRPROG-mkdir} 6744af7230Smrgmvprog=${MVPROG-mv} 6844af7230Smrgrmprog=${RMPROG-rm} 6944af7230Smrgstripprog=${STRIPPROG-strip} 7044af7230Smrg 7144af7230Smrgposix_glob='?' 7244af7230Smrginitialize_posix_glob=' 7344af7230Smrg test "$posix_glob" != "?" || { 7444af7230Smrg if (set -f) 2>/dev/null; then 7544af7230Smrg posix_glob= 7644af7230Smrg else 7744af7230Smrg posix_glob=: 7844af7230Smrg fi 7944af7230Smrg } 8044af7230Smrg' 818ae04fa6Smrg 828ae04fa6Smrgposix_mkdir= 838ae04fa6Smrg 848ae04fa6Smrg# Desired mode of installed file. 858ae04fa6Smrgmode=0755 868ae04fa6Smrg 8744af7230Smrgchgrpcmd= 888ae04fa6Smrgchmodcmd=$chmodprog 898ae04fa6Smrgchowncmd= 9044af7230Smrgmvcmd=$mvprog 918ae04fa6Smrgrmcmd="$rmprog -f" 9244af7230Smrgstripcmd= 9344af7230Smrg 948ae04fa6Smrgsrc= 958ae04fa6Smrgdst= 968ae04fa6Smrgdir_arg= 9744af7230Smrgdst_arg= 9844af7230Smrg 9944af7230Smrgcopy_on_change=false 1008ae04fa6Smrgno_target_directory= 1018ae04fa6Smrg 10244af7230Smrgusage="\ 10344af7230SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1048ae04fa6Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1058ae04fa6Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1068ae04fa6Smrg or: $0 [OPTION]... -d DIRECTORIES... 1078ae04fa6Smrg 1088ae04fa6SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1098ae04fa6SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1108ae04fa6SmrgIn the 4th, create DIRECTORIES. 1118ae04fa6Smrg 1128ae04fa6SmrgOptions: 11344af7230Smrg --help display this help and exit. 11444af7230Smrg --version display version info and exit. 11544af7230Smrg 11644af7230Smrg -c (ignored) 11744af7230Smrg -C install only if different (preserve the last data modification time) 11844af7230Smrg -d create directories instead of installing files. 11944af7230Smrg -g GROUP $chgrpprog installed files to GROUP. 12044af7230Smrg -m MODE $chmodprog installed files to MODE. 12144af7230Smrg -o USER $chownprog installed files to USER. 12244af7230Smrg -s $stripprog installed files. 12344af7230Smrg -t DIRECTORY install into DIRECTORY. 12444af7230Smrg -T report an error if DSTFILE is a directory. 1258ae04fa6Smrg 1268ae04fa6SmrgEnvironment variables override the default commands: 12744af7230Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12844af7230Smrg RMPROG STRIPPROG 1298ae04fa6Smrg" 1308ae04fa6Smrg 1318ae04fa6Smrgwhile test $# -ne 0; do 1328ae04fa6Smrg case $1 in 13344af7230Smrg -c) ;; 13444af7230Smrg 13544af7230Smrg -C) copy_on_change=true;; 1368ae04fa6Smrg 13744af7230Smrg -d) dir_arg=true;; 1388ae04fa6Smrg 1398ae04fa6Smrg -g) chgrpcmd="$chgrpprog $2" 14044af7230Smrg shift;; 1418ae04fa6Smrg 1428ae04fa6Smrg --help) echo "$usage"; exit $?;; 1438ae04fa6Smrg 1448ae04fa6Smrg -m) mode=$2 1458ae04fa6Smrg case $mode in 1468ae04fa6Smrg *' '* | *' '* | *' 1478ae04fa6Smrg'* | *'*'* | *'?'* | *'['*) 1488ae04fa6Smrg echo "$0: invalid mode: $mode" >&2 1498ae04fa6Smrg exit 1;; 1508ae04fa6Smrg esac 15144af7230Smrg shift;; 1528ae04fa6Smrg 1538ae04fa6Smrg -o) chowncmd="$chownprog $2" 15444af7230Smrg shift;; 1558ae04fa6Smrg 15644af7230Smrg -s) stripcmd=$stripprog;; 1578ae04fa6Smrg 15844af7230Smrg -t) dst_arg=$2 159405c8079Smrg # Protect names problematic for `test' and other utilities. 160405c8079Smrg case $dst_arg in 161405c8079Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 162405c8079Smrg esac 16344af7230Smrg shift;; 1648ae04fa6Smrg 16544af7230Smrg -T) no_target_directory=true;; 1668ae04fa6Smrg 1678ae04fa6Smrg --version) echo "$0 $scriptversion"; exit $?;; 1688ae04fa6Smrg 1698ae04fa6Smrg --) shift 1708ae04fa6Smrg break;; 1718ae04fa6Smrg 1728ae04fa6Smrg -*) echo "$0: invalid option: $1" >&2 1738ae04fa6Smrg exit 1;; 1748ae04fa6Smrg 1758ae04fa6Smrg *) break;; 1768ae04fa6Smrg esac 17744af7230Smrg shift 1788ae04fa6Smrgdone 1798ae04fa6Smrg 18044af7230Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1818ae04fa6Smrg # When -d is used, all remaining arguments are directories to create. 1828ae04fa6Smrg # When -t is used, the destination is already specified. 1838ae04fa6Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1848ae04fa6Smrg for arg 1858ae04fa6Smrg do 18644af7230Smrg if test -n "$dst_arg"; then 1878ae04fa6Smrg # $@ is not empty: it contains at least $arg. 18844af7230Smrg set fnord "$@" "$dst_arg" 1898ae04fa6Smrg shift # fnord 1908ae04fa6Smrg fi 1918ae04fa6Smrg shift # arg 19244af7230Smrg dst_arg=$arg 193405c8079Smrg # Protect names problematic for `test' and other utilities. 194405c8079Smrg case $dst_arg in 195405c8079Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 196405c8079Smrg esac 1978ae04fa6Smrg done 1988ae04fa6Smrgfi 1998ae04fa6Smrg 2008ae04fa6Smrgif test $# -eq 0; then 2018ae04fa6Smrg if test -z "$dir_arg"; then 2028ae04fa6Smrg echo "$0: no input file specified." >&2 2038ae04fa6Smrg exit 1 2048ae04fa6Smrg fi 2058ae04fa6Smrg # It's OK to call `install-sh -d' without argument. 2068ae04fa6Smrg # This can happen when creating conditional directories. 2078ae04fa6Smrg exit 0 2088ae04fa6Smrgfi 2098ae04fa6Smrg 2108ae04fa6Smrgif test -z "$dir_arg"; then 211405c8079Smrg do_exit='(exit $ret); exit $ret' 212405c8079Smrg trap "ret=129; $do_exit" 1 213405c8079Smrg trap "ret=130; $do_exit" 2 214405c8079Smrg trap "ret=141; $do_exit" 13 215405c8079Smrg trap "ret=143; $do_exit" 15 2168ae04fa6Smrg 2178ae04fa6Smrg # Set umask so as not to create temps with too-generous modes. 2188ae04fa6Smrg # However, 'strip' requires both read and write access to temps. 2198ae04fa6Smrg case $mode in 2208ae04fa6Smrg # Optimize common cases. 2218ae04fa6Smrg *644) cp_umask=133;; 2228ae04fa6Smrg *755) cp_umask=22;; 2238ae04fa6Smrg 2248ae04fa6Smrg *[0-7]) 2258ae04fa6Smrg if test -z "$stripcmd"; then 2268ae04fa6Smrg u_plus_rw= 2278ae04fa6Smrg else 2288ae04fa6Smrg u_plus_rw='% 200' 2298ae04fa6Smrg fi 2308ae04fa6Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2318ae04fa6Smrg *) 2328ae04fa6Smrg if test -z "$stripcmd"; then 2338ae04fa6Smrg u_plus_rw= 2348ae04fa6Smrg else 2358ae04fa6Smrg u_plus_rw=,u+rw 2368ae04fa6Smrg fi 2378ae04fa6Smrg cp_umask=$mode$u_plus_rw;; 2388ae04fa6Smrg esac 2398ae04fa6Smrgfi 2408ae04fa6Smrg 2418ae04fa6Smrgfor src 2428ae04fa6Smrgdo 243405c8079Smrg # Protect names problematic for `test' and other utilities. 2448ae04fa6Smrg case $src in 245405c8079Smrg -* | [=\(\)!]) src=./$src;; 2468ae04fa6Smrg esac 2478ae04fa6Smrg 2488ae04fa6Smrg if test -n "$dir_arg"; then 2498ae04fa6Smrg dst=$src 2508ae04fa6Smrg dstdir=$dst 2518ae04fa6Smrg test -d "$dstdir" 2528ae04fa6Smrg dstdir_status=$? 2538ae04fa6Smrg else 2548ae04fa6Smrg 2558ae04fa6Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2568ae04fa6Smrg # might cause directories to be created, which would be especially bad 2578ae04fa6Smrg # if $src (and thus $dsttmp) contains '*'. 2588ae04fa6Smrg if test ! -f "$src" && test ! -d "$src"; then 2598ae04fa6Smrg echo "$0: $src does not exist." >&2 2608ae04fa6Smrg exit 1 2618ae04fa6Smrg fi 2628ae04fa6Smrg 26344af7230Smrg if test -z "$dst_arg"; then 2648ae04fa6Smrg echo "$0: no destination specified." >&2 2658ae04fa6Smrg exit 1 2668ae04fa6Smrg fi 26744af7230Smrg dst=$dst_arg 2688ae04fa6Smrg 2698ae04fa6Smrg # If destination is a directory, append the input filename; won't work 2708ae04fa6Smrg # if double slashes aren't ignored. 2718ae04fa6Smrg if test -d "$dst"; then 2728ae04fa6Smrg if test -n "$no_target_directory"; then 27344af7230Smrg echo "$0: $dst_arg: Is a directory" >&2 2748ae04fa6Smrg exit 1 2758ae04fa6Smrg fi 2768ae04fa6Smrg dstdir=$dst 2778ae04fa6Smrg dst=$dstdir/`basename "$src"` 2788ae04fa6Smrg dstdir_status=0 2798ae04fa6Smrg else 2808ae04fa6Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2818ae04fa6Smrg dstdir=` 2828ae04fa6Smrg (dirname "$dst") 2>/dev/null || 2838ae04fa6Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2848ae04fa6Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2858ae04fa6Smrg X"$dst" : 'X\(//\)$' \| \ 2868ae04fa6Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2878ae04fa6Smrg echo X"$dst" | 2888ae04fa6Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2898ae04fa6Smrg s//\1/ 2908ae04fa6Smrg q 2918ae04fa6Smrg } 2928ae04fa6Smrg /^X\(\/\/\)[^/].*/{ 2938ae04fa6Smrg s//\1/ 2948ae04fa6Smrg q 2958ae04fa6Smrg } 2968ae04fa6Smrg /^X\(\/\/\)$/{ 2978ae04fa6Smrg s//\1/ 2988ae04fa6Smrg q 2998ae04fa6Smrg } 3008ae04fa6Smrg /^X\(\/\).*/{ 3018ae04fa6Smrg s//\1/ 3028ae04fa6Smrg q 3038ae04fa6Smrg } 3048ae04fa6Smrg s/.*/./; q' 3058ae04fa6Smrg ` 3068ae04fa6Smrg 3078ae04fa6Smrg test -d "$dstdir" 3088ae04fa6Smrg dstdir_status=$? 3098ae04fa6Smrg fi 3108ae04fa6Smrg fi 3118ae04fa6Smrg 3128ae04fa6Smrg obsolete_mkdir_used=false 3138ae04fa6Smrg 3148ae04fa6Smrg if test $dstdir_status != 0; then 3158ae04fa6Smrg case $posix_mkdir in 3168ae04fa6Smrg '') 3178ae04fa6Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3188ae04fa6Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3198ae04fa6Smrg umask=`umask` 3208ae04fa6Smrg case $stripcmd.$umask in 3218ae04fa6Smrg # Optimize common cases. 3228ae04fa6Smrg *[2367][2367]) mkdir_umask=$umask;; 3238ae04fa6Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3248ae04fa6Smrg 3258ae04fa6Smrg *[0-7]) 3268ae04fa6Smrg mkdir_umask=`expr $umask + 22 \ 3278ae04fa6Smrg - $umask % 100 % 40 + $umask % 20 \ 3288ae04fa6Smrg - $umask % 10 % 4 + $umask % 2 3298ae04fa6Smrg `;; 3308ae04fa6Smrg *) mkdir_umask=$umask,go-w;; 3318ae04fa6Smrg esac 3328ae04fa6Smrg 3338ae04fa6Smrg # With -d, create the new directory with the user-specified mode. 3348ae04fa6Smrg # Otherwise, rely on $mkdir_umask. 3358ae04fa6Smrg if test -n "$dir_arg"; then 3368ae04fa6Smrg mkdir_mode=-m$mode 3378ae04fa6Smrg else 3388ae04fa6Smrg mkdir_mode= 3398ae04fa6Smrg fi 3408ae04fa6Smrg 3418ae04fa6Smrg posix_mkdir=false 3428ae04fa6Smrg case $umask in 3438ae04fa6Smrg *[123567][0-7][0-7]) 3448ae04fa6Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3458ae04fa6Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3468ae04fa6Smrg ;; 3478ae04fa6Smrg *) 3488ae04fa6Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3498ae04fa6Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3508ae04fa6Smrg 3518ae04fa6Smrg if (umask $mkdir_umask && 3528ae04fa6Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3538ae04fa6Smrg then 3548ae04fa6Smrg if test -z "$dir_arg" || { 3558ae04fa6Smrg # Check for POSIX incompatibilities with -m. 3568ae04fa6Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3578ae04fa6Smrg # other-writeable bit of parent directory when it shouldn't. 3588ae04fa6Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3598ae04fa6Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3608ae04fa6Smrg case $ls_ld_tmpdir in 3618ae04fa6Smrg d????-?r-*) different_mode=700;; 3628ae04fa6Smrg d????-?--*) different_mode=755;; 3638ae04fa6Smrg *) false;; 3648ae04fa6Smrg esac && 3658ae04fa6Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3668ae04fa6Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3678ae04fa6Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3688ae04fa6Smrg } 3698ae04fa6Smrg } 3708ae04fa6Smrg then posix_mkdir=: 3718ae04fa6Smrg fi 3728ae04fa6Smrg rmdir "$tmpdir/d" "$tmpdir" 3738ae04fa6Smrg else 3748ae04fa6Smrg # Remove any dirs left behind by ancient mkdir implementations. 3758ae04fa6Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3768ae04fa6Smrg fi 3778ae04fa6Smrg trap '' 0;; 3788ae04fa6Smrg esac;; 3798ae04fa6Smrg esac 3808ae04fa6Smrg 3818ae04fa6Smrg if 3828ae04fa6Smrg $posix_mkdir && ( 3838ae04fa6Smrg umask $mkdir_umask && 3848ae04fa6Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3858ae04fa6Smrg ) 3868ae04fa6Smrg then : 3878ae04fa6Smrg else 3888ae04fa6Smrg 3898ae04fa6Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3908ae04fa6Smrg # or it failed possibly due to a race condition. Create the 3918ae04fa6Smrg # directory the slow way, step by step, checking for races as we go. 3928ae04fa6Smrg 3938ae04fa6Smrg case $dstdir in 39444af7230Smrg /*) prefix='/';; 395405c8079Smrg [-=\(\)!]*) prefix='./';; 39644af7230Smrg *) prefix='';; 3978ae04fa6Smrg esac 3988ae04fa6Smrg 39944af7230Smrg eval "$initialize_posix_glob" 4008ae04fa6Smrg 4018ae04fa6Smrg oIFS=$IFS 4028ae04fa6Smrg IFS=/ 40344af7230Smrg $posix_glob set -f 4048ae04fa6Smrg set fnord $dstdir 4058ae04fa6Smrg shift 40644af7230Smrg $posix_glob set +f 4078ae04fa6Smrg IFS=$oIFS 4088ae04fa6Smrg 4098ae04fa6Smrg prefixes= 4108ae04fa6Smrg 4118ae04fa6Smrg for d 4128ae04fa6Smrg do 413405c8079Smrg test X"$d" = X && continue 4148ae04fa6Smrg 4158ae04fa6Smrg prefix=$prefix$d 4168ae04fa6Smrg if test -d "$prefix"; then 4178ae04fa6Smrg prefixes= 4188ae04fa6Smrg else 4198ae04fa6Smrg if $posix_mkdir; then 4208ae04fa6Smrg (umask=$mkdir_umask && 4218ae04fa6Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4228ae04fa6Smrg # Don't fail if two instances are running concurrently. 4238ae04fa6Smrg test -d "$prefix" || exit 1 4248ae04fa6Smrg else 4258ae04fa6Smrg case $prefix in 4268ae04fa6Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4278ae04fa6Smrg *) qprefix=$prefix;; 4288ae04fa6Smrg esac 4298ae04fa6Smrg prefixes="$prefixes '$qprefix'" 4308ae04fa6Smrg fi 4318ae04fa6Smrg fi 4328ae04fa6Smrg prefix=$prefix/ 4338ae04fa6Smrg done 4348ae04fa6Smrg 4358ae04fa6Smrg if test -n "$prefixes"; then 4368ae04fa6Smrg # Don't fail if two instances are running concurrently. 4378ae04fa6Smrg (umask $mkdir_umask && 4388ae04fa6Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4398ae04fa6Smrg test -d "$dstdir" || exit 1 4408ae04fa6Smrg obsolete_mkdir_used=true 4418ae04fa6Smrg fi 4428ae04fa6Smrg fi 4438ae04fa6Smrg fi 4448ae04fa6Smrg 4458ae04fa6Smrg if test -n "$dir_arg"; then 4468ae04fa6Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4478ae04fa6Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4488ae04fa6Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4498ae04fa6Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4508ae04fa6Smrg else 4518ae04fa6Smrg 4528ae04fa6Smrg # Make a couple of temp file names in the proper directory. 4538ae04fa6Smrg dsttmp=$dstdir/_inst.$$_ 4548ae04fa6Smrg rmtmp=$dstdir/_rm.$$_ 4558ae04fa6Smrg 4568ae04fa6Smrg # Trap to clean up those temp files at exit. 4578ae04fa6Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4588ae04fa6Smrg 4598ae04fa6Smrg # Copy the file name to the temp name. 4608ae04fa6Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4618ae04fa6Smrg 4628ae04fa6Smrg # and set any options; do chmod last to preserve setuid bits. 4638ae04fa6Smrg # 4648ae04fa6Smrg # If any of these fail, we abort the whole thing. If we want to 4658ae04fa6Smrg # ignore errors from any of these, just make sure not to ignore 4668ae04fa6Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4678ae04fa6Smrg # 46844af7230Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46944af7230Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 47044af7230Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 47144af7230Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 47244af7230Smrg 47344af7230Smrg # If -C, don't bother to copy if it wouldn't change the file. 47444af7230Smrg if $copy_on_change && 47544af7230Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 47644af7230Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47744af7230Smrg 47844af7230Smrg eval "$initialize_posix_glob" && 47944af7230Smrg $posix_glob set -f && 48044af7230Smrg set X $old && old=:$2:$4:$5:$6 && 48144af7230Smrg set X $new && new=:$2:$4:$5:$6 && 48244af7230Smrg $posix_glob set +f && 48344af7230Smrg 48444af7230Smrg test "$old" = "$new" && 48544af7230Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 48644af7230Smrg then 48744af7230Smrg rm -f "$dsttmp" 48844af7230Smrg else 48944af7230Smrg # Rename the file to the real destination. 49044af7230Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 49144af7230Smrg 49244af7230Smrg # The rename failed, perhaps because mv can't rename something else 49344af7230Smrg # to itself, or perhaps because mv is so ancient that it does not 49444af7230Smrg # support -f. 49544af7230Smrg { 49644af7230Smrg # Now remove or move aside any old file at destination location. 49744af7230Smrg # We try this two ways since rm can't unlink itself on some 49844af7230Smrg # systems and the destination file might be busy for other 49944af7230Smrg # reasons. In this case, the final cleanup might fail but the new 50044af7230Smrg # file should still install successfully. 50144af7230Smrg { 50244af7230Smrg test ! -f "$dst" || 50344af7230Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 50444af7230Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 50544af7230Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 50644af7230Smrg } || 50744af7230Smrg { echo "$0: cannot unlink or rename $dst" >&2 50844af7230Smrg (exit 1); exit 1 50944af7230Smrg } 51044af7230Smrg } && 51144af7230Smrg 51244af7230Smrg # Now rename the file to the real destination. 51344af7230Smrg $doit $mvcmd "$dsttmp" "$dst" 51444af7230Smrg } 51544af7230Smrg fi || exit 1 5168ae04fa6Smrg 5178ae04fa6Smrg trap '' 0 5188ae04fa6Smrg fi 5198ae04fa6Smrgdone 5208ae04fa6Smrg 5218ae04fa6Smrg# Local variables: 5228ae04fa6Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5238ae04fa6Smrg# time-stamp-start: "scriptversion=" 5248ae04fa6Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52544af7230Smrg# time-stamp-time-zone: "UTC" 52644af7230Smrg# time-stamp-end: "; # UTC" 5278ae04fa6Smrg# End: 528