186d7f5d3SJohn Marino#!/bin/sh 286d7f5d3SJohn Marino# install - install a program, script, or datafile 386d7f5d3SJohn Marino 486d7f5d3SJohn Marinoscriptversion=2006-10-14.15 586d7f5d3SJohn Marino 686d7f5d3SJohn Marino# This originates from X11R5 (mit/util/scripts/install.sh), which was 786d7f5d3SJohn Marino# later released in X11R6 (xc/config/util/install.sh) with the 886d7f5d3SJohn Marino# following copyright and license. 986d7f5d3SJohn Marino# 1086d7f5d3SJohn Marino# Copyright (C) 1994 X Consortium 1186d7f5d3SJohn Marino# 1286d7f5d3SJohn Marino# Permission is hereby granted, free of charge, to any person obtaining a copy 1386d7f5d3SJohn Marino# of this software and associated documentation files (the "Software"), to 1486d7f5d3SJohn Marino# deal in the Software without restriction, including without limitation the 1586d7f5d3SJohn Marino# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1686d7f5d3SJohn Marino# sell copies of the Software, and to permit persons to whom the Software is 1786d7f5d3SJohn Marino# furnished to do so, subject to the following conditions: 1886d7f5d3SJohn Marino# 1986d7f5d3SJohn Marino# The above copyright notice and this permission notice shall be included in 2086d7f5d3SJohn Marino# all copies or substantial portions of the Software. 2186d7f5d3SJohn Marino# 2286d7f5d3SJohn Marino# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2386d7f5d3SJohn Marino# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2486d7f5d3SJohn Marino# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 2586d7f5d3SJohn Marino# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2686d7f5d3SJohn Marino# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 2786d7f5d3SJohn Marino# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2886d7f5d3SJohn Marino# 2986d7f5d3SJohn Marino# Except as contained in this notice, the name of the X Consortium shall not 3086d7f5d3SJohn Marino# be used in advertising or otherwise to promote the sale, use or other deal- 3186d7f5d3SJohn Marino# ings in this Software without prior written authorization from the X Consor- 3286d7f5d3SJohn Marino# tium. 3386d7f5d3SJohn Marino# 3486d7f5d3SJohn Marino# 3586d7f5d3SJohn Marino# FSF changes to this file are in the public domain. 3686d7f5d3SJohn Marino# 3786d7f5d3SJohn Marino# Calling this script install-sh is preferred over install.sh, to prevent 3886d7f5d3SJohn Marino# `make' implicit rules from creating a file called install from it 3986d7f5d3SJohn Marino# when there is no Makefile. 4086d7f5d3SJohn Marino# 4186d7f5d3SJohn Marino# This script is compatible with the BSD install script, but was written 4286d7f5d3SJohn Marino# from scratch. 4386d7f5d3SJohn Marino 4486d7f5d3SJohn Marinonl=' 4586d7f5d3SJohn Marino' 4686d7f5d3SJohn MarinoIFS=" "" $nl" 4786d7f5d3SJohn Marino 4886d7f5d3SJohn Marino# set DOITPROG to echo to test this script 4986d7f5d3SJohn Marino 5086d7f5d3SJohn Marino# Don't use :- since 4.3BSD and earlier shells don't like it. 5186d7f5d3SJohn Marinodoit="${DOITPROG-}" 5286d7f5d3SJohn Marinoif test -z "$doit"; then 5386d7f5d3SJohn Marino doit_exec=exec 5486d7f5d3SJohn Marinoelse 5586d7f5d3SJohn Marino doit_exec=$doit 5686d7f5d3SJohn Marinofi 5786d7f5d3SJohn Marino 5886d7f5d3SJohn Marino# Put in absolute file names if you don't have them in your path; 5986d7f5d3SJohn Marino# or use environment vars. 6086d7f5d3SJohn Marino 6186d7f5d3SJohn Marinomvprog="${MVPROG-mv}" 6286d7f5d3SJohn Marinocpprog="${CPPROG-cp}" 6386d7f5d3SJohn Marinochmodprog="${CHMODPROG-chmod}" 6486d7f5d3SJohn Marinochownprog="${CHOWNPROG-chown}" 6586d7f5d3SJohn Marinochgrpprog="${CHGRPPROG-chgrp}" 6686d7f5d3SJohn Marinostripprog="${STRIPPROG-strip}" 6786d7f5d3SJohn Marinormprog="${RMPROG-rm}" 6886d7f5d3SJohn Marinomkdirprog="${MKDIRPROG-mkdir}" 6986d7f5d3SJohn Marino 7086d7f5d3SJohn Marinoposix_glob= 7186d7f5d3SJohn Marinoposix_mkdir= 7286d7f5d3SJohn Marino 7386d7f5d3SJohn Marino# Desired mode of installed file. 7486d7f5d3SJohn Marinomode=0755 7586d7f5d3SJohn Marino 7686d7f5d3SJohn Marinochmodcmd=$chmodprog 7786d7f5d3SJohn Marinochowncmd= 7886d7f5d3SJohn Marinochgrpcmd= 7986d7f5d3SJohn Marinostripcmd= 8086d7f5d3SJohn Marinormcmd="$rmprog -f" 8186d7f5d3SJohn Marinomvcmd="$mvprog" 8286d7f5d3SJohn Marinosrc= 8386d7f5d3SJohn Marinodst= 8486d7f5d3SJohn Marinodir_arg= 8586d7f5d3SJohn Marinodstarg= 8686d7f5d3SJohn Marinono_target_directory= 8786d7f5d3SJohn Marino 8886d7f5d3SJohn Marinousage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 8986d7f5d3SJohn Marino or: $0 [OPTION]... SRCFILES... DIRECTORY 9086d7f5d3SJohn Marino or: $0 [OPTION]... -t DIRECTORY SRCFILES... 9186d7f5d3SJohn Marino or: $0 [OPTION]... -d DIRECTORIES... 9286d7f5d3SJohn Marino 9386d7f5d3SJohn MarinoIn the 1st form, copy SRCFILE to DSTFILE. 9486d7f5d3SJohn MarinoIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 9586d7f5d3SJohn MarinoIn the 4th, create DIRECTORIES. 9686d7f5d3SJohn Marino 9786d7f5d3SJohn MarinoOptions: 9886d7f5d3SJohn Marino-c (ignored) 9986d7f5d3SJohn Marino-d create directories instead of installing files. 10086d7f5d3SJohn Marino-g GROUP $chgrpprog installed files to GROUP. 10186d7f5d3SJohn Marino-m MODE $chmodprog installed files to MODE. 10286d7f5d3SJohn Marino-o USER $chownprog installed files to USER. 10386d7f5d3SJohn Marino-s $stripprog installed files. 10486d7f5d3SJohn Marino-t DIRECTORY install into DIRECTORY. 10586d7f5d3SJohn Marino-T report an error if DSTFILE is a directory. 10686d7f5d3SJohn Marino--help display this help and exit. 10786d7f5d3SJohn Marino--version display version info and exit. 10886d7f5d3SJohn Marino 10986d7f5d3SJohn MarinoEnvironment variables override the default commands: 11086d7f5d3SJohn Marino CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 11186d7f5d3SJohn Marino" 11286d7f5d3SJohn Marino 11386d7f5d3SJohn Marinowhile test $# -ne 0; do 11486d7f5d3SJohn Marino case $1 in 11586d7f5d3SJohn Marino -c) shift 11686d7f5d3SJohn Marino continue;; 11786d7f5d3SJohn Marino 11886d7f5d3SJohn Marino -d) dir_arg=true 11986d7f5d3SJohn Marino shift 12086d7f5d3SJohn Marino continue;; 12186d7f5d3SJohn Marino 12286d7f5d3SJohn Marino -g) chgrpcmd="$chgrpprog $2" 12386d7f5d3SJohn Marino shift 12486d7f5d3SJohn Marino shift 12586d7f5d3SJohn Marino continue;; 12686d7f5d3SJohn Marino 12786d7f5d3SJohn Marino --help) echo "$usage"; exit $?;; 12886d7f5d3SJohn Marino 12986d7f5d3SJohn Marino -m) mode=$2 13086d7f5d3SJohn Marino shift 13186d7f5d3SJohn Marino shift 13286d7f5d3SJohn Marino case $mode in 13386d7f5d3SJohn Marino *' '* | *' '* | *' 13486d7f5d3SJohn Marino'* | *'*'* | *'?'* | *'['*) 13586d7f5d3SJohn Marino echo "$0: invalid mode: $mode" >&2 13686d7f5d3SJohn Marino exit 1;; 13786d7f5d3SJohn Marino esac 13886d7f5d3SJohn Marino continue;; 13986d7f5d3SJohn Marino 14086d7f5d3SJohn Marino -o) chowncmd="$chownprog $2" 14186d7f5d3SJohn Marino shift 14286d7f5d3SJohn Marino shift 14386d7f5d3SJohn Marino continue;; 14486d7f5d3SJohn Marino 14586d7f5d3SJohn Marino -s) stripcmd=$stripprog 14686d7f5d3SJohn Marino shift 14786d7f5d3SJohn Marino continue;; 14886d7f5d3SJohn Marino 14986d7f5d3SJohn Marino -t) dstarg=$2 15086d7f5d3SJohn Marino shift 15186d7f5d3SJohn Marino shift 15286d7f5d3SJohn Marino continue;; 15386d7f5d3SJohn Marino 15486d7f5d3SJohn Marino -T) no_target_directory=true 15586d7f5d3SJohn Marino shift 15686d7f5d3SJohn Marino continue;; 15786d7f5d3SJohn Marino 15886d7f5d3SJohn Marino --version) echo "$0 $scriptversion"; exit $?;; 15986d7f5d3SJohn Marino 16086d7f5d3SJohn Marino --) shift 16186d7f5d3SJohn Marino break;; 16286d7f5d3SJohn Marino 16386d7f5d3SJohn Marino -*) echo "$0: invalid option: $1" >&2 16486d7f5d3SJohn Marino exit 1;; 16586d7f5d3SJohn Marino 16686d7f5d3SJohn Marino *) break;; 16786d7f5d3SJohn Marino esac 16886d7f5d3SJohn Marinodone 16986d7f5d3SJohn Marino 17086d7f5d3SJohn Marinoif test $# -ne 0 && test -z "$dir_arg$dstarg"; then 17186d7f5d3SJohn Marino # When -d is used, all remaining arguments are directories to create. 17286d7f5d3SJohn Marino # When -t is used, the destination is already specified. 17386d7f5d3SJohn Marino # Otherwise, the last argument is the destination. Remove it from $@. 17486d7f5d3SJohn Marino for arg 17586d7f5d3SJohn Marino do 17686d7f5d3SJohn Marino if test -n "$dstarg"; then 17786d7f5d3SJohn Marino # $@ is not empty: it contains at least $arg. 17886d7f5d3SJohn Marino set fnord "$@" "$dstarg" 17986d7f5d3SJohn Marino shift # fnord 18086d7f5d3SJohn Marino fi 18186d7f5d3SJohn Marino shift # arg 18286d7f5d3SJohn Marino dstarg=$arg 18386d7f5d3SJohn Marino done 18486d7f5d3SJohn Marinofi 18586d7f5d3SJohn Marino 18686d7f5d3SJohn Marinoif test $# -eq 0; then 18786d7f5d3SJohn Marino if test -z "$dir_arg"; then 18886d7f5d3SJohn Marino echo "$0: no input file specified." >&2 18986d7f5d3SJohn Marino exit 1 19086d7f5d3SJohn Marino fi 19186d7f5d3SJohn Marino # It's OK to call `install-sh -d' without argument. 19286d7f5d3SJohn Marino # This can happen when creating conditional directories. 19386d7f5d3SJohn Marino exit 0 19486d7f5d3SJohn Marinofi 19586d7f5d3SJohn Marino 19686d7f5d3SJohn Marinoif test -z "$dir_arg"; then 19786d7f5d3SJohn Marino trap '(exit $?); exit' 1 2 13 15 19886d7f5d3SJohn Marino 19986d7f5d3SJohn Marino # Set umask so as not to create temps with too-generous modes. 20086d7f5d3SJohn Marino # However, 'strip' requires both read and write access to temps. 20186d7f5d3SJohn Marino case $mode in 20286d7f5d3SJohn Marino # Optimize common cases. 20386d7f5d3SJohn Marino *644) cp_umask=133;; 20486d7f5d3SJohn Marino *755) cp_umask=22;; 20586d7f5d3SJohn Marino 20686d7f5d3SJohn Marino *[0-7]) 20786d7f5d3SJohn Marino if test -z "$stripcmd"; then 20886d7f5d3SJohn Marino u_plus_rw= 20986d7f5d3SJohn Marino else 21086d7f5d3SJohn Marino u_plus_rw='% 200' 21186d7f5d3SJohn Marino fi 21286d7f5d3SJohn Marino cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 21386d7f5d3SJohn Marino *) 21486d7f5d3SJohn Marino if test -z "$stripcmd"; then 21586d7f5d3SJohn Marino u_plus_rw= 21686d7f5d3SJohn Marino else 21786d7f5d3SJohn Marino u_plus_rw=,u+rw 21886d7f5d3SJohn Marino fi 21986d7f5d3SJohn Marino cp_umask=$mode$u_plus_rw;; 22086d7f5d3SJohn Marino esac 22186d7f5d3SJohn Marinofi 22286d7f5d3SJohn Marino 22386d7f5d3SJohn Marinofor src 22486d7f5d3SJohn Marinodo 22586d7f5d3SJohn Marino # Protect names starting with `-'. 22686d7f5d3SJohn Marino case $src in 22786d7f5d3SJohn Marino -*) src=./$src ;; 22886d7f5d3SJohn Marino esac 22986d7f5d3SJohn Marino 23086d7f5d3SJohn Marino if test -n "$dir_arg"; then 23186d7f5d3SJohn Marino dst=$src 23286d7f5d3SJohn Marino dstdir=$dst 23386d7f5d3SJohn Marino test -d "$dstdir" 23486d7f5d3SJohn Marino dstdir_status=$? 23586d7f5d3SJohn Marino else 23686d7f5d3SJohn Marino 23786d7f5d3SJohn Marino # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 23886d7f5d3SJohn Marino # might cause directories to be created, which would be especially bad 23986d7f5d3SJohn Marino # if $src (and thus $dsttmp) contains '*'. 24086d7f5d3SJohn Marino if test ! -f "$src" && test ! -d "$src"; then 24186d7f5d3SJohn Marino echo "$0: $src does not exist." >&2 24286d7f5d3SJohn Marino exit 1 24386d7f5d3SJohn Marino fi 24486d7f5d3SJohn Marino 24586d7f5d3SJohn Marino if test -z "$dstarg"; then 24686d7f5d3SJohn Marino echo "$0: no destination specified." >&2 24786d7f5d3SJohn Marino exit 1 24886d7f5d3SJohn Marino fi 24986d7f5d3SJohn Marino 25086d7f5d3SJohn Marino dst=$dstarg 25186d7f5d3SJohn Marino # Protect names starting with `-'. 25286d7f5d3SJohn Marino case $dst in 25386d7f5d3SJohn Marino -*) dst=./$dst ;; 25486d7f5d3SJohn Marino esac 25586d7f5d3SJohn Marino 25686d7f5d3SJohn Marino # If destination is a directory, append the input filename; won't work 25786d7f5d3SJohn Marino # if double slashes aren't ignored. 25886d7f5d3SJohn Marino if test -d "$dst"; then 25986d7f5d3SJohn Marino if test -n "$no_target_directory"; then 26086d7f5d3SJohn Marino echo "$0: $dstarg: Is a directory" >&2 26186d7f5d3SJohn Marino exit 1 26286d7f5d3SJohn Marino fi 26386d7f5d3SJohn Marino dstdir=$dst 26486d7f5d3SJohn Marino dst=$dstdir/`basename "$src"` 26586d7f5d3SJohn Marino dstdir_status=0 26686d7f5d3SJohn Marino else 26786d7f5d3SJohn Marino # Prefer dirname, but fall back on a substitute if dirname fails. 26886d7f5d3SJohn Marino dstdir=` 26986d7f5d3SJohn Marino (dirname "$dst") 2>/dev/null || 27086d7f5d3SJohn Marino expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 27186d7f5d3SJohn Marino X"$dst" : 'X\(//\)[^/]' \| \ 27286d7f5d3SJohn Marino X"$dst" : 'X\(//\)$' \| \ 27386d7f5d3SJohn Marino X"$dst" : 'X\(/\)' \| . 2>/dev/null || 27486d7f5d3SJohn Marino echo X"$dst" | 27586d7f5d3SJohn Marino sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 27686d7f5d3SJohn Marino s//\1/ 27786d7f5d3SJohn Marino q 27886d7f5d3SJohn Marino } 27986d7f5d3SJohn Marino /^X\(\/\/\)[^/].*/{ 28086d7f5d3SJohn Marino s//\1/ 28186d7f5d3SJohn Marino q 28286d7f5d3SJohn Marino } 28386d7f5d3SJohn Marino /^X\(\/\/\)$/{ 28486d7f5d3SJohn Marino s//\1/ 28586d7f5d3SJohn Marino q 28686d7f5d3SJohn Marino } 28786d7f5d3SJohn Marino /^X\(\/\).*/{ 28886d7f5d3SJohn Marino s//\1/ 28986d7f5d3SJohn Marino q 29086d7f5d3SJohn Marino } 29186d7f5d3SJohn Marino s/.*/./; q' 29286d7f5d3SJohn Marino ` 29386d7f5d3SJohn Marino 29486d7f5d3SJohn Marino test -d "$dstdir" 29586d7f5d3SJohn Marino dstdir_status=$? 29686d7f5d3SJohn Marino fi 29786d7f5d3SJohn Marino fi 29886d7f5d3SJohn Marino 29986d7f5d3SJohn Marino obsolete_mkdir_used=false 30086d7f5d3SJohn Marino 30186d7f5d3SJohn Marino if test $dstdir_status != 0; then 30286d7f5d3SJohn Marino case $posix_mkdir in 30386d7f5d3SJohn Marino '') 30486d7f5d3SJohn Marino # Create intermediate dirs using mode 755 as modified by the umask. 30586d7f5d3SJohn Marino # This is like FreeBSD 'install' as of 1997-10-28. 30686d7f5d3SJohn Marino umask=`umask` 30786d7f5d3SJohn Marino case $stripcmd.$umask in 30886d7f5d3SJohn Marino # Optimize common cases. 30986d7f5d3SJohn Marino *[2367][2367]) mkdir_umask=$umask;; 31086d7f5d3SJohn Marino .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 31186d7f5d3SJohn Marino 31286d7f5d3SJohn Marino *[0-7]) 31386d7f5d3SJohn Marino mkdir_umask=`expr $umask + 22 \ 31486d7f5d3SJohn Marino - $umask % 100 % 40 + $umask % 20 \ 31586d7f5d3SJohn Marino - $umask % 10 % 4 + $umask % 2 31686d7f5d3SJohn Marino `;; 31786d7f5d3SJohn Marino *) mkdir_umask=$umask,go-w;; 31886d7f5d3SJohn Marino esac 31986d7f5d3SJohn Marino 32086d7f5d3SJohn Marino # With -d, create the new directory with the user-specified mode. 32186d7f5d3SJohn Marino # Otherwise, rely on $mkdir_umask. 32286d7f5d3SJohn Marino if test -n "$dir_arg"; then 32386d7f5d3SJohn Marino mkdir_mode=-m$mode 32486d7f5d3SJohn Marino else 32586d7f5d3SJohn Marino mkdir_mode= 32686d7f5d3SJohn Marino fi 32786d7f5d3SJohn Marino 32886d7f5d3SJohn Marino posix_mkdir=false 32986d7f5d3SJohn Marino case $umask in 33086d7f5d3SJohn Marino *[123567][0-7][0-7]) 33186d7f5d3SJohn Marino # POSIX mkdir -p sets u+wx bits regardless of umask, which 33286d7f5d3SJohn Marino # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 33386d7f5d3SJohn Marino ;; 33486d7f5d3SJohn Marino *) 33586d7f5d3SJohn Marino tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 33686d7f5d3SJohn Marino trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 33786d7f5d3SJohn Marino 33886d7f5d3SJohn Marino if (umask $mkdir_umask && 33986d7f5d3SJohn Marino exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 34086d7f5d3SJohn Marino then 34186d7f5d3SJohn Marino if test -z "$dir_arg" || { 34286d7f5d3SJohn Marino # Check for POSIX incompatibilities with -m. 34386d7f5d3SJohn Marino # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 34486d7f5d3SJohn Marino # other-writeable bit of parent directory when it shouldn't. 34586d7f5d3SJohn Marino # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 34686d7f5d3SJohn Marino ls_ld_tmpdir=`ls -ld "$tmpdir"` 34786d7f5d3SJohn Marino case $ls_ld_tmpdir in 34886d7f5d3SJohn Marino d????-?r-*) different_mode=700;; 34986d7f5d3SJohn Marino d????-?--*) different_mode=755;; 35086d7f5d3SJohn Marino *) false;; 35186d7f5d3SJohn Marino esac && 35286d7f5d3SJohn Marino $mkdirprog -m$different_mode -p -- "$tmpdir" && { 35386d7f5d3SJohn Marino ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 35486d7f5d3SJohn Marino test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 35586d7f5d3SJohn Marino } 35686d7f5d3SJohn Marino } 35786d7f5d3SJohn Marino then posix_mkdir=: 35886d7f5d3SJohn Marino fi 35986d7f5d3SJohn Marino rmdir "$tmpdir/d" "$tmpdir" 36086d7f5d3SJohn Marino else 36186d7f5d3SJohn Marino # Remove any dirs left behind by ancient mkdir implementations. 36286d7f5d3SJohn Marino rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 36386d7f5d3SJohn Marino fi 36486d7f5d3SJohn Marino trap '' 0;; 36586d7f5d3SJohn Marino esac;; 36686d7f5d3SJohn Marino esac 36786d7f5d3SJohn Marino 36886d7f5d3SJohn Marino if 36986d7f5d3SJohn Marino $posix_mkdir && ( 37086d7f5d3SJohn Marino umask $mkdir_umask && 37186d7f5d3SJohn Marino $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 37286d7f5d3SJohn Marino ) 37386d7f5d3SJohn Marino then : 37486d7f5d3SJohn Marino else 37586d7f5d3SJohn Marino 37686d7f5d3SJohn Marino # The umask is ridiculous, or mkdir does not conform to POSIX, 37786d7f5d3SJohn Marino # or it failed possibly due to a race condition. Create the 37886d7f5d3SJohn Marino # directory the slow way, step by step, checking for races as we go. 37986d7f5d3SJohn Marino 38086d7f5d3SJohn Marino case $dstdir in 38186d7f5d3SJohn Marino /*) prefix=/ ;; 38286d7f5d3SJohn Marino -*) prefix=./ ;; 38386d7f5d3SJohn Marino *) prefix= ;; 38486d7f5d3SJohn Marino esac 38586d7f5d3SJohn Marino 38686d7f5d3SJohn Marino case $posix_glob in 38786d7f5d3SJohn Marino '') 38886d7f5d3SJohn Marino if (set -f) 2>/dev/null; then 38986d7f5d3SJohn Marino posix_glob=true 39086d7f5d3SJohn Marino else 39186d7f5d3SJohn Marino posix_glob=false 39286d7f5d3SJohn Marino fi ;; 39386d7f5d3SJohn Marino esac 39486d7f5d3SJohn Marino 39586d7f5d3SJohn Marino oIFS=$IFS 39686d7f5d3SJohn Marino IFS=/ 39786d7f5d3SJohn Marino $posix_glob && set -f 39886d7f5d3SJohn Marino set fnord $dstdir 39986d7f5d3SJohn Marino shift 40086d7f5d3SJohn Marino $posix_glob && set +f 40186d7f5d3SJohn Marino IFS=$oIFS 40286d7f5d3SJohn Marino 40386d7f5d3SJohn Marino prefixes= 40486d7f5d3SJohn Marino 40586d7f5d3SJohn Marino for d 40686d7f5d3SJohn Marino do 40786d7f5d3SJohn Marino test -z "$d" && continue 40886d7f5d3SJohn Marino 40986d7f5d3SJohn Marino prefix=$prefix$d 41086d7f5d3SJohn Marino if test -d "$prefix"; then 41186d7f5d3SJohn Marino prefixes= 41286d7f5d3SJohn Marino else 41386d7f5d3SJohn Marino if $posix_mkdir; then 41486d7f5d3SJohn Marino (umask=$mkdir_umask && 41586d7f5d3SJohn Marino $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 41686d7f5d3SJohn Marino # Don't fail if two instances are running concurrently. 41786d7f5d3SJohn Marino test -d "$prefix" || exit 1 41886d7f5d3SJohn Marino else 41986d7f5d3SJohn Marino case $prefix in 42086d7f5d3SJohn Marino *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 42186d7f5d3SJohn Marino *) qprefix=$prefix;; 42286d7f5d3SJohn Marino esac 42386d7f5d3SJohn Marino prefixes="$prefixes '$qprefix'" 42486d7f5d3SJohn Marino fi 42586d7f5d3SJohn Marino fi 42686d7f5d3SJohn Marino prefix=$prefix/ 42786d7f5d3SJohn Marino done 42886d7f5d3SJohn Marino 42986d7f5d3SJohn Marino if test -n "$prefixes"; then 43086d7f5d3SJohn Marino # Don't fail if two instances are running concurrently. 43186d7f5d3SJohn Marino (umask $mkdir_umask && 43286d7f5d3SJohn Marino eval "\$doit_exec \$mkdirprog $prefixes") || 43386d7f5d3SJohn Marino test -d "$dstdir" || exit 1 43486d7f5d3SJohn Marino obsolete_mkdir_used=true 43586d7f5d3SJohn Marino fi 43686d7f5d3SJohn Marino fi 43786d7f5d3SJohn Marino fi 43886d7f5d3SJohn Marino 43986d7f5d3SJohn Marino if test -n "$dir_arg"; then 44086d7f5d3SJohn Marino { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 44186d7f5d3SJohn Marino { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 44286d7f5d3SJohn Marino { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 44386d7f5d3SJohn Marino test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 44486d7f5d3SJohn Marino else 44586d7f5d3SJohn Marino 44686d7f5d3SJohn Marino # Make a couple of temp file names in the proper directory. 44786d7f5d3SJohn Marino dsttmp=$dstdir/_inst.$$_ 44886d7f5d3SJohn Marino rmtmp=$dstdir/_rm.$$_ 44986d7f5d3SJohn Marino 45086d7f5d3SJohn Marino # Trap to clean up those temp files at exit. 45186d7f5d3SJohn Marino trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 45286d7f5d3SJohn Marino 45386d7f5d3SJohn Marino # Copy the file name to the temp name. 45486d7f5d3SJohn Marino (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 45586d7f5d3SJohn Marino 45686d7f5d3SJohn Marino # and set any options; do chmod last to preserve setuid bits. 45786d7f5d3SJohn Marino # 45886d7f5d3SJohn Marino # If any of these fail, we abort the whole thing. If we want to 45986d7f5d3SJohn Marino # ignore errors from any of these, just make sure not to ignore 46086d7f5d3SJohn Marino # errors from the above "$doit $cpprog $src $dsttmp" command. 46186d7f5d3SJohn Marino # 46286d7f5d3SJohn Marino { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ 46386d7f5d3SJohn Marino && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ 46486d7f5d3SJohn Marino && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ 46586d7f5d3SJohn Marino && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 46686d7f5d3SJohn Marino 46786d7f5d3SJohn Marino # Now rename the file to the real destination. 46886d7f5d3SJohn Marino { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \ 46986d7f5d3SJohn Marino || { 47086d7f5d3SJohn Marino # The rename failed, perhaps because mv can't rename something else 47186d7f5d3SJohn Marino # to itself, or perhaps because mv is so ancient that it does not 47286d7f5d3SJohn Marino # support -f. 47386d7f5d3SJohn Marino 47486d7f5d3SJohn Marino # Now remove or move aside any old file at destination location. 47586d7f5d3SJohn Marino # We try this two ways since rm can't unlink itself on some 47686d7f5d3SJohn Marino # systems and the destination file might be busy for other 47786d7f5d3SJohn Marino # reasons. In this case, the final cleanup might fail but the new 47886d7f5d3SJohn Marino # file should still install successfully. 47986d7f5d3SJohn Marino { 48086d7f5d3SJohn Marino if test -f "$dst"; then 48186d7f5d3SJohn Marino $doit $rmcmd -f "$dst" 2>/dev/null \ 48286d7f5d3SJohn Marino || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \ 48386d7f5d3SJohn Marino && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\ 48486d7f5d3SJohn Marino || { 48586d7f5d3SJohn Marino echo "$0: cannot unlink or rename $dst" >&2 48686d7f5d3SJohn Marino (exit 1); exit 1 48786d7f5d3SJohn Marino } 48886d7f5d3SJohn Marino else 48986d7f5d3SJohn Marino : 49086d7f5d3SJohn Marino fi 49186d7f5d3SJohn Marino } && 49286d7f5d3SJohn Marino 49386d7f5d3SJohn Marino # Now rename the file to the real destination. 49486d7f5d3SJohn Marino $doit $mvcmd "$dsttmp" "$dst" 49586d7f5d3SJohn Marino } 49686d7f5d3SJohn Marino } || exit 1 49786d7f5d3SJohn Marino 49886d7f5d3SJohn Marino trap '' 0 49986d7f5d3SJohn Marino fi 50086d7f5d3SJohn Marinodone 50186d7f5d3SJohn Marino 50286d7f5d3SJohn Marino# Local variables: 50386d7f5d3SJohn Marino# eval: (add-hook 'write-file-hooks 'time-stamp) 50486d7f5d3SJohn Marino# time-stamp-start: "scriptversion=" 50586d7f5d3SJohn Marino# time-stamp-format: "%:y-%02m-%02d.%02H" 50686d7f5d3SJohn Marino# time-stamp-end: "$" 50786d7f5d3SJohn Marino# End: 508