Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [116]

By Root 867 0
= = = = = = = = = = = = = = = = = ' ;

The $BUILDBEGIN script is executed, if it exists, on the remote system in the context of the login shell early in the command sequence. It can provide login customizations, such as augmenting PATH when shell startup files cannot do this (e.g., for ksh and sh). It can also write additional information to standard error or standard output, and thus, to the build-log file. Shells in the Bourne-shell family use the dot command to execute commands in the current shell, whereas shells in the C-shell family use the source command. The bash and zsh shells support both commands.

Unfortunately, some shells, including the POSIX one, abort execution of the dot command if the specified file does not exist. This makes simple code like . $BUILDBEGIN || true fail, despite the use of the true command at the end of the conditional. We therefore also need a file-existence test, and we have to handle the source command as well. Because two shells recognize both the dot command and the source command, we must do this in a single complex command that relies on the equal precedence of the Boolean operators:

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

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

true ;

We are not happy with the complexity of this statement, but the severe design requirement that build-all must work for all login shells forces it upon us, and we could find no acceptable simpler solution.

We assume that the startup script has been debugged before build-all is used. Otherwise, if execution of the $BUILDBEGIN script terminates with an error, there may be two attempts to execute it.

Based on long experience, we find it useful to record extra information in the build logs, so there are a score of echo commands for that purpose, carefully formatted for better log-file readability:

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' ;

It is also sometimes useful to know how long a build takes (on one of our older systems, the GNU C compiler build takes nearly a day), so the script reports before and after dates. These are obtained on the remote host, which might be in a different time zone, or suffer from clock skew, and it may be important later to match timestamps of installed files with entries in the build logs. There is no portable way to use echo to generate a partial line, so we use printf:

printf 'Remote date: ' ;

date $DATEFLAGS ;

Similarly, we record system and GNU compiler version information, since that may be needed in bug reports:

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 ;

There is no common way with other compilers to get version information, so we cannot handle that task in build-all. Instead, we can produce any desired reports from suitable commands in the $BUILDBEGIN script. Our script continues, providing additional information:

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' ;

Running out of disk space has proven to be a common cause of failures, so we use df to report on the available space before and after the build:

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

df $builddir | $INDENT ;

configure and make can be influenced by environment variables, so we finish off the log-file header with a sorted list of them:

echo 'Environment:' ;

env | env LC_ALL=C sort | $INDENT ;

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

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

The env command in the middle stage

Return Main Page Previous Page Next Page

®Online Book Reader