#!/bin/bash . /etc/sysconfig/autoport . /usr/share/autodist/webbuild-functions NUM=`echo "$QUERY_STRING" | sed -n 's/^.*NUM=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` HOST=`echo "$QUERY_STRING" | sed -n 's/^.*HOST=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` REP=`echo "$QUERY_STRING" | sed -n 's/^.*REP=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"` AS_HOST=`echo "$QUERY_STRING" | sed -n 's/^.*AS_HOST=\([^&]*\).*$/\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"` function resolve_logname() { local l=$1 local jobname=$2 unset SUBJOBNAME OPERATIONNAME OPERATIONSTATUS SUBJOBNAME=`echo $l | sed "s|.*/${jobname}_\(.*\)\..*|\1|"` [ "${SUBJOBNAME:0:1}" = "_" ] && SUBJOBNAME=$l [ "$SUBJOBNAME" = "$l" ] && SUBJOBNAME=`echo $l | sed "s|.*/\(.*\)\..*|\1|"` SUBJOBNAME=${SUBJOBNAME/__*} [ "${BUILDOPERATION[$b]}" ] && \ OPERATIONNAME=${BUILDOPERATION[$b]} || OPERATIONNAME=`echo $l | sed "s|\(.*\)/.*/.*|\1|"` [ "${BUILDOPERATIONSTATUS[$b]}" ] && \ OPERATIONSTATUS=${BUILDOPERATIONSTATUS[$b]} || OPERATIONSTATUS=`echo $l | sed "s|.*/\(.*\)/.*|\1|"` } [ ! "$FORMAT" ] && FORMAT=html [ "$LINES" ] || LINES=5 [ "$HOST" ] || HOST=0 [ "$AS_HOST" ] || AS_HOST=0 [ "$AS_HOST" -a "$HOST" != "0" ] && HOST_ADD="&HOST=$HOST" if [ "$AS_HOST" = "0" -a "$FORMAT" = "xml" ]; then echo -e "Content-type: text/xml\nPragma: no-cache\n" echo -n "$r(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_CHROOT[$i]}" ]; then echo "$r(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_NATIVE[$i]}" ]; then echo "$r(${AUTOPORT_ARCH[$i]}) " elif [ "${AUTOPORT_CROSS[$i]}" ]; then echo "$r(${AUTOPORT_CROSS[$i]};${AUTOPORT_ARCH[$i]}) " fi done done echo "
" exit 0 elif [ "$AS_HOST" = "0" ]; then echo "Show: [All hosts] [Build hosts monitor]
" for h in `seq 0 ${#AUTOPORT_CGI_HOST[*]}`; do curl --connect-timeout 20 "${AUTOPORT_CGI_HOST[$h]}?AS_HOST=$h&SHOWINDEX=1" 2>/dev/null done echo "
" fi [ ! "$SHOWLOG" -a "$HOST" = "$AS_HOST" ] && echo "

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

" if [ "$SHOWLOG" -a "$HOST" != "$AS_HOST" ]; then curl "${AUTOPORT_CGI_HOST[$HOST]}?AS_HOST=$HOST&SHOWLOG=$SHOWLOG&NUM=$NUM&REP=$REP&LOG=$LOG" 2>/dev/null else for i in `seq 0 ${#AUTOPORT_ARCH[*]}`; do if [ "$SHOWLOG" = "monitor" ]; then echo "

Build hosts monitor

