Last active
February 6, 2024 11:06
-
-
Save sarkrui/6aaaaeee84607af4e5ae6668d22f47dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to check connectivity and ensure VPN connection | |
# Perform a curl command to check connectivity to google.com | |
if curl -s --connect-timeout 2 google.com > /dev/null; then | |
echo "ok" | |
else | |
# If curl command fails, attempt to connect to VPN using GlobalProtect | |
globalprotect connect | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Check connectivity and ensure VPN connection via GlobalProtect | |
Wants=network-online.target | |
After=network-online.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/autoconnect | |
RemainAfterExit=yes | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Timer to periodically check connectivity and ensure VPN connection | |
[Timer] | |
OnBootSec=0min | |
OnUnitActiveSec=30sec | |
Unit=autoconnect.service | |
[Install] | |
WantedBy=timers.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit on any error | |
set -e | |
# Download the autoconnect script and set executable permissions | |
curl -o /usr/local/bin/autoconnect "https://gist.githubusercontent.com/sarkrui/6aaaaeee84607af4e5ae6668d22f47dd/raw/autoconnect" | |
chmod +x /usr/local/bin/autoconnect | |
# Download the systemd service and timer files | |
curl -o /etc/systemd/system/autoconnect.service "https://gist.githubusercontent.com/sarkrui/6aaaaeee84607af4e5ae6668d22f47dd/raw/autoconnect.service" | |
curl -o /etc/systemd/system/autoconnect.timer "https://gist.githubusercontent.com/sarkrui/6aaaaeee84607af4e5ae6668d22f47dd/raw/autoconnect.timer" | |
# Reload systemd to recognize the new units | |
systemctl daemon-reload | |
# Enable and start the service | |
systemctl enable autoconnect.service | |
systemctl start autoconnect.service | |
# Enable and start the timer | |
systemctl enable autoconnect.timer | |
systemctl start autoconnect.timer | |
echo "Installation and setup completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment