Blame autotools/install-sh

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