aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/contrib
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-12-21 06:15:57 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-12-23 21:09:23 +0100
commitf4cf3ae124651918aaa46528cb9b07a34f874f90 (patch)
tree5a3b045d8e17df6f12b318f02b62f6b31a89e586 /contrib
parentwg: do not use AI_ADDRCONFIG (diff)
downloadwireguard-tools-f4cf3ae124651918aaa46528cb9b07a34f874f90.tar.xz
wireguard-tools-f4cf3ae124651918aaa46528cb9b07a34f874f90.zip
wg-config: cleanups
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/wg-config/tungate2
-rwxr-xr-xcontrib/wg-config/wg-config13
2 files changed, 8 insertions, 7 deletions
diff --git a/contrib/wg-config/tungate b/contrib/wg-config/tungate
index b537b81..034e8b8 100755
--- a/contrib/wg-config/tungate
+++ b/contrib/wg-config/tungate
@@ -31,7 +31,7 @@ check_loop() {
set_route "$ip"
trap unwind INT TERM EXIT
- while read; do
+ while read -r; do
[[ $(short_route "$ip") != "$(short_route default)" ]] && set_route "$ip"
done < <(exec ip monitor route)
}
diff --git a/contrib/wg-config/wg-config b/contrib/wg-config/wg-config
index d7ea38c..d6447eb 100755
--- a/contrib/wg-config/wg-config
+++ b/contrib/wg-config/wg-config
@@ -1,7 +1,8 @@
#!/bin/bash
set -e -o pipefail
-export PATH="$(dirname "$(readlink -f "$0")"):$PATH"
+SELF="$(readlink -f "${BASH_SOURCE[0]}")"
+export PATH="${SELF%/*}:$PATH"
cmd() {
echo "[#] $*" >&2
@@ -9,7 +10,7 @@ cmd() {
}
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() {
@@ -121,7 +122,7 @@ cmd_add() {
[[ -n $CONFIG_FILE || -n $CONFIG_FILE_CONTENTS ]] || { echo "$PROGRAM: --config is required for add subcommand" >&2; exit 1; }
auto_su
trap unwind INT TERM EXIT
- [[ $(type -t pre_add) == function ]] && pre_add || true
+ [[ $(type -t pre_add) != function ]] || pre_add
add_if
set_config
for i in "${ADDRESSES[@]}"; do
@@ -140,17 +141,17 @@ cmd_add() {
add_route "$i"
fi
done
- [[ $(type -t post_add) == function ]] && post_add || true
+ [[ $(type -t post_add) != function ]] || post_add
trap - INT TERM EXIT
}
cmd_del() {
auto_su
- [[ $(type -t pre_del) == function ]] && pre_del || true
+ [[ $(type -t pre_del) != function ]] || pre_del
killall tungate 2>/dev/null || true
[[ -n $CONFIG_FILE ]] && save_config
del_if
- [[ $(type -t post_del) == function ]] && post_del || true
+ [[ $(type -t post_del) != function ]] || post_del
}
declare INTERFACE="$2"