#!/bin/bash

# This is the custom decode file. Make sure all valid codes exit with "exit 1".
# To enable the codes below, the "#" must be removed from the start.
# This would allow the node to be disabled with the code 12001
# This would allow the node to be enabled with the code 12002

#if [ "$1" = "12001" ] ; then "$SCRIPT"/disable ; exit 1 ; fi
#if [ "$1" = "12002" ] ; then "$SCRIPT"/enable ; exit 1 ; fi
# This is the on-air audio test script code. If you do not want to 
# use it, just comment it out with a "#" below:

if [ "$1" = "AA33BB" ] ; then
  "$SCRIPT"/audio_level_test
fi

# This portion is for the speaktime script
if [ "$USE_SPEAKTIME" = "YES" ] && [ "$1" = "C" ] ; then
  /home/irlp/features/speaktime/speaktime
  exit 1
fi

# This portion is for the speakdate script
if [ "$USE_SPEAKDATE" = "YES" ] && [ "$1" = "CC" ] ; then
  /home/irlp/features/speakdate/speakdate
  exit 1
fi

# This portion is for the star69 script
if [ "$USE_STAR69" = "YES" ] && [ "$1" = "S69" ] ; then
  /home/irlp/features/star69/star69
  exit 1
fi

if [ "$USE_ECHOIRLP" = "YES" ] ; then

  if [ "$1" = "73" ] ; then
    "$ECHO_SCRIPT"/echo_end
     /home/irlp/scripts/end
    exit 1
  fi

  # Echolink Prefix detector
  eval `echo $1 | awk -v num=1 '{
       print "PRE="substr($1,1,num);
       print "NODE="substr($1,(num)+1,length($1))}'`

  #Call echolink conferences using star node method
  if [ "$PRE" = "S" ] ; then "$ECHO_SCRIPT"/echo_call $NODE ; exit 1 ; fi

fi
if [ "$1" = "123" ] ; then sudo service openvpn restart ; exit 1 ; fi
if [ "$1" = "321" ] ; then sudo service openvpn stop ; exit 1 ; fi
if [ "$1" = "234" ] ; then sudo service networking restart ; exit 1 ; fi
if [ "$1" = "999" ] ; then sudo shutdown -h now ; exit 1 ; fi
if [ "$1" = "888" ] ; then sudo shutdown -r now ; exit 1 ; fi

exit 0
