summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-04-28 17:00:07 +0200
committerGitHub <noreply@github.com>2026-04-28 17:00:07 +0200
commit9c8f3d15cd8ba9f3e0ecdfe7081f7f2d13a59453 (patch)
tree3ce5f40d490d29566a37efc1defc597e283dcce9 /src/helpers
parente834a6d51090b2a9261f80464be05d4984cbcce0 (diff)
parente8434e64bada81aabed2cfe614d64cd213110984 (diff)
downloadvyos-1x-9c8f3d15cd8ba9f3e0ecdfe7081f7f2d13a59453.tar.gz
vyos-1x-9c8f3d15cd8ba9f3e0ecdfe7081f7f2d13a59453.zip
Merge pull request #5146 from c-po/serial
utils: T8541: add write-config-file-value helper
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/write-config-file-value.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/helpers/write-config-file-value.py b/src/helpers/write-config-file-value.py
new file mode 100644
index 000000000..f3993223c
--- /dev/null
+++ b/src/helpers/write-config-file-value.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) VyOS Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from argparse import ArgumentParser
+from shlex import split as shlex_split
+
+from vyos.utils.config import write_saved_value
+
+def _split_quoted(s: str) -> list[str]:
+ parts = shlex_split(s)
+ if not parts:
+ raise ValueError('empty string')
+ return parts
+
+if __name__ == '__main__':
+ parser = ArgumentParser()
+ parser.add_argument(
+ '--path',
+ required=True,
+ help='Quoted CLI path, e.g. "system console device ttyS1 speed"',
+ )
+ parser.add_argument(
+ '--value',
+ required=False,
+ help='Value for the node, e.g. "9600". If omitted, creates a valueless node.',
+ )
+ parser.add_argument(
+ '--config-file',
+ required=True,
+ help=f'Path to saved config.boot',
+ )
+ args = parser.parse_args()
+
+ path = _split_quoted(args.path)
+ write_saved_value(path, value=args.value, config_path=args.config_file)