Advertisement
remim

VPN-BT-Keep-0.2

Jan 13th, 2019
9,776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.06 KB | None | 0 0
  1. #!/bin/bash
  2. # VPN-BT-Keep-0.2 201901150500 not validated; Also available at http://paste.debian.net/plain/1060550
  3. # This program stops a program when your VPN connection is lost then restarts it after the connection is re-established.
  4. # From https://www.debian-fr.org/t/ordonner-a-transmission-de-se-fermer-si-la-connexion-vpn-est-perdue/78326
  5. # and https://www.wareziens.net/forum/viewtopic.php?id=36487&p=
  6.  
  7. UUID_VPN=00589c54-affc-43bd-b252-fee06ded1a89 # UUID_VPN DE SIMULATION À MODIFIER AVEC LE VOTRE # UUID_VPN OF SIMULATION TO MODIFY WITH YOUR
  8.  
  9. # nmcli --pretty connection show --active
  10. # une fois sans avoir activé le vpn et une fois avec le vpn actif.
  11. # once without having activated the vpn and once with the active vpn.
  12. # sélectionnez l'identification uuid correspondante au vpn
  13. # select the uuid identification corresponding to the vpn
  14.  
  15. function is_vpn_active() {
  16. nmcli --terse --fields uuid  connection  show --active | fgrep --quiet $UUID_VPN && echo 1 || echo 0
  17. }
  18.  
  19. #Attmept a VPN connection until connected
  20. function connectVPN()
  21. {
  22.     while : #If the connection is just started or lost, try to reconnect then break out once connected.
  23.     do
  24.         connected=$(is_vpn_active) #Store the current state of the VPN connection.
  25.         if [ "$connected" = "1" ]; then
  26.             echo "connectVPN: vpn up"
  27.             echo ""
  28.             transmission-gtk &
  29.             break
  30.         else
  31.             echo "connectVPN: vpn down, Attempting VPN connection in 20 seconds."
  32.             sleep 20 #Give the VPN time to recover so we don't abuse it with reconnection requests.
  33.             echo "nordvpn connect ..." #Retry the VPN : Ligne de connexion au VPN à adapter. VPN connection line to adapt.
  34.         fi
  35.         done
  36. }
  37.  
  38. #Monitor the VPN and secure VPN dependancies.
  39. connectVPN
  40. date
  41. while true; do
  42.     vpnstring=$(is_vpn_active)    #Define a string to test, 0 = no connection, 1 = connected.
  43.     case $vpnstring in
  44.     "0")
  45.         date
  46.         killall transmission-gtk
  47.         connectVPN
  48.     ;;
  49.     "1")
  50.         sleep 1
  51.     ;;
  52.     esac
  53. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement