#!/bin/bash
################################################################################
#                               Bash.template                                  #
#                                                                              #
# This template is a standard starting point for new Bash scripts.             #
#                                                                              #
# Add a description of the program in this space.                              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
# Change History                                                               #
# 2023/02/24   David Both    Original code.                                    #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
#                                                                              #
################################################################################
################################################################################
################################################################################
#                                                                              #
#  Copyright (C) 2007, 2023 David Both                                         #
#  LinuxGeek46@both.org                                                        #
#                                                                              #
#  This program is free software; you can redistribute it and/or modify        #
#  it under the terms of the GNU General Public License as published by        #
#  the Free Software Foundation; either version 2 of the License, or           #
#  (at your option) any later version.                                         #
#                                                                              #
#  This program is distributed in the hope that it will be useful,             #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of              #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
#  GNU General Public License for more details.                                #
#                                                                              #
#  You should have received a copy of the GNU General Public License           #
#  along with this program; if not, write to the Free Software                 #
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   #
#                                                                              #
################################################################################
################################################################################
################################################################################

################################################################################
# Help                                                                         #
################################################################################
Help()
{
   # Display Help
   echo "                  MyProgram "
   echo ""
   echo "Add a description of the program"
   echo
   echo "Syntax:  mymotd [-g|h|v|V]"
   echo "options:"
   echo "g     Print the GPL license notification."
   echo "h     Print this Help."
   echo "v     Verbose mode."
   echo "V     Print software version and exit."
   echo
}

################################################################################
# Print the GPL license header                                                 #
################################################################################
gpl()
{
   echo
   echo "################################################################################"
   echo "#  Copyright (C) 2007, 2023  David Both                                        #"
   echo "#  http://www.both.org                                                         #"
   echo "#                                                                              #"
   echo "#  This program is free software; you can redistribute it and/or modify        #"
   echo "#  it under the terms of the GNU General Public License as published by        #"
   echo "#  the Free Software Foundation; either version 2 of the License, or           #"
   echo "#  (at your option) any later version.                                         #"
   echo "#                                                                              #"
   echo "#  This program is distributed in the hope that it will be useful,             #"
   echo "#  but WITHOUT ANY WARRANTY; without even the implied warranty of              #"
   echo "#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #"
   echo "#  GNU General Public License for more details.                                #"
   echo "#                                                                              #"
   echo "#  You should have received a copy of the GNU General Public License           #"
   echo "#  along with this program; if not, write to the Free Software                 #"
   echo "#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   #"
   echo "################################################################################"
   echo
}

################################################################################
# Quit nicely with messages as appropriate                                     #
################################################################################
Quit()
{
   if [ $verbose = 1 ]
      then
      if [ $error = 0 ]
         then
         echo "Program terminated normally"
      else
         echo "Program terminated with error ID $ErrorMsg";
      fi
   fi
   exit $error
}

################################################################################
# Display verbose messages in a common format                                  #
################################################################################
PrintMsg()
{
   if  [ $verbose = 1 ] && [ -n "$Msg" ]
   then
      echo "########## $Msg ##########"
      # Set the message to null
      Msg=""
   fi
}

################################################################################
# Convert KB to GB                                                             #
################################################################################
kb2gb()
{
   # Convert KBytes to Giga using 1024
   echo "scale=3;$number/1024/1024" | bc
}


################################################################################
################################################################################
# Main program                                                                 #
################################################################################
################################################################################
# Set initial variables
badoption=0
error=0
host=""
verbose=0
Version=01.00.04
ErrorMsg="0"


#---------------------------------------------------------------------------
# Check for root. Delete if necessary.

# if [ `id -u` != 0 ]
# then
#    echo ""
#    echo "You must be root user to run this program"
#    echo ""
#    Quit 1
# fi
# 
# #---------------------------------------------------------------------------
# # Check for Linux
# 
# if [[ "$(uname -s)" != "Linux" ]]
# then
#    echo ""
#    echo "This script only runs on Linux -- OS detected: $(uname -s)."
#    echo ""
#    Quit 1
#fi
#---------------------------------------------------------------------------

################################################################################
# Process the input options. Add options as needed.                            #
################################################################################
# Get the options
while getopts ":ghrvV" option; do
   case $option in
      g) # display GPL
         gpl
         Quit;;
      h) # display Help
         Help
         Quit;;
      v) # Set verbose mode
         verbose=1;;
      V) # Print the software version
         echo "Version = $Version"
         Quit;;
     \?) # incorrect option
         badoption=1;;
   esac
done

if [ $badoption = 1 ]
then
   echo "ERROR: Invalid option"
   Help
   verbose=1
   error=1
   ErrorMsg="10T"
   Quit $error
fi

################################################################################
################################################################################
# The main body of your program goes here.
################################################################################
################################################################################


Quit

################################################################################
# End of program
################################################################################

