Blame install-sh

rpm-build 2bd099
#!/bin/sh
rpm-build 2bd099
#
rpm-build 2bd099
# install - install a program, script, or datafile
rpm-build 2bd099
#
rpm-build 2bd099
# This originates from X11R5 (mit/util/scripts/install.sh), which was
rpm-build 2bd099
# later released in X11R6 (xc/config/util/install.sh) with the
rpm-build 2bd099
# following copyright and license.
rpm-build 2bd099
#
rpm-build 2bd099
# Copyright (C) 1994 X Consortium
rpm-build 2bd099
#
rpm-build 2bd099
# Permission is hereby granted, free of charge, to any person obtaining a copy
rpm-build 2bd099
# of this software and associated documentation files (the "Software"), to
rpm-build 2bd099
# deal in the Software without restriction, including without limitation the
rpm-build 2bd099
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
rpm-build 2bd099
# sell copies of the Software, and to permit persons to whom the Software is
rpm-build 2bd099
# furnished to do so, subject to the following conditions:
rpm-build 2bd099
#
rpm-build 2bd099
# The above copyright notice and this permission notice shall be included in
rpm-build 2bd099
# all copies or substantial portions of the Software.
rpm-build 2bd099
#
rpm-build 2bd099
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
rpm-build 2bd099
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
rpm-build 2bd099
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
rpm-build 2bd099
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
rpm-build 2bd099
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
rpm-build 2bd099
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rpm-build 2bd099
#
rpm-build 2bd099
# Except as contained in this notice, the name of the X Consortium shall not
rpm-build 2bd099
# be used in advertising or otherwise to promote the sale, use or other deal-
rpm-build 2bd099
# ings in this Software without prior written authorization from the X Consor-
rpm-build 2bd099
# tium.
rpm-build 2bd099
#
rpm-build 2bd099
#
rpm-build 2bd099
# FSF changes to this file are in the public domain.
rpm-build 2bd099
#
rpm-build 2bd099
# Calling this script install-sh is preferred over install.sh, to prevent
rpm-build 2bd099
# `make' implicit rules from creating a file called install from it
rpm-build 2bd099
# when there is no Makefile.
rpm-build 2bd099
#
rpm-build 2bd099
# This script is compatible with the BSD install script, but was written
rpm-build 2bd099
# from scratch.  It can only install one file at a time, a restriction
rpm-build 2bd099
# shared with many OS's install programs.
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
# set DOITPROG to echo to test this script
rpm-build 2bd099
rpm-build 2bd099
# Don't use :- since 4.3BSD and earlier shells don't like it.
rpm-build 2bd099
doit="${DOITPROG-}"
rpm-build 2bd099
rpm-build 2bd099
rpm-build 2bd099
# put in absolute paths if you don't have them in your path; or use env. vars.
rpm-build 2bd099
rpm-build 2bd099
mvprog="${MVPROG-mv}"
rpm-build 2bd099
cpprog="${CPPROG-cp}"
rpm-build 2bd099
chmodprog="${CHMODPROG-chmod}"
rpm-build 2bd099
chownprog="${CHOWNPROG-chown}"
rpm-build 2bd099
chgrpprog="${CHGRPPROG-chgrp}"
rpm-build 2bd099
stripprog="${STRIPPROG-strip}"
rpm-build 2bd099
rmprog="${RMPROG-rm}"
rpm-build 2bd099
mkdirprog="${MKDIRPROG-mkdir}"
rpm-build 2bd099
rpm-build 2bd099
transformbasename=""
rpm-build 2bd099
transform_arg=""
rpm-build 2bd099
instcmd="$mvprog"
rpm-build 2bd099
chmodcmd="$chmodprog 0755"
rpm-build 2bd099
chowncmd=""
rpm-build 2bd099
chgrpcmd=""
rpm-build 2bd099
stripcmd=""
rpm-build 2bd099
rmcmd="$rmprog -f"
rpm-build 2bd099
mvcmd="$mvprog"
rpm-build 2bd099
src=""
rpm-build 2bd099
dst=""
rpm-build 2bd099
dir_arg=""
rpm-build 2bd099
rpm-build 2bd099
while [ x"$1" != x ]; do
rpm-build 2bd099
    case $1 in
