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