Save the following script to /etc/NetworkManager/dispatcher.d/02vpn :
#! /bin/bashDon't forget to mark the script as executable with chmod:
REQUIRED_CONNECTION_NAME="virt0"
VPN_CONNECTION_NAME="baitis vpn"
activ_con=$(nmcli con status | grep "${REQUIRED_CONNECTION_NAME}")
activ_vpn=$(nmcli con status | grep "${VPN_CONNECTION_NAME}")
if [ "${activ_con}" -a ! "${activ_vpn}" ];
then
nmcli con up id "${VPN_CONNECTION_NAME}"
fi
chmod +x /etc/NetworkManager/dispatcher.d/02vpn
VPN_CONNECTION_NAME should correspond to whatever VPN connection you have configured using Network Manager. If, for some reason, you can't configure VPN connections in Network Manager, you may need to install the appropriate plug-in:
apt-get install network-manager-openvpn network-manager-openvpn-gnome