rpm-build 2bd099
	-c) instcmd=$cpprog
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-d) dir_arg=true
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-m) chmodcmd="$chmodprog $2"
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-o) chowncmd="$chownprog $2"
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-g) chgrpcmd="$chgrpprog $2"
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-s) stripcmd=$stripprog
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
rpm-build 2bd099
	*)  if [ x"$src" = x ]
rpm-build 2bd099
	    then
rpm-build 2bd099
		src=$1
rpm-build 2bd099
	    else
rpm-build 2bd099
		# this colon is to work around a 386BSD /bin/sh bug
rpm-build 2bd099
		:
rpm-build 2bd099
		dst=$1
rpm-build 2bd099
	    fi
rpm-build 2bd099
	    shift
rpm-build 2bd099
	    continue;;
rpm-build 2bd099
    esac
rpm-build 2bd099
done
rpm-build 2bd099
rpm-build 2bd099
if [ x"$src" = x ]
rpm-build 2bd099
then
rpm-build 2bd099
	echo "$0: no input file specified" >&2
rpm-build 2bd099
	exit 1
rpm-build 2bd099
else
rpm-build 2bd099
	:
rpm-build 2bd099
fi
rpm-build 2bd099
rpm-build 2bd099
if [ x"$dir_arg" != x ]; then
rpm-build 2bd099
	dst=$src
rpm-build 2bd099
	src=""
rpm-build 2bd099
rpm-build 2bd099
	if [ -d "$dst" ]; then
rpm-build 2bd099
		instcmd=:
rpm-build 2bd099
		chmodcmd=""
rpm-build 2bd099
	else
rpm-build 2bd099
		instcmd=$mkdirprog
rpm-build 2bd099
	fi
rpm-build 2bd099
else
rpm-build 2bd099
rpm-build 2bd099
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
rpm-build 2bd099
# might cause directories to be created, which would be especially bad
rpm-build 2bd099
# if $src (and thus $dsttmp) contains '*'.
rpm-build 2bd099
rpm-build 2bd099
	if [ -f "$src" ] || [ -d "$src" ]
rpm-build 2bd099
	then
rpm-build 2bd099
		:
rpm-build 2bd099
	else
rpm-build 2bd099
		echo "$0: $src does not exist" >&2
rpm-build 2bd099
		exit 1
rpm-build 2bd099
	fi
rpm-build 2bd099
rpm-build 2bd099
	if [ x"$dst" = x ]
rpm-build 2bd099
	then
rpm-build 2bd099
		echo "$0: no destination specified" >&2
rpm-build 2bd099
		exit 1
rpm-build 2bd099
	else
rpm-build 2bd099
		:
rpm-build 2bd099
	fi
rpm-build 2bd099
rpm-build 2bd099
# If destination is a directory, append the input filename; if your system
rpm-build 2bd099
# does not like double slashes in filenames, you may need to add some logic
rpm-build 2bd099
rpm-build 2bd099
	if [ -d "$dst" ]
rpm-build 2bd099
	then
rpm-build 2bd099
		dst=$dst/`basename "$src"`
rpm-build 2bd099
	else
rpm-build 2bd099
		:
rpm-build 2bd099
	fi
rpm-build 2bd099
fi
rpm-build 2bd099
rpm-build 2bd099
## this sed command emulates the dirname command
rpm-build 2bd099
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
rpm-build 2bd099
rpm-build 2bd099
# Make sure that the destination directory exists.
rpm-build 2bd099
#  this part is taken from Noah Friedman's mkinstalldirs script
rpm-build 2bd099
rpm-build 2bd099
# Skip lots of stat calls in the usual case.
rpm-build 2bd099
if [ ! -d "$dstdir" ]; then
rpm-build 2bd099
defaultIFS='
rpm-build 2bd099
	'
