Just for posterity here is my script for the Custom switch behaviour in gl-switch.d
#!/bin/sh
action=$1
if [ "$action" = "on" ];then
sed -i "9s/option proxy_mode '5'/option proxy_mode '1'/" /etc/config/vpnpolicy
result=`curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"wg-client\",\"get_status\",{}],\"id\":1}" | jsonfilter -e @.result`
status=`echo $result | jsonfilter -e @.status`
group_id=`echo $result | jsonfilter -e @.group_id`
peer_id=`echo $result | jsonfilter -e @.peer_id`
if [ "$status" = "0" -a -n "$group_id" -a "$group_id" != "0" -a -n "$peer_id" -a "$peer_id" != "0" ];then
curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"wg-client\",\"start\",{\"group_id\":$group_id,\"peer_id\":$peer_id}],\"id\":1}"
fi
fi
if [ "$action" = "off" ];then
sed -i "9s/option proxy_mode '1'/option proxy_mode '5'/" /etc/config/vpnpolicy
curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"wg-client\",\"stop\",{}],\"id\":1}"
fi
if [ "$action" = "on" ];then
result=`curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"ovpn-client\",\"get_status\",{}],\"id\":1}" | jsonfilter -e @.result`
status=`echo $result | jsonfilter -e @.status`
group_id=`echo $result | jsonfilter -e @.group_id`
client_id=`echo $result | jsonfilter -e @.client_id`
if [ "$status" != "0" -a -n "$group_id" -a -n "$client_id" ];then
curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"ovpn-client\",\"stop\",{\"group_id\":$group_id,\"client_id\":$client_id}],\"id\":1}"
fi
fi
if [ "$action" = "off" ];then
result=`curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"ovpn-client\",\"get_status\",{}],\"id\":1}" | jsonfilter -e @.result`
status=`echo $result | jsonfilter -e @.status`
group_id=`echo $result | jsonfilter -e @.group_id`
client_id=`echo $result | jsonfilter -e @.client_id`
if [ "$status" = "0" -a -n "$group_id" -a "$group_id" != "0" -a -n "$client_id" -a "$client_id" != "0" ];then
curl -H 'glinet: 1' -s -k http://127.0.0.1/rpc -d "{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":[\"\",\"ovpn-client\",\"start\",{\"group_id\":$group_id,\"client_id\":$client_id}],\"id\":1}"
fi
fi
sleep 5