Expose DNS setting in the network widget
This commit is contained in:
@@ -39,6 +39,7 @@ GROUP_DESCRIPTIONS[config]="System configuration helpers"
|
|||||||
GROUP_DESCRIPTIONS[debug]="Diagnostics and support logs"
|
GROUP_DESCRIPTIONS[debug]="Diagnostics and support logs"
|
||||||
GROUP_DESCRIPTIONS[default]="Default application selection"
|
GROUP_DESCRIPTIONS[default]="Default application selection"
|
||||||
GROUP_DESCRIPTIONS[dev]="Omarchy development tools"
|
GROUP_DESCRIPTIONS[dev]="Omarchy development tools"
|
||||||
|
GROUP_DESCRIPTIONS[dns]="DNS resolver configuration"
|
||||||
GROUP_DESCRIPTIONS[drive]="Drive selection and encryption"
|
GROUP_DESCRIPTIONS[drive]="Drive selection and encryption"
|
||||||
GROUP_DESCRIPTIONS[font]="Font management"
|
GROUP_DESCRIPTIONS[font]="Font management"
|
||||||
GROUP_DESCRIPTIONS[games]="Game launchers and helpers"
|
GROUP_DESCRIPTIONS[games]="Game launchers and helpers"
|
||||||
|
|||||||
Executable
+176
@@ -0,0 +1,176 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# omarchy:summary=Show or configure the system DNS provider
|
||||||
|
# omarchy:args=[Cloudflare|Google|DHCP|Custom]
|
||||||
|
# omarchy:examples=omarchy dns | omarchy dns Cloudflare | omarchy dns Custom
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
provider_from_arg() {
|
||||||
|
case "${1:-}" in
|
||||||
|
Cloudflare | cloudflare)
|
||||||
|
echo "Cloudflare"
|
||||||
|
;;
|
||||||
|
Google | google)
|
||||||
|
echo "Google"
|
||||||
|
;;
|
||||||
|
DHCP | dhcp)
|
||||||
|
echo "DHCP"
|
||||||
|
;;
|
||||||
|
Custom | custom)
|
||||||
|
echo "Custom"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
current_dns_provider() {
|
||||||
|
local dns=""
|
||||||
|
local compact=""
|
||||||
|
|
||||||
|
dns=$(awk -F= '
|
||||||
|
/^[[:space:]]*#/ { next }
|
||||||
|
/^[[:space:]]*DNS[[:space:]]*=/ {
|
||||||
|
value=$0
|
||||||
|
sub(/^[^=]*=/, "", value)
|
||||||
|
print value
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
' /etc/systemd/resolved.conf 2>/dev/null || true)
|
||||||
|
|
||||||
|
compact=$(printf '%s' "$dns" | tr -d '[:space:]')
|
||||||
|
|
||||||
|
if [[ -z $compact ]]; then
|
||||||
|
echo "DHCP"
|
||||||
|
elif [[ $dns == *"cloudflare-dns.com"* || $dns == *"1.1.1.1"* || $dns == *"2606:4700:4700::1111"* ]]; then
|
||||||
|
echo "Cloudflare"
|
||||||
|
elif [[ $dns == *"dns.google"* || $dns == *"8.8.8.8"* || $dns == *"2001:4860:4860::8888"* ]]; then
|
||||||
|
echo "Google"
|
||||||
|
else
|
||||||
|
echo "Custom"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
self_path() {
|
||||||
|
local self="${BASH_SOURCE[0]}"
|
||||||
|
|
||||||
|
if [[ $self != /* ]]; then
|
||||||
|
self=$(command -v -- "$self")
|
||||||
|
fi
|
||||||
|
|
||||||
|
readlink -f "$self"
|
||||||
|
}
|
||||||
|
|
||||||
|
require_root() {
|
||||||
|
if (( EUID == 0 )); then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v pkexec >/dev/null; then
|
||||||
|
echo "Error: pkexec is required to change DNS settings." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec pkexec "$(self_path)" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
lock_dns_to_resolved() {
|
||||||
|
local file=""
|
||||||
|
|
||||||
|
for file in /etc/systemd/network/*.network; do
|
||||||
|
[[ -f $file ]] || continue
|
||||||
|
if ! grep -q "^\[DHCPv4\]" "$file"; then continue; fi
|
||||||
|
|
||||||
|
if ! sed -n '/^\[DHCPv4\]/,/^\[/p' "$file" | grep -q "^UseDNS="; then
|
||||||
|
sed -i '/^\[DHCPv4\]/a UseDNS=no' "$file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q "^\[IPv6AcceptRA\]" "$file" && ! sed -n '/^\[IPv6AcceptRA\]/,/^\[/p' "$file" | grep -q "^UseDNS="; then
|
||||||
|
sed -i '/^\[IPv6AcceptRA\]/a UseDNS=no' "$file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
unlock_dns_to_dhcp() {
|
||||||
|
local file=""
|
||||||
|
|
||||||
|
for file in /etc/systemd/network/*.network; do
|
||||||
|
[[ -f $file ]] || continue
|
||||||
|
sed -i '/^\[DHCPv4\]/{n;/^UseDNS=no$/d}' "$file"
|
||||||
|
sed -i '/^\[IPv6AcceptRA\]/{n;/^UseDNS=no$/d}' "$file"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: omarchy-dns [Cloudflare|Google|DHCP|Custom]" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( $# == 0 )); then
|
||||||
|
current_dns_provider
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( $# > 1 )); then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! provider=$(provider_from_arg "$1"); then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
require_root "$provider"
|
||||||
|
|
||||||
|
case "$provider" in
|
||||||
|
Cloudflare)
|
||||||
|
tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
||||||
|
[Resolve]
|
||||||
|
DNS=1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
|
||||||
|
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
||||||
|
DNSOverTLS=opportunistic
|
||||||
|
EOF
|
||||||
|
lock_dns_to_resolved
|
||||||
|
;;
|
||||||
|
|
||||||
|
Google)
|
||||||
|
tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
||||||
|
[Resolve]
|
||||||
|
DNS=8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
|
||||||
|
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
||||||
|
DNSOverTLS=opportunistic
|
||||||
|
EOF
|
||||||
|
lock_dns_to_resolved
|
||||||
|
;;
|
||||||
|
|
||||||
|
DHCP)
|
||||||
|
tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
||||||
|
[Resolve]
|
||||||
|
DNSOverTLS=no
|
||||||
|
EOF
|
||||||
|
unlock_dns_to_dhcp
|
||||||
|
;;
|
||||||
|
|
||||||
|
Custom)
|
||||||
|
echo "Enter your DNS servers (space-separated, e.g. '192.168.1.1 1.1.1.1'):"
|
||||||
|
if ! read -r dns_servers; then
|
||||||
|
dns_servers=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $dns_servers ]]; then
|
||||||
|
echo "Error: No DNS servers provided." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tee /etc/systemd/resolved.conf >/dev/null <<EOF
|
||||||
|
[Resolve]
|
||||||
|
DNS=$dns_servers
|
||||||
|
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
||||||
|
EOF
|
||||||
|
lock_dns_to_resolved
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
systemctl restart systemd-networkd systemd-resolved
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# omarchy:summary=Configure the system DNS provider
|
|
||||||
# omarchy:args=[Cloudflare|Google|DHCP|Custom]
|
|
||||||
# omarchy:requires-sudo=true
|
|
||||||
|
|
||||||
lock_dns_to_resolved() {
|
|
||||||
for file in /etc/systemd/network/*.network; do
|
|
||||||
[[ -f $file ]] || continue
|
|
||||||
if ! grep -q "^\[DHCPv4\]" "$file"; then continue; fi
|
|
||||||
|
|
||||||
if ! sed -n '/^\[DHCPv4\]/,/^\[/p' "$file" | grep -q "^UseDNS="; then
|
|
||||||
sudo sed -i '/^\[DHCPv4\]/a UseDNS=no' "$file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if grep -q "^\[IPv6AcceptRA\]" "$file" && ! sed -n '/^\[IPv6AcceptRA\]/,/^\[/p' "$file" | grep -q "^UseDNS="; then
|
|
||||||
sudo sed -i '/^\[IPv6AcceptRA\]/a UseDNS=no' "$file"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
unlock_dns_to_dhcp() {
|
|
||||||
for file in /etc/systemd/network/*.network; do
|
|
||||||
[[ -f $file ]] || continue
|
|
||||||
sudo sed -i '/^\[DHCPv4\]/{n;/^UseDNS=no$/d}' "$file"
|
|
||||||
sudo sed -i '/^\[IPv6AcceptRA\]/{n;/^UseDNS=no$/d}' "$file"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ -z $1 ]]; then
|
|
||||||
dns=$(gum choose --height 6 --header "Select DNS provider" Cloudflare Google DHCP Custom)
|
|
||||||
else
|
|
||||||
dns=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$dns" in
|
|
||||||
Cloudflare)
|
|
||||||
sudo tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
|
||||||
[Resolve]
|
|
||||||
DNS=1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
|
|
||||||
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
|
||||||
DNSOverTLS=opportunistic
|
|
||||||
EOF
|
|
||||||
lock_dns_to_resolved
|
|
||||||
;;
|
|
||||||
|
|
||||||
Google)
|
|
||||||
sudo tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
|
||||||
[Resolve]
|
|
||||||
DNS=8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
|
|
||||||
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
|
||||||
DNSOverTLS=opportunistic
|
|
||||||
EOF
|
|
||||||
lock_dns_to_resolved
|
|
||||||
;;
|
|
||||||
|
|
||||||
DHCP)
|
|
||||||
sudo tee /etc/systemd/resolved.conf >/dev/null <<'EOF'
|
|
||||||
[Resolve]
|
|
||||||
DNSOverTLS=no
|
|
||||||
EOF
|
|
||||||
unlock_dns_to_dhcp
|
|
||||||
;;
|
|
||||||
|
|
||||||
Custom)
|
|
||||||
echo "Enter your DNS servers (space-separated, e.g. '192.168.1.1 1.1.1.1'):"
|
|
||||||
read -r dns_servers
|
|
||||||
|
|
||||||
if [[ -z $dns_servers ]]; then
|
|
||||||
echo "Error: No DNS servers provided."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo tee /etc/systemd/resolved.conf >/dev/null <<EOF
|
|
||||||
[Resolve]
|
|
||||||
DNS=$dns_servers
|
|
||||||
FallbackDNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
|
|
||||||
EOF
|
|
||||||
lock_dns_to_resolved
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
sudo systemctl restart systemd-networkd systemd-resolved
|
|
||||||
@@ -155,7 +155,11 @@
|
|||||||
"setup.default.editor.helix": {"icon":"","label":"Helix","when":"omarchy-cmd-present helix","checked":"[[ \"$(omarchy-default-editor)\" == \"helix\" ]]","action":"omarchy-default-editor helix"},
|
"setup.default.editor.helix": {"icon":"","label":"Helix","when":"omarchy-cmd-present helix","checked":"[[ \"$(omarchy-default-editor)\" == \"helix\" ]]","action":"omarchy-default-editor helix"},
|
||||||
"setup.default.editor.vim": {"icon":"","label":"Vim","when":"omarchy-cmd-present vim","checked":"[[ \"$(omarchy-default-editor)\" == \"vim\" ]]","action":"omarchy-default-editor vim"},
|
"setup.default.editor.vim": {"icon":"","label":"Vim","when":"omarchy-cmd-present vim","checked":"[[ \"$(omarchy-default-editor)\" == \"vim\" ]]","action":"omarchy-default-editor vim"},
|
||||||
"setup.default.editor.emacs": {"icon":"","label":"Emacs","when":"omarchy-cmd-present emacs","checked":"[[ \"$(omarchy-default-editor)\" == \"emacs\" ]]","action":"omarchy-default-editor emacs"},
|
"setup.default.editor.emacs": {"icon":"","label":"Emacs","when":"omarchy-cmd-present emacs","checked":"[[ \"$(omarchy-default-editor)\" == \"emacs\" ]]","action":"omarchy-default-editor emacs"},
|
||||||
"setup.dns": {"icon":"","label":"DNS","keywords":"network","action":"omarchy-launch-floating-terminal-with-presentation omarchy-setup-dns"},
|
"setup.dns": {"icon":"","label":"DNS","keywords":"network resolver"},
|
||||||
|
"setup.dns.dhcp": {"icon":"","label":"DHCP","keywords":"router automatic","checked":"[[ $(omarchy-dns) == \"DHCP\" ]]","action":"omarchy-dns DHCP"},
|
||||||
|
"setup.dns.cloudflare": {"icon":"","label":"Cloudflare","checked":"[[ $(omarchy-dns) == \"Cloudflare\" ]]","action":"omarchy-dns Cloudflare"},
|
||||||
|
"setup.dns.google": {"icon":"","label":"Google","checked":"[[ $(omarchy-dns) == \"Google\" ]]","action":"omarchy-dns Google"},
|
||||||
|
"setup.dns.custom": {"icon":"","label":"Custom","checked":"[[ $(omarchy-dns) == \"Custom\" ]]","action":"omarchy-launch-floating-terminal-with-presentation omarchy-dns Custom"},
|
||||||
"setup.security": {"icon":"","label":"Security","keywords":"fingerprint fido2"},
|
"setup.security": {"icon":"","label":"Security","keywords":"fingerprint fido2"},
|
||||||
"setup.config": {"icon":"","label":"Config","keywords":"files hyprland bar quickshell walker"},
|
"setup.config": {"icon":"","label":"Config","keywords":"files hyprland bar quickshell walker"},
|
||||||
"setup.security.fingerprint": {"icon":"","label":"Fingerprint","action":"omarchy-launch-floating-terminal-with-presentation omarchy-setup-security-fingerprint"},
|
"setup.security.fingerprint": {"icon":"","label":"Fingerprint","action":"omarchy-launch-floating-terminal-with-presentation omarchy-setup-security-fingerprint"},
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ Example `shell.json` (bar subtree only shown):
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `media` | MPRIS now-playing — scrolling track + artist, cover-art popup | left = play/pause · middle = next · scroll = prev/next · right = popup |
|
| `media` | MPRIS now-playing — scrolling track + artist, cover-art popup | left = play/pause · middle = next · scroll = prev/next · right = popup |
|
||||||
| `audioPanel` | Volume icon + popup with master slider, output-device picker, per-app mixer | left = popup · right = mute · middle = audio TUI · scroll = volume |
|
| `audioPanel` | Volume icon + popup with master slider, output-device picker, per-app mixer | left = popup · right = mute · middle = audio TUI · scroll = volume |
|
||||||
| `networkPanel` | Wi-Fi/Ethernet icon + popup with Wi-Fi scan, signal, connect | left = popup · right = nmtui |
|
| `networkPanel` | Wi-Fi/Ethernet icon + popup with Wi-Fi scan, signal, connect, DNS provider selection | left = popup · right = nmtui |
|
||||||
| `bluetoothPanel` | Bluetooth icon + popup with device list, connect/disconnect, battery | left = popup · right = toggle radio · middle = bluetoothctl TUI |
|
| `bluetoothPanel` | Bluetooth icon + popup with device list, connect/disconnect, battery | left = popup · right = toggle radio · middle = bluetoothctl TUI |
|
||||||
| `calendar` | Clock + popup with month-grid calendar | left = popup · right = tz selector |
|
| `calendar` | Clock + popup with month-grid calendar | left = popup · right = tz selector |
|
||||||
| `notificationCenter` | Bell with badge + popup with recent notifications, DND toggle | left = popup · right = toggle DND |
|
| `notificationCenter` | Bell with badge + popup with recent notifications, DND toggle | left = popup · right = toggle DND |
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ Item {
|
|||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
if (!detailsProc.running) detailsProc.running = true
|
if (!detailsProc.running) detailsProc.running = true
|
||||||
if (!dnsProc.running) dnsProc.running = true
|
if (!dnsProc.running) {
|
||||||
|
dnsProc.command = ["bash", "-lc", root.dnsCommand("")]
|
||||||
|
dnsProc.running = true
|
||||||
|
}
|
||||||
if (!wifiProc.running) {
|
if (!wifiProc.running) {
|
||||||
scanning = true
|
scanning = true
|
||||||
wifiProc.running = true
|
wifiProc.running = true
|
||||||
@@ -110,7 +113,9 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dnsCommand(provider) {
|
function dnsCommand(provider) {
|
||||||
return "pkexec " + root.bar.shellQuote(root.bar.omarchyPath + "/bin/omarchy-setup-dns") + " " + root.bar.shellQuote(provider)
|
var command = root.bar ? root.bar.shellQuote(root.bar.omarchyPath + "/bin/omarchy-dns") : "omarchy-dns"
|
||||||
|
if (provider) command += " " + root.bar.shellQuote(provider)
|
||||||
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDns(provider) {
|
function setDns(provider) {
|
||||||
@@ -208,19 +213,6 @@ iwctl station "$station" get-networks rssi-dbms 2>/dev/null \\
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: dnsProc
|
id: dnsProc
|
||||||
command: ["bash", "-c", `
|
|
||||||
dns=$(awk -F= '/^[[:space:]]*DNS[[:space:]]*=/ { value=$0; sub(/^[^=]*=/, "", value); print value; exit }' /etc/systemd/resolved.conf 2>/dev/null)
|
|
||||||
compact=$(printf '%s' "$dns" | tr -d '[:space:]')
|
|
||||||
if [[ -z $compact ]]; then
|
|
||||||
echo DHCP
|
|
||||||
elif [[ $dns == *cloudflare-dns.com* || $dns == *"1.1.1.1"* || $dns == *"2606:4700:4700::1111"* ]]; then
|
|
||||||
echo Cloudflare
|
|
||||||
elif [[ $dns == *dns.google* || $dns == *"8.8.8.8"* || $dns == *"2001:4860:4860::8888"* ]]; then
|
|
||||||
echo Google
|
|
||||||
else
|
|
||||||
echo Custom
|
|
||||||
fi
|
|
||||||
`]
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
waitForEnd: true
|
waitForEnd: true
|
||||||
onStreamFinished: root.updateDns(text)
|
onStreamFinished: root.updateDns(text)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ echo "Reset DNS configuration to DHCP (remove forced Cloudflare DNS)"
|
|||||||
|
|
||||||
# Reset DNS to use DHCP by default instead of forcing Cloudflare
|
# Reset DNS to use DHCP by default instead of forcing Cloudflare
|
||||||
# This preserves local development environments (.local domains, etc.)
|
# This preserves local development environments (.local domains, etc.)
|
||||||
# Users can still opt-in to Cloudflare DNS using: omarchy-setup-dns cloudflare
|
# Users can still opt-in to Cloudflare DNS using: omarchy-dns Cloudflare
|
||||||
|
|
||||||
if [[ -f /etc/systemd/resolved.conf ]]; then
|
if [[ -f /etc/systemd/resolved.conf ]]; then
|
||||||
# Backup current config with timestamp
|
# Backup current config with timestamp
|
||||||
@@ -27,5 +27,5 @@ if [[ -f /etc/systemd/resolved.conf ]]; then
|
|||||||
sudo systemctl restart systemd-resolved
|
sudo systemctl restart systemd-resolved
|
||||||
|
|
||||||
echo "DNS configuration reset to use DHCP (router DNS)"
|
echo "DNS configuration reset to use DHCP (router DNS)"
|
||||||
echo "To use Cloudflare DNS, run: omarchy-setup-dns Cloudflare"
|
echo "To use Cloudflare DNS, run: omarchy-dns Cloudflare"
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user