|
12 | 12 | from commonwealth.utils.general import HostOs, CpuType, get_cpu_type, get_host_os |
13 | 13 | from commonwealth.utils.logs import InterceptHandler, init_logger |
14 | 14 | from loguru import logger |
| 15 | +import configparser |
15 | 16 |
|
16 | 17 | SERVICE_NAME = "blueos_startup_update" |
17 | 18 |
|
@@ -440,6 +441,56 @@ def fix_wpa_service() -> bool: |
440 | 441 | return True |
441 | 442 |
|
442 | 443 |
|
| 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 | + |
443 | 494 | def main() -> int: |
444 | 495 | start = time.time() |
445 | 496 | # check if boot_loop_detector exists |
@@ -490,7 +541,12 @@ def main() -> int: |
490 | 541 | ] |
491 | 542 | ) |
492 | 543 | 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 | + ) |
494 | 550 |
|
495 | 551 | logger.info("The following patches will be applied if needed:") |
496 | 552 | for patch in patches_to_apply: |
|
0 commit comments