Add some boilerplate
[buildd-scripts.git] / bin / get_package
1 #!/bin/bash
2
3 CLIENT=$1
4 LOGDIR=/home/build/logs
5 LOGFILE=/var/log/builder.log
6 STATEDIR=/home/build/state
7
8 cd in
9
10 while true; do
11     FILE=$(ls -1 *.q 2>/dev/null| head -1)
12     if [ "$FILE"x = ""x ]; then
13         # If we didn't find a job
14         echo NOPACKAGE
15         exit 1
16     fi
17     NUM=$(echo $FILE | cut -d. -f1)
18     mv $NUM.q $NUM.proc
19     if [ $? -ne 0 ]; then # we clashed
20         echo NOPACKAGE
21         exit 1
22     fi
23
24     PKG_VER_ARCH=$(cat $NUM.proc)
25
26     DATE=$(date)
27
28     if [ -f ${LOGDIR}/${ARCH}/PASS/${PKG_VER_ARCH}.log ] || [ -f ${LOGDIR}/${ARCH}/FAIL/${PKG_VER_ARCH}.log ]; then
29         for file in ${LOGDIR}/${ARCH}/{PASS,FAIL}/${PKG_VER_ARCH}.log; do
30             # Ignore and try again
31             if [ -f  $file ]; then
32                 echo "$DATE: Ignoring package $NUM: $PKG_VER_ARCH, already have logfile $file" >> $LOGFILE
33             fi
34         done
35         continue
36     fi
37
38     # else
39     echo "$DATE: Queued package $NUM: $PKG_VER_ARCH on $CLIENT" >> $LOGFILE
40     echo "$DATE: Queued package $NUM: $PKG_VER_ARCH on $CLIENT" > $STATEDIR/$NUM.running
41     echo "$NUM $PKG_VER_ARCH"
42     exit 0
43 done
44
45 exit 0
46