Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [119]

By Root 1000 0
to local errors can, and should, be reported to the package developers. Few developers have access to a wide range of platforms, so it is only from installer feedback that they can make their packages more portable and more robust. Before doing so, however, it is always a good idea to check the release notes for the package (typically in files named BUGS, FAQ, INSTALL, PROBLEMS, or README) to find out whether the problem that you discovered has already been reported, but is just not fixed yet. The software model where developers get rapid installer feedback has proven to be extremely productive, and Eric Raymond has written about it in an interesting extended essay in book form.[6]

* * *

Example 8-2. The build-all program

#! /bin/sh -

# Build one or more packages in parallel on one or more build hosts.

#

# Usage:

# build-all [ --? ]

# [ --all "..." ]

# [ --check "..." ]

# [ --configure "..." ]

# [ --environment "..." ]

# [ --help ]

# [ --logdirectory dir ]

# [ --on "[user@]host[:dir][,envfile] ..." ]

# [ --source "dir ..." ]

# [ --userhosts "file(s)" ]

# [ --version ]

# package(s)

#

# Optional initialization files:

# $HOME/.build/directories list of source directories

# $HOME/.build/userhosts list of [user@]host[:dir][,envfile]

IFS='

'

PATH=/usr/local/bin:/bin:/usr/bin

export PATH

UMASK=002

umask $UMASK

build_one( )

{

# Usage:

# build_one [user@]host[:build-directory][,envfile]

arg="`eval echo $1`"

userhost="`echo $arg | sed -e 's/:.*$//'`"

user="`echo $userhost | sed -e s'/@.*$//'`"

test "$user" = "$userhost" && user=$USER

host="`echo $userhost | sed -e s'/^[^@]*@//'`"

envfile="`echo $arg | sed -e 's/^[^,]*,//'`"

test "$envfile" = "$arg" && envfile=/dev/null

builddir="`echo $arg | sed -e s'/^.*://' -e 's/,.*//'`"

test "$builddir" = "$arg" && builddir=/tmp

parbase=`basename $PARFILE`

# NB: update find_package( ) if these patterns are changed

package="`echo $parbase | \

sed -e 's/[.]jar$//' \

-e 's/[.]tar[.]bz2$//' \

-e 's/[.]tar[.]gz$//' \

-e 's/[.]tar[.]Z$//' \

-e 's/[.]tar$//' \

-e 's/[.]tgz$//' \

-e 's/[.]zip$//'`"

# Copy the package file if we cannot see it on the remote host

echo $SSH $SSHFLAGS $userhost "test -f $PARFILE"

if $SSH $SSHFLAGS $userhost "test -f $PARFILE"

then

parbaselocal=$PARFILE

else

parbaselocal=$parbase

echo $SCP $PARFILE $userhost:$builddir

$SCP $PARFILE $userhost:$builddir

fi

# Unbundle the archive file on the remote host, build, and

# check it, running in the background

sleep 1 # to guarantee unique log filename

now="`date $DATEFLAGS`"

logfile="$package.$host.$now.log"

nice $SSH $SSHFLAGS $userhost "

echo '= = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = = = = = = = = = = = =' ;

test -f $BUILDBEGIN && . $BUILDBEGIN || \

test -f $BUILDBEGIN && source $BUILDBEGIN || \

true ;

echo 'Package: $package' ;

echo 'Archive: $PARFILE' ;

echo 'Date: $now' ;

echo 'Local user: $USER' ;

echo 'Local host: `hostname`' ;

echo 'Local log directory: $LOGDIR' ;

echo 'Local log file: $logfile' ;

echo 'Remote user: $user' ;

echo 'Remote host: $host' ;

echo 'Remote directory: $builddir' ;

printf 'Remote date: ' ;

date $DATEFLAGS ;

printf 'Remote uname: ' ;

uname -a || true ;

printf 'Remote gcc version: ' ;

gcc --version | head -n 1 || echo ;

printf 'Remote g++ version: ' ;

g++ --version | head -n 1 || echo ;

echo 'Configure environment: `$STRIPCOMMENTS $envfile | $JOINLINES`' ;

echo 'Extra environment: $EXTRAENVIRONMENT' ;

echo 'Configure directory: $CONFIGUREDIR' ;

echo 'Configure flags: $CONFIGUREFLAGS' ;

echo 'Make all targets: $ALLTARGETS' ;

echo 'Make check targets: $CHECKTARGETS' ;

echo 'Disk free report for $builddir/$package:' ;

df $builddir | $INDENT ;

echo 'Environment:' ;

env | env LC_ALL=C sort | $INDENT ;

echo '= = = = = = = = = = = = = = = = = = = = = = = =

= = = = = = = = = = = = = = = = = = = = = = = = = = =' ;

umask $UMASK ;

cd $builddir || exit 1 ;

/bin/rm -rf $builddir/$package ;

$PAR $parbaselocal ;

test "$parbase" = "$parbaselocal"

Return Main Page Previous Page Next Page

®Online Book Reader