wg-config: cleanups
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
a488f1b084
commit
f4cf3ae124
|
@ -31,7 +31,7 @@ check_loop() {
|
||||||
set_route "$ip"
|
set_route "$ip"
|
||||||
trap unwind INT TERM EXIT
|
trap unwind INT TERM EXIT
|
||||||
|
|
||||||
while read; do
|
while read -r; do
|
||||||
[[ $(short_route "$ip") != "$(short_route default)" ]] && set_route "$ip"
|
[[ $(short_route "$ip") != "$(short_route default)" ]] && set_route "$ip"
|
||||||
done < <(exec ip monitor route)
|
done < <(exec ip monitor route)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e -o pipefail
|
set -e -o pipefail
|
||||||
|
|
||||||
export PATH="$(dirname "$(readlink -f "$0")"):$PATH"
|
SELF="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||||
|
export PATH="${SELF%/*}:$PATH"
|
||||||
|
|
||||||
cmd() {
|
cmd() {
|
||||||
echo "[#] $*" >&2
|
echo "[#] $*" >&2
|
||||||
|
@ -9,7 +10,7 @@ cmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto_su() {
|
auto_su() {
|
||||||
[[ $UID != 0 ]] && exec sudo -p "$PROGRAM must be run as root. Please enter the password for %u to continue: " "$(readlink -f "$0")" "${ARGS[@]}" || true
|
[[ $UID == 0 ]] || exec sudo -p "$PROGRAM must be run as root. Please enter the password for %u to continue: " "$SELF" "${ARGS[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
unwind() {
|
unwind() {
|
||||||
|
@ -121,7 +122,7 @@ cmd_add() {
|
||||||
[[ -n $CONFIG_FILE || -n $CONFIG_FILE_CONTENTS ]] || { echo "$PROGRAM: --config is required for add subcommand" >&2; exit 1; }
|
[[ -n $CONFIG_FILE || -n $CONFIG_FILE_CONTENTS ]] || { echo "$PROGRAM: --config is required for add subcommand" >&2; exit 1; }
|
||||||
auto_su
|
auto_su
|
||||||
trap unwind INT TERM EXIT
|
trap unwind INT TERM EXIT
|
||||||
[[ $(type -t pre_add) == function ]] && pre_add || true
|
[[ $(type -t pre_add) != function ]] || pre_add
|
||||||
add_if
|
add_if
|
||||||
set_config
|
set_config
|
||||||
for i in "${ADDRESSES[@]}"; do
|
for i in "${ADDRESSES[@]}"; do
|
||||||
|
@ -140,17 +141,17 @@ cmd_add() {
|
||||||
add_route "$i"
|
add_route "$i"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
[[ $(type -t post_add) == function ]] && post_add || true
|
[[ $(type -t post_add) != function ]] || post_add
|
||||||
trap - INT TERM EXIT
|
trap - INT TERM EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_del() {
|
cmd_del() {
|
||||||
auto_su
|
auto_su
|
||||||
[[ $(type -t pre_del) == function ]] && pre_del || true
|
[[ $(type -t pre_del) != function ]] || pre_del
|
||||||
killall tungate 2>/dev/null || true
|
killall tungate 2>/dev/null || true
|
||||||
[[ -n $CONFIG_FILE ]] && save_config
|
[[ -n $CONFIG_FILE ]] && save_config
|
||||||
del_if
|
del_if
|
||||||
[[ $(type -t post_del) == function ]] && post_del || true
|
[[ $(type -t post_del) != function ]] || post_del
|
||||||
}
|
}
|
||||||
|
|
||||||
declare INTERFACE="$2"
|
declare INTERFACE="$2"
|
||||||
|
|
Loading…
Reference in a new issue