summaryrefslogtreecommitdiffstats
path: root/bin/cgi-bin/nph-logwatch
blob: e3e230e28de926725ba88f762e7d6d6dcad302bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash

# Copyright © 2017 Holger Levsen (holger@layer-acht.org)
# released under the GPLv=2

set -e

echo "HTTP/1.0 200 OK"
echo "Connection: close"
echo 'Content-type: text/plain; charset="utf-8"'
echo ""

TARGET=${QUERY_STRING}

#
# sanitize input
#
WORKER=$(basename $(dirname $TARGET))
BUILD=$(basename $TARGET)

#
# we only work on known files…
#
DIR=/var/lib/jenkins/userContent/reproducible/debian/build_service/$WORKER
FILE=$DIR/$BUILD/console.log

# keep commented code for debugging…
if [ ! -d $DIR ] ; then
	echo "$DIR does not exist."
	#echo "Wanted $TARGET but $DIR does not exist."
	exit 0
elif [ ! -f $FILE ] ; then
	echo "$FILE does not exist."
	#echo "Wanted $TARGET but $FILE does not exist."
	exit 0
fi

#
# this build exists, what about this one:
#
let NEW_BUILD=$BUILD+1

#
# if this ain't the latest build, just cat it's logfile
#
if [ -e $DIR/$NEW_BUILD/console.log ] ; then
	cat $FILE
#
# if the worker ain't running, just cat the logfile
#
elif [ ! -z "$(ps fax|grep -v grep|grep 'reproducible_worker $WORKER.sh ')" ] ; then
	cat $FILE
#
# FIXME: we should really just convert 'latest' into a number here and use the tail below… 
#
elif [ "$BUILD" = "latest" ] ; then
	cat $FILE
else
	#
	# else, we tail the logfile and kill the tail process, once the next build
	# has been started
	#
	tail -c +0 -f $FILE &
	TAILPID=$!
	while ! test -f $DIR/$NEW_BUILD/console.log ; do
		sleep 1
	done
	kill -9 $TAILPID
fi
echo