install-sh revision 1
1N/A# install - install a program, script, or datafile 1N/A# following copyright and license. 1N/A# Copyright (C) 1994 X Consortium 1N/A# Permission is hereby granted, free of charge, to any person obtaining a copy 1N/A# of this software and associated documentation files (the "Software"), to 1N/A# deal in the Software without restriction, including without limitation the 1N/A# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 1N/A# sell copies of the Software, and to permit persons to whom the Software is 1N/A# furnished to do so, subject to the following conditions: 1N/A# The above copyright notice and this permission notice shall be included in 1N/A# all copies or substantial portions of the Software. 1N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1N/A# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1N/A# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 1N/A# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 1N/A# Except as contained in this notice, the name of the X Consortium shall not 1N/A# be used in advertising or otherwise to promote the sale, use or other deal- 1N/A# ings in this Software without prior written authorization from the X Consor- 1N/A# FSF changes to this file are in the public domain. 1N/A# Calling this script install-sh is preferred over install.sh, to prevent 1N/A# `make' implicit rules from creating a file called install from it 1N/A# when there is no Makefile. 1N/A# This script is compatible with the BSD install script, but was written 1N/A# from scratch. It can only install one file at a time, a restriction 1N/A# shared with many OS's install programs. 1N/A# set DOITPROG to echo to test this script 1N/A# Don't use :- since 4.3BSD and earlier shells don't like it. 1N/A# put in absolute paths if you don't have them in your path; or use env. vars. 1N/Ausage=
"Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 1N/A or: $0 [OPTION]... SRCFILES... DIRECTORY 1N/A or: $0 [OPTION]... -t DIRECTORY SRCFILES... 1N/A or: $0 [OPTION]... -d DIRECTORIES... 1N/AIn the 1st form, copy SRCFILE to DSTFILE. 1N/AIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 1N/AIn the 4th, create DIRECTORIES. 1N/A-d create directories instead of installing files. 1N/A-t DIRECTORY install into DIRECTORY. 1N/A-T report an error if DSTFILE is a directory. 1N/A--help display this help and exit. 1N/A--version display version info and exit. 1N/AEnvironment variables override the default commands: 1N/A CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG 1N/Awhile test -n
"$1";
do 1N/A *)
# When -d is used, all remaining arguments are directories to create. 1N/A # When -t is used, the destination is already specified. 1N/A # Otherwise, the last argument is the destination. Remove it from $@. 1N/A # $@ is not empty: it contains at least $arg. 1N/Aif test -z
"$1";
then 1N/A echo "$0: no input file specified." >&
2 1N/A # It's OK to call `install-sh -d' without argument. 1N/A # This can happen when creating conditional directories. 1N/A # Protect names starting with `-'. 1N/A # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 1N/A # might cause directories to be created, which would be especially bad 1N/A # if $src (and thus $dsttmp) contains '*'. 1N/A echo "$0: $src does not exist." >&
2 1N/A echo "$0: no destination specified." >&
2 1N/A # Protect names starting with `-'. 1N/A # If destination is a directory, append the input filename; won't work 1N/A # if double slashes aren't ignored. 1N/A # This sed command emulates the dirname command. 1N/A dstdir=
`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'` 1N/A # Make sure that the destination directory exists. 1N/A # Skip lots of stat calls in the usual case. 1N/A # Some sh's can't handle IFS=/ for some reason. 1N/A # mkdir can fail with a `File exist' error in case several 1N/A # install-sh are creating the directory concurrently. This 1N/A # Make a couple of temp file names in the proper directory. 1N/A # Trap to clean up those temp files at exit. 1N/A trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 1N/A trap '(exit $?); exit' 1 2 13 15 1N/A # Copy the file name to the temp name. 1N/A # and set any options; do chmod last to preserve setuid bits. 1N/A # If any of these fail, we abort the whole thing. If we want to 1N/A # ignore errors from any of these, just make sure not to ignore 1N/A # errors from the above "$doit $cpprog $src $dsttmp" command. 1N/A # Now rename the file to the real destination. 1N/A # The rename failed, perhaps because mv can't rename something else 1N/A # to itself, or perhaps because mv is so ancient that it does not 1N/A # Now remove or move aside any old file at destination location. 1N/A # We try this two ways since rm can't unlink itself on some 1N/A # systems and the destination file might be busy for other 1N/A # reasons. In this case, the final cleanup might fail but the new 1N/A # file should still install successfully. 1N/A # Now rename the file to the real destination. 1N/A fi ||
{ (exit 1); exit 1; } 1N/A# The final little trick to "correctly" pass the exit status to the exit trap. 1N/A# eval: (add-hook 'write-file-hooks 'time-stamp) 1N/A# time-stamp-start: "scriptversion=" 1N/A# time-stamp-format: "%:y-%02m-%02d.%02H" 1N/A# time-stamp-end: "$"