This commit is contained in:
parent
7e5d880156
commit
d93f63cf82
40 changed files with 448 additions and 649 deletions
|
|
@ -1,11 +1,5 @@
|
|||
#!/bin/bash -x
|
||||
|
||||
PIPE="/var/run/vpnd.sock"
|
||||
send_cmd() {
|
||||
[ -p $PIPE ] && echo "$@" > $PIPE && \
|
||||
cat < $PIPE
|
||||
}
|
||||
|
||||
send_router_cmd() {
|
||||
touch "${HOME}/.local/state/.vpn_loading"
|
||||
pkill -36 dwmblocks
|
||||
|
|
@ -13,51 +7,40 @@ send_router_cmd() {
|
|||
rm "${HOME}/.local/state/.vpn_loading"
|
||||
}
|
||||
|
||||
awg-quick() {
|
||||
PIPE="/var/run/vpnd.sock"
|
||||
|
||||
[ -p $PIPE ] &&
|
||||
echo "$@" > $PIPE &&
|
||||
cat < $PIPE
|
||||
}
|
||||
|
||||
DEFAULT_LINK="$(resolvectl status | grep 'Default Route: yes' -B10 | grep 'Link' | tail -1 | grep -Eo '\(.*\)' | tr -d '()')"
|
||||
|
||||
if resolvectl domain "$DEFAULT_LINK" | grep -q 'wzray.com'; then
|
||||
IS_LOCAL=1
|
||||
fi
|
||||
|
||||
IFNAME='ext'
|
||||
IFNAME="awg_ext"
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
'i'|'int') IFNAME='int';;
|
||||
'-v'|'--verbose') VERBOSE=1;;
|
||||
*) echo "Wrong argument!"; exit 1;;
|
||||
i|int|internal) IFNAME='awg_int';;
|
||||
*) echo "Wrong argument!" >&2; exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -z "${VERBOSE}" ]; then
|
||||
exec &>/dev/null
|
||||
UP_NAME="$(ip link | grep 'awg_' | cut -d ' ' -f 2 | sed 's,:,,')"
|
||||
|
||||
if [ -n "$UP_NAME" ]; then
|
||||
awg-quick down "$UP_NAME"
|
||||
elif [ -n "$IS_LOCAL" ]; then
|
||||
send_router_cmd toggle
|
||||
else
|
||||
set -x
|
||||
awg-quick up "${IFNAME}"
|
||||
fi
|
||||
|
||||
UP_NAME="$(send_cmd status)"
|
||||
|
||||
if [ -n "$IS_LOCAL" ]; then
|
||||
if [ -n "$UP_NAME" ]; then
|
||||
send_cmd down
|
||||
else
|
||||
send_router_cmd toggle
|
||||
fi
|
||||
else
|
||||
if [ -n "${UP_NAME}" ]; then
|
||||
if [ "${UP_NAME}" != "${IFNAME}" ]; then
|
||||
send_cmd down
|
||||
send_cmd up "$IFNAME"
|
||||
else
|
||||
send_cmd down
|
||||
fi
|
||||
else
|
||||
send_cmd up "$IFNAME"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
pkill -36 dwmblocks
|
||||
|
||||
# vim: ft=bash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue