#!/bin/sh
#  $Id: gateway_restart.sh 58770 2015-03-31 12:26:18Z pc161604 $
#  Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
#  This software code contains proprietary information
#  and should be treated as confidential.
#
#  Component: Secure Global Desktop Gateway
#  Author: Bill Weir

N=""
C=""
if echo -n | grep n > /dev/null
then
  C="\c"
else
  N="-n"
fi
case "$MACHINEARCH" in
i3li*|ppli*) N="$N -e" ;;
esac
_ss_headlines="--------------------------------------------------------------------------"


[ "${trace}" = "x" ] && set -x

usage() {
    echo "${i18n_restartusage10_gw}"
    exit 1
}

# Must be root user to bind to privileged port
u="`LANG=C LC_ALL=C id | sed 's/.*uid=\([0-9][0-9]*\).*/\1/'`"
if [ "$u" = "0" ]
then
  : # all is okay
else
  echo "You must be root to run this program"
  exit 15
fi


ASK="t"
case "$1" in
--force) ASK=""; shift
esac

[ -n "$1" ] && usage

. ${INSTDIR}/etc/version

[ -n "${ASK}" ] && {
    a_confirm="${i18n_no}"
[ -z "${i18n_yes}" ] && i18n_yes="${a_yes}"
[ -z "${i18n_no}" ] && i18n_no="${a_no}"
[ -z "${i18n_case_yes}" ] && i18n_case_yes="${a_case_yes}"
[ -z "${i18n_case_no}" ] && i18n_case_no="${a_case_no}"
[ -z "${i18n_s_yes}" ] && i18n_s_yes="${s_yes}"
[ -z "${i18n_s_no}" ] && i18n_s_no="${s_no}"
[ "" != "NOPROMPT" ] && echo ""
echo # blank line between prompt and question
_valid=false
while [ $_valid = false ]
do
  echo $N "${i18n_confirmstop30_gw} [$a_confirm] $C"
  read _answer
  if [ -z "$_answer" ]
  then
    _answer="$a_confirm"   # default
  fi
  case "$_answer" in
    [${i18n_case_yes}]* )
	    _answer=$i18n_s_yes
	    _valid=true
	    ;;
    [${i18n_case_no}]* )
	    _answer=$i18n_s_no
	    _valid=true
	    ;;
  esac
done
a_confirm="$_answer"

    case "${a_confirm}" in
    [${i18n_case_no}]* ) exit 1
    esac
}

${INSTDIR}/bin/gateway stop --force && ${INSTDIR}/bin/gateway start

exit 0
