install-sh revision 88cd5fc2
188cd5fc2Smrg#!/bin/sh 288cd5fc2Smrg# install - install a program, script, or datafile 388cd5fc2Smrg 488cd5fc2Smrgscriptversion=2011-11-20.07; # UTC 588cd5fc2Smrg 688cd5fc2Smrg# This originates from X11R5 (mit/util/scripts/install.sh), which was 788cd5fc2Smrg# later released in X11R6 (xc/config/util/install.sh) with the 888cd5fc2Smrg# following copyright and license. 988cd5fc2Smrg# 1088cd5fc2Smrg# Copyright (C) 1994 X Consortium 1188cd5fc2Smrg# 1288cd5fc2Smrg# Permission is hereby granted, free of charge, to any person obtaining a copy 1388cd5fc2Smrg# of this software and associated documentation files (the "Software"), to 1488cd5fc2Smrg# deal in the Software without restriction, including without limitation the 1588cd5fc2Smrg# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1688cd5fc2Smrg# sell copies of the Software, and to permit persons to whom the Software is 1788cd5fc2Smrg# furnished to do so, subject to the following conditions: 1888cd5fc2Smrg# 1988cd5fc2Smrg# The above copyright notice and this permission notice shall be included in 2088cd5fc2Smrg# all copies or substantial portions of the Software. 2188cd5fc2Smrg# 2288cd5fc2Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2388cd5fc2Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2488cd5fc2Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2588cd5fc2Smrg# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2688cd5fc2Smrg# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2788cd5fc2Smrg# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2888cd5fc2Smrg# 2988cd5fc2Smrg# Except as contained in this notice, the name of the X Consortium shall not 3088cd5fc2Smrg# be used in advertising or otherwise to promote the sale, use or other deal- 3188cd5fc2Smrg# ings in this Software without prior written authorization from the X Consor- 3288cd5fc2Smrg# tium. 3388cd5fc2Smrg# 3488cd5fc2Smrg# 3588cd5fc2Smrg# FSF changes to this file are in the public domain. 3688cd5fc2Smrg# 3788cd5fc2Smrg# Calling this script install-sh is preferred over install.sh, to prevent 3888cd5fc2Smrg# 'make' implicit rules from creating a file called install from it 3988cd5fc2Smrg# when there is no Makefile. 4088cd5fc2Smrg# 4188cd5fc2Smrg# This script is compatible with the BSD install script, but was written 4288cd5fc2Smrg# from scratch. 4388cd5fc2Smrg 4488cd5fc2Smrgnl=' 4588cd5fc2Smrg' 4688cd5fc2SmrgIFS=" "" $nl" 4788cd5fc2Smrg 4888cd5fc2Smrg# set DOITPROG to echo to test this script 4988cd5fc2Smrg 5088cd5fc2Smrg# Don't use :- since 4.3BSD and earlier shells don't like it. 5188cd5fc2Smrgdoit=${DOITPROG-} 5288cd5fc2Smrgif test -z "$doit"; then 5388cd5fc2Smrg doit_exec=exec 5488cd5fc2Smrgelse 5588cd5fc2Smrg doit_exec=$doit 5688cd5fc2Smrgfi 5788cd5fc2Smrg 5888cd5fc2Smrg# Put in absolute file names if you don't have them in your path; 5988cd5fc2Smrg# or use environment vars. 6088cd5fc2Smrg 6188cd5fc2Smrgchgrpprog=${CHGRPPROG-chgrp} 6288cd5fc2Smrgchmodprog=${CHMODPROG-chmod} 6388cd5fc2Smrgchownprog=${CHOWNPROG-chown} 6488cd5fc2Smrgcmpprog=${CMPPROG-cmp} 6588cd5fc2Smrgcpprog=${CPPROG-cp} 6688cd5fc2Smrgmkdirprog=${MKDIRPROG-mkdir} 6788cd5fc2Smrgmvprog=${MVPROG-mv} 6888cd5fc2Smrgrmprog=${RMPROG-rm} 6988cd5fc2Smrgstripprog=${STRIPPROG-strip} 7088cd5fc2Smrg 7188cd5fc2Smrgposix_glob='?' 7288cd5fc2Smrginitialize_posix_glob=' 7388cd5fc2Smrg test "$posix_glob" != "?" || { 7488cd5fc2Smrg if (set -f) 2>/dev/null; then 7588cd5fc2Smrg posix_glob= 7688cd5fc2Smrg else 7788cd5fc2Smrg posix_glob=: 7888cd5fc2Smrg fi 7988cd5fc2Smrg } 8088cd5fc2Smrg' 8188cd5fc2Smrg 8288cd5fc2Smrgposix_mkdir= 8388cd5fc2Smrg 8488cd5fc2Smrg# Desired mode of installed file. 8588cd5fc2Smrgmode=0755 8688cd5fc2Smrg 8788cd5fc2Smrgchgrpcmd= 8888cd5fc2Smrgchmodcmd=$chmodprog 8988cd5fc2Smrgchowncmd= 9088cd5fc2Smrgmvcmd=$mvprog 9188cd5fc2Smrgrmcmd="$rmprog -f" 9288cd5fc2Smrgstripcmd= 9388cd5fc2Smrg 9488cd5fc2Smrgsrc= 9588cd5fc2Smrgdst= 9688cd5fc2Smrgdir_arg= 9788cd5fc2Smrgdst_arg= 9888cd5fc2Smrg 9988cd5fc2Smrgcopy_on_change=false 10088cd5fc2Smrgno_target_directory= 10188cd5fc2Smrg 10288cd5fc2Smrgusage="\ 10388cd5fc2SmrgUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE 10488cd5fc2Smrg or: $0 [OPTION]... SRCFILES... DIRECTORY 10588cd5fc2Smrg or: $0 [OPTION]... -t DIRECTORY SRCFILES... 10688cd5fc2Smrg or: $0 [OPTION]... -d DIRECTORIES... 10788cd5fc2Smrg 10888cd5fc2SmrgIn the 1st form, copy SRCFILE to DSTFILE. 10988cd5fc2SmrgIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 11088cd5fc2SmrgIn the 4th, create DIRECTORIES. 11188cd5fc2Smrg 11288cd5fc2SmrgOptions: 11388cd5fc2Smrg --help display this help and exit. 11488cd5fc2Smrg --version display version info and exit. 11588cd5fc2Smrg 11688cd5fc2Smrg -c (ignored) 11788cd5fc2Smrg -C install only if different (preserve the last data modification time) 11888cd5fc2Smrg -d create directories instead of installing files. 11988cd5fc2Smrg -g GROUP $chgrpprog installed files to GROUP. 12088cd5fc2Smrg -m MODE $chmodprog installed files to MODE. 12188cd5fc2Smrg -o USER $chownprog installed files to USER. 12288cd5fc2Smrg -s $stripprog installed files. 12388cd5fc2Smrg -t DIRECTORY install into DIRECTORY. 12488cd5fc2Smrg -T report an error if DSTFILE is a directory. 12588cd5fc2Smrg 12688cd5fc2SmrgEnvironment variables override the default commands: 12788cd5fc2Smrg CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 12888cd5fc2Smrg RMPROG STRIPPROG 12988cd5fc2Smrg" 13088cd5fc2Smrg 13188cd5fc2Smrgwhile test $# -ne 0; do 13288cd5fc2Smrg case $1 in 13388cd5fc2Smrg -c) ;; 13488cd5fc2Smrg 13588cd5fc2Smrg -C) copy_on_change=true;; 13688cd5fc2Smrg 13788cd5fc2Smrg -d) dir_arg=true;; 13888cd5fc2Smrg 13988cd5fc2Smrg -g) chgrpcmd="$chgrpprog $2" 14088cd5fc2Smrg shift;; 14188cd5fc2Smrg 14288cd5fc2Smrg --help) echo "$usage"; exit $?;; 14388cd5fc2Smrg 14488cd5fc2Smrg -m) mode=$2 14588cd5fc2Smrg case $mode in 14688cd5fc2Smrg *' '* | *' '* | *' 14788cd5fc2Smrg'* | *'*'* | *'?'* | *'['*) 14888cd5fc2Smrg echo "$0: invalid mode: $mode" >&2 14988cd5fc2Smrg exit 1;; 15088cd5fc2Smrg esac 15188cd5fc2Smrg shift;; 15288cd5fc2Smrg 15388cd5fc2Smrg -o) chowncmd="$chownprog $2" 15488cd5fc2Smrg shift;; 15588cd5fc2Smrg 15688cd5fc2Smrg -s) stripcmd=$stripprog;; 15788cd5fc2Smrg 15888cd5fc2Smrg -t) dst_arg=$2 15988cd5fc2Smrg # Protect names problematic for 'test' and other utilities. 16088cd5fc2Smrg case $dst_arg in 16188cd5fc2Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 16288cd5fc2Smrg esac 16388cd5fc2Smrg shift;; 16488cd5fc2Smrg 16588cd5fc2Smrg -T) no_target_directory=true;; 16688cd5fc2Smrg 16788cd5fc2Smrg --version) echo "$0 $scriptversion"; exit $?;; 16888cd5fc2Smrg 16988cd5fc2Smrg --) shift 17088cd5fc2Smrg break;; 17188cd5fc2Smrg 17288cd5fc2Smrg -*) echo "$0: invalid option: $1" >&2 17388cd5fc2Smrg exit 1;; 17488cd5fc2Smrg 17588cd5fc2Smrg *) break;; 17688cd5fc2Smrg esac 17788cd5fc2Smrg shift 17888cd5fc2Smrgdone 17988cd5fc2Smrg 18088cd5fc2Smrgif test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 18188cd5fc2Smrg # When -d is used, all remaining arguments are directories to create. 18288cd5fc2Smrg # When -t is used, the destination is already specified. 18388cd5fc2Smrg # Otherwise, the last argument is the destination. Remove it from $@. 18488cd5fc2Smrg for arg 18588cd5fc2Smrg do 18688cd5fc2Smrg if test -n "$dst_arg"; then 18788cd5fc2Smrg # $@ is not empty: it contains at least $arg. 18888cd5fc2Smrg set fnord "$@" "$dst_arg" 18988cd5fc2Smrg shift # fnord 19088cd5fc2Smrg fi 19188cd5fc2Smrg shift # arg 19288cd5fc2Smrg dst_arg=$arg 19388cd5fc2Smrg # Protect names problematic for 'test' and other utilities. 19488cd5fc2Smrg case $dst_arg in 19588cd5fc2Smrg -* | [=\(\)!]) dst_arg=./$dst_arg;; 19688cd5fc2Smrg esac 19788cd5fc2Smrg done 19888cd5fc2Smrgfi 19988cd5fc2Smrg 20088cd5fc2Smrgif test $# -eq 0; then 20188cd5fc2Smrg if test -z "$dir_arg"; then 20288cd5fc2Smrg echo "$0: no input file specified." >&2 20388cd5fc2Smrg exit 1 20488cd5fc2Smrg fi 20588cd5fc2Smrg # It's OK to call 'install-sh -d' without argument. 20688cd5fc2Smrg # This can happen when creating conditional directories. 20788cd5fc2Smrg exit 0 20888cd5fc2Smrgfi 20988cd5fc2Smrg 21088cd5fc2Smrgif test -z "$dir_arg"; then 21188cd5fc2Smrg do_exit='(exit $ret); exit $ret' 21288cd5fc2Smrg trap "ret=129; $do_exit" 1 21388cd5fc2Smrg trap "ret=130; $do_exit" 2 21488cd5fc2Smrg trap "ret=141; $do_exit" 13 21588cd5fc2Smrg trap "ret=143; $do_exit" 15 21688cd5fc2Smrg 21788cd5fc2Smrg # Set umask so as not to create temps with too-generous modes. 21888cd5fc2Smrg # However, 'strip' requires both read and write access to temps. 21988cd5fc2Smrg case $mode in 22088cd5fc2Smrg # Optimize common cases. 22188cd5fc2Smrg *644) cp_umask=133;; 22288cd5fc2Smrg *755) cp_umask=22;; 22388cd5fc2Smrg 22488cd5fc2Smrg *[0-7]) 22588cd5fc2Smrg if test -z "$stripcmd"; then 22688cd5fc2Smrg u_plus_rw= 22788cd5fc2Smrg else 22888cd5fc2Smrg u_plus_rw='% 200' 22988cd5fc2Smrg fi 23088cd5fc2Smrg cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 23188cd5fc2Smrg *) 23288cd5fc2Smrg if test -z "$stripcmd"; then 23388cd5fc2Smrg u_plus_rw= 23488cd5fc2Smrg else 23588cd5fc2Smrg u_plus_rw=,u+rw 23688cd5fc2Smrg fi 23788cd5fc2Smrg cp_umask=$mode$u_plus_rw;; 23888cd5fc2Smrg esac 23988cd5fc2Smrgfi 24088cd5fc2Smrg 24188cd5fc2Smrgfor src 24288cd5fc2Smrgdo 24388cd5fc2Smrg # Protect names problematic for 'test' and other utilities. 24488cd5fc2Smrg case $src in 24588cd5fc2Smrg -* | [=\(\)!]) src=./$src;; 24688cd5fc2Smrg esac 24788cd5fc2Smrg 24888cd5fc2Smrg if test -n "$dir_arg"; then 24988cd5fc2Smrg dst=$src 25088cd5fc2Smrg dstdir=$dst 25188cd5fc2Smrg test -d "$dstdir" 25288cd5fc2Smrg dstdir_status=$? 25388cd5fc2Smrg else 25488cd5fc2Smrg 25588cd5fc2Smrg # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 25688cd5fc2Smrg # might cause directories to be created, which would be especially bad 25788cd5fc2Smrg # if $src (and thus $dsttmp) contains '*'. 25888cd5fc2Smrg if test ! -f "$src" && test ! -d "$src"; then 25988cd5fc2Smrg echo "$0: $src does not exist." >&2 26088cd5fc2Smrg exit 1 26188cd5fc2Smrg fi 26288cd5fc2Smrg 26388cd5fc2Smrg if test -z "$dst_arg"; then 26488cd5fc2Smrg echo "$0: no destination specified." >&2 26588cd5fc2Smrg exit 1 26688cd5fc2Smrg fi 26788cd5fc2Smrg dst=$dst_arg 26888cd5fc2Smrg 26988cd5fc2Smrg # If destination is a directory, append the input filename; won't work 27088cd5fc2Smrg # if double slashes aren't ignored. 27188cd5fc2Smrg if test -d "$dst"; then 27288cd5fc2Smrg if test -n "$no_target_directory"; then 27388cd5fc2Smrg echo "$0: $dst_arg: Is a directory" >&2 27488cd5fc2Smrg exit 1 27588cd5fc2Smrg fi 27688cd5fc2Smrg dstdir=$dst 27788cd5fc2Smrg dst=$dstdir/`basename "$src"` 27888cd5fc2Smrg dstdir_status=0 27988cd5fc2Smrg else 28088cd5fc2Smrg # Prefer dirname, but fall back on a substitute if dirname fails. 28188cd5fc2Smrg dstdir=` 28288cd5fc2Smrg (dirname "$dst") 2>/dev/null || 28388cd5fc2Smrg expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 28488cd5fc2Smrg X"$dst" : 'X\(//\)[^/]' \| \ 28588cd5fc2Smrg X"$dst" : 'X\(//\)$' \| \ 28688cd5fc2Smrg X"$dst" : 'X\(/\)' \| . 2>/dev/null || 28788cd5fc2Smrg echo X"$dst" | 28888cd5fc2Smrg sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 28988cd5fc2Smrg s//\1/ 29088cd5fc2Smrg q 29188cd5fc2Smrg } 29288cd5fc2Smrg /^X\(\/\/\)[^/].*/{ 29388cd5fc2Smrg s//\1/ 29488cd5fc2Smrg q 29588cd5fc2Smrg } 29688cd5fc2Smrg /^X\(\/\/\)$/{ 29788cd5fc2Smrg s//\1/ 29888cd5fc2Smrg q 29988cd5fc2Smrg } 30088cd5fc2Smrg /^X\(\/\).*/{ 30188cd5fc2Smrg s//\1/ 30288cd5fc2Smrg q 30388cd5fc2Smrg } 30488cd5fc2Smrg s/.*/./; q' 30588cd5fc2Smrg ` 30688cd5fc2Smrg 30788cd5fc2Smrg test -d "$dstdir" 30888cd5fc2Smrg dstdir_status=$? 30988cd5fc2Smrg fi 31088cd5fc2Smrg fi 31188cd5fc2Smrg 31288cd5fc2Smrg obsolete_mkdir_used=false 31388cd5fc2Smrg 31488cd5fc2Smrg if test $dstdir_status != 0; then 31588cd5fc2Smrg case $posix_mkdir in 31688cd5fc2Smrg '') 31788cd5fc2Smrg # Create intermediate dirs using mode 755 as modified by the umask. 31888cd5fc2Smrg # This is like FreeBSD 'install' as of 1997-10-28. 31988cd5fc2Smrg umask=`umask` 32088cd5fc2Smrg case $stripcmd.$umask in 32188cd5fc2Smrg # Optimize common cases. 32288cd5fc2Smrg *[2367][2367]) mkdir_umask=$umask;; 32388cd5fc2Smrg .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 32488cd5fc2Smrg 32588cd5fc2Smrg *[0-7]) 32688cd5fc2Smrg mkdir_umask=`expr $umask + 22 \ 32788cd5fc2Smrg - $umask % 100 % 40 + $umask % 20 \ 32888cd5fc2Smrg - $umask % 10 % 4 + $umask % 2 32988cd5fc2Smrg `;; 33088cd5fc2Smrg *) mkdir_umask=$umask,go-w;; 33188cd5fc2Smrg esac 33288cd5fc2Smrg 33388cd5fc2Smrg # With -d, create the new directory with the user-specified mode. 33488cd5fc2Smrg # Otherwise, rely on $mkdir_umask. 33588cd5fc2Smrg if test -n "$dir_arg"; then 33688cd5fc2Smrg mkdir_mode=-m$mode 33788cd5fc2Smrg else 33888cd5fc2Smrg mkdir_mode= 33988cd5fc2Smrg fi 34088cd5fc2Smrg 34188cd5fc2Smrg posix_mkdir=false 34288cd5fc2Smrg case $umask in 34388cd5fc2Smrg *[123567][0-7][0-7]) 34488cd5fc2Smrg # POSIX mkdir -p sets u+wx bits regardless of umask, which 34588cd5fc2Smrg # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 34688cd5fc2Smrg ;; 34788cd5fc2Smrg *) 34888cd5fc2Smrg tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 34988cd5fc2Smrg trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 35088cd5fc2Smrg 35188cd5fc2Smrg if (umask $mkdir_umask && 35288cd5fc2Smrg exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 35388cd5fc2Smrg then 35488cd5fc2Smrg if test -z "$dir_arg" || { 35588cd5fc2Smrg # Check for POSIX incompatibilities with -m. 35688cd5fc2Smrg # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 35788cd5fc2Smrg # other-writable bit of parent directory when it shouldn't. 35888cd5fc2Smrg # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 35988cd5fc2Smrg ls_ld_tmpdir=`ls -ld "$tmpdir"` 36088cd5fc2Smrg case $ls_ld_tmpdir in 36188cd5fc2Smrg d????-?r-*) different_mode=700;; 36288cd5fc2Smrg d????-?--*) different_mode=755;; 36388cd5fc2Smrg *) false;; 36488cd5fc2Smrg esac && 36588cd5fc2Smrg $mkdirprog -m$different_mode -p -- "$tmpdir" && { 36688cd5fc2Smrg ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 36788cd5fc2Smrg test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 36888cd5fc2Smrg } 36988cd5fc2Smrg } 37088cd5fc2Smrg then posix_mkdir=: 37188cd5fc2Smrg fi 37288cd5fc2Smrg rmdir "$tmpdir/d" "$tmpdir" 37388cd5fc2Smrg else 37488cd5fc2Smrg # Remove any dirs left behind by ancient mkdir implementations. 37588cd5fc2Smrg rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 37688cd5fc2Smrg fi 37788cd5fc2Smrg trap '' 0;; 37888cd5fc2Smrg esac;; 37988cd5fc2Smrg esac 38088cd5fc2Smrg 38188cd5fc2Smrg if 38288cd5fc2Smrg $posix_mkdir && ( 38388cd5fc2Smrg umask $mkdir_umask && 38488cd5fc2Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 38588cd5fc2Smrg ) 38688cd5fc2Smrg then : 38788cd5fc2Smrg else 38888cd5fc2Smrg 38988cd5fc2Smrg # The umask is ridiculous, or mkdir does not conform to POSIX, 39088cd5fc2Smrg # or it failed possibly due to a race condition. Create the 39188cd5fc2Smrg # directory the slow way, step by step, checking for races as we go. 39288cd5fc2Smrg 39388cd5fc2Smrg case $dstdir in 39488cd5fc2Smrg /*) prefix='/';; 39588cd5fc2Smrg [-=\(\)!]*) prefix='./';; 39688cd5fc2Smrg *) prefix='';; 39788cd5fc2Smrg esac 39888cd5fc2Smrg 39988cd5fc2Smrg eval "$initialize_posix_glob" 40088cd5fc2Smrg 40188cd5fc2Smrg oIFS=$IFS 40288cd5fc2Smrg IFS=/ 40388cd5fc2Smrg $posix_glob set -f 40488cd5fc2Smrg set fnord $dstdir 40588cd5fc2Smrg shift 40688cd5fc2Smrg $posix_glob set +f 40788cd5fc2Smrg IFS=$oIFS 40888cd5fc2Smrg 40988cd5fc2Smrg prefixes= 41088cd5fc2Smrg 41188cd5fc2Smrg for d 41288cd5fc2Smrg do 41388cd5fc2Smrg test X"$d" = X && continue 41488cd5fc2Smrg 41588cd5fc2Smrg prefix=$prefix$d 41688cd5fc2Smrg if test -d "$prefix"; then 41788cd5fc2Smrg prefixes= 41888cd5fc2Smrg else 41988cd5fc2Smrg if $posix_mkdir; then 42088cd5fc2Smrg (umask=$mkdir_umask && 42188cd5fc2Smrg $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 42288cd5fc2Smrg # Don't fail if two instances are running concurrently. 42388cd5fc2Smrg test -d "$prefix" || exit 1 42488cd5fc2Smrg else 42588cd5fc2Smrg case $prefix in 42688cd5fc2Smrg *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42788cd5fc2Smrg *) qprefix=$prefix;; 42888cd5fc2Smrg esac 42988cd5fc2Smrg prefixes="$prefixes '$qprefix'" 43088cd5fc2Smrg fi 43188cd5fc2Smrg fi 43288cd5fc2Smrg prefix=$prefix/ 43388cd5fc2Smrg done 43488cd5fc2Smrg 43588cd5fc2Smrg if test -n "$prefixes"; then 43688cd5fc2Smrg # Don't fail if two instances are running concurrently. 43788cd5fc2Smrg (umask $mkdir_umask && 43888cd5fc2Smrg eval "\$doit_exec \$mkdirprog $prefixes") || 43988cd5fc2Smrg test -d "$dstdir" || exit 1 44088cd5fc2Smrg obsolete_mkdir_used=true 44188cd5fc2Smrg fi 44288cd5fc2Smrg fi 44388cd5fc2Smrg fi 44488cd5fc2Smrg 44588cd5fc2Smrg if test -n "$dir_arg"; then 44688cd5fc2Smrg { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44788cd5fc2Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44888cd5fc2Smrg { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44988cd5fc2Smrg test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 45088cd5fc2Smrg else 45188cd5fc2Smrg 45288cd5fc2Smrg # Make a couple of temp file names in the proper directory. 45388cd5fc2Smrg dsttmp=$dstdir/_inst.$$_ 45488cd5fc2Smrg rmtmp=$dstdir/_rm.$$_ 45588cd5fc2Smrg 45688cd5fc2Smrg # Trap to clean up those temp files at exit. 45788cd5fc2Smrg trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45888cd5fc2Smrg 45988cd5fc2Smrg # Copy the file name to the temp name. 46088cd5fc2Smrg (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 46188cd5fc2Smrg 46288cd5fc2Smrg # and set any options; do chmod last to preserve setuid bits. 46388cd5fc2Smrg # 46488cd5fc2Smrg # If any of these fail, we abort the whole thing. If we want to 46588cd5fc2Smrg # ignore errors from any of these, just make sure not to ignore 46688cd5fc2Smrg # errors from the above "$doit $cpprog $src $dsttmp" command. 46788cd5fc2Smrg # 46888cd5fc2Smrg { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 46988cd5fc2Smrg { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 47088cd5fc2Smrg { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 47188cd5fc2Smrg { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 47288cd5fc2Smrg 47388cd5fc2Smrg # If -C, don't bother to copy if it wouldn't change the file. 47488cd5fc2Smrg if $copy_on_change && 47588cd5fc2Smrg old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 47688cd5fc2Smrg new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 47788cd5fc2Smrg 47888cd5fc2Smrg eval "$initialize_posix_glob" && 47988cd5fc2Smrg $posix_glob set -f && 48088cd5fc2Smrg set X $old && old=:$2:$4:$5:$6 && 48188cd5fc2Smrg set X $new && new=:$2:$4:$5:$6 && 48288cd5fc2Smrg $posix_glob set +f && 48388cd5fc2Smrg 48488cd5fc2Smrg test "$old" = "$new" && 48588cd5fc2Smrg $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 48688cd5fc2Smrg then 48788cd5fc2Smrg rm -f "$dsttmp" 48888cd5fc2Smrg else 48988cd5fc2Smrg # Rename the file to the real destination. 49088cd5fc2Smrg $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 49188cd5fc2Smrg 49288cd5fc2Smrg # The rename failed, perhaps because mv can't rename something else 49388cd5fc2Smrg # to itself, or perhaps because mv is so ancient that it does not 49488cd5fc2Smrg # support -f. 49588cd5fc2Smrg { 49688cd5fc2Smrg # Now remove or move aside any old file at destination location. 49788cd5fc2Smrg # We try this two ways since rm can't unlink itself on some 49888cd5fc2Smrg # systems and the destination file might be busy for other 49988cd5fc2Smrg # reasons. In this case, the final cleanup might fail but the new 50088cd5fc2Smrg # file should still install successfully. 50188cd5fc2Smrg { 50288cd5fc2Smrg test ! -f "$dst" || 50388cd5fc2Smrg $doit $rmcmd -f "$dst" 2>/dev/null || 50488cd5fc2Smrg { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 50588cd5fc2Smrg { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 50688cd5fc2Smrg } || 50788cd5fc2Smrg { echo "$0: cannot unlink or rename $dst" >&2 50888cd5fc2Smrg (exit 1); exit 1 50988cd5fc2Smrg } 51088cd5fc2Smrg } && 51188cd5fc2Smrg 51288cd5fc2Smrg # Now rename the file to the real destination. 51388cd5fc2Smrg $doit $mvcmd "$dsttmp" "$dst" 51488cd5fc2Smrg } 51588cd5fc2Smrg fi || exit 1 51688cd5fc2Smrg 51788cd5fc2Smrg trap '' 0 51888cd5fc2Smrg fi 51988cd5fc2Smrgdone 52088cd5fc2Smrg 52188cd5fc2Smrg# Local variables: 52288cd5fc2Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 52388cd5fc2Smrg# time-stamp-start: "scriptversion=" 52488cd5fc2Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 52588cd5fc2Smrg# time-stamp-time-zone: "UTC" 52688cd5fc2Smrg# time-stamp-end: "; # UTC" 52788cd5fc2Smrg# End: 528