Blame install-sh

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