Classic Shell Scripting - Arnold Robbins [120]
cd $package/$CONFIGUREDIR || exit 1 ;
test -f configure && \
chmod a+x configure && \
env `$STRIPCOMMENTS $envfile | $JOINLINES` \
$EXTRAENVIRONMENT \
nice time ./configure $CONFIGUREFLAGS ;
nice time make $ALLTARGETS && nice time make $CHECKTARGETS ;
echo '= = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = =' ;
echo 'Disk free report for $builddir/$package:' ;
df $builddir | $INDENT ;
printf 'Remote date: ' ;
date $DATEFLAGS ;
cd ;
test -f $BUILDEND && . $BUILDEND || \
test -f $BUILDEND && source $BUILDEND || \
true ;
echo '= = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = = = = = =' ;
" < /dev/null > "$LOGDIR/$logfile" 2>&1 &
}
error( )
{
echo "$@" 1>&2
usage_and_exit 1
}
find_file( )
{
# Usage:
# find_file file program-and-args
# Return 0 (success) if found, 1 (failure) if not found
if test -r "$1"
then
PAR="$2"
PARFILE="$1"
return 0
else
return 1
fi
}
find_package( )
{
# Usage: find_package package-x.y.z
base=`echo "$1" | sed -e 's/[-_][.]*[0-9].*$//'`
PAR=
PARFILE=
for srcdir in $SRCDIRS
do
test "$srcdir" = "." && srcdir="`pwd`"
for subdir in "$base" ""
do
# NB: update package setting in build_one( ) if this list changes
find_file $srcdir/$subdir/$1.tar.gz "tar xfz" && return
find_file $srcdir/$subdir/$1.tar.Z "tar xfz" && return
find_file $srcdir/$subdir/$1.tar "tar xf" && return
find_file $srcdir/$subdir/$1.tar.bz2 "tar xfj" && return
find_file $srcdir/$subdir/$1.tgz "tar xfz" && return
find_file $srcdir/$subdir/$1.zip "unzip -q" && return
find_file $srcdir/$subdir/$1.jar "jar xf" && return
done
done
}
set_userhosts( )
{
# Usage: set_userhosts file(s)
for u in "$@"
do
if test -r "$u"
then
ALTUSERHOSTS="$ALTUSERHOSTS $u"
elif test -r "$BUILDHOME/$u"
then
ALTUSERHOSTS="$ALTUSERHOSTS $BUILDHOME/$u"
else
error "File not found: $u"
fi
done
}
usage( )
{
cat < $PROGRAM [ --? ] [ --all "..." ] [ --check "..." ] [ --configure "..." ] [ --environment "..." ] [ --help ] [ --logdirectory dir ] [ --on "[user@]host[:dir][,envfile] ..." ] [ --source "dir ..." ] [ --userhosts "file(s)" ] [ --version ] package(s) EOF } usage_and_exit( ) { usage exit $1 } version( ) { echo "$PROGRAM version $VERSION" } warning( ) { echo "$@" 1>&2 EXITCODE=`expr $EXITCODE + 1` } ALLTARGETS= altlogdir= altsrcdirs= ALTUSERHOSTS= BUILDBEGIN=./.build/begin BUILDEND=./.build/end BUILDHOME=$HOME/.build CHECKTARGETS=check CONFIGUREDIR=. CONFIGUREFLAGS= DATEFLAGS="+%Y.%m.%d.%H.%M.%S" EXITCODE=0 EXTRAENVIRONMENT= INDENT="awk '{ print \"\t\t\t\" \$0 }'" JOINLINES="tr '\n' '\040'" LOGDIR= PROGRAM=`basename $0` SCP=scp SSH=ssh SSHFLAGS=${SSHFLAGS--x} STRIPCOMMENTS='sed -e s/#.*$//' userhosts= VERSION=1.0 # Default initialization files defaultdirectories=$BUILDHOME/directories defaultuserhosts=$BUILDHOME/userhosts # List of places to find package distributions, with a default # list if the user has no personalized list: SRCDIRS="`$STRIPCOMMENTS $defaultdirectories 2> /dev/null`" test -z "$SRCDIRS" && \ SRCDIRS=" . /usr/local/src /usr/local/gnu/src $HOME/src $HOME/gnu/src /tmp /usr/tmp /var/tmp " while test $# -gt 0 do case $1 in --all | --al | --a | -all | -al | -a ) shift ALLTARGETS="$1" ;; --cd | -cd ) shift CONFIGUREDIR="$1" ;; --check | --chec | --che | --ch | -check | -chec | -che | -ch ) shift CHECKTARGETS="$1" ;; --configure | --configur | --configu | --config | --confi | \ --conf | --con | --co | \ -configure | -configur | -configu | -config | -confi | \ -conf | -con | -co ) shift CONFIGUREFLAGS="$1" ;; --environment | --environmen | --environme | --environm | --environ | \ --enviro | --envir | --envi | --env | --en | --e | \ -environment | -environmen | -environme | -environm | -environ | \ -enviro | -envir | -envi | -env | -en | -e ) shift EXTRAENVIRONMENT="$1" ;; --help | --hel | --he | --h | '--?' | -help | -hel