#!/bin/sh

export PATH=/usr/bin:/usr/sbin:$PATH


printUsage() {
  echo "sshx is commandline wrapper to execute command on the cluster system which currently hosts the ADP resource"
  echo "if the local node hosts the ADP, the command is executed on the local node"
  echo "sshadp [-i] [-p] [-c] [-t <time in sec>] [-e <time in sec>] <command>"
}

if [ "$#" == "0" ]
then
  printUsage; exit 1;
fi

option=""
# evaluate options
while getopts "ipct:e:" OPT
do
  case ${OPT} in
    i)
      option="${option} --irrc"
      ;;
    p)
      option="${option} --nodecheck=ping";
      ;;
    c)
      option="${option} --nodecheck=crm";
      ;;
    t)
      option="${option} --sshlock_timeout=${OPTARG}";
      ;;
    e)
      option="${option} --sshexec_timeout=${OPTARG}";
      ;;
    \?)
      printUsage; exit 1;
      ;;
  esac
done

shift $((OPTIND-1))

WS_BASE=/opt/webservice
${WS_BASE}/scripts/swupdated sshadp ${option} "$1"
