Blame jemalloc/build-aux/install-sh

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