#!/bin/bash
# When tun0 goes down, print an error on screen.

VPNUP=1

while true; do

	/sbin/ip link | /bin/grep -q tun0
	RETVAL=$?

	if [ $VPNUP -eq 1 ]; then
		if [ $RETVAL -ne 0 ]; then
			# VPN has gone down!
			notify-send -u critical "tun0 is down"
			VPNUP=0
		fi
	else
		if [ $RETVAL -eq 0 ]; then
			# VPN is up!
			VPNUP=1

			# TODO remove notification somehow
		fi
	fi

	sleep 1

done

