f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# install - install a program, script, or datafile
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# This comes from X11R5 (mit/util/scripts/install.sh).
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Copyright 1991 by the Massachusetts Institute of Technology
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Permission to use, copy, modify, distribute, and sell this software and its
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# documentation for any purpose is hereby granted without fee, provided that
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# the above copyright notice appear in all copies and that both that
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# copyright notice and this permission notice appear in supporting
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# documentation, and that the name of M.I.T. not be used in advertising or
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# publicity pertaining to distribution of the software without specific,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# written prior permission. M.I.T. makes no representations about the
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# suitability of this software for any purpose. It is provided "as is"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# without express or implied warranty.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Calling this script install-sh is preferred over install.sh, to prevent
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# `make' implicit rules from creating a file called install from it
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# when there is no Makefile.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# This script is compatible with the BSD install script, but was written
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# from scratch. It can only install one file at a time, a restriction
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# shared with many OS's install programs.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# set DOITPROG to echo to test this script
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Don't use :- since 4.3BSD and earlier shells don't like it.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# put in absolute paths if you don't have them in your path; or use env. vars.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntwhile [ x"$1" != x ]; do
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt *) if [ x"$src" = x ]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt # this colon is to work around a 386BSD /bin/sh bug
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif [ x"$src" = x ]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt echo "install: no input file specified"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif [ x"$dir_arg" != x ]; then
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ -d $dst ]; then
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# might cause directories to be created, which would be especially bad
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# if $src (and thus $dsttmp) contains '*'.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt echo "install: $src does not exist"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$dst" = x ]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt echo "install: no destination specified"
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# If destination is a directory, append the input filename; if your system
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# does not like double slashes in filenames, you may need to add some logic
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt## this sed command emulates the dirname command
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntdstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Make sure that the destination directory exists.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# this part is taken from Noah Friedman's mkinstalldirs script
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Skip lots of stat calls in the usual case.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif [ ! -d "$dstdir" ]; then
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Some sh's can't handle IFS=/ for some reason.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntset - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ ! -d "${pathcomp}" ] ;
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntif [ x"$dir_arg" != x ]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# If we're going to rename the final executable, determine the name now.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# don't allow the sed command to completely eliminate the filename
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$dstfile" = x ]
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Make a temp file name in the proper directory.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Move or copy the file name to the temp name
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# and set any options; do chmod last to preserve setuid bits
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# If any of these fail, we abort the whole thing. If we want to
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# ignore errors from any of these, just make sure not to ignore
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# errors from the above "$doit $instcmd $src $dsttmp" command.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt# Now rename the file to the real destination.