#!/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"` AS_SECONDARY=`echo "$QUERY_STRING" | sed -n 's/^.*AS_SECONDARY=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` SHOWLOG=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWLOG=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` SHOWINDEX=`echo "$QUERY_STRING" | sed -n 's/^.*SHOWINDEX=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` LINES=`echo "$QUERY_STRING" | sed -n 's/^.*LINES=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` FORMAT=`echo "$QUERY_STRING" | sed -n 's/^.*FORMAT=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` [ ! "$FORMAT" ] && FORMAT=html [ "$LINES" ] || LINES=5 [ "$AS_SECONDARY" ] && SECONDARY_ADD="&SECONDARY=1" if [ ! "$AS_SECONDARY" -a "$FORMAT" = "xml" ]; then echo -e "Content-type: text/xml\nPragma: no-cache\n" echo -n "ALL]
" [ "$SHOWINDEX" -o ! "$AS_SECONDARY" ] && \ for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do [ "${AUTOPORT_ARCH[$i]}" ] || continue [ "${AUTOPORT_DISABLE[$i]}" -a "${AUTOPORT_DISABLE[$i]}" != "0" ] && continue if [ "${AUTOPORT_UPDATE[$i]}" ]; then echo "${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_CHROOT[$i]}" ]; then echo "${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_NATIVE[$i]}" ]; then echo "${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_CROSS[$i]}" ]; then echo "${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_CROSS[$i]};${AUTOPORT_ARCH[$i]}) " fi done if [ "$SHOWINDEX" ]; then exit 0 else curl "$AUTOPORT_CGI_SECONDARY?AS_SECONDARY=1&SHOWINDEX=1" 2>/dev/null fi [ ! "$AS_SECONDARY" ] && echo "
" [ ! "$SHOWLOG" -a "$SECONDARY" = "$AS_SECONDARY" ] && echo "

Host: `hostname -s` (`uname -m`, kernel `uname -r`)

" if [ "$SHOWLOG" -a "$SECONDARY" != "$AS_SECONDARY" ]; then curl "$AUTOPORT_CGI_SECONDARY?AS_SECONDARY=1&SHOWLOG=$SHOWLOG&NUM=$NUM&LOG=$LOG" 2>/dev/null else for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do [ "${AUTOPORT_ARCH[$i]}" ] || continue [ "${AUTOPORT_DISABLE[$i]}" -a "${AUTOPORT_DISABLE[$i]}" != "0" ] && continue if [ "${AUTOPORT_UPDATE[$i]}" ]; then LOGFILE="/var/autodist/log/autodist.log" LASTLOGFILE="/var/autodist/log/autodist-last.log" elif [ "${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" AUTODISTLOGFILE="/var/autoport/${AUTOPORT_CHROOT[$i]}/home/${AUTOPORT_CHROOT_USER[$i]}/.autoport/${AUTOPORT_ARCH[$i]}/${AUTOPORT_REPOSITORIES[$i]}.log" elif [ "${AUTOPORT_NATIVE[$i]}" ]; then LOGFILE="/var/autodist/log/autoport-native-${AUTOPORT_REPOSITORIES[$i]}-${AUTOPORT_ARCH[$i]}.log" LASTLOGFILE="/var/autodist/log/autoport-native-${AUTOPORT_REPOSITORIES[$i]}-${AUTOPORT_ARCH[$i]}-last.log" AUTODISTLOGFILE="/var/autodist/.autoport/${AUTOPORT_ARCH[$i]}/${AUTOPORT_REPOSITORIES[$i]}.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" ]; then if [ "$SECONDARY" = "$AS_SECONDARY" -a "$NUM" = "$i" ]; then echo "

$SHOWLOG log in ${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}):

