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