43 lines
1.0 KiB
Bash
43 lines
1.0 KiB
Bash
#!/bin/bash
|
|
|
|
# Try connecting to ProtonVPN with retries
|
|
MAX_RETRIES=5
|
|
RETRY_DELAY=10 # seconds
|
|
TRIES=0
|
|
|
|
while [[ $TRIES -lt $MAX_RETRIES ]]; do
|
|
echo "Attempting to connect to ProtonVPN (try #$((TRIES+1)))..."
|
|
|
|
protonvpn-cli c -r
|
|
|
|
# Check if the connection was successful
|
|
if protonvpn-cli status | grep -q "Connected"; then
|
|
echo "VPN connected successfully!"
|
|
break
|
|
fi
|
|
|
|
echo "VPN connection failed, retrying in $RETRY_DELAY seconds..."
|
|
sleep $RETRY_DELAY
|
|
((TRIES++))
|
|
done
|
|
|
|
# If the connection still failed after retries, exit
|
|
if ! protonvpn-cli status | grep -q "Connected"; then
|
|
echo "Failed to establish VPN connection after $MAX_RETRIES attempts. Exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
# Start the main Python script in the background
|
|
python3 /main.py &
|
|
MAIN_PID=$!
|
|
|
|
# Monitor VPN connection
|
|
while true; do
|
|
if ! protonvpn-cli status | grep -q "Connected"; then
|
|
echo "VPN disconnected! Stopping main.py..."
|
|
kill $MAIN_PID
|
|
exit 1
|
|
fi
|
|
sleep 5 # Check every 5 seconds
|
|
done
|