#!/usr/bin/env bash exec 2>/dev/null if [ "$QUERY_STRING" = "full_build" ]; then if printf %s "$HTTP_REFERER" | grep -qE '^https?://([^/]+\.)?fsfe\.org/'; then touch ./full_build fi printf 'Location: ./\n\n' exit 0 fi timestamp(){ date -d "@$1" +"%F %T (%Z)" } duration(){ minutes=$(($1 / 60)) if [ "${minutes}" == "1" ]; then minutes="${minutes} minute" else minutes="${minutes} minutes" fi seconds=$(($1 % 60)) if [ "${seconds}" == "1" ]; then seconds="${seconds} second" else seconds="${seconds} seconds" fi echo "${minutes} ${seconds}" } web_tab(){ tabname="$1" tablabel="$2" tabcontent="$3" [ -n "$4" ] && checked='checked="checked"' || checked='' cat <
${tabcontent}
EOF } htmlcat(){ sed 's;&;\&\;;g; s;<;\<\;;g; s;>;\>\;;g; s;";\"\;;g; s;'\'';\&apos\;;g;' $@ } start_time=$(cat "start_time" || stat -c %Y "$0" || echo 0) t_gitupdate=$(stat -c %Y "GITlatest" ||echo 0) t_phase_1=$(stat -c %Y "phase_1" ||echo 0) t_makefile=$(stat -c %Y "Makefile" ||echo 0) t_phase_2=$(stat -c %Y "phase_2" ||echo 0) t_manifest=$(stat -c %Y "manifest" ||echo 0) t_stagesync=$(stat -c %Y "stagesync" ||echo 0) end_time=$(cat "end_time" || echo 0) duration=$(($end_time - $start_time)) term_status=$(if [ "$duration" -gt 0 -a -f lasterror ]; then echo Error elif [ "$duration" -gt 0 ]; then echo Success fi) printf %s\\n\\n "Content-Type: text/html;charset=utf-8" cat < Build status

Build report

Start time:
$(timestamp ${start_time})
End time:
$([ "$duration" -gt 0 ] && timestamp ${end_time})
Duration:
$([ "$duration" -gt 0 ] && duration ${duration})
Termination Status:
${term_status:-running...}
$(if [ ./full_build -nt ./index.cgi ]; then printf 'Full rebuild will be started within next minute.' else printf 'Schedule full rebuild' fi)

Previous builds

$( web_tab 'tab-prev' '' " latest
$( ls -t status_*.html |head -n10 |while read stat; do t="${stat#status_}" t="${t%.html}" printf '%s - %s
' \ "$stat" "$(timestamp "$t")" "$(sed -rn 's;^.*
Duration:
(.+)
.*$;\1;p;T;q' "$stat")" done )" )

GIT changes

$( if [ ${start_time} -le ${t_gitupdate} ]; then web_tab "tab-git" \ "at $(timestamp ${t_gitupdate})" \ "
$(htmlcat GITlatest)
" \ "checked" else web_tab "tab-git" \ "Unconditional build, changes ignored" fi)

Phase 1

$( if [ $start_time -lt $t_phase_1 -a $start_time -lt $t_gitupdate ]; then web_tab "tab-phase-1" \ "$(duration $(($t_phase_1 - $t_gitupdate)))" \ "
$(htmlcat  phase_1)
" elif [ $start_time -lt $t_phase_1 ]; then web_tab "tab-phase-1" \ "$(duration $(($t_phase_1 - $start_time)))" \ "
$(htmlcat phase_1)
" else web_tab "tab-phase-1" \ "waiting..." fi)

Phase 2 Makefile

$( if [ $start_time -lt $t_makefile ]; then web_tab "tab-makefile" \ "$(duration $(($t_makefile - $t_phase_1)) )" \ "
$(htmlcat Makefile)
" else web_tab "tab-makefile" \ "waiting..." fi)

Phase 2

$( if [ $start_time -lt $t_phase_2 ]; then web_tab "tab-phase-2" \ "$(duration $(($t_phase_2 - $t_makefile)) )" \ "
$(htmlcat phase_2)
" else web_tab "tab-phase-2" \ "waiting..." fi)

Target update

$( if [ ${start_time} -lt ${t_stagesync} -a -s stagesync ]; then web_tab "tab-sync" \ "$(($(wc -l stagesync |cut -f1 -d\ ) - 4)) updated files" \ "
$(htmlcat stagesync)
" elif [ -z ${term_status} ]; then web_tab "tab-sync" \ "waiting..." else web_tab "tab-sync" \ "-" fi)

Errors

$( if [ -f lasterror ]; then web_tab "tab-errors" \ "There were errors" \ "
$(htmlcat lasterror)
" \ "checked" else web_tab "tab-errors" \ "none" fi)

File Manifest

$( if [ $start_time -lt $t_manifest ]; then web_tab "tab-manifest" \ "$(wc -l manifest | cut -d\ -f1) files" \ "view" else web_tab "tab-manifest" \ "waiting..." fi) HTML_END