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