" icecream-monitor $ICECREAM_MONITOR_HOST listcs | \ while read line; do [ "${line:0:8}" = "200 done" ] && printon= if [ "$printon" ]; then set -- $line case $2 in \(*) echo "$line
" ;; *) echo "$line
" ;; esac fi [ "${line:0:6}" = "listcs" ] && printon=1 done echo "
" RELOADTIME=15000 break fi RNUM=-1 for r in ${AUTOPORT_REPOSITORIES[$i]}; do [ "${AUTOPORT_ARCH[$i]}" ] || continue [ "${AUTOPORT_DISABLE[$i]}" -a "${AUTOPORT_DISABLE[$i]}" != "0" ] && continue RNUM=`expr $RNUM + 1` LOGDIR=`environment_logdir $i` AUTOPORTLOGDIR=`environment_autoport_logdir $i` ENVROOTDIR=`environment_rootdir $i` if [ "${AUTOPORT_UPDATE[$i]}" ]; then LOGFILE="$LOGDIR/autodist.log" LASTLOGFILE="$LOGDIR/autodist-last.log" STATEFILE="$LOGDIR/autoupdate-current" LASTSTATEFILE="$LOGDIR/autoupdate-last" elif [ "${AUTOPORT_CHROOT[$i]}" ]; then LOGFILE="/var/autodist/log/autoport-chroot-$r-${AUTOPORT_CHROOT[$i]}.log" LASTLOGFILE="/var/autodist/log/autoport-chroot-$r-${AUTOPORT_CHROOT[$i]}-last.log" AUTODISTLOGFILE="$AUTOPORTLOGDIR/${AUTOPORT_ARCH[$i]}/$r-current.log" AUTODISTSTATEFILE="$AUTOPORTLOGDIR/autoport-$r-current" elif [ "${AUTOPORT_NATIVE[$i]}" ]; then LOGFILE="/var/autodist/log/autoport-native-$r-${AUTOPORT_ARCH[$i]}.log" LASTLOGFILE="/var/autodist/log/autoport-native-$r-${AUTOPORT_ARCH[$i]}-last.log" AUTODISTLOGFILE="$AUTOPORTLOGDIR/${AUTOPORT_ARCH[$i]}/$r-current.log" AUTODISTSTATEFILE="$AUTOPORTLOGDIR/autoport-$r-current" elif [ "${AUTOPORT_CROSS[$i]}" ]; then LOGFILE="$LOGDIR/autoport-cross-$r-${AUTOPORT_CROSS[$i]}.log" LASTLOGFILE="$LOGDIR/autoport-cross-$r-${AUTOPORT_CROSS[$i]}-last.log" else continue fi if [ "$SHOWLOG" ]; then if [ "$HOST" = "$AS_HOST" -a "$NUM" = "$i" -a "$REP" = "$RNUM" ]; then echo -n "

$SHOWLOG log in " if [ "${AUTOPORT_UPDATE[$i]}" ]; then echo -n "update" elif [ "${AUTOPORT_CHROOT[$i]}" ]; then echo -n "${AUTOPORT_CHROOT[i]} chroot" elif [ "${AUTOPORT_NATIVE[$i]}" ]; then echo -n "native" elif [ "${AUTOPORT_CROSS[$i]}" ]; then echo -n "cross" fi echo " environment for ${AUTOPORT_ARCH[$i]}" [ "${SHOWLOG}" = "current" -o "${SHOWLOG}" = "last" -a ! "${AUTOPORT_UPDATE[$i]}" ] && echo -n " ($r)" echo -n ":

" cat << _EOF
_EOF echo -n "
"
         if [ "$SHOWLOG" = "current" ]; then
            RELOADTIME=3600000
            cat $LOGFILE | parse_build_output
         elif [ "$SHOWLOG" = "last" ]; then
            cat $LASTLOGFILE | parse_build_output
            LASTLOGDETAILS=`tail $LASTLOGFILE | grep "See .* for details" | sed "s|.*See \(.*\) for details.*|\1|"`
            cat $ENVROOTDIR/$LASTLOGDETAILS | parse_build_output
         else
            # Security check
            [ "${SHOWLOG/\/\.}" != "${SHOWLOG}" ] && continue
            BUILDLOGDIR="$LOGDIR"
            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 if [ -r ${BUILDLOGDIR}${SHOWLOG} ]; then LOGFILESIZE=`stat -c %s ${BUILDLOGDIR}${SHOWLOG}` LOGDATE=`stat -c %y ${BUILDLOGDIR}${SHOWLOG}` echo -n "${SHOWLOG} ($LOGDATE; $LOGFILESIZE):" if [ $LOGFILESIZE -lt 131072 ]; then cat ${BUILDLOGDIR}${SHOWLOG} | parse_build_output else head -c 65535 ${BUILDLOGDIR}${SHOWLOG} | parse_build_output echo "
