I was able to solve the problem with the help of someone from the team of the device (NetModule is the company:
http://www.netmodule.com/ ).
The final working script is the following:
Code:
#!/bin/sh
# openvpn settings
SERVER="192.168.100.199"
PORT="1194"
# helpers
CLI="/usr/local/sbin/cli"
LOG="/usr/bin/logger -p local1.notice -t maintenance"
#some variables
OpenVPNConfFile=/etc/openvpn/tunnel0.conf
remoteLine="$(grep '^remote' "$OpenVPNConfFile")"
currentIP=$(echo "$remoteLine" | cut -d' ' -f 2)
currentPort=$(echo "$remoteLine" | cut -d' ' -f 3)
$LOG "running"
# make bottom led blinking in red
# echo "timer" > "/sys/class/leds/ind4:red/trigger"
# echo "500" > "/sys/class/leds/ind4:red/delay_on"
# echo "500" > "/sys/class/leds/ind4:red/delay_off"
# turn on solid red for bottom led (labelled IN2)
echo "1" > "/sys/class/leds/ind4:red/brightness"
echo "1" > "/sys/class/leds/ind4:green/brightness"
if [ $SERVER = $currentIP -a $PORT = $currentPort ]
then
$LOG "openvpn is the same as the config on the usb. exiting..."
echo "0" > "/sys/class/leds/ind4:red/brightness"
echo "0" > "/sys/class/leds/ind4:green/brightness"
exit 0
else
# reconfigure openvpn
$LOG "changing openvpn config (server=$SERVER, port=$PORT)"
# $CLI set "openvpn.tunnel.0.server=$SERVER" "openvpn.tunnel.0.port=$PORT" || $LOG "unable to change config"
sed -i "s/^remote.*/remote $SERVER $PORT/g" /etc/openvpn/tunnel0.conf
# wait a bit
sleep 3
# restart openvpn
$CLI restart "openvpn"
# turn off bottom led again
sleep 3
echo "0" > "/sys/class/leds/ind4:red/brightness"
echo "0" > "/sys/class/leds/ind4:green/brightness"
$LOG "finished"
exit 0
fi
Thank you very much to all that have helped here and the team at NetModule.