install-sh revision 9bd41f2c
19bd41f2cSmrg#!/bin/sh 29bd41f2cSmrg# install - install a program, script, or datafile 39bd41f2cSmrg 49bd41f2cSmrgscriptversion=2006-10-14.15 59bd41f2cSmrg 69bd41f2cSmrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 79bd41f2cSmrg# later released in X11R6 (xc/config/util/install.sh) with the 89bd41f2cSmrg# following copyright and license. 99bd41f2cSmrg# 109bd41f2cSmrg# Copyright (C) 1994 X Consortium 119bd41f2cSmrg# 129bd41f2cSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy 139bd41f2cSmrg# of this software and associated documentation files (the "Software"), to 149bd41f2cSmrg# deal in the Software without restriction, including without limitation the 159bd41f2cSmrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 169bd41f2cSmrg# sell copies of the Software, and to permit persons to whom the Software is 179bd41f2cSmrg# furnished to do so, subject to the following conditions: 189bd41f2cSmrg# 199bd41f2cSmrg# The above copyright notice and this permission notice shall be included in 209bd41f2cSmrg# all copies or substantial portions of the Software. 219bd41f2cSmrg# 229bd41f2cSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 239bd41f2cSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 249bd41f2cSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259bd41f2cSmrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 269bd41f2cSmrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 279bd41f2cSmrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 289bd41f2cSmrg# 299bd41f2cSmrg# Except as contained in this notice, the name of the X Consortium shall not 309bd41f2cSmrg# be used in advertising or otherwise to promote the sale, use or other deal- 319bd41f2cSmrg# ings in this Software without prior written authorization from the X Consor- 329bd41f2cSmrg# tium. 339bd41f2cSmrg# 349bd41f2cSmrg# 359bd41f2cSmrg# FSF changes to this file are in the public domain. 369bd41f2cSmrg# 379bd41f2cSmrg# Calling this script install-sh is preferred over install.sh, to prevent 389bd41f2cSmrg# `make' implicit rules from creating a file called install from it 399bd41f2cSmrg# when there is no Makefile. 409bd41f2cSmrg# 419bd41f2cSmrg# This script is compatible with the BSD install script, but was written 429bd41f2cSmrg# from scratch. 439bd41f2cSmrg 449bd41f2cSmrgnl=' 459bd41f2cSmrg' 469bd41f2cSmrgIFS=" "" $nl" 479bd41f2cSmrg 489bd41f2cSmrg# set DOITPROG to echo to test this script 499bd41f2cSmrg 509bd41f2cSmrg# Don't use :- since 4.3BSD and earlier shells don't like it. 519bd41f2cSmrgdoit="${DOITPROG-}" 529bd41f2cSmrgif test -z "$doit"; then 539bd41f2cSmrg doit_exec=exec 549bd41f2cSmrgelse 559bd41f2cSmrg doit_exec=$doit 569bd41f2cSmrgfi 579bd41f2cSmrg 589bd41f2cSmrg# Put in absolute file names if you don't have them in your path; 599bd41f2cSmrg# or use environment vars. 609bd41f2cSmrg 619bd41f2cSmrgmvprog="${MVPROG-mv}" 629bd41f2cSmrgcpprog="${CPPROG-cp}" 639bd41f2cSmrgchmodprog="${CHMODPROG-chmod}" 649bd41f2cSmrgchownprog="${CHOWNPROG-chown}" 659bd41f2cSmrgchgrpprog="${CHGRPPROG-chgrp}" 669bd41f2cSmrgstripprog="${STRIPPROG-strip}" 679bd41f2cSmrgrmprog="${RMPROG-rm}" 689bd41f2cSmrgmkdirprog="${MKDIRPROG-mkdir}" 699bd41f2cSmrg 709bd41f2cSmrgposix_glob= 719bd41f2cSmrgposix_mkdir= 729bd41f2cSmrg 739bd41f2cSmrg# Desired mode of installed file. 749bd41f2cSmrgmode=0755 759bd41f2cSmrg 769bd41f2cSmrgchmodcmd=$chmodprog 779bd41f2cSmrgchowncmd= 789bd41f2cSmrgchgrpcmd= 799bd41f2cSmrgstripcmd= 809bd41f2cSmrgrmcmd="$rmprog -f" 819bd41f2cSmrgmvcmd="$mvprog" 829bd41f2cSmrgsrc= 839bd41f2cSmrgdst= 849bd41f2cSmrgdir_arg= 859bd41f2cSmrgdstarg= 869bd41f2cSmrgno_target_directory= 879bd41f2cSmrg 889bd41f2cSmrgusage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 899bd41f2cSmrg or: $0 [OPTION]... SRCFILES... DIRECTORY 909bd41f2cSmrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 919bd41f2cSmrg or: $0 [OPTION]... -d DIRECTORIES... 929bd41f2cSmrg 939bd41f2cSmrgIn the 1st form, copy SRCFILE to DSTFILE. 949bd41f2cSmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 959bd41f2cSmrgIn the 4th, create DIRECTORIES. 969bd41f2cSmrg 979bd41f2cSmrgOptions: 989bd41f2cSmrg-c (ignored) 999bd41f2cSmrg-d create directories instead of installing files. 1009bd41f2cSmrg-g GROUP $chgrpprog installed files to GROUP. 1019bd41f2cSmrg-m MODE $chmodprog installed files to MODE. 1029bd41f2cSmrg-o USER $chownprog installed files to USER. 1039bd41f2cSmrg-s $stripprog installed files. 1049bd41f2cSmrg-t DIRECTORY install into DIRECTORY. 1059bd41f2cSmrg-T report an error if DSTFILE is a directory. 1069bd41f2cSmrg--help display this help and exit. 1079bd41f2cSmrg--version display version info and exit. 1089bd41f2cSmrg 1099bd41f2cSmrgEnvironment variables override the default commands: 1109bd41f2cSmrg CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 1119bd41f2cSmrg" 1129bd41f2cSmrg 1139bd41f2cSmrgwhile test $# -ne 0; do 1149bd41f2cSmrg case $1 in 1159bd41f2cSmrg -c) shift 1169bd41f2cSmrg continue;; 1179bd41f2cSmrg 1189bd41f2cSmrg -d) dir_arg=true 1199bd41f2cSmrg shift 1209bd41f2cSmrg continue;; 1219bd41f2cSmrg 1229bd41f2cSmrg -g) chgrpcmd="$chgrpprog $2" 1239bd41f2cSmrg shift 1249bd41f2cSmrg shift 1259bd41f2cSmrg continue;; 1269bd41f2cSmrg 1279bd41f2cSmrg --help) echo "$usage"; exit $?;; 1289bd41f2cSmrg 1299bd41f2cSmrg -m) mode=$2 1309bd41f2cSmrg shift 1319bd41f2cSmrg shift 1329bd41f2cSmrg case $mode in 1339bd41f2cSmrg *' '* | *' '* | *' 1349bd41f2cSmrg'* | *'*'* | *'?'* | *'['*) 1359bd41f2cSmrg echo "$0: invalid mode: $mode" >&2 1369bd41f2cSmrg exit 1;; 1379bd41f2cSmrg esac 1389bd41f2cSmrg continue;; 1399bd41f2cSmrg 1409bd41f2cSmrg -o) chowncmd="$chownprog $2" 1419bd41f2cSmrg shift 1429bd41f2cSmrg shift 1439bd41f2cSmrg continue;; 1449bd41f2cSmrg 1459bd41f2cSmrg -s) stripcmd=$stripprog 1469bd41f2cSmrg shift 1479bd41f2cSmrg continue;; 1489bd41f2cSmrg 1499bd41f2cSmrg -t) dstarg=$2 1509bd41f2cSmrg shift 1519bd41f2cSmrg shift 1529bd41f2cSmrg continue;; 1539bd41f2cSmrg 1549bd41f2cSmrg -T) no_target_directory=true 1559bd41f2cSmrg shift 1569bd41f2cSmrg continue;; 1579bd41f2cSmrg 1589bd41f2cSmrg --version) echo "$0 $scriptversion"; exit $?;; 1599bd41f2cSmrg 1609bd41f2cSmrg --) shift 1619bd41f2cSmrg break;; 1629bd41f2cSmrg 1639bd41f2cSmrg -*) echo "$0: invalid option: $1" >&2 1649bd41f2cSmrg exit 1;; 1659bd41f2cSmrg 1669bd41f2cSmrg *) break;; 1679bd41f2cSmrg esac 1689bd41f2cSmrgdone 1699bd41f2cSmrg 1709bd41f2cSmrgif test $# -ne 0 && test -z "$dir_arg$dstarg"; then 1719bd41f2cSmrg # When -d is used, all remaining arguments are directories to create. 1729bd41f2cSmrg # When -t is used, the destination is already specified. 1739bd41f2cSmrg # Otherwise, the last argument is the destination. Remove it from $@. 1749bd41f2cSmrg for arg 1759bd41f2cSmrg do 1769bd41f2cSmrg if test -n "$dstarg"; then 1779bd41f2cSmrg # $@ is not empty: it contains at least $arg. 1789bd41f2cSmrg set fnord "$@" "$dstarg" 1799bd41f2cSmrg shift # fnord 1809bd41f2cSmrg fi 1819bd41f2cSmrg shift # arg 1829bd41f2cSmrg dstarg=$arg 1839bd41f2cSmrg done 1849bd41f2cSmrgfi 1859bd41f2cSmrg 1869bd41f2cSmrgif test $# -eq 0; then 1879bd41f2cSmrg if test -z "$dir_arg"; then 1889bd41f2cSmrg echo "$0: no input file specified." >&2 1899bd41f2cSmrg exit 1 1909bd41f2cSmrg fi 1919bd41f2cSmrg # It's OK to call `install-sh -d' without argument. 1929bd41f2cSmrg # This can happen when creating conditional directories. 1939bd41f2cSmrg exit 0 1949bd41f2cSmrgfi 1959bd41f2cSmrg 1969bd41f2cSmrgif test -z "$dir_arg"; then 1979bd41f2cSmrg trap '(exit $?); exit' 1 2 13 15 1989bd41f2cSmrg 1999bd41f2cSmrg # Set umask so as not to create temps with too-generous modes. 2009bd41f2cSmrg # However, 'strip' requires both read and write access to temps. 2019bd41f2cSmrg case $mode in 2029bd41f2cSmrg # Optimize common cases. 2039bd41f2cSmrg *644) cp_umask=133;; 2049bd41f2cSmrg *755) cp_umask=22;; 2059bd41f2cSmrg 2069bd41f2cSmrg *[0-7]) 2079bd41f2cSmrg if test -z "$stripcmd"; then 2089bd41f2cSmrg u_plus_rw= 2099bd41f2cSmrg else 2109bd41f2cSmrg u_plus_rw='% 200' 2119bd41f2cSmrg fi 2129bd41f2cSmrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2139bd41f2cSmrg *) 2149bd41f2cSmrg if test -z "$stripcmd"; then 2159bd41f2cSmrg u_plus_rw= 2169bd41f2cSmrg else 2179bd41f2cSmrg u_plus_rw=,u+rw 2189bd41f2cSmrg fi 2199bd41f2cSmrg cp_umask=$mode$u_plus_rw;; 2209bd41f2cSmrg esac 2219bd41f2cSmrgfi 2229bd41f2cSmrg 2239bd41f2cSmrgfor src 2249bd41f2cSmrgdo 2259bd41f2cSmrg # Protect names starting with `-'. 2269bd41f2cSmrg case $src in 2279bd41f2cSmrg -*) src=./$src ;; 2289bd41f2cSmrg esac 2299bd41f2cSmrg 2309bd41f2cSmrg if test -n "$dir_arg"; then 2319bd41f2cSmrg dst=$src 2329bd41f2cSmrg dstdir=$dst 2339bd41f2cSmrg test -d "$dstdir" 2349bd41f2cSmrg dstdir_status=$? 2359bd41f2cSmrg else 2369bd41f2cSmrg 2379bd41f2cSmrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2389bd41f2cSmrg # might cause directories to be created, which would be especially bad 2399bd41f2cSmrg # if $src (and thus $dsttmp) contains '*'. 2409bd41f2cSmrg if test ! -f "$src" && test ! -d "$src"; then 2419bd41f2cSmrg echo "$0: $src does not exist." >&2 2429bd41f2cSmrg exit 1 2439bd41f2cSmrg fi 2449bd41f2cSmrg 2459bd41f2cSmrg if test -z "$dstarg"; then 2469bd41f2cSmrg echo "$0: no destination specified." >&2 2479bd41f2cSmrg exit 1 2489bd41f2cSmrg fi 2499bd41f2cSmrg 2509bd41f2cSmrg dst=$dstarg 2519bd41f2cSmrg # Protect names starting with `-'. 2529bd41f2cSmrg case $dst in 2539bd41f2cSmrg -*) dst=./$dst ;; 2549bd41f2cSmrg esac 2559bd41f2cSmrg 2569bd41f2cSmrg # If destination is a directory, append the input filename; won't work 2579bd41f2cSmrg # if double slashes aren't ignored. 2589bd41f2cSmrg if test -d "$dst"; then 2599bd41f2cSmrg if test -n "$no_target_directory"; then 2609bd41f2cSmrg echo "$0: $dstarg: Is a directory" >&2 2619bd41f2cSmrg exit 1 2629bd41f2cSmrg fi 2639bd41f2cSmrg dstdir=$dst 2649bd41f2cSmrg dst=$dstdir/`basename "$src"` 2659bd41f2cSmrg dstdir_status=0 2669bd41f2cSmrg else 2679bd41f2cSmrg # Prefer dirname, but fall back on a substitute if dirname fails. 2689bd41f2cSmrg dstdir=` 2699bd41f2cSmrg (dirname "$dst") 2>/dev/null || 2709bd41f2cSmrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2719bd41f2cSmrg X"$dst" : 'X\(//\)[^/]' \| \ 2729bd41f2cSmrg X"$dst" : 'X\(//\)$' \| \ 2739bd41f2cSmrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2749bd41f2cSmrg echo X"$dst" | 2759bd41f2cSmrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2769bd41f2cSmrg s//\1/ 2779bd41f2cSmrg q 2789bd41f2cSmrg } 2799bd41f2cSmrg /^X\(\/\/\)[^/].*/{ 2809bd41f2cSmrg s//\1/ 2819bd41f2cSmrg q 2829bd41f2cSmrg } 2839bd41f2cSmrg /^X\(\/\/\)$/{ 2849bd41f2cSmrg s//\1/ 2859bd41f2cSmrg q 2869bd41f2cSmrg } 2879bd41f2cSmrg /^X\(\/\).*/{ 2889bd41f2cSmrg s//\1/ 2899bd41f2cSmrg q 2909bd41f2cSmrg } 2919bd41f2cSmrg s/.*/./; q' 2929bd41f2cSmrg ` 2939bd41f2cSmrg 2949bd41f2cSmrg test -d "$dstdir" 2959bd41f2cSmrg dstdir_status=$? 2969bd41f2cSmrg fi 2979bd41f2cSmrg fi 2989bd41f2cSmrg 2999bd41f2cSmrg obsolete_mkdir_used=false 3009bd41f2cSmrg 3019bd41f2cSmrg if test $dstdir_status != 0; then 3029bd41f2cSmrg case $posix_mkdir in 3039bd41f2cSmrg '') 3049bd41f2cSmrg # Create intermediate dirs using mode 755 as modified by the umask. 3059bd41f2cSmrg # This is like FreeBSD 'install' as of 1997-10-28. 3069bd41f2cSmrg umask=`umask` 3079bd41f2cSmrg case $stripcmd.$umask in 3089bd41f2cSmrg # Optimize common cases. 3099bd41f2cSmrg *[2367][2367]) mkdir_umask=$umask;; 3109bd41f2cSmrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3119bd41f2cSmrg 3129bd41f2cSmrg *[0-7]) 3139bd41f2cSmrg mkdir_umask=`expr $umask + 22 \ 3149bd41f2cSmrg - $umask % 100 % 40 + $umask % 20 \ 3159bd41f2cSmrg - $umask % 10 % 4 + $umask % 2 3169bd41f2cSmrg `;; 3179bd41f2cSmrg *) mkdir_umask=$umask,go-w;; 3189bd41f2cSmrg esac 3199bd41f2cSmrg 3209bd41f2cSmrg # With -d, create the new directory with the user-specified mode. 3219bd41f2cSmrg # Otherwise, rely on $mkdir_umask. 3229bd41f2cSmrg if test -n "$dir_arg"; then 3239bd41f2cSmrg mkdir_mode=-m$mode 3249bd41f2cSmrg else 3259bd41f2cSmrg mkdir_mode= 3269bd41f2cSmrg fi 3279bd41f2cSmrg 3289bd41f2cSmrg posix_mkdir=false 3299bd41f2cSmrg case $umask in 3309bd41f2cSmrg *[123567][0-7][0-7]) 3319bd41f2cSmrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3329bd41f2cSmrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3339bd41f2cSmrg ;; 3349bd41f2cSmrg *) 3359bd41f2cSmrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3369bd41f2cSmrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3379bd41f2cSmrg 3389bd41f2cSmrg if (umask $mkdir_umask && 3399bd41f2cSmrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3409bd41f2cSmrg then 3419bd41f2cSmrg if test -z "$dir_arg" || { 3429bd41f2cSmrg # Check for POSIX incompatibilities with -m. 3439bd41f2cSmrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3449bd41f2cSmrg # other-writeable bit of parent directory when it shouldn't. 3459bd41f2cSmrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3469bd41f2cSmrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3479bd41f2cSmrg case $ls_ld_tmpdir in 3489bd41f2cSmrg d????-?r-*) different_mode=700;; 3499bd41f2cSmrg d????-?--*) different_mode=755;; 3509bd41f2cSmrg *) false;; 3519bd41f2cSmrg esac && 3529bd41f2cSmrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3539bd41f2cSmrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3549bd41f2cSmrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3559bd41f2cSmrg } 3569bd41f2cSmrg } 3579bd41f2cSmrg then posix_mkdir=: 3589bd41f2cSmrg fi 3599bd41f2cSmrg rmdir "$tmpdir/d" "$tmpdir" 3609bd41f2cSmrg else 3619bd41f2cSmrg # Remove any dirs left behind by ancient mkdir implementations. 3629bd41f2cSmrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3639bd41f2cSmrg fi 3649bd41f2cSmrg trap '' 0;; 3659bd41f2cSmrg esac;; 3669bd41f2cSmrg esac 3679bd41f2cSmrg 3689bd41f2cSmrg if 3699bd41f2cSmrg $posix_mkdir && ( 3709bd41f2cSmrg umask $mkdir_umask && 3719bd41f2cSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3729bd41f2cSmrg ) 3739bd41f2cSmrg then : 3749bd41f2cSmrg else 3759bd41f2cSmrg 3769bd41f2cSmrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3779bd41f2cSmrg # or it failed possibly due to a race condition. Create the 3789bd41f2cSmrg # directory the slow way, step by step, checking for races as we go. 3799bd41f2cSmrg 3809bd41f2cSmrg case $dstdir in 3819bd41f2cSmrg /*) prefix=/ ;; 3829bd41f2cSmrg -*) prefix=./ ;; 3839bd41f2cSmrg *) prefix= ;; 3849bd41f2cSmrg esac 3859bd41f2cSmrg 3869bd41f2cSmrg case $posix_glob in 3879bd41f2cSmrg '') 3889bd41f2cSmrg if (set -f) 2>/dev/null; then 3899bd41f2cSmrg posix_glob=true 3909bd41f2cSmrg else 3919bd41f2cSmrg posix_glob=false 3929bd41f2cSmrg fi ;; 3939bd41f2cSmrg esac 3949bd41f2cSmrg 3959bd41f2cSmrg oIFS=$IFS 3969bd41f2cSmrg IFS=/ 3979bd41f2cSmrg $posix_glob && set -f 3989bd41f2cSmrg set fnord $dstdir 3999bd41f2cSmrg shift 4009bd41f2cSmrg $posix_glob && set +f 4019bd41f2cSmrg IFS=$oIFS 4029bd41f2cSmrg 4039bd41f2cSmrg prefixes= 4049bd41f2cSmrg 4059bd41f2cSmrg for d 4069bd41f2cSmrg do 4079bd41f2cSmrg test -z "$d" && continue 4089bd41f2cSmrg 4099bd41f2cSmrg prefix=$prefix$d 4109bd41f2cSmrg if test -d "$prefix"; then 4119bd41f2cSmrg prefixes= 4129bd41f2cSmrg else 4139bd41f2cSmrg if $posix_mkdir; then 4149bd41f2cSmrg (umask=$mkdir_umask && 4159bd41f2cSmrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4169bd41f2cSmrg # Don't fail if two instances are running concurrently. 4179bd41f2cSmrg test -d "$prefix" || exit 1 4189bd41f2cSmrg else 4199bd41f2cSmrg case $prefix in 4209bd41f2cSmrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4219bd41f2cSmrg *) qprefix=$prefix;; 4229bd41f2cSmrg esac 4239bd41f2cSmrg prefixes="$prefixes '$qprefix'" 4249bd41f2cSmrg fi 4259bd41f2cSmrg fi 4269bd41f2cSmrg prefix=$prefix/ 4279bd41f2cSmrg done 4289bd41f2cSmrg 4299bd41f2cSmrg if test -n "$prefixes"; then 4309bd41f2cSmrg # Don't fail if two instances are running concurrently. 4319bd41f2cSmrg (umask $mkdir_umask && 4329bd41f2cSmrg eval "\$doit_exec \$mkdirprog $prefixes") || 4339bd41f2cSmrg test -d "$dstdir" || exit 1 4349bd41f2cSmrg obsolete_mkdir_used=true 4359bd41f2cSmrg fi 4369bd41f2cSmrg fi 4379bd41f2cSmrg fi 4389bd41f2cSmrg 4399bd41f2cSmrg if test -n "$dir_arg"; then 4409bd41f2cSmrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4419bd41f2cSmrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4429bd41f2cSmrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4439bd41f2cSmrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4449bd41f2cSmrg else 4459bd41f2cSmrg 4469bd41f2cSmrg # Make a couple of temp file names in the proper directory. 4479bd41f2cSmrg dsttmp=$dstdir/_inst.$$_ 4489bd41f2cSmrg rmtmp=$dstdir/_rm.$$_ 4499bd41f2cSmrg 4509bd41f2cSmrg # Trap to clean up those temp files at exit. 4519bd41f2cSmrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4529bd41f2cSmrg 4539bd41f2cSmrg # Copy the file name to the temp name. 4549bd41f2cSmrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4559bd41f2cSmrg 4569bd41f2cSmrg # and set any options; do chmod last to preserve setuid bits. 4579bd41f2cSmrg # 4589bd41f2cSmrg # If any of these fail, we abort the whole thing. If we want to 4599bd41f2cSmrg # ignore errors from any of these, just make sure not to ignore 4609bd41f2cSmrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4619bd41f2cSmrg # 4629bd41f2cSmrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 4639bd41f2cSmrg && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 4649bd41f2cSmrg && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ 4659bd41f2cSmrg && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 4669bd41f2cSmrg 4679bd41f2cSmrg # Now rename the file to the real destination. 4689bd41f2cSmrg { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \ 4699bd41f2cSmrg || { 4709bd41f2cSmrg # The rename failed, perhaps because mv can't rename something else 4719bd41f2cSmrg # to itself, or perhaps because mv is so ancient that it does not 4729bd41f2cSmrg # support -f. 4739bd41f2cSmrg 4749bd41f2cSmrg # Now remove or move aside any old file at destination location. 4759bd41f2cSmrg # We try this two ways since rm can't unlink itself on some 4769bd41f2cSmrg # systems and the destination file might be busy for other 4779bd41f2cSmrg # reasons. In this case, the final cleanup might fail but the new 4789bd41f2cSmrg # file should still install successfully. 4799bd41f2cSmrg { 4809bd41f2cSmrg if test -f "$dst"; then 4819bd41f2cSmrg $doit $rmcmd -f "$dst" 2>/dev/null \ 4829bd41f2cSmrg || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \ 4839bd41f2cSmrg && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\ 4849bd41f2cSmrg || { 4859bd41f2cSmrg echo "$0: cannot unlink or rename $dst" >&2 4869bd41f2cSmrg (exit 1); exit 1 4879bd41f2cSmrg } 4889bd41f2cSmrg else 4899bd41f2cSmrg : 4909bd41f2cSmrg fi 4919bd41f2cSmrg } && 4929bd41f2cSmrg 4939bd41f2cSmrg # Now rename the file to the real destination. 4949bd41f2cSmrg $doit $mvcmd "$dsttmp" "$dst" 4959bd41f2cSmrg } 4969bd41f2cSmrg } || exit 1 4979bd41f2cSmrg 4989bd41f2cSmrg trap '' 0 4999bd41f2cSmrg fi 5009bd41f2cSmrgdone 5019bd41f2cSmrg 5029bd41f2cSmrg# Local variables: 5039bd41f2cSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5049bd41f2cSmrg# time-stamp-start: "scriptversion=" 5059bd41f2cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 5069bd41f2cSmrg# time-stamp-end: "$" 5079bd41f2cSmrg# End: 508