From 495138ffe43b4fea431c9af72ab77a67eab793d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Mon, 27 Nov 2017 10:33:16 +0000 Subject: [PATCH] Try to guess pref in glorytun-run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- systemd/glorytun-run | 16 ++++++++++++---- systemd/glorytun-setup | 12 ++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/systemd/glorytun-run b/systemd/glorytun-run index 17746b9..48a6617 100755 --- a/systemd/glorytun-run +++ b/systemd/glorytun-run @@ -1,5 +1,7 @@ #!/bin/sh +set -e + if [ ! -f "$1" ]; then echo "usage: $(basename "$0") FILE" exit 1 @@ -11,10 +13,16 @@ DEV="gt${HOST:+c}-$(basename "$1")" # Setting BIND is like going to 'expert mode' # This helper is pretty stupid and still needs some work -if [ -n "$HOST" ] && [ -z "$BIND" ]; then - BIND=$(ip route get "$HOST" | awk '/src/{getline;print $0}' RS=' ') - ip rule add from "$BIND" table main pref 32000 - ip rule add from all table 200 pref 32001 +if [ -n "$HOST" ]; then + if [ -z "$PREF" ]; then + PREF=$(ip rule | awk '/from all lookup main/{print $1; exit}' | tr -d :) + PREF=$((PREF-1)) + fi + if [ -z "$BIND" ]; then + BIND=$(ip route get "$HOST" | awk '/src/{getline;print $0}' RS=' ') + ip rule add from "$BIND" table main pref "$((PREF-1))" + fi + ip rule add from all table 200 pref "$PREF" fi exec glorytun \ diff --git a/systemd/glorytun-setup b/systemd/glorytun-setup index e4565ec..e6e2b15 100755 --- a/systemd/glorytun-setup +++ b/systemd/glorytun-setup @@ -24,16 +24,20 @@ if [ -z "$KEY" ]; then fi # install files - mkdir -p /etc/glorytun -env | grep 'TABLE=\|HOST=' > /etc/glorytun/"$NAME" + +cat > /etc/glorytun/"$NAME" < /etc/glorytun/"$NAME".key ) -# start services +# always reload +systemctl daemon-reload +# start services _ask "Start glorytun now ? (enter to skip)" START case "$START" in y*|Y*) - systemctl daemon-reload systemctl start systemd-networkd systemctl start glorytun@"$NAME" ;; esac