From a671b5081c19707d1fc94f2ca8815d1a6ecf1c6c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 23 Jan 2022 23:12:37 +0100 Subject: [PATCH] gluon-core: preserve explicitly marked network and system sections A section can be marked as preseved by setting the gluon_preserve option to 1. In addition the following conditions must hold: - The preserved section must not already exist after OpenWrt's and Gluons setup scripts run. Modifying existing sections is currently unsupported. - Preserved sections must be named, so it can be detected whether a section conflicts with a preexisting one. --- .../lib/gluon/upgrade/997-migrate-preserved | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 package/gluon-core/luasrc/lib/gluon/upgrade/997-migrate-preserved diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/997-migrate-preserved b/package/gluon-core/luasrc/lib/gluon/upgrade/997-migrate-preserved new file mode 100755 index 00000000..c40bbc9f --- /dev/null +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/997-migrate-preserved @@ -0,0 +1,19 @@ +#!/usr/bin/lua + +local uci = require('simple-uci').cursor() + +for _, config in ipairs({'system', 'network'}) do + uci:foreach(config .. '_gluon-old', nil, function(s) + if s.gluon_preserve ~= '1' then return end + + -- Unnamed sections can't be preserved + if s['.anonymous'] then return end + + -- We don't allow overwriting existing sections + if uci:get(config, s['.name']) then return end + + uci:section(config, s['.type'], s['.name'], s) + end) + + uci:save(config) +end