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