#! /bin/ash
# for more info about color in bash - http://www.faqs.org/docs/abs/HTML/colorizing.html 
# This disables the CTRL-C key
trap "echo -e '    \033[1m\033[31m\033[47mDo not hit CTRL-C!\033[0m'" INT

#Get some date related data from the system
bigdate=$(ls -l --full-time menu.s | grep 'root')
#trim the junk to get down to the Day Of Week
dow=${bigdate% *}
dow=${dow% *}
dow=${dow% *}
dow=${dow% *}
dow=${dow% *}
dow=${dow##* }
# echo "Day of week is $dow"
#Trim data again to get just the date
smallerdate=${bigdate##*$dow}
date=${smallerdate%% m*}
#echo "The date is $date "
date=${date#* }
# echo "The date is $date"
#Trim date again to get just the year
year=${date##* }
#echo "The year is $year."
#Again to get the day and month
day=${date% *}
day=${day% *}
month=${day% *}
day=${day##* }
#echo "The day is $day."
#echo "The month is $month."
#Print the welcome menu to the screen
/bin/setterm -clear
echo " "
echo " "
echo " "
echo " "
echo -e "         \033[47m\033[30m . Welcome to the \033[34mDigital Airline \033[47m\033[30mImaging System . \033[0m            "
echo -e "                          \033[1mThe date is $dow, $day $month $year \033[0m"
echo " "
echo " "
echo " " 
echo " " 
echo " "
echo " "
#set the password
pass=$year$month$day
userpass="xx"
#Ask for the password and verify it
until [ "$pass" = "$userpass" ]; do
   echo " "
   echo " "
   echo " "
   echo " "
   echo -en "     \033[32mPlease, enter the password: \033[0m"
   echo " " 
   echo " "
   echo " " 
   setterm -foreground black
   read userpass
   setterm -foreground white

   if [ "$pass" != "$userpass" ]; then 
      echo -e "     \033[31mYou entered \033[0m\033[1m$userpass \033[0m"
      echo -e "     \033[31m\033[5m That was not the correct password \033[0m"
      echo -e "     \033[31mRemember that capitalization counts \033[0m"
   else
      echo " "
      echo -e "     \033[1mThat was correct \033[0m"
      echo -e "     \033[1mThank you \033[0m"
      echo " "
      echo " "
      echo " "
      echo " "
   fi
   
done

#Get the IP address from local info
 bigip=$(ifconfig | grep 'inet addr:')
 ip=${bigip## *addr:}
 ip=${ip%% *}
 #     echo " Your address is $ip "
 #Trim out data to get the subnet
 subnet=${ip#*.}
 subnet=${subnet%%.*}
 #     echo "  Your subnet is $subnet "
 shortip=${ip#*.}
 shortip=${shortip#*.}
 shortip=${shortip%%.*}
 #      echo "  Your short ip address is $shortip "
 #if [ shortip > 3 ]; then
 #      echo "  and you have a DHCP address "
 #else
 #      echo "  but this is not a workstation "
 #fi
#Set the local ZENWorks server
 if [ subnet=100 ]; then
    server='ZFD1'
 elif [ subnet=83 ]; then
    server='ZFD2'
 else 
    server='UNKNOWN'
    echo "Your server is $server"
    exit 1
 fi

#     echo "Your local ZENWorks server is $server "

#Display the menu with options
function press_enter
{
    echo " "
    echo -n "            Press enter to continue"
    read
    setterm -clear
}

selection=
until [ "$selection" = "0" ] ; do
   echo " "
   echo " "
   echo " "
   echo -e "               \033[1m\033[34m\033[47mImaging Menu \033[0m"
   echo " "
   echo -e "     \033[1m\033[32m1 \033[0m\033[1m- Display local ZENWorks server \033[0m"
   echo -e "     \033[1m\033[32m2 \033[0m\033[1m- Install XP Image \033[0m"
   echo -e "     \033[1m\033[32m3 \033[0m\033[1m- Install ACU image \033[0m"
   echo -e "     \033[1m\033[32m4 \033[0m\033[1m- Install GX270 \033[0m"
   echo -e "     \033[1m\033[32m5 \033[0m\033[1m- Install GX240 \033[0m"
   echo -e "     \033[1m\033[32m6 \033[0m\033[1m- Install D400 \033[0m"
   echo " "
   echo -e "     \033[1m\033[32m9 \033[0m\033[1m- Reboot \033[0m"
   echo -e "     \033[1m\033[32m0 \033[0m\033[1m- Exit \033[0m"
   echo " "
   echo -en "          \033[1m\033[32mEnter Selection: \033[0m"
   echo " "
   echo " "
   read selection
   echo " "
   case $selection in
     1 ) echo "     Your local ZENWorks server is $server" ; press_enter ;;
     2 ) img rp $server //$server/vol1/data/images/xpfat32.zmg ; reboot ;;
     3 ) img rp $server //$server/vol1/data/images/acu.zmg ; reboot ;;
     4 ) img rp $server //$server/vol1/data/images/xp.zmg ; img rp $server //$server/vol1/data/images/270drive.zmg ; img rp $server //$server/vol1/data/images/acu.zmg ; reboot ;;
     5 ) img rp $server //$server/vol1/data/images/xp.zmg ; img rp $server //$server/vol1/data/images/driver.zmg ; img rp $server //$server/vol1/data/images/sp240.zmg ; img rp $server //$server/vol1/data/images/acu.zmg ; reboot ;;
     6 ) img rp $server //$server/vol1/data/images/xpfat32.zmg ; img rp $server //$server/vol1/data/images/boot400.zmg ; img rp $server //$server/vol1/data/images/drivertst.zmg ; img rp $server //$server/vol1/data/images/sp400.zmg ; img rp $server //$server/vol1/data/images/acu.zmg ; reboot ;;
     9 ) reboot ;;
     0 ) ash /bin/prompt.s ;;
     * ) echo "     Please enter 1, 2, 3, 4, 5, or 0" ; press_enter
   esac
done
