mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to invoke resolvconf (if installed) to add/remove lokinet into/from the resolvconf DNS
|
|
# server list. This script does not add if any of these are true:
|
|
#
|
|
# - /sbin/resolvconf does not exist
|
|
# - the systemd-resolved service is active
|
|
# - the `bind=` entry in the [dns] section of lokinet.ini is commented out
|
|
# - a `no-resolvconf=1` item is present in the [dns] section of lokinet.ini
|
|
#
|
|
# It always attempts to remove if resolvconf is installed (so that commenting out while running,
|
|
# then stopping still removes the added entry).
|
|
#
|
|
# Usage: lokinet-resolvconf {add|remove} /etc/loki/lokinet.ini
|
|
|
|
set -e
|
|
|
|
action="$1"
|
|
conf="$2"
|
|
|
|
if [[ ! ("$action" == "add" || "$action" == "remove") || ! -f "$conf" ]]; then
|
|
echo "Usage: $0 {add|remove} /path/to/lokinet.ini" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! [ -x /sbin/resolvconf ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ -x /bin/systemctl ] && /bin/systemctl --quiet is-active systemd-resolved.service; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$action" == "add" ]; then
|
|
if ! [ -x /sbin/resolvconf ]; then exit 0; fi
|
|
|
|
lokinet_ns=$(perl -e 'while (<>) {
|
|
if ((/^\[dns\]/ ... /^\[/)) {
|
|
if (/^bind\s*=\s*(127.*):53\s*$/) {
|
|
$ns=$1;
|
|
} elsif (/^no-resolvconf\s*=\s*1\s*/) {
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
print $ns' "$conf")
|
|
|
|
if [ -n "$lokinet_ns" ]; then
|
|
echo "nameserver $lokinet_ns" | /sbin/resolvconf -a lo.000lokinet
|
|
fi
|
|
else
|
|
/sbin/resolvconf -d lo.000lokinet
|
|
fi
|