aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/bin/togglevpn
blob: f4dc1f17286ccfb51db673d5384d5861308df7d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

if [ -f "$HOME/.cache/openvpnpid" ]; then
  rm ~/.cache/openvpnpid
  sudo killall -SIGINT openvpn
  exit
fi

if [ ! -f "$HOME/.config/ovpn/conf.ovpn" ]; then
  notify-send " OpenVPN" "Can't start VPN. Configuration file is missing"
  exit
fi

sudo openvpn "$HOME/.config/ovpn/conf.ovpn" &
PID=$!
notify-send " OpenVPN" "VPN is being initialized"
echo $PID > ~/.cache/openvpnpid
killall -40 waybar
wait $PID
notify-send " OpenVPN" "VPN service has stopped with exit code $?"
rm -f ~/.cache/openvpnpid
killall -40 waybar