" cat << _EOF
_EOF echo -n "
"
         if [ "$SHOWLOG" = "current" ]; then
            RELOADTIME=600000
            cat $LOGFILE | sed "s|<|\<|g"
         elif [ "$SHOWLOG" = "last" ]; then
            cat $LASTLOGFILE | sed "s|<|\<|g"
         else
            # Security check
            [ "${SHOWLOG/\/\.}" != "${SHOWLOG}" ] && continue
            if [ "${AUTOPORT_CHROOT[$i]}" ]; then
               BUILDLOGDIR="/var/autoport/${AUTOPORT_CHROOT[$i]}/home/${AUTOPORT_CHROOT_USER[$i]}/.autodist/log/"
           elif [ "${AUTOPORT_NATIVE[$i]}" -o "${AUTOPORT_UPDATE[$i]}" ]; then
               BUILDLOGDIR="/var/autodist/log/"
            fi
            if [ "${SHOWLOG/\/ok\/}" != "${SHOWLOG}" -o "${SHOWLOG/\failed\/}" != "${SHOWLOG}" ]; then
               SHOWLOGPKG=${SHOWLOG/*\/}
               [ "${SHOWLOGPKG}" ] || continue
               echo ""
               for t in prepare update build install send; do
                  echo -n "" || echo ""
                  [ -e ${BUILDLOGDIR}${t}/failed/${SHOWLOGPKG} ] && echo -n "" || echo ""
                  echo ""
               done
               echo "
Last ${SHOWLOGPKG} logs:
$t:" [ -e ${BUILDLOGDIR}${t}/ok/${SHOWLOGPKG} ] && echo -n "OKFAILED
" fi [ -e ${BUILDLOGDIR}${SHOWLOG} ] && cat ${BUILDLOGDIR}${SHOWLOG} | sed "s|<|\<|g" fi echo "
" fi elif [ ! "$SHOWLOG" ]; then RELOADTIME=60000 [[ "$NUM" && "$NUM" != "$i" ]] && continue [[ "$SECONDARY" = "$AS_SECONDARY" ]] || continue if [ "${AUTOPORT_UPDATE[$i]}" ]; then echo "* ${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) (type:autodist update)" echo " [ log last ]" fi if [ "${AUTOPORT_CHROOT[$i]}" ]; then echo "* ${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) (type:chroot autoport chroot:${AUTOPORT_CHROOT[$i]})" echo " [ log last ]" fi if [ "${AUTOPORT_NATIVE[$i]}" ]; then echo "* ${AUTOPORT_REPOSITORIES[$i]}(${AUTOPORT_ARCH[$i]}) (type:native autoport)" echo " [ log last ]" fi if [ "${AUTOPORT_CROSS[$i]}" ]; then echo "* cross-platform autoport (arch:${AUTOPORT_CROSS[$i]})" echo " [ last ]" fi cat << _EOF
_EOF echo "
"
      if [ "${AUTOPORT_UPDATE[$i]}" ]; then
         unset STARTTIME ENDTIME JOBON BUILDNOW BUILDLOG SCHEDULED
         BUILDNOWIDX=0
         while read line; do
            set -- $line
            if [[ "${line:0:1}" = $'\r' ]]; then
               PREF=`echo $1 | tr -d "\r"`
            else
               PREF=$1
            fi
            case $PREF in
               "%%" ) if [ "$2 $3" == "Autodist started" ]; then
                         STARTTIME=`echo $line | sed "s|.* @ ||"`
                      elif [ "$2 $3 $4" == "All jobs done" ]; then
                         ENDTIME=`echo $line | sed "s|.* @ ||"`
                      elif [ "$2 $3" == "autoupdate jobs:" ]; then
                         SCHEDULED=`echo $line | sed "s|.*autoupdate jobs: ||"`
                      elif [ "$2" == "Doing" ]; then
                         BUILDNOW[$BUILDNOWIDX]="$3"
                         BUILDNOWIDX=`expr $BUILDNOWIDX + 1`
                      #elif [ "$2" != "Starting" -a "$2" != "Updating" ]; then
                      #   [ "$JOBON" ] || echo $line
                      fi ;;
               "?=") if [ "$2" == "See" ]; then
                        BUILDLOG[$BUILDNOWIDX-1]=`echo $line | sed "s|.*autodist/log/||"`
                     fi ;;
               "=>") JOBON=1 ;;
               "%!"|"!!") BUILDNOW[$BUILDNOWIDX-1]="${BUILDNOW[$BUILDNOWIDX-1]} $line"; JOBON= ;;
               "==") [ "${2:0:2}" == "==" ] && JOBON= ;;
               "Hunk"|"") ;;
               *) [ "$JOBON" ] || {
                     line=`echo $line | sed "s|.*\r||"`
                     echo $line
                  } ;;
            esac
         done < $LOGFILE
      else
         unset STARTTIME ENDTIME BUILDNOW BUILDLOG AUTODISTON LASTLINE SCHEDULED
         while read line; do
            line=`echo $line | sed "s|.*\r||"`
            set -- $line
            case $1 in
               "%%" ) AUTODISTON=1 ;;
               "^"|"="*|""|"!"|"|"|"#"|"->") ;; #comment
               "+") [ "$STARTTIME" ] || STARTTIME=`echo $line | sed "s|.*start at ||"` ;;
               "-") ENDTIME=`echo $line | sed "s|.*end at ||"` ;;
               [A-Za-z0-9]*) ;;
               ">") [ "$SCHEDULED" ] || SCHEDULED=`echo $line | sed "s|.*Scheduled jobs: ||"` ;;
               *) [ ! "$AUTODISTON" ] && echo $line ;;
            esac
         done < $LOGFILE
         BUILDNOWIDX=1
         while read line; do
            line=`echo $line | sed "s|.*\r||"`
            set -- $line
            case $1 in
               "%%" ) if [ "$2" == "Doing" ]; then
                         if [ "$3" != "${BUILDNOW[$BUILDNOWIDX-1]}" ]; then
                            BUILDNOW[$BUILDNOWIDX]="$3"
                            BUILDNOWIDX=`expr $BUILDNOWIDX + 1`
                         fi
                         JOBON=1
                      fi ;;
               "?=") if [ "$2" == "See" ]; then
                        BUILDLOG[$BUILDNOWIDX-1]=`echo $line | sed "s|.*autodist/log/||"`
                     fi ;;
               "=>") JOBON=1 ;;
               "%!"|"!!") BUILDNOW[$BUILDNOWIDX-1]="${BUILDNOW[$BUILDNOWIDX-1]} $line"; JOBON= ;;
               "==") [ "${2:0:2}" == "==" ] && JOBON= ;;
               "Hunk"|"") ;;
               *) [ "$JOBON" ] || echo $line ;;
            esac
         done < $AUTODISTLOGFILE
         LASTLINE=$line
      fi
         echo "Start: $STARTTIME"
         echo "Scheduled jobs: $SCHEDULED"
         for b in `seq 1 ${#BUILDNOW[*]}`; do
            set -- ${BUILDNOW[$b]}
            if [ "${BUILDLOG[$b]}" ]; then
               echo "$1: $2 $3 $4 $5 $6 "
            elif [ "$1" ]; then
               echo "$1: $2 $3 $4 $5 $6 "
            fi
         done
         if [ "$LASTLINE" ]; then
            set -- $LASTLINE
            [ "$1" = "^" ] && echo "${2} ${3} ${4} ${5} ${6} ${7}"
         fi
         [ "$ENDTIME" ] && echo "End: $ENDTIME" || echo "End: in progress"
      echo 
#      grep -v "^=" $LOGFILE | tail -n "$LINES" | sed "s|.*\r||"
#      echo
      echo "
" fi done if [ "$AUTOPORT_CGI_SECONDARY" -a ! "$SHOWLOG" ]; then if [ "$NUM" -a "$SECONDARY" ]; then curl "$AUTOPORT_CGI_SECONDARY?AS_SECONDARY=1&LINES=$LINES&NUM=$NUM&SECONDARY=$SECONDARY" 2>/dev/null elif [ ! "$NUM" ]; then curl "$AUTOPORT_CGI_SECONDARY?AS_SECONDARY=1&LINES=$LINES" 2>/dev/null fi fi fi [ ! "$AS_SECONDARY" ] && echo "

Generated by autodist CGI interface. Last update: `date`" if [ ! "$AS_SECONDARY" -a "$FORMAT" = "xml" ]; then echo -n "]]>" [ "$RELOADTIME" ] && echo -n "$RELOADTIME" echo "" fi