Try to guess pref in glorytun-run

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2017-11-27 10:33:16 +00:00
parent e26ecf37a3
commit 495138ffe4
2 changed files with 20 additions and 8 deletions

View File

@@ -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 \

View File

@@ -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" <<EOF
${HOST:+HOST="$HOST"}
EOF
( umask 077; echo "$KEY" > /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