35 lines
1.3 KiB
Bash
35 lines
1.3 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
export LC_ALL=C
|
|
APP_DIR=/private/etc/reims-host-dns
|
|
PLIST=/Library/LaunchDaemons/com.reimsgo.dns-proxy.plist
|
|
SERVICE=system/com.reimsgo.dns-proxy
|
|
BACKUP="$APP_DIR/dns-proxy.previous-dns"
|
|
LOCAL_DISABLE="$APP_DIR/Disable-Host-DNS.command"
|
|
|
|
sudo -v
|
|
if [ -f "$BACKUP" ]; then
|
|
services=$(networksetup -listallnetworkservices)
|
|
snapshots=$(sudo cat "$BACKUP")
|
|
printf '%s\n\n' "$snapshots" | while IFS= read -r svc && [ -n "$svc" ]; do
|
|
set --
|
|
while IFS= read -r value && [ -n "$value" ]; do
|
|
set -- "$@" "$value"
|
|
done
|
|
printf '%s\n' "$services" | sed '1d' | grep -Fxq -e "$svc" -e "*$svc" || continue
|
|
current=$(networksetup -getdnsservers "$svc")
|
|
[ "$current" = 127.0.0.1 ] || continue
|
|
if [ "$*" = Empty ] || [ "$*" = "There aren't any DNS Servers set on $svc." ]; then
|
|
sudo networksetup -setdnsservers "$svc" Empty
|
|
else
|
|
sudo networksetup -setdnsservers "$svc" "$@"
|
|
fi
|
|
done
|
|
fi
|
|
if sudo launchctl print "$SERVICE" >/dev/null 2>&1; then
|
|
sudo launchctl bootout "$SERVICE"
|
|
fi
|
|
sudo dscacheutil -flushcache
|
|
sudo rm -f "$PLIST" "$APP_DIR/dns-proxy.pl" "$APP_DIR/dns-proxy.conf" "$APP_DIR/dns-proxy.conf.new" "$BACKUP" "$LOCAL_DISABLE"
|
|
echo "Host DNS is disabled."
|