Skip to content

Commit 5eedb20

Browse files
Williangalvanipatrickelectric
authored andcommitted
blueos_startup_update: add networkmanager setup
1 parent 39b1c21 commit 5eedb20

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

core/tools/blueos_startup_update/blueos_startup_update.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import time
88
from typing import List, Tuple
9+
import configparser
910

1011
import appdirs
1112
from commonwealth.utils.commands import run_command, save_file, locate_file, load_file
@@ -442,6 +443,56 @@ def fix_wpa_service() -> bool:
442443
return True
443444

444445

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

497548
logger.info("The following patches will be applied if needed:")
498549
for name, patch in patches_to_apply:

0 commit comments

Comments
 (0)