+ if [ "$tmpfile" ]; then
+ #### Disable output redirection (and flush) so that we can grep.
+ #### If $tmpfile is null, don't need to do this because the
+ #### outputs weren't redirected, modulo a small race condition
+ #### between setting tmpfile and redirecting the outputs.
+ exec 1>&3 3>&- 2>&4 4>&-
+
+ if [ "$logfile" != - ]; then
+ exec 3>&1 >"$logfile" 2>&1
+ fi
+
+ if [ -f "$tmpfile" ]; then
+ cat "$tmpfile"
+ grep -E 'Error|warn' "$tmpfile"
+ rm "$tmpfile"
+ fi
+ fi
+
+ #### Put info message on stdout, and in log if not stdout.
+ if [ $status -ne 0 -o $verbose -ge 1 -o "$directory" ]; then
+ [ $status -eq 0 ] && result=succeeded || result=failed
+ if [ "$logfile" = - ]; then
+ echo "build $result"
+ else
+ message="build $result, build log is in ${directory:+$directory/}$logfile"
+ echo "$message" >&3
+ fi
+ fi
+
+ #### Heirloom shell does not like "trap - signal".
+ trap '' EXIT
+ exit $status
+}
+
+#### Exit with error message.
+die() {
+ status=1 # It should already be, but just in case the code below changes.
+ echo "$0: $*" 1>&2
+ cleanup
+}
+
+#### Download sources from repo. With git and on master, the
+#### directory will be nmh, but with snapshot, it will be
+#### nmh-master.
+download_sources() {
+ [ $verbose -ge 1 ] && echo downloading . . . >&3
+ gitdir=`finddir git`
+ if [ "$gitdir" ]; then
+ #### Use git repo.
+ [ "$verbose" -eq 0 ] && git_opts=--quiet
+ [ "$branch" = master ] ||
+ git_opts="${git_opts:+$git_opts }--branch $branch"
+ if "$gitdir"/git clone --depth 1 $git_opts "git://$gitrepo/nmh.git" >&3
+ then
+ directory=nmh
+ cd "$directory" || die "failed to clone $directory"
+ printf "commit %s\n" `git log --max-count=1 --pretty=format:%H`
+ else
+ die 'failed to clone git repo'
+ fi