#!/bin/sh
#
# 2010, grifter
# script to check the regnum online warzone status
# use ./warstatus.sh -c to enable colours
#

rm /tmp/warstatus.php 2>/dev/null
wget -q -O /tmp/warstatus.php "http://regnumonline.com.ar/ranking/index.php?l=1&realm=0&opt=1&world=horus"

IMPERIA=`grep -i keep /tmp/warstatus.php | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`
SHAANARID=`grep -i keep /tmp/warstatus.php | tail -n +2 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`
EFERIAS=`grep -i keep /tmp/warstatus.php | tail -n +3 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`

AGGERSBORG=`grep -i fort_ /tmp/warstatus.php | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`
TRELLEBORG=`grep -i fort_ /tmp/warstatus.php | tail -n +2 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`

MENIRAH=`grep -i fort_ /tmp/warstatus.php | tail -n +3 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`
SAMAL=`grep -i fort_ /tmp/warstatus.php | tail -n +4 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`

ALGAROS=`grep -i fort_ /tmp/warstatus.php | tail -n +5 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`
HERBRED=`grep -i fort_ /tmp/warstatus.php | tail -n +6 | head -n 1 | grep -ioE 'alsius|ignis|syrtis'`

if [ "$1" = -c ]; then

echo -e "\033[1;34m╭───────────────────╮\033[0m"
case $IMPERIA in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;34m│ Imperia\033[0m    ${REALM}\033[1;34m│\033[0m"

case $AGGERSBORG in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;34m│ Aggersborg\033[0m ${REALM}\033[1;34m│\033[0m"

case $TRELLEBORG in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;34m│ Trelleborg\033[0m ${REALM}\033[1;34m│\033[0m"
echo -e "\033[1;34m╰───────────────────╯\033[0m"
echo ""

echo -e "\033[1;31m╭───────────────────╮\033[0m"
case $SHAANARID in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;31m│ Shaanarid\033[0m  ${REALM}\033[1;31m│\033[0m"

case $MENIRAH in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;31m│ Menirah\033[0m    ${REALM}\033[1;31m│\033[0m"

case $SAMAL in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;31m│ Samal\033[0m      ${REALM}\033[1;31m│\033[0m"
echo -e "\033[1;31m╰───────────────────╯\033[0m"
echo ""

echo -e "\033[1;32m╭───────────────────╮\033[0m"
case $EFERIAS in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;32m│ Eferias\033[0m    ${REALM}\033[1;32m│\033[0m"

case $ALGAROS in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;32m│ Algaros\033[0m    ${REALM}\033[1;32m│\033[0m"

case $HERBRED in
   alsius)
           REALM="\033[1;34mAlsius\033[0m "
	   ;;
   syrtis)
           REALM="\033[1;32mSyrtis\033[0m "
	   ;;
   ignis)
           REALM="\033[1;31mIgnis\033[0m  "
esac
echo -e "\033[1;32m│ Herbred\033[0m    ${REALM}\033[1;32m│\033[0m"
echo -e "\033[1;32m╰───────────────────╯\033[0m"
echo ""

if [ "$SHAANARID" = alsius ] && [ "$MENIRAH" = alsius ] && [ "$SAMAL" = alsius ]; then echo -e "\033[1;31mREALM IN DANGER BY \033[1;34mALSIUS\033[1;31m!\033[0m"; fi
if [ "$SHAANARID" = syrtis ] && [ "$MENIRAH" = syrtis ] && [ "$SAMAL" = syrtis ]; then echo -e "\033[1;31mREALM IN DANGER BY \033[1;32mSYRTIS\033[1;31m!\033[0m!"; fi
if [ "$SHAANARID" = ignis ] && [ "$MENIRAH" = ignis ] && [ "$SAMAL" = ignis ]; then echo -e "\033[1;32mRealm is safe\033[0m"; else echo -e "\033[1;33mUnder Attack!\033[0m"; fi


else

echo "Imperia is owned by: $IMPERIA"
echo "Aggersborg is owned by: $AGGERSBORG"
echo "Trelleborg is owned by: $TRELLEBORG"
echo ""
echo "Shaanarid is owned by: $SHAANARID"
echo "Menirah is owned by: $MENIRAH"
echo "Samal is owned by: $SAMAL"
echo ""
echo "Eferias is owned by: $EFERIAS"
echo "Algaros is owned by: $ALGAROS"
echo "Herbred is owned by: $HERBRED"
echo ""

# notify-send "Ignis" "Shaanarid $SHAANARID - Samal $SAMAL - Menirah $MENIRAH"

if [ "$SHAANARID" = alsius ] && [ "$MENIRAH" = alsius ] && [ "$SAMAL" = alsius ]; then echo "REALM IN DANGER BY ALSIUS!"; fi
if [ "$SHAANARID" = syrtis ] && [ "$MENIRAH" = syrtis ] && [ "$SAMAL" = syrtis ]; then echo "REALM IN DANGER BY SYRTIS!"; fi
if [ "$SHAANARID" = ignis ] && [ "$MENIRAH" = ignis ] && [ "$SAMAL" = ignis ]; then echo "Realm is safe"; else echo "Under Attack!"; fi

fi

echo ""

rm /tmp/warstatus.php
