Blame nss/tests/pkcs11/netscape/trivial/install-sh

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