
#!/bin/sh
# File	: upd_netapp-link.sh
# By	: MaartenDeBoer.nl, 180904
# Subject	: Script to update web-page of netapp.link (netapp.agrarix.com)
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
LOG="${HOME}/log/${PGM}.log"

DATI=`date +%Y%m%d-%H%M%S`
PAGE="/var/www/vhosts/netapp.agrarix.com/html/index.html"
ETC="${HOME}/etc/netapp-link"

BGCOLOR="#1E4B8E"

echo "`date` ${PGM} started."|tee -a ${LOG}

if [ ! -f ${ETC} ]; then
  echo "Input (etc) file (${ETC}) NOT found. Exiting"
  exit 2
fi

# Creating backup of index(PAGE)file
cp ${PAGE} ${PAGE}_${DATI}

# Creating HEAD
echo "<!DOCTYPE HTML> " > ${PAGE}
echo "<HTML> " >> ${PAGE}
echo "  <HEAD> " >> ${PAGE}
if [ -f ${ETC}.head ]; then
  cat ${ETC}.head >> ${PAGE}
fi
echo "  </HEAD> " >> ${PAGE}
echo "<BODY aLink=red link=red vLink=red>" >> ${PAGE}

# 1st TABLE
echo "<TABLE class='table2-class' border=0 width='100%' id='table1' cellpadding='0' cellspacing='0'> " >> ${PAGE}

# 1st (menu)row
cat << EOT >> ${PAGE}

  <tr>
    <td>
    <table class='table2-class' border=0 width='100%' id='table2' cellspacing='0'> 
      <tr>
        <td bgcolor=${BGCOLOR} width="5">
        </td>
        <td bgcolor=${BGCOLOR} align='left' height="30">
          <font size='2' color=white face='Arial'> 
            <a href='//netapp.com' target="_blank"> <B>NetApp.com </a>
            <a href='//mysupport.netapp.com' target="_blank"> <B>Support </a>
            <a href='//community.netapp.com' target="_blank"> <B>Community </a>
            <a href='//blog.netapp.com' target="_blank"> <B>Blog </a>
            <a href='//www.netapp.com/us/services-support/university/index.aspx' target="_blank">  <B>Training </a>
          </font>
        </td>
        <td bgcolor=${BGCOLOR} align='right'>
          <font size='2' color=white face='Arial'>
            <a href='mailto:netapp@agrarix.nl' target="_blank"> <B>Contact </a>
          </font>
        </td>
        <td bgcolor=${BGCOLOR} width="5">
        </td>
      </tr>

    </table>
    </td>
  </tr>

EOT


# 2nd (menu)row
cat << EOT >> ${PAGE}

  <tr>
    <td>
      <table class='table3-class' border=0 width='100%' id='table3' cellspacing='0'>
        <tr>
          <td width='95%'>
            <table class='table4-class' border=0 width='100%' id='table4' cellspacing='0'>

              <tr>
                <td height="50" width="30%" >
                  <font size='6' color=${BGCOLOR} face='Arial'> 
                    <img src="netapp-logo.png" alt="NetApp-logo"> Link
                  </font>
                </td>
                <td bgcolor=white align='left'>
                  <font size='5' color=${BGCOLOR} face='Arial'> 
Collection of NetApp related links.
                  </font>
                  <font size='3' color=${BGCOLOR} face='Arial'> 
When you have more, please <a href='mailto:netapp@agrarix.nl' target="_blank">contact</a> us.
                  </font>
                </td>
             </tr>

EOT

ROWCNT=0
cat ${ETC}|sort|while read LINE
do
ROWCNT=`expr ${ROWCNT} + 1`
#echo  "${LINE}"
SUBJECT=`echo "${LINE}" | grep -v ^# |awk -F\; '{print $1}'`
URL=`echo "${LINE}" | grep -v ^# |awk -F\; '{print $2}'`
DESCRIPTION=`echo "${LINE}" | grep -v ^# |awk -F\; '{print $3}'`

echo "${SUBJECT}=${URL}=${DESCRIPTION}"

if [ "${SUBJECT}" != "" ]; then

if [ $((ROWCNT%2)) -eq 0 ]; then
# Even
  BGCOLOR="white"
else
# Odd
  BGCOLOR="#F0F0F0"
fi


echo "              <tr>" >> ${PAGE}
echo "                <td bgcolor=${BGCOLOR}>" >> ${PAGE}
echo "                  <font size='5' color=black face='Arial'> " >> ${PAGE}
echo "                    <a href='${URL}' target="_blank">${SUBJECT} </a>" >> ${PAGE}
echo "                  </font>" >> ${PAGE}
echo "                </td>" >> ${PAGE}
echo "                <td bgcolor=${BGCOLOR}>" >> ${PAGE}
echo "                  <font size='3' color=black face='Arial'> ${DESCRIPTION} " >> ${PAGE}
echo "                  </font>" >> ${PAGE}
echo "                </td>" >> ${PAGE}
echo "              </tr>" >> ${PAGE}

fi  # [ .. != "" ]

done  # while read LINE


# For last row
cat << EOT >> ${PAGE}

            </table>
          </td>

          <td bgcolor=white>
          </td>
        </tr>
      </table>
    </td>
  </tr>

EOT

# Last row
cat << EOT >> ${PAGE}

  <tr>
    <td bgcolor=#1E4B8E align='center'>
      <font size='1' color=lightblue face='Arial'> 
        <a href='//agrarix.it' target="_blank">Selected by Agrarix IT</a>
      </font>
      <font color=${BGCOLOR} face='Arial'> 
        `date +%Y-%m-%d-%H-%M-%S`
      </font>

    </td>
  </tr>

EOT

# End of 1st table
echo "</TABLE>" >> ${PAGE}
echo "</HTML>" >> ${PAGE}




exit 0

