/ scripts / vpn.sh
vpn.sh
 1  # Check if openvpn is running and get its PID
 2  pid=$(pgrep openvpn)
 3  
 4  if [ -n "$pid" ]; then
 5      notify-send "OpenVPN is already running. Killing the process."
 6  else
 7      notify-send "Connecting to OpenVPN"
 8  fi
 9  
10  password=$(zenity --password --title="Enter sudo password")
11  if [ -z "$password" ]; then
12    zenity --error --text="No password entered. Exiting."
13    exit 1
14  fi
15  
16  if [ -n "$pid" ]; then
17     echo "$password" | sudo -S pkill openvpn
18     sleep 3
19     pid=$(pgrep openvpn)
20     if [ -z "$pid" ]; then
21         notify-send "Successfully stopped OpenVPN"
22         exit 1
23     else
24         notify-send "Failed to stop OpenVPN. Wrong password"
25         exit 1
26     fi
27  else
28     echo "$password" | sudo -S openvpn --config ~/Documents/Laptop/sirazulhaq0205_profile.ovpn --daemon
29     sleep 3
30     pid=$(pgrep openvpn)
31     if [ -n "$pid" ]; then
32         notify-send "Successfully started OpenVPN"
33         exit 1
34     else
35         notify-send "Failed to start OpenVPN. Wrong password"
36         exit 1
37     fi
38  fi