install-sh revision e5410a46
11f0ac6a5Smrg#!/bin/sh 21f0ac6a5Smrg# install - install a program, script, or datafile 31f0ac6a5Smrg 4e5410a46Smrgscriptversion=2009-04-28.21; # UTC 51f0ac6a5Smrg 61f0ac6a5Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 71f0ac6a5Smrg# later released in X11R6 (xc/config/util/install.sh) with the 81f0ac6a5Smrg# following copyright and license. 91f0ac6a5Smrg# 101f0ac6a5Smrg# Copyright (C) 1994 X Consortium 111f0ac6a5Smrg# 121f0ac6a5Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 131f0ac6a5Smrg# of this software and associated documentation files (the "Software"), to 141f0ac6a5Smrg# deal in the Software without restriction, including without limitation the 151f0ac6a5Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 161f0ac6a5Smrg# sell copies of the Software, and to permit persons to whom the Software is 171f0ac6a5Smrg# furnished to do so, subject to the following conditions: 181f0ac6a5Smrg# 191f0ac6a5Smrg# The above copyright notice and this permission notice shall be included in 201f0ac6a5Smrg# all copies or substantial portions of the Software. 211f0ac6a5Smrg# 221f0ac6a5Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 231f0ac6a5Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 241f0ac6a5Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 251f0ac6a5Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 261f0ac6a5Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 271f0ac6a5Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 281f0ac6a5Smrg# 291f0ac6a5Smrg# Except as contained in this notice, the name of the X Consortium shall not 301f0ac6a5Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 311f0ac6a5Smrg# ings in this Software without prior written authorization from the X Consor- 321f0ac6a5Smrg# tium. 331f0ac6a5Smrg# 341f0ac6a5Smrg# 351f0ac6a5Smrg# FSF changes to this file are in the public domain. 361f0ac6a5Smrg# 371f0ac6a5Smrg# Calling this script install-sh is preferred over install.sh, to prevent 381f0ac6a5Smrg# `make' implicit rules from creating a file called install from it 391f0ac6a5Smrg# when there is no Makefile. 401f0ac6a5Smrg# 411f0ac6a5Smrg# This script is compatible with the BSD install script, but was written 421f0ac6a5Smrg# from scratch. 431f0ac6a5Smrg 441f0ac6a5Smrgnl=' 451f0ac6a5Smrg' 461f0ac6a5SmrgIFS=" "" $nl" 471f0ac6a5Smrg 481f0ac6a5Smrg# set DOITPROG to echo to test this script 491f0ac6a5Smrg 501f0ac6a5Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 51e5410a46Smrgdoit=${DOITPROG-} 521f0ac6a5Smrgif test -z "$doit"; then 531f0ac6a5Smrg doit_exec=exec 541f0ac6a5Smrgelse 551f0ac6a5Smrg doit_exec=$doit 561f0ac6a5Smrgfi 571f0ac6a5Smrg 581f0ac6a5Smrg# Put in absolute file names if you don't have them in your path; 591f0ac6a5Smrg# or use environment vars. 601f0ac6a5Smrg 61e5410a46Smrgchgrpprog=${CHGRPPROG-chgrp} 62e5410a46Smrgchmodprog=${CHMODPROG-chmod} 63e5410a46Smrgchownprog=${CHOWNPROG-chown} 64e5410a46Smrgcmpprog=${CMPPROG-cmp} 65e5410a46Smrgcpprog=${CPPROG-cp} 66e5410a46Smrgmkdirprog=${MKDIRPROG-mkdir} 67e5410a46Smrgmvprog=${MVPROG-mv} 68e5410a46Smrgrmprog=${RMPROG-rm} 69e5410a46Smrgstripprog=${STRIPPROG-strip} 70e5410a46Smrg 71e5410a46Smrgposix_glob='?' 72e5410a46Smrginitialize_posix_glob=' 73e5410a46Smrg test "$posix_glob" != "?" || { 74e5410a46Smrg if (set -f) 2>/dev/null; then 75e5410a46Smrg posix_glob= 76e5410a46Smrg else 77e5410a46Smrg posix_glob=: 78e5410a46Smrg fi 79e5410a46Smrg } 80e5410a46Smrg' 811f0ac6a5Smrg 821f0ac6a5Smrgposix_mkdir= 831f0ac6a5Smrg 841f0ac6a5Smrg# Desired mode of installed file. 851f0ac6a5Smrgmode=0755 861f0ac6a5Smrg 87e5410a46Smrgchgrpcmd= 881f0ac6a5Smrgchmodcmd=$chmodprog 891f0ac6a5Smrgchowncmd= 90e5410a46Smrgmvcmd=$mvprog 911f0ac6a5Smrgrmcmd="$rmprog -f" 92e5410a46Smrgstripcmd= 93e5410a46Smrg 941f0ac6a5Smrgsrc= 951f0ac6a5Smrgdst= 961f0ac6a5Smrgdir_arg= 97e5410a46Smrgdst_arg= 98e5410a46Smrg 99e5410a46Smrgcopy_on_change=false 1001f0ac6a5Smrgno_target_directory= 1011f0ac6a5Smrg 102e5410a46Smrgusage="\ 103e5410a46SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1041f0ac6a5Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 1051f0ac6a5Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1061f0ac6a5Smrg or: $0 [OPTION]... -d DIRECTORIES... 1071f0ac6a5Smrg 1081f0ac6a5SmrgIn the 1st form, copy SRCFILE to DSTFILE. 1091f0ac6a5SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1101f0ac6a5SmrgIn the 4th, create DIRECTORIES. 1111f0ac6a5Smrg 1121f0ac6a5SmrgOptions: 113e5410a46Smrg --help display this help and exit. 114e5410a46Smrg --version display version info and exit. 115e5410a46Smrg 116e5410a46Smrg -c (ignored) 117e5410a46Smrg -C install only if different (preserve the last data modification time) 118e5410a46Smrg -d create directories instead of installing files. 119e5410a46Smrg -g GROUP $chgrpprog installed files to GROUP. 120e5410a46Smrg -m MODE $chmodprog installed files to MODE. 121e5410a46Smrg -o USER $chownprog installed files to USER. 122e5410a46Smrg -s $stripprog installed files. 123e5410a46Smrg -t DIRECTORY install into DIRECTORY. 124e5410a46Smrg -T report an error if DSTFILE is a directory. 1251f0ac6a5Smrg 1261f0ac6a5SmrgEnvironment variables override the default commands: 127e5410a46Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128e5410a46Smrg RMPROG STRIPPROG 1291f0ac6a5Smrg" 1301f0ac6a5Smrg 1311f0ac6a5Smrgwhile test $# -ne 0; do 1321f0ac6a5Smrg case $1 in 133e5410a46Smrg -c) ;; 134e5410a46Smrg 135e5410a46Smrg -C) copy_on_change=true;; 1361f0ac6a5Smrg 137e5410a46Smrg -d) dir_arg=true;; 1381f0ac6a5Smrg 1391f0ac6a5Smrg -g) chgrpcmd="$chgrpprog $2" 140e5410a46Smrg shift;; 1411f0ac6a5Smrg 1421f0ac6a5Smrg --help) echo "$usage"; exit $?;; 1431f0ac6a5Smrg 1441f0ac6a5Smrg -m) mode=$2 1451f0ac6a5Smrg case $mode in 1461f0ac6a5Smrg *' '* | *' '* | *' 1471f0ac6a5Smrg'* | *'*'* | *'?'* | *'['*) 1481f0ac6a5Smrg echo "$0: invalid mode: $mode" >&2 1491f0ac6a5Smrg exit 1;; 1501f0ac6a5Smrg esac 151e5410a46Smrg shift;; 1521f0ac6a5Smrg 1531f0ac6a5Smrg -o) chowncmd="$chownprog $2" 154e5410a46Smrg shift;; 1551f0ac6a5Smrg 156e5410a46Smrg -s) stripcmd=$stripprog;; 1571f0ac6a5Smrg 158e5410a46Smrg -t) dst_arg=$2 159e5410a46Smrg shift;; 1601f0ac6a5Smrg 161e5410a46Smrg -T) no_target_directory=true;; 1621f0ac6a5Smrg 1631f0ac6a5Smrg --version) echo "$0 $scriptversion"; exit $?;; 1641f0ac6a5Smrg 1651f0ac6a5Smrg --) shift 1661f0ac6a5Smrg break;; 1671f0ac6a5Smrg 1681f0ac6a5Smrg -*) echo "$0: invalid option: $1" >&2 1691f0ac6a5Smrg exit 1;; 1701f0ac6a5Smrg 1711f0ac6a5Smrg *) break;; 1721f0ac6a5Smrg esac 173e5410a46Smrg shift 1741f0ac6a5Smrgdone 1751f0ac6a5Smrg 176e5410a46Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 1771f0ac6a5Smrg # When -d is used, all remaining arguments are directories to create. 1781f0ac6a5Smrg # When -t is used, the destination is already specified. 1791f0ac6a5Smrg # Otherwise, the last argument is the destination. Remove it from $@. 1801f0ac6a5Smrg for arg 1811f0ac6a5Smrg do 182e5410a46Smrg if test -n "$dst_arg"; then 1831f0ac6a5Smrg # $@ is not empty: it contains at least $arg. 184e5410a46Smrg set fnord "$@" "$dst_arg" 1851f0ac6a5Smrg shift # fnord 1861f0ac6a5Smrg fi 1871f0ac6a5Smrg shift # arg 188e5410a46Smrg dst_arg=$arg 1891f0ac6a5Smrg done 1901f0ac6a5Smrgfi 1911f0ac6a5Smrg 1921f0ac6a5Smrgif test $# -eq 0; then 1931f0ac6a5Smrg if test -z "$dir_arg"; then 1941f0ac6a5Smrg echo "$0: no input file specified." >&2 1951f0ac6a5Smrg exit 1 1961f0ac6a5Smrg fi 1971f0ac6a5Smrg # It's OK to call `install-sh -d' without argument. 1981f0ac6a5Smrg # This can happen when creating conditional directories. 1991f0ac6a5Smrg exit 0 2001f0ac6a5Smrgfi 2011f0ac6a5Smrg 2021f0ac6a5Smrgif test -z "$dir_arg"; then 2031f0ac6a5Smrg trap '(exit $?); exit' 1 2 13 15 2041f0ac6a5Smrg 2051f0ac6a5Smrg # Set umask so as not to create temps with too-generous modes. 2061f0ac6a5Smrg # However, 'strip' requires both read and write access to temps. 2071f0ac6a5Smrg case $mode in 2081f0ac6a5Smrg # Optimize common cases. 2091f0ac6a5Smrg *644) cp_umask=133;; 2101f0ac6a5Smrg *755) cp_umask=22;; 2111f0ac6a5Smrg 2121f0ac6a5Smrg *[0-7]) 2131f0ac6a5Smrg if test -z "$stripcmd"; then 2141f0ac6a5Smrg u_plus_rw= 2151f0ac6a5Smrg else 2161f0ac6a5Smrg u_plus_rw='% 200' 2171f0ac6a5Smrg fi 2181f0ac6a5Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 2191f0ac6a5Smrg *) 2201f0ac6a5Smrg if test -z "$stripcmd"; then 2211f0ac6a5Smrg u_plus_rw= 2221f0ac6a5Smrg else 2231f0ac6a5Smrg u_plus_rw=,u+rw 2241f0ac6a5Smrg fi 2251f0ac6a5Smrg cp_umask=$mode$u_plus_rw;; 2261f0ac6a5Smrg esac 2271f0ac6a5Smrgfi 2281f0ac6a5Smrg 2291f0ac6a5Smrgfor src 2301f0ac6a5Smrgdo 2311f0ac6a5Smrg # Protect names starting with `-'. 2321f0ac6a5Smrg case $src in 233e5410a46Smrg -*) src=./$src;; 2341f0ac6a5Smrg esac 2351f0ac6a5Smrg 2361f0ac6a5Smrg if test -n "$dir_arg"; then 2371f0ac6a5Smrg dst=$src 2381f0ac6a5Smrg dstdir=$dst 2391f0ac6a5Smrg test -d "$dstdir" 2401f0ac6a5Smrg dstdir_status=$? 2411f0ac6a5Smrg else 2421f0ac6a5Smrg 2431f0ac6a5Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 2441f0ac6a5Smrg # might cause directories to be created, which would be especially bad 2451f0ac6a5Smrg # if $src (and thus $dsttmp) contains '*'. 2461f0ac6a5Smrg if test ! -f "$src" && test ! -d "$src"; then 2471f0ac6a5Smrg echo "$0: $src does not exist." >&2 2481f0ac6a5Smrg exit 1 2491f0ac6a5Smrg fi 2501f0ac6a5Smrg 251e5410a46Smrg if test -z "$dst_arg"; then 2521f0ac6a5Smrg echo "$0: no destination specified." >&2 2531f0ac6a5Smrg exit 1 2541f0ac6a5Smrg fi 2551f0ac6a5Smrg 256e5410a46Smrg dst=$dst_arg 2571f0ac6a5Smrg # Protect names starting with `-'. 2581f0ac6a5Smrg case $dst in 259e5410a46Smrg -*) dst=./$dst;; 2601f0ac6a5Smrg esac 2611f0ac6a5Smrg 2621f0ac6a5Smrg # If destination is a directory, append the input filename; won't work 2631f0ac6a5Smrg # if double slashes aren't ignored. 2641f0ac6a5Smrg if test -d "$dst"; then 2651f0ac6a5Smrg if test -n "$no_target_directory"; then 266e5410a46Smrg echo "$0: $dst_arg: Is a directory" >&2 2671f0ac6a5Smrg exit 1 2681f0ac6a5Smrg fi 2691f0ac6a5Smrg dstdir=$dst 2701f0ac6a5Smrg dst=$dstdir/`basename "$src"` 2711f0ac6a5Smrg dstdir_status=0 2721f0ac6a5Smrg else 2731f0ac6a5Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 2741f0ac6a5Smrg dstdir=` 2751f0ac6a5Smrg (dirname "$dst") 2>/dev/null || 2761f0ac6a5Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 2771f0ac6a5Smrg X"$dst" : 'X\(//\)[^/]' \| \ 2781f0ac6a5Smrg X"$dst" : 'X\(//\)$' \| \ 2791f0ac6a5Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 2801f0ac6a5Smrg echo X"$dst" | 2811f0ac6a5Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 2821f0ac6a5Smrg s//\1/ 2831f0ac6a5Smrg q 2841f0ac6a5Smrg } 2851f0ac6a5Smrg /^X\(\/\/\)[^/].*/{ 2861f0ac6a5Smrg s//\1/ 2871f0ac6a5Smrg q 2881f0ac6a5Smrg } 2891f0ac6a5Smrg /^X\(\/\/\)$/{ 2901f0ac6a5Smrg s//\1/ 2911f0ac6a5Smrg q 2921f0ac6a5Smrg } 2931f0ac6a5Smrg /^X\(\/\).*/{ 2941f0ac6a5Smrg s//\1/ 2951f0ac6a5Smrg q 2961f0ac6a5Smrg } 2971f0ac6a5Smrg s/.*/./; q' 2981f0ac6a5Smrg ` 2991f0ac6a5Smrg 3001f0ac6a5Smrg test -d "$dstdir" 3011f0ac6a5Smrg dstdir_status=$? 3021f0ac6a5Smrg fi 3031f0ac6a5Smrg fi 3041f0ac6a5Smrg 3051f0ac6a5Smrg obsolete_mkdir_used=false 3061f0ac6a5Smrg 3071f0ac6a5Smrg if test $dstdir_status != 0; then 3081f0ac6a5Smrg case $posix_mkdir in 3091f0ac6a5Smrg '') 3101f0ac6a5Smrg # Create intermediate dirs using mode 755 as modified by the umask. 3111f0ac6a5Smrg # This is like FreeBSD 'install' as of 1997-10-28. 3121f0ac6a5Smrg umask=`umask` 3131f0ac6a5Smrg case $stripcmd.$umask in 3141f0ac6a5Smrg # Optimize common cases. 3151f0ac6a5Smrg *[2367][2367]) mkdir_umask=$umask;; 3161f0ac6a5Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 3171f0ac6a5Smrg 3181f0ac6a5Smrg *[0-7]) 3191f0ac6a5Smrg mkdir_umask=`expr $umask + 22 \ 3201f0ac6a5Smrg - $umask % 100 % 40 + $umask % 20 \ 3211f0ac6a5Smrg - $umask % 10 % 4 + $umask % 2 3221f0ac6a5Smrg `;; 3231f0ac6a5Smrg *) mkdir_umask=$umask,go-w;; 3241f0ac6a5Smrg esac 3251f0ac6a5Smrg 3261f0ac6a5Smrg # With -d, create the new directory with the user-specified mode. 3271f0ac6a5Smrg # Otherwise, rely on $mkdir_umask. 3281f0ac6a5Smrg if test -n "$dir_arg"; then 3291f0ac6a5Smrg mkdir_mode=-m$mode 3301f0ac6a5Smrg else 3311f0ac6a5Smrg mkdir_mode= 3321f0ac6a5Smrg fi 3331f0ac6a5Smrg 3341f0ac6a5Smrg posix_mkdir=false 3351f0ac6a5Smrg case $umask in 3361f0ac6a5Smrg *[123567][0-7][0-7]) 3371f0ac6a5Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 3381f0ac6a5Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 3391f0ac6a5Smrg ;; 3401f0ac6a5Smrg *) 3411f0ac6a5Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 3421f0ac6a5Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 3431f0ac6a5Smrg 3441f0ac6a5Smrg if (umask $mkdir_umask && 3451f0ac6a5Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 3461f0ac6a5Smrg then 3471f0ac6a5Smrg if test -z "$dir_arg" || { 3481f0ac6a5Smrg # Check for POSIX incompatibilities with -m. 3491f0ac6a5Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 3501f0ac6a5Smrg # other-writeable bit of parent directory when it shouldn't. 3511f0ac6a5Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 3521f0ac6a5Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 3531f0ac6a5Smrg case $ls_ld_tmpdir in 3541f0ac6a5Smrg d????-?r-*) different_mode=700;; 3551f0ac6a5Smrg d????-?--*) different_mode=755;; 3561f0ac6a5Smrg *) false;; 3571f0ac6a5Smrg esac && 3581f0ac6a5Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 3591f0ac6a5Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 3601f0ac6a5Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 3611f0ac6a5Smrg } 3621f0ac6a5Smrg } 3631f0ac6a5Smrg then posix_mkdir=: 3641f0ac6a5Smrg fi 3651f0ac6a5Smrg rmdir "$tmpdir/d" "$tmpdir" 3661f0ac6a5Smrg else 3671f0ac6a5Smrg # Remove any dirs left behind by ancient mkdir implementations. 3681f0ac6a5Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 3691f0ac6a5Smrg fi 3701f0ac6a5Smrg trap '' 0;; 3711f0ac6a5Smrg esac;; 3721f0ac6a5Smrg esac 3731f0ac6a5Smrg 3741f0ac6a5Smrg if 3751f0ac6a5Smrg $posix_mkdir && ( 3761f0ac6a5Smrg umask $mkdir_umask && 3771f0ac6a5Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 3781f0ac6a5Smrg ) 3791f0ac6a5Smrg then : 3801f0ac6a5Smrg else 3811f0ac6a5Smrg 3821f0ac6a5Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 3831f0ac6a5Smrg # or it failed possibly due to a race condition. Create the 3841f0ac6a5Smrg # directory the slow way, step by step, checking for races as we go. 3851f0ac6a5Smrg 3861f0ac6a5Smrg case $dstdir in 387e5410a46Smrg /*) prefix='/';; 388e5410a46Smrg -*) prefix='./';; 389e5410a46Smrg *) prefix='';; 3901f0ac6a5Smrg esac 3911f0ac6a5Smrg 392e5410a46Smrg eval "$initialize_posix_glob" 3931f0ac6a5Smrg 3941f0ac6a5Smrg oIFS=$IFS 3951f0ac6a5Smrg IFS=/ 396e5410a46Smrg $posix_glob set -f 3971f0ac6a5Smrg set fnord $dstdir 3981f0ac6a5Smrg shift 399e5410a46Smrg $posix_glob set +f 4001f0ac6a5Smrg IFS=$oIFS 4011f0ac6a5Smrg 4021f0ac6a5Smrg prefixes= 4031f0ac6a5Smrg 4041f0ac6a5Smrg for d 4051f0ac6a5Smrg do 4061f0ac6a5Smrg test -z "$d" && continue 4071f0ac6a5Smrg 4081f0ac6a5Smrg prefix=$prefix$d 4091f0ac6a5Smrg if test -d "$prefix"; then 4101f0ac6a5Smrg prefixes= 4111f0ac6a5Smrg else 4121f0ac6a5Smrg if $posix_mkdir; then 4131f0ac6a5Smrg (umask=$mkdir_umask && 4141f0ac6a5Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 4151f0ac6a5Smrg # Don't fail if two instances are running concurrently. 4161f0ac6a5Smrg test -d "$prefix" || exit 1 4171f0ac6a5Smrg else 4181f0ac6a5Smrg case $prefix in 4191f0ac6a5Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 4201f0ac6a5Smrg *) qprefix=$prefix;; 4211f0ac6a5Smrg esac 4221f0ac6a5Smrg prefixes="$prefixes '$qprefix'" 4231f0ac6a5Smrg fi 4241f0ac6a5Smrg fi 4251f0ac6a5Smrg prefix=$prefix/ 4261f0ac6a5Smrg done 4271f0ac6a5Smrg 4281f0ac6a5Smrg if test -n "$prefixes"; then 4291f0ac6a5Smrg # Don't fail if two instances are running concurrently. 4301f0ac6a5Smrg (umask $mkdir_umask && 4311f0ac6a5Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 4321f0ac6a5Smrg test -d "$dstdir" || exit 1 4331f0ac6a5Smrg obsolete_mkdir_used=true 4341f0ac6a5Smrg fi 4351f0ac6a5Smrg fi 4361f0ac6a5Smrg fi 4371f0ac6a5Smrg 4381f0ac6a5Smrg if test -n "$dir_arg"; then 4391f0ac6a5Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 4401f0ac6a5Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 4411f0ac6a5Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 4421f0ac6a5Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 4431f0ac6a5Smrg else 4441f0ac6a5Smrg 4451f0ac6a5Smrg # Make a couple of temp file names in the proper directory. 4461f0ac6a5Smrg dsttmp=$dstdir/_inst.$$_ 4471f0ac6a5Smrg rmtmp=$dstdir/_rm.$$_ 4481f0ac6a5Smrg 4491f0ac6a5Smrg # Trap to clean up those temp files at exit. 4501f0ac6a5Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 4511f0ac6a5Smrg 4521f0ac6a5Smrg # Copy the file name to the temp name. 4531f0ac6a5Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 4541f0ac6a5Smrg 4551f0ac6a5Smrg # and set any options; do chmod last to preserve setuid bits. 4561f0ac6a5Smrg # 4571f0ac6a5Smrg # If any of these fail, we abort the whole thing. If we want to 4581f0ac6a5Smrg # ignore errors from any of these, just make sure not to ignore 4591f0ac6a5Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 4601f0ac6a5Smrg # 461e5410a46Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 462e5410a46Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 463e5410a46Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 464e5410a46Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 465e5410a46Smrg 466e5410a46Smrg # If -C, don't bother to copy if it wouldn't change the file. 467e5410a46Smrg if $copy_on_change && 468e5410a46Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 469e5410a46Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 470e5410a46Smrg 471e5410a46Smrg eval "$initialize_posix_glob" && 472e5410a46Smrg $posix_glob set -f && 473e5410a46Smrg set X $old && old=:$2:$4:$5:$6 && 474e5410a46Smrg set X $new && new=:$2:$4:$5:$6 && 475e5410a46Smrg $posix_glob set +f && 476e5410a46Smrg 477e5410a46Smrg test "$old" = "$new" && 478e5410a46Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 479e5410a46Smrg then 480e5410a46Smrg rm -f "$dsttmp" 481e5410a46Smrg else 482e5410a46Smrg # Rename the file to the real destination. 483e5410a46Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 484e5410a46Smrg 485e5410a46Smrg # The rename failed, perhaps because mv can't rename something else 486e5410a46Smrg # to itself, or perhaps because mv is so ancient that it does not 487e5410a46Smrg # support -f. 488e5410a46Smrg { 489e5410a46Smrg # Now remove or move aside any old file at destination location. 490e5410a46Smrg # We try this two ways since rm can't unlink itself on some 491e5410a46Smrg # systems and the destination file might be busy for other 492e5410a46Smrg # reasons. In this case, the final cleanup might fail but the new 493e5410a46Smrg # file should still install successfully. 494e5410a46Smrg { 495e5410a46Smrg test ! -f "$dst" || 496e5410a46Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 497e5410a46Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 498e5410a46Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 499e5410a46Smrg } || 500e5410a46Smrg { echo "$0: cannot unlink or rename $dst" >&2 501e5410a46Smrg (exit 1); exit 1 502e5410a46Smrg } 503e5410a46Smrg } && 504e5410a46Smrg 505e5410a46Smrg # Now rename the file to the real destination. 506e5410a46Smrg $doit $mvcmd "$dsttmp" "$dst" 507e5410a46Smrg } 508e5410a46Smrg fi || exit 1 5091f0ac6a5Smrg 5101f0ac6a5Smrg trap '' 0 5111f0ac6a5Smrg fi 5121f0ac6a5Smrgdone 5131f0ac6a5Smrg 5141f0ac6a5Smrg# Local variables: 5151f0ac6a5Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 5161f0ac6a5Smrg# time-stamp-start: "scriptversion=" 5171f0ac6a5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 518e5410a46Smrg# time-stamp-time-zone: "UTC" 519e5410a46Smrg# time-stamp-end: "; # UTC" 5201f0ac6a5Smrg# End: 521