blob: 7704565388ed7ba4e93b55b46cfc3925d6610dc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/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
fi
if [ $# -eq 0 ]; then
echo "error: no command specified"
exit 1
fi
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
echo "resolver: $domain_name_servers"
ENV=
for var in DISPLAY HOME PWD EDITOR USER XAUTHORITY LANG DBUS_SESSION_BUS_ADDRESS; do
value="${!var}"
if [ ! -z "$value" ]; then
ENV="$ENV --env $var=$value"
fi
done
_doas="doas"
if ! command -v doas &>/dev/null; then
_doas="sudo"
fi
$_doas captive-netns-helper \
--nameserver $domain_name_servers \
--ns-file /run/netns/captive \
--uid $(id -u) --gid $(id -g) $ENV "$@"
|