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 #!/bin/sh
set -e
if [ ! -f "$1" ]; then if [ ! -f "$1" ]; then
echo "usage: $(basename "$0") FILE" echo "usage: $(basename "$0") FILE"
exit 1 exit 1
@@ -11,10 +13,16 @@ DEV="gt${HOST:+c}-$(basename "$1")"
# Setting BIND is like going to 'expert mode' # Setting BIND is like going to 'expert mode'
# This helper is pretty stupid and still needs some work # This helper is pretty stupid and still needs some work
if [ -n "$HOST" ] && [ -z "$BIND" ]; then 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=' ') BIND=$(ip route get "$HOST" | awk '/src/{getline;print $0}' RS=' ')
ip rule add from "$BIND" table main pref 32000 ip rule add from "$BIND" table main pref "$((PREF-1))"
ip rule add from all table 200 pref 32001 fi
ip rule add from all table 200 pref "$PREF"
fi fi
exec glorytun \ exec glorytun \

View File

@@ -24,16 +24,20 @@ if [ -z "$KEY" ]; then
fi fi
# install files # install files
mkdir -p /etc/glorytun 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 ) ( 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 _ask "Start glorytun now ? (enter to skip)" START
case "$START" in y*|Y*) case "$START" in y*|Y*)
systemctl daemon-reload
systemctl start systemd-networkd systemctl start systemd-networkd
systemctl start glorytun@"$NAME" ;; systemctl start glorytun@"$NAME" ;;
esac esac