Last active
September 27, 2022 06:09
-
-
Save rodneyshupe/195735f94ff8702c61f36da671800b59 to your computer and use it in GitHub Desktop.
Connect / Disconnect from Wireguard Client on GL MT1300 travel router.
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
#!/usr/bin/env sh | |
function usage() { | |
cat << EOF | |
Usage: $0 [options...] | |
This script allows for easy access to connect or disconnect the wireguard vpn client. | |
Options: | |
-h show the help and exit | |
-u wireguard Up | |
-d wireguard Down | |
-t wireguard toggle | |
-s display wireguard status | |
EOF | |
} | |
function parse_args() { | |
while getopts ":hudts" OPT; do | |
case $OPT in | |
h) | |
usage | |
exit 0 | |
;; | |
u) | |
MODE="1" | |
;; | |
d) | |
MODE="0" | |
;; | |
t) | |
if [ $(uci get wireguard.@proxy[0].enable) -ne 1 ]; then | |
MODE="1" | |
else | |
MODE="0" | |
fi | |
;; | |
s) | |
if [ $(uci get wireguard.@proxy[0].enable) -ne 1 ]; then | |
echo "Status: Down" | |
else | |
echo "Status: Up" | |
fi | |
exit 0 | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
echo "" | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
} | |
function wireguard_enable() { | |
local _ENABLE=${1:-1} | |
if [ $_ENABLE -eq 1 ]; then | |
if [ $(uci get wireguard.@proxy[0].enable) -ne 1 ]; then | |
echo "Connecting to VPN..." | |
uci set wireguard.@proxy[0].enable='1' | |
uci commit | |
/etc/init.d/wireguard reload >/dev/null 2>&1 | |
fi | |
else | |
echo "Disconnecting from VPN..." | |
uci set wireguard.@proxy[0].enable='0' | |
uci commit | |
/etc/init.d/wireguard reload >/dev/null 2>&1 | |
fi | |
} | |
if [ $(uci get wireguard.@proxy[0].enable) -ne 1 ]; then | |
MODE="1" | |
else | |
MODE="0" | |
fi | |
parse_args $@ | |
wireguard_enable $MODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment