I tried to make it a bit more resilient to changes and different scenarios.
I found it to be not reliable when started through systemd. therefore i used autoexec.py in /storage/.kodi/userdata/autoexec.py with the following content:
And for the actual connection if have this in /storage/connect_vpn.sh:
Bash
		
					
				#!/bin/bash
VPN=`connmanctl vpnconnections | awk '{print $NF}'`
if route -n | grep wg0 >/dev/null; then 
        connmanctl disconnect $VPN
        sleep 2s
fi
if [[ ! -z $1 ]] && [[ $1 == "stop" ]]; then
        exit 0;
fi
LIF=`route -n | grep ^0.0.0.0 | awk '{print $NF}'`
OR=`route -n | grep ^0.0.0.0 | awk '{print $2}'`
if [[ ! -z "$OR" ]]; then
        LIFT="wifi";
        if [[ "$LIF" == "eth0" ]]; then
                LIFT="cable";
        fi
        LOC=`connmanctl services | grep '^\*' | grep $LIFT | awk '{print $NF}'`
        connmanctl connect $VPN
        sleep 2s
        connmanctl move-after $VPN $LOC
        #sometimes it just reset VPN.. we keep trying... and trying...
        while true; do
                GIF=`route -n | grep ^0.0.0.0 | awk '{print $NF}'`
                if [[ $GIF == "wg0" ]]; then
                        connmanctl move-after $VPN $LOC
                else
                        sleep 5s
                fi
        done
fiHth. A fix in connman would certainly be nicer!
 
		