<------ CUT (long file) ------>" tail -c 65535 ${BUILDLOGDIR}${SHOWLOG} | parse_build_output fi fi fi echo -n "
" echo -n "
" # break fi [ "${AUTOPORT_UPDATE[$i]}" ] && break elif [ ! "$SHOWLOG" ]; then RELOADTIME=600000 [[ "$NUM" && "$NUM" != "$i" ]] && continue [[ "$HOST" = "$AS_HOST" ]] || continue if [ "${AUTOPORT_UPDATE[$i]}" ]; then echo "* $r(${AUTOPORT_ARCH[$i]}) (type:autodist update)" echo " [ log last ]" fi if [ "${AUTOPORT_CHROOT[$i]}" ]; then echo "* $r(${AUTOPORT_ARCH[$i]}) (type:chroot autoport chroot:${AUTOPORT_CHROOT[$i]})" echo " [ log last ]" fi if [ "${AUTOPORT_NATIVE[$i]}" ]; then echo "* $r(${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 -n "
"
      unset BUILDNOWIDX BUILDLOG BUILDNOW BUILDNOWSTATUS SCHEDULED STARTTIME AUTODIST_PID ENDTIME
      if [ "${AUTOPORT_UPDATE[$i]}" ]; then
         BUILDNOWIDX=0
         STARTTIME=`head $LOGFILE | grep "%% Autodist started" | sed "s|.* @ ||"`
         AUTODIST_PID=`head $LOGFILE | grep "%% Autodist started" | sed "s|.*PID \([0-9]*\) .*|\1|"`
         SCHEDULED=`head $LOGFILE | grep "%% autoupdate jobs:" | sed "s|.*autoupdate jobs: ||"`
         ENDTIME=`tail $LOGFILE | grep "%% All jobs done @" | sed "s|.*@ ||"`
         while read line; do
            set -- $line
            for c in `seq 0 ${#BUILDNOW[*]}`; do
               if [ "${BUILDNOW[c]}" = "$1" ]; then
                  BUILDNOWIDX=$c
                  break
               else
                  BUILDNOWIDX=$c
               fi
            done
            BUILDNOW[$BUILDNOWIDX]="$1"
            [ "$4" ] && BUILDLOG[$BUILDNOWIDX]="${BUILDLOG[$BUILDNOWIDX]} `echo $4 | sed "s|.*autodist/log/||"`"
#            BUILDLOG[$BUILDNOWIDX]="${BUILDLOG[$BUILDNOWIDX]} $2/$3/$1.i586"
            BUILDNOWSTATUS[$BUILDNOWIDX]=$3
            BUILDNOWIDX=`expr $BUILDNOWIDX + 1`
         done < $STATEFILE
      else
         STARTTIME=`head $LOGFILE | grep "^+ .*start at " | sed "s|.*start at ||"`
#         AUTODIST_PID=`head $LOGFILE | grep "%% Autodist started" | sed "s|.*PID \([0-9]*\) .*|\1|"`
         SCHEDULED=`head -n 40 $LOGFILE | grep -m 1 "^> .*Scheduled jobs: " | sed "s|.*Scheduled jobs: ||"`
         ENDTIME=`tail $LOGFILE | grep "^- .*end at " | sed "s|.*end at ||"`
         if [ -e "$AUTODISTSTATEFILE" ]; then
            while read line; do
               set -- $line
               for c in `seq 0 ${#BUILDNOW[*]}`; do
                  if [ "${BUILDNOW[c]}" = "$1" ]; then
                     BUILDNOWIDX=$c
                     break
                  else
                     BUILDNOWIDX=$c
                  fi
               done
               BUILDNOW[$BUILDNOWIDX]="$1"
               if [ "$4" ]; then
                  BUILDLOG[$BUILDNOWIDX]="${BUILDLOG[$BUILDNOWIDX]} `echo $4 | sed "s|.*/log/||"`"
               else
                  if [ "$2" = "port" ]; then
                     CURRLOGFILE=build/$3/$1.${AUTOPORT_ARCH[$i]}
                  else
                     CURRLOGFILE=$2/$3/$1.${AUTOPORT_ARCH[$i]}
                  fi
                  BUILDLOG[$BUILDNOWIDX]="${BUILDLOG[$BUILDNOWIDX]} $CURRLOGFILE"
               fi
#               BUILDLOG[$BUILDNOWIDX]="${BUILDLOG[$BUILDNOWIDX]} $2/$3/$1.i586"
               BUILDNOWSTATUS[$BUILDNOWIDX]=$3
               BUILDNOWIDX=`expr $BUILDNOWIDX + 1`
            done < $AUTODISTSTATEFILE
            for p in `dirname $LOGFILE`/current.*; do
               CURRENT_FILE=`basename $p`
               AUTODIST_PID=${p/*.}
               grep "autodist" /proc/$AUTODIST_PID/status &>/dev/null && break
               AUTODIST_PID=
            done
         fi
      fi
      [ "$STARTTIME" ] && echo "Start: $STARTTIME"
      [ "$SCHEDULED" ] && echo "Scheduled jobs: $SCHEDULED"
      LASTJOBNAME=
      for b in `seq 0 ${#BUILDNOW[*]}`; do
#         set -- ${BUILDNOW[$b]}
         JOBNAME=${BUILDNOW[$b]}
         [ "$JOBNAME" ] || continue
         if [ "$JOBNAME" != "$LASTJOBNAME" ]; then
            [ "$LASTJOBNAME" -a "$JOBNAME" ] && echo
            if [ "${BUILDLOG[$b]}" ]; then
               resolve_logname ${BUILDLOG[$b]/* } $JOBNAME
               if [ "${OPERATIONSTATUS}" = "ok" ]; then
                  WEBBUILD_APPEND="&LOGSTATUSOK=true"
               else
                  WEBBUILD_APPEND="&LOGSTATUSOK=false"
               fi
               echo -n "$JOBNAME: "
            else
               echo -n "$JOBNAME: "
            fi
         fi
         rowcnt=0
         if [ "${BUILDLOG[$b]}" ]; then
            for l in ${BUILDLOG[$b]}; do
               resolve_logname $l $JOBNAME
#               if [ $rowcnt -ge 4 ]; then
#                  echo
#                  rowcnt=0
#               fi
               case $OPERATIONNAME-$OPERATIONSTATUS in 
                  build-ok|send-ok|install-ok|retryinstall-ok)
                     echo -n "$OPERATIONNAME:$OPERATIONSTATUS"
                     ;;
                  update-failed|autoupdate-failed)
                     if [ "${BUILDNOWSTATUS[$b]}" = "4" ]; then
                        echo -n "$OPERATIONNAME:up-to-date"
                     elif [ "${BUILDNOWSTATUS[$b]}" = "3" ]; then
                        echo -n "$OPERATIONNAME:unknown"
                     elif [ "${BUILDNOWSTATUS[$b]}" = "2" ]; then
                        echo -n "$OPERATIONNAME:newer"
                     else
                        echo -n "$OPERATIONNAME:$OPERATIONSTATUS"
                     fi
                     ;;
                  *-ok) echo -n "$OPERATIONNAME:$OPERATIONSTATUS"
                     ;;
                  *)
                     echo -n "$OPERATIONNAME:$OPERATIONSTATUS"
                     ;;
               esac
#               [ "$SUBJOBNAME" != "$JOBNAME" ] && echo -en "($SUBJOBNAME)"
               echo -n " "
               rowcnt=`expr $rowcnt + 1`
            done
         fi
         if [[ $b -eq $BUILDNOWIDX-1 && ! "$ENDTIME" ]]; then
            echo -n "${BUILDOPERATION[$b]}(in progress...)"
         fi
         LASTJOBNAME=$JOBNAME
      done
      [ "$LASTJOBNAME" ] && echo
      if [ "$ENDTIME" ]; then
         echo "End: $ENDTIME"
      elif [ "$AUTODIST_PID" ]; then
         echo "End: in progress"
      fi
      echo
#      grep -v "^=" $LOGFILE | tail -n "$LINES" | sed "s|.*\r||"
#      echo
      echo "
" fi done done # only root host (0) calls other hosts if [ "$AS_HOST" = "0" -a ! "$SHOWLOG" ]; then for h in `seq 1 ${#AUTOPORT_CGI_HOST[*]}`; do WBHOSTURL=`echo ${AUTOPORT_CGI_HOST[$h]} | sed "s|^\(http[s]*://[^/]*\).*$|\1|"` if [ "$WBHOSTURL" ]; then curl -m1 -s -I ${WBHOSTURL} >/dev/null || continue if [ "$NUM" -a "$HOST" = "$h" ]; then curl "${AUTOPORT_CGI_HOST[$h]}?AS_HOST=$h&LINES=$LINES&NUM=$NUM&REP=$RNUM&HOST=$HOST" 2>/dev/null elif [ ! "$NUM" ]; then curl "${AUTOPORT_CGI_HOST[$h]}?AS_HOST=$h&LINES=$LINES" 2>/dev/null fi fi done fi fi if [ "$AS_HOST" = "0" ]; then echo "

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