#!/bin/bash
#
################################################################################
#
#                     S H E L L   S C R I P T  F I L E
#
#                         COPYRIGHT 2011 MOTOROLA
#                           All Rights Reserved
#
################################################################################
#
#   FILE NAME       : omc_ipconfig
#   FUNCTION        : 
#   PARAMETERS      :  
#                      
################################################################################
#
################################################################################
#
# Revision History:
#
# Date      Prob#          Description
# --------- -------------  -----------------------------------------------------
# 01-MAr-11   Initial version
################################################################################

################################# Includes #####################################

SUCCESS=0
ERROR=1

################################# functions ####################################

# ---------------------------------------------------------------------------
# Function: 
#    show_menu
#   show and execute main menu
# Input: None.
# ---------------------------------------------------------------------------
function show_menu
{
  while [ 1 ]
  do
	  printf "\n"
	  printf "          1 -> Show System Geographical Area\n"
	  printf "          2 -> Select a state\n"
	  printf "          3 -> Update system geographical area\n"
	  printf "          q -> Quit\n"
	  printf "\n"
	  printf "  Choice? "
	  read -r userchoice

	  case $userchoice in

	"1")
		/opt/Motorola/mcd5000/omcserver/bin/omc_ipds_config show_geographic_area
		;;
	"2")
		# printf "\nUpdate geographic area table:\n"
		/opt/Motorola/mcd5000/omcserver/bin/omc_ipds_config update_geographic_area -gname all
		;;
	"3")
		# printf "\nUpdate geographic area table:\n"
		/opt/Motorola/mcd5000/omcserver/bin/omc_ipds_config update_geographic_area -gname current
		;;
		
	"q")
		printf "\nQuitting...\n"
		exit
		;;
	*)
		printf "\n     -->  Input error: please insert 1-3,q  <--\n\n"
		;;
	esac
  done
}	


# ---------------------------------------------------------------------------
# Function: 
#    print in console and syslog.
# Input:
#    ${*} - one or more string parameters
# ---------------------------------------------------------------------------

function print_in_console_and_syslog
{
    printf ".... $1 ....\n"
    /usr/bin/logger -t $1
} 

# ---------------------------------------------------------------------------
# Function: 
#    Check if the script was executed as root user:
#       - root:        pass
#       - other username: terminate
# ---------------------------------------------------------------------------
function check_user
{
    if [[ "$(id -un)" != "root" ]]; then
        abort_script "You need root privileges to run this script"
    fi
}

# ---------------------------------------------------------------------------
# Function: 
#    Print error message on stdout and in syslog, clean up 
#    terminate script
# Input:
#    ${*} - one or more string parameters
# ---------------------------------------------------------------------------
function abort_script
{
    print_in_console_and_syslog "ERROR: ${*}"
    exit $FAILURE
}

# ---------------------------------------------------------------------------
# Function: 
#    get state name parameter from user
# ---------------------------------------------------------------------------
function input_state_name_from_user
{
	answered="false"
	while [ $answered == "false" ]; do
		read -p "Enter state name:" STATE_NAMe
		answered="true"
	done
}

################################# Main Body ####################################
STATE_NAME=
show_menu


#################################  E N D    ####################################
