33 lines
1.1 KiB
Bash
33 lines
1.1 KiB
Bash
|
#!/bin/bash
|
||
|
# The purpose of this script is to check if VPN connection is active
|
||
|
# This script will be called (via a service) in 2 situations:
|
||
|
# On a regular basis when transmission is running
|
||
|
# This will be achieved with a timer started and stopped with transmission service
|
||
|
# On transmission starting
|
||
|
# When the script exits with failure, associated service should try to start transmission service
|
||
|
# Thus this script will be executed again
|
||
|
# We can enter an infinite loop, but this will effectively prevent transmission from connecting
|
||
|
# If both services are stopped, this script will never be run by error
|
||
|
|
||
|
source "$run_directory/variables.conf"
|
||
|
|
||
|
# Parameters
|
||
|
myip_request="curl -s -4 https://ifconfig.co"
|
||
|
vpn_service="openvpn-client@vpn.service"
|
||
|
transmission_service="transmission-daemon.service"
|
||
|
|
||
|
# Main process
|
||
|
ip=$($myip_request)
|
||
|
if [[ $ip = $real_ip ]]; then
|
||
|
systemctl stop $transmission_service
|
||
|
systemctl stop $vpn_service
|
||
|
sleep 3
|
||
|
systemctl start $vpn_service
|
||
|
sleep 5
|
||
|
exit 1
|
||
|
elif [[ $ip =~ (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3} ]]; then
|
||
|
exit 0
|
||
|
else
|
||
|
exit 1
|
||
|
fi
|