#!/bin/bash

# Add this script to /etc/NetworkManager/dispatcher.d/ to have it auto-execute on connect

vpn_connection_name="token vpn"

active_wifi=$(nmcli --fields type c s --active | grep wifi)
active_ethernet=$(nmcli --fields type c s --active | grep ethernet)
active_vpn=$(nmcli --fields name c s --active | grep "${vpn_connection_name}")

if [ "${active_wifi}" ] || [ "${active_ethernet}" ] ; then
  if [ ! "${active_vpn}" ] ; then
    nmcli con up id "${vpn_connection_name}"
  fi
fi