rpm-build 2bd099
IFS="${IFS-$defaultIFS}"
rpm-build 2bd099
rpm-build 2bd099
oIFS=$IFS
rpm-build 2bd099
# Some sh's can't handle IFS=/ for some reason.
rpm-build 2bd099
IFS='%'
rpm-build 2bd099
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
rpm-build 2bd099
IFS=$oIFS
rpm-build 2bd099
rpm-build 2bd099
pathcomp=''
rpm-build 2bd099
rpm-build 2bd099
while [ $# -ne 0 ] ; do
rpm-build 2bd099
	pathcomp=$pathcomp$1
rpm-build 2bd099
	shift
rpm-build 2bd099
rpm-build 2bd099
	if [ ! -d "$pathcomp" ] ;
rpm-build 2bd099
        then
rpm-build 2bd099
		$mkdirprog "$pathcomp"
rpm-build 2bd099
	else
rpm-build 2bd099
		:
rpm-build 2bd099
	fi
rpm-build 2bd099
rpm-build 2bd099
	pathcomp=$pathcomp/
rpm-build 2bd099
done
rpm-build 2bd099
fi
rpm-build 2bd099
rpm-build 2bd099
if [ x"$dir_arg" != x ]
rpm-build 2bd099
then
rpm-build 2bd099
	$doit $instcmd "$dst" &&
rpm-build 2bd099
rpm-build 2bd099
	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
rpm-build 2bd099
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
rpm-build 2bd099
	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
rpm-build 2bd099
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
rpm-build 2bd099
else
rpm-build 2bd099
rpm-build 2bd099
# If we're going to rename the final executable, determine the name now.
rpm-build 2bd099
rpm-build 2bd099
	if [ x"$transformarg" = x ]
rpm-build 2bd099
	then
rpm-build 2bd099
		dstfile=`basename "$dst"`
rpm-build 2bd099
	else
rpm-build 2bd099
		dstfile=`basename "$dst" $transformbasename |
rpm-build 2bd099
			sed $transformarg`$transformbasename
rpm-build 2bd099
	fi
rpm-build 2bd099
rpm-build 2bd099
# don't allow the sed command to completely eliminate the filename
rpm-build 2bd099
rpm-build 2bd099
	if [ x"$dstfile" = x ]
rpm-build 2bd099
	then
rpm-build 2bd099
		dstfile=`basename "$dst"`
rpm-build 2bd099
	else
rpm-build 2bd099
		:
rpm-build 2bd099
	fi
rpm-build 2bd099
rpm-build 2bd099
# Make a couple of temp file names in the proper directory.
rpm-build 2bd099
rpm-build 2bd099
	dsttmp=$dstdir/#inst.$$#
rpm-build 2bd099
	rmtmp=$dstdir/#rm.$$#
rpm-build 2bd099
rpm-build 2bd099
# Trap to clean up temp files at exit.
rpm-build 2bd099
rpm-build 2bd099
	trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
rpm-build 2bd099
	trap '(exit $?); exit' 1 2 13 15
rpm-build 2bd099
rpm-build 2bd099
# Move or copy the file name to the temp name
rpm-build 2bd099
rpm-build 2bd099
	$doit $instcmd "$src" "$dsttmp" &&
rpm-build 2bd099
rpm-build 2bd099
# and set any options; do chmod last to preserve setuid bits
rpm-build 2bd099
rpm-build 2bd099
# If any of these fail, we abort the whole thing.  If we want to
rpm-build 2bd099
# ignore errors from any of these, just make sure not to ignore
rpm-build 2bd099
# errors from the above "$doit $instcmd $src $dsttmp" command.
rpm-build 2bd099
rpm-build 2bd099
	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
rpm-build 2bd099
	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
rpm-build 2bd099
	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
rpm-build 2bd099
	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
rpm-build 2bd099
rpm-build 2bd099
# Now remove or move aside any old file at destination location.  We try this
rpm-build 2bd099
# two ways since rm can't unlink itself on some systems and the destination
rpm-build 2bd099
# file might be busy for other reasons.  In this case, the final cleanup
rpm-build 2bd099
# might fail but the new file should still install successfully.
rpm-build 2bd099
rpm-build 2bd099
{
rpm-build 2bd099
	if [ -f "$dstdir/$dstfile" ]
rpm-build 2bd099
	then
rpm-build 2bd099
		$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
rpm-build 2bd099
		$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
rpm-build 2bd099
		{
rpm-build 2bd099
		  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
rpm-build 2bd099
		  (exit 1); exit
rpm-build 2bd099
		}
rpm-build 2bd099
	else
rpm-build 2bd099
		:
rpm-build 2bd099
	fi
rpm-build 2bd099
} &&
rpm-build 2bd099
rpm-build 2bd099
# Now rename the file to the real destination.
rpm-build 2bd099
rpm-build 2bd099
	$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
rpm-build 2bd099
rpm-build 2bd099
fi &&
rpm-build 2bd099
rpm-build 2bd099
# The final little trick to "correctly" pass the exit status to the exit trap.
rpm-build 2bd099
rpm-build 2bd099
{
rpm-build 2bd099
	(exit 0); exit
rpm-build 2bd099
}