Adding nss-mdns for Avahi mDNS for local domain resolving etc.

Now only modifiying /etc/nsswitch.conf is necesarry. https://wiki.archlinux.org/title/Avahi#systemd-resolved_prevents_nss-mdns_from_working

Fixes #80
This commit is contained in:
Hadi Chokr
2025-03-05 12:09:14 +00:00
committed by Harald Sitter
parent 6c7c7c060e
commit bfda7db36c
3 changed files with 58 additions and 0 deletions

View File

@@ -5,4 +5,5 @@
Packages=bind
iproute2
nfs-utils
nss-mdns # Needed for Avahi mDNS for local domain resolving etc.
ufw # Simple firewall; consider switching to firewalld once the KCM supports zones

View File

@@ -0,0 +1,57 @@
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2025 Hadi Chokr <hadichokr@icloud.com>
import os
import sys
def modify_nsswitch():
path = "/etc/nsswitch.conf"
print(f"Checking {path}...") # Debug line
# Read the file
try:
with open(path, "r") as file:
lines = file.readlines()
except Exception as e:
print(f"Error reading {path}: {e}", file=sys.stderr)
raise # Re-raise the exception
modified = False
# Process each line
for i, line in enumerate(lines):
print(f"Checking line: {line.strip()}") # Debug line
if line.startswith("hosts:"):
if "mymachines" in line and "mdns_minimal" not in line:
lines[i] = line.replace("mymachines", "mymachines mdns_minimal [NOTFOUND=return]", 1)
modified = True
print("Added mdns_minimal after mymachines.") # Debug line
elif "mymachines" not in line and "mdns_minimal" not in line:
lines[i] = line.replace("hosts:", "hosts: mdns_minimal [NOTFOUND=return] ", 1)
modified = True
print("Added mdns_minimal.") # Debug line
break
if not modified:
raise RuntimeError("Expected modification but no changes were made.")
# Write back the modified file
try:
with open(path, "w") as file:
file.writelines(lines)
print("Updated /etc/nsswitch.conf")
except Exception as e:
print(f"Error writing to {path}: {e}", file=sys.stderr)
raise # Re-raise the exception
if __name__ == "__main__":
if os.geteuid() != 0:
print("This script must be run as root.", file=sys.stderr)
sys.exit(1)
try:
modify_nsswitch()
except Exception as e:
print(f"Fatal error: {e}", file=sys.stderr)
sys.exit(1)