From e5c61bdfef7a060120625ff50e302923753b2ef3 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 26 Apr 2026 19:38:17 +0200 Subject: utils: T8541: add write-config-file-value helper Introduce src/helpers/write-config-file-value.py to patch a saved config.boot from scripts by writing a quoted CLI path with an optional value (omit --value to create a valueless node). Extend vyos.utils.config.write_saved_value() to safely update saved configs: create missing parent nodes before tagging (ConfigTree.set_tag requires nodes to exist) and then write the requested value/valueless leaf back to disk. Remove the legacy serial console activation script which is now replaced by the helper-based approach. The helper is run once during ISO Image assembly and will inject the approprate serial console defintiions into config.boot.default. --- src/activation-scripts/05-serial_console.py | 43 ----------------------------- 1 file changed, 43 deletions(-) delete mode 100755 src/activation-scripts/05-serial_console.py (limited to 'src/activation-scripts') diff --git a/src/activation-scripts/05-serial_console.py b/src/activation-scripts/05-serial_console.py deleted file mode 100755 index ccda2ac4e..000000000 --- a/src/activation-scripts/05-serial_console.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (C) VyOS Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this library. If not, see . - -from vyos.configtree import ConfigTree -from vyos.system.image import is_live_boot -from vyos.utils.kernel import get_kernel_serial_console -from vyos.utils.serial import is_tty - -base = ['system', 'console', 'device'] - -def activate(config: ConfigTree): - # Configure the kernel serial console only once during live boot. During - # installation, the user can define the console type (VT TTY or serial - # TTY). If this is not limited to live boot, the serial interface will - # always be re-added during system boot, even if it was removed from - # config.boot. - if not is_live_boot(): - return - - # Parse current kernel cmdline and continue only for valid serial console - # data. Prevent writing incomplete/invalid console settings to config.boot. - console_type, console_num, console_speed = get_kernel_serial_console() - device = f'{console_type}{console_num}' - if not is_tty(device) or not console_speed: - return - - # The kernel was booted with a configured serial console, but no console - # is configured via CLI; align/fix the CLI configuration. - if not config.exists(base + [device]): - config.set(base + [device, 'speed'], value=console_speed) - config.set_tag(base) -- cgit v1.2.3