#! /bin/bash # script to generate html pages # tnka@linux-sottises.net # check general config file exists if ! [ -f /etc/mrtnk.setup ];then echo "Error: you have to put mrtnk.setup in /etc" exit 1 fi # Config file must be given if ! [ "$1" ];then echo "Error: provide the config file name" exit 1 fi # General Parameters . /etc/mrtnk.setup # Config file must be given if ! [ "$1" ];then echo "Provide the config file name!!" exit 1 fi MOMENT=(day week month year) # Configuration file is read from command line CONFIG=$1 # Determine extension EXT=`cat $CONFIG|grep -i html_extension|grep -v "#"|cut -d'"' -f2` if [ -z "$EXT" ];then EXT="html" fi NOLOGO=`cat $CONFIG|grep -i NO_LOGO|grep -v "#"` # Determine all the targets TARGET_LIST=(`cat $CONFIG|grep -i target|grep -v "#"|cut -d"[" -f2|cut -d "]" -f1`) ###### Beginning of the index page ########### INDEX="$HTML/stats_mrtnk.$EXT" echo "" > $INDEX echo "" >> $INDEX echo "" >> $INDEX echo "STATS MRTNK" >> $INDEX echo "" >> $INDEX echo "" >> $INDEX echo "" >> $INDEX echo "" >> $INDEX if [ -f "$CONF/index_head_mrtnk" ];then cat "$CONF/index_head_mrtnk" >> $INDEX fi echo "" >> $INDEX if [ -f "$CONF/index_body_mrtnk" ];then cat "$CONF/index_body_mrtnk" >> $INDEX else echo "" >> $INDEX fi echo "
" >> $INDEX ####### end beginning of INDEX # Loop on all the targets for i in "${TARGET_LIST[@]}"; do TITLE=`cat $CONFIG|grep -i title|grep -i "\[$i\]"|grep -v "#"|cut -d'"' -f2` DIRECTORY=`cat $CONFIG|grep -i directory|grep -i "\[$i\]"|grep -v "#"|cut -d'"' -f2` SUPPRESS=`cat $CONFIG|grep -i suppress|grep -i "\[$i\]"|grep -v "#"|cut -d'"' -f2` # see what graphics to suppress TESTS[0]=`echo $SUPPRESS|grep -i d` TESTS[1]=`echo $SUPPRESS|grep -i w` TESTS[2]=`echo $SUPPRESS|grep -i m` TESTS[3]=`echo $SUPPRESS|grep -i y` if [ -n "$DIRECTORY" ];then if ! [ -d "$HTML/$DIRECTORY" ];then mkdir "$HTML/$DIRECTORY" fi if ! [ -d "$HTML/$DIRECTORY/$IMAGES" ];then mkdir "$HTML/$DIRECTORY/$IMAGES" fi FILE="$HTML/$DIRECTORY/$i.$EXT" IMAGEDIR="$HTML/$DIRECTORY/$IMAGES" IMAGEWEB="$DIRECTORY/$IMAGES" else FILE="$HTML/$i.$EXT" IMAGEDIR="$HTML/$IMAGES" IMAGEWEB="$IMAGES" fi echo "" > $FILE echo "" >> $FILE echo "" >> $FILE echo "$TITLE" >> $FILE echo "" >> $FILE echo "" >> $FILE echo "" >> $FILE echo "" >> $FILE if [ -f "$CONF/head_mrtnk" ];then cat "$CONF/head_mrtnk" >> $FILE fi echo "" >> $FILE if [ -f "$CONF/body_mrtnk" ];then cat "$CONF/body_mrtnk" >> $FILE else echo "" >> $FILE fi echo "
" >> $FILE for j in 0 1 2 3; do if [ -z "${TESTS[$j]}" ]; then if [ -f "$IMAGEDIR/$i-${MOMENT[j]}.png" ];then W=`cat $IMAGEDIR/$i.${MOMENT[j]}.size|cut -d"x" -f1` H=`cat $IMAGEDIR/$i.${MOMENT[j]}.size|cut -d"x" -f2` echo "" >> $FILE ## Day Image for Index ## if [ "$j" = "0" ];then echo "" >> $INDEX fi fi fi done echo "
" >> $FILE echo "\"$i\"" >> $FILE echo "



" >> $INDEX echo "" >> $INDEX echo "\"$i\"" >> $INDEX echo "



" >> $FILE if [ -z "$NOLOGO" ]; then echo "
" >> $FILE echo "" >> $FILE echo "\"MRTNK\"" >> $FILE echo "   " >> $FILE echo "" >> $FILE echo "\"RRDTOOL\"" >> $FILE fi if [ -f "$CONF/foot_mrtnk" ];then cat "$CONF/foot_mrtnk" >> $FILE fi echo "" >> $FILE echo "" >> $FILE done ### end loop on all targets #### Go on with index echo "" >> $INDEX if [ -z "$NOLOGO" ]; then echo "
" >> $INDEX echo "" >> $INDEX echo "\"MRTNK\"" >> $INDEX echo "   " >> $INDEX echo "" >> $INDEX echo "\"RRDTOOL\"" >> $INDEX fi if [ -f "$CONF/index_foot_mrtnk" ];then cat "$CONF/index_foot_mrtnk" >> $INDEX fi echo "" >> $INDEX echo "" >> $INDEX