#!/bin/bash
#
# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/scripts/Create-ParaStatus
# ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---

config=default
 
while [ "$1" ] ; do
        case "$1" in
                -cfg)   config=$2 ; shift ; shift ;;
                *)      echo
			echo "Usage: $0 [ -cfg <config> ]"
			echo
			echo " Show the current status of a parallel build."
			echo
			echo "	-cfg <config>	the configuration to use"
			echo
			exit 1 ;;
        esac
done    

. scripts/parse-config
qdir="$base/build/$ROCKCFG_ID/ROCK/queue"

if [ ! -d $qdir ] ; then
        echo
        echo "$qdir:"
        echo "Queue not found! Please start 'Build-Target -cfg $config'"
        echo "first on the master node ..."
        echo
        exit 1
fi

date '+%H:%M %Y-%m-%d:%t--- current status ---' | expand -t20
cat $qdir/*.stat $qdir/*.lock 2> /dev/null | expand -t30
if [ -f $qdir/queue.txt ] ; then
	while read line ; do
		set $line ; cat $qdir/$1-$6.todo 2> /dev/null
	done < $qdir/queue.txt | expand -t30
else
	echo -e 'Queue file not found!\tDisplaying' \
		'all prepared jobs:' | expand -t30
	cat $qdir/*.todo 2> /dev/null | sort -n -r -k9 | expand -t30
fi
date '+%H:%M %Y-%m-%d:%t----------------------' | expand -t20