diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-04-19 23:05:26 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-04-19 23:05:26 +0300 |
commit | e7dc6c669106d4dc7c1ef78a867127c3157612c1 (patch) | |
tree | d0c2098c6ce6dbd4305c6fa986da50e63e419df4 | |
parent | a9ddb043cc9742ca8b0d7c6828f92c4b59085e43 (diff) |
-rwxr-xr-x | captive-portal.sh | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/captive-portal.sh b/captive-portal.sh index 92f3b16..7704565 100755 --- a/captive-portal.sh +++ b/captive-portal.sh @@ -1,5 +1,9 @@ #!/bin/bash +get_default_iface() { + ip -4 r show default | grep -v tun | awk '{print $5}' +} + if [ $EUID -eq 0 ]; then echo "error: this script should not be launched as root" exit 1 @@ -10,13 +14,23 @@ if [ $# -eq 0 ]; then exit 1 fi -export $(dhcpcd -U $IFACE) +IFACE=$(get_default_iface) + +if dhcpcd -U $IFACE 1>/dev/null 2>&1; then + echo "using dhcpcd" + export $(dhcpcd -U $IFACE) +elif nmcli 1>/dev/null 2>&1; then + echo "using nmcli" + domain_name_servers=$(nmcli device show $IFACE | grep IP4.DNS | awk '{print $2}' | head -1) +fi + if [ -z "$domain_name_servers" ]; then echo "error: \$domain_name_servers variable not found" exit 1 fi -IFACE=wlp3s0 +echo "resolver: $domain_name_servers" + ENV= for var in DISPLAY HOME PWD EDITOR USER XAUTHORITY LANG DBUS_SESSION_BUS_ADDRESS; do value="${!var}" @@ -33,4 +47,4 @@ fi $_doas captive-netns-helper \ --nameserver $domain_name_servers \ --ns-file /run/netns/captive \ - --uid $(id -u) --gid $(id -g) $ENV "$@"
\ No newline at end of file + --uid $(id -u) --gid $(id -g) $ENV "$@" |