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