From 7459de4fb94a718cac8b9e24b6d5df64e44032de Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Fri, 13 Dec 2024 14:58:36 +0100 Subject: [PATCH] fix: using a default when upgrading the module --- imageroot/bin/expand-config | 3 +-- imageroot/update-module.d/20gateway_default | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 imageroot/update-module.d/20gateway_default diff --git a/imageroot/bin/expand-config b/imageroot/bin/expand-config index 8174e42..cf12757 100755 --- a/imageroot/bin/expand-config +++ b/imageroot/bin/expand-config @@ -46,8 +46,7 @@ with open("dnsmasq.d/00config.conf", "w") as file: # write dhcp-server configuration if config["dhcp-server"]["enabled"]: file.write("dhcp-range=set:default," + config["dhcp-server"]["start"] + "," + config["dhcp-server"]["end"] + "," + str(config["dhcp-server"]["lease"]) + "h\n") - # due to gateway field introduced in later releases, we need to check if it's present - if 'gateway' in config ['dhcp-server'] and config["dhcp-server"]["gateway"] != "": + if config["dhcp-server"]["gateway"] != "": file.write("dhcp-option=tag:default,option:router," + config["dhcp-server"]["gateway"] + "\n") # write dns-server configuration, if no local Samba DC is present diff --git a/imageroot/update-module.d/20gateway_default b/imageroot/update-module.d/20gateway_default new file mode 100755 index 0000000..c85ed95 --- /dev/null +++ b/imageroot/update-module.d/20gateway_default @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json + +config = json.load(open('config.json')) + +if config['dhcp-server']['enabled']: + if 'gateway' not in config['dhcp-server'] and config['dhcp-server']['gateway'] == '': + # the field is left empty, to avoid assigning a default value + # this is because if in any case the interface the dhcp-server is running + # has two or more ips, a default gateway might cause way too many issues + config['dhcp-server']['gateway'] = '' + +json.dump(config, fp=open('config.json', 'w'))