diff --git a/Makefile b/Makefile index 59013b5..f0c3375 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ sysconfigdir= ${sysconfdir}/sysconfig configdir = ${sysconfdir}/autodist localstatedir= /var piddir= ${localstatedir}/run/autodist +cgidir = ${localstatedir}/www/cgi-bin srcdir = . DESTDIR = @@ -63,6 +64,7 @@ install-programs: @$(INSTALL_SCRIPT) autoport-chroot $(DESTDIR)$(sbindir)/autoport-chroot @$(INSTALL_SCRIPT) autoport-fix-environment $(DESTDIR)$(bindir)/autoport-fix-environment @$(INSTALL_SCRIPT) etc/autodist/scripts/* $(DESTDIR)$(configdir)/scripts/ + @$(INSTALL_SCRIPT) autodist-cgi $(DESTDIR)$(cgidir)/autodist install-data: @$(INSTALL_DATA) etc/autodist/config $(DESTDIR)$(configdir)/config diff --git a/autoport-cgi b/autoport-cgi new file mode 100755 index 0000000..18114d4 --- /dev/null +++ b/autoport-cgi @@ -0,0 +1,78 @@ +#!/bin/bash +. /etc/sysconfig/autoport + +NUM=`echo "$QUERY_STRING" | sed -n 's/^.*NUM=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` +SECONDARY=`echo "$QUERY_STRING" | sed -n 's/^.*SECONDARY=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` +SHOWLOG=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWLOG=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` +SHOWLASTLOG=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWLASTLOG=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` +LINES=`echo "$QUERY_STRING" | sed -n 's/^.*LINES=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` + +[ "$LINES" ] || LINES=5 +[ "$SECONDARY" ] && SECONDARY_ADD="&SECONDARY=1" + +if [ "$SHOWLOG" -o "$SHOWLASTLOG" ]; then + echo -e "Content-type: text/plain; charset=UTF-8\n\n" +else + echo -e "Content-type: text/html; charset=UTF-8\n\n" +fi + +for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do + [ "${AUTOPORT_ARCH[$i]}" ] || continue + [ "${AUTOPORT_DISABLE[$i]}" -a "${AUTOPORT_DISABLE[$i]}" != "0" ] && continue + + if [ "${AUTOPORT_CHROOT[$i]}" ]; then + LOGFILE="/var/autodist/log/autoport-chroot-${AUTOPORT_CHROOT[$i]}.log" + LASTLOGFILE="/var/autodist/log/autoport-chroot-${AUTOPORT_CHROOT[$i]}-last.log" + elif [ "${AUTOPORT_NATIVE[$i]}" ]; then + LOGFILE="/var/autodist/log/autoport-native-${AUTOPORT_ARCH[$i]}.log" + LASTLOGFILE="/var/autodist/log/autoport-native-${AUTOPORT_ARCH[$i]}-last.log" + elif [ "${AUTOPORT_CROSS[$i]}" ]; then + LOGFILE="/var/autodist/log/autoport-cross-${AUTOPORT_CROSS[$i]}.log" + LASTLOGFILE="/var/autodist/log/autoport-cross-${AUTOPORT_CROSS[$i]}-last.log" + else + continue + fi + + if [ "$SHOWLOG" -a "$NUM" = "$i" ]; then + if [ ! "$SECONDARY" ]; then + cat $LOGFILE + else + curl "$AUTOPORT_CGI_SECONDARY?SHOWLOG=1&NUM=$i" + fi + exit 0 + elif [ "$SHOWLASTLOG" -a "$NUM" = "$i" ]; then + if [ ! "$SECONDARY" ]; then + cat $LASTLOGFILE + else + curl "$AUTOPORT_CGI_SECONDARY?SHOWLASTLOG=1&NUM=$i" + fi + exit 0 + elif [ ! "$SHOWLOG" -a ! "$SHOWLASTLOG" ]; then + [[ "$NUM" && "$NUM" != "$i" ]] && continue + + if [ "${AUTOPORT_CHROOT[$i]}" ]; then + echo "* chroot autoport (arch:${AUTOPORT_ARCH[$i]},channels:${AUTOPORT_REPOSITORIES[$i]},chroot:${AUTOPORT_CHROOT[$i]})" + echo " [ last ]" + fi + + if [ "${AUTOPORT_NATIVE[$i]}" ]; then + echo "* native autoport (arch:${AUTOPORT_ARCH[$i]},channels:${AUTOPORT_REPOSITORIES[$i]})" + echo " [ last ]" + fi + + if [ "${AUTOPORT_CROSS[$i]}" ]; then + echo "* cross-platform autoport (${AUTOPORT_CROSS[$i]})" + echo " [ last ]" + fi + echo "
"
+      grep -v "^=" $LOGFILE | tail -n "$LINES"
+      echo
+      echo "
" + fi +done + +[ "$NUM" ] && NUM=`expr $NUM - $i` + +if [ "$AUTOPORT_CGI_SECONDARY" -a ! "$SHOWLOG" -a ! "$SHOWLASTLOG" ]; then + curl "$AUTOPORT_CGI_SECONDARY?SECONDARY=1&LINES=$LINES&NUM=$NUM" +fi