Skip to content

Commit 1472edb

Browse files
blueos_startup_update: add networkmanager setup
1 parent 104dc15 commit 1472edb

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

core/tools/blueos_startup_update/blueos_startup_update.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from commonwealth.utils.general import HostOs, CpuType, get_cpu_type, get_host_os
1313
from commonwealth.utils.logs import InterceptHandler, init_logger
1414
from loguru import logger
15+
import configparser
1516

1617
SERVICE_NAME = "blueos_startup_update"
1718

@@ -440,6 +441,56 @@ def fix_wpa_service() -> bool:
440441
return True
441442

442443

444+
def configure_network_manager() -> bool:
445+
"""
446+
Ensures NetworkManager.conf has [main] section with dns=none set if dns is not already configured
447+
"""
448+
logger.info("Configuring NetworkManager DNS settings...")
449+
file_path = "/etc/NetworkManager/NetworkManager.conf"
450+
451+
config = configparser.ConfigParser()
452+
453+
# Try to read existing file
454+
result = run_command(f"test -f {file_path} && cat {file_path}", check=False)
455+
if result.returncode != 0:
456+
# File doesn't exist, create with template
457+
content = """[main]
458+
plugins=ifupdown,keyfile
459+
dns=none
460+
461+
[ifupdown]
462+
managed=false
463+
464+
[device]
465+
wifi.scan-rand-mac-address=no
466+
"""
467+
run_command(f"echo '{content}' | sudo tee {file_path}", check=False)
468+
return True
469+
470+
config.read_string(result.stdout)
471+
472+
# Check if we need to make changes
473+
if "main" in config.sections() and "dns" in config["main"]:
474+
return False
475+
476+
# Add our settings if needed
477+
if "main" not in config:
478+
config.add_section("main")
479+
if "dns" not in config["main"]:
480+
config["main"]["dns"] = "none"
481+
482+
# Write back if changes were made
483+
content = ""
484+
for section in config.sections():
485+
content += f"[{section}]\n"
486+
for key, value in config[section].items():
487+
content += f"{key}={value}\n"
488+
content += "\n"
489+
490+
run_command(f"echo '{content}' | sudo tee {file_path}", check=False)
491+
return True
492+
493+
443494
def main() -> int:
444495
start = time.time()
445496
# check if boot_loop_detector exists
@@ -490,7 +541,12 @@ def main() -> int:
490541
]
491542
)
492543
if host_os == HostOs.Bookworm:
493-
patches_to_apply.extend([fix_wpa_service])
544+
patches_to_apply.extend(
545+
[
546+
fix_wpa_service,
547+
configure_network_manager,
548+
]
549+
)
494550

495551
logger.info("The following patches will be applied if needed:")
496552
for patch in patches_to_apply:

0 commit comments

Comments
 (0)