-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2372 from freifunk-gluon/uci-regen
Regenerate network and system UCI configs on every reconfigure, switch to role-based interface configuration
- Loading branch information
Showing
33 changed files
with
353 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/sh | ||
|
||
NETWORK_CFG='/etc/config/network' | ||
NETWORK_SAVED="${NETWORK_CFG}_gluon-old" | ||
|
||
SYSTEM_CFG='/etc/config/system' | ||
SYSTEM_SAVED="${SYSTEM_CFG}_gluon-old" | ||
|
||
# Make sure everything is saved before we move away the config files | ||
uci commit | ||
|
||
# Save old configs (unless there is already a saved config, | ||
# which means that the previous upgrade was interrupted) | ||
if [ -s "$NETWORK_CFG" ] && ! [ -s "$NETWORK_SAVED" ]; then | ||
mv -f "$NETWORK_CFG" "$NETWORK_SAVED" | ||
fi | ||
if [ -s "$SYSTEM_CFG" ] && ! [ -s "$SYSTEM_SAVED" ]; then | ||
mv -f "$SYSTEM_CFG" "$SYSTEM_SAVED" | ||
fi | ||
|
||
# Generate a new network config | ||
rm -f /etc/board.json "$NETWORK_CFG" "$SYSTEM_CFG" | ||
config_generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
package/gluon-core/luasrc/lib/gluon/upgrade/002-migrate-system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/lua | ||
|
||
local uci = require('simple-uci').cursor() | ||
|
||
-- Migrate system section | ||
local system = uci:get_all('system_gluon-old', '@system[0]') | ||
if system then | ||
uci:tset('system', '@system[0]', system) | ||
end | ||
|
||
-- Migrate ntp section | ||
local ntp = uci:get_all('system_gluon-old', 'ntp') | ||
if ntp then | ||
uci:tset('system', 'ntp', ntp) | ||
end | ||
|
||
-- Migrate gpio_switch sections | ||
-- | ||
-- Only the value is copied from the old config, so updates to names and | ||
-- pins are preserved | ||
uci:foreach('system', 'gpio_switch', function(s) | ||
local name = s['.name'] | ||
local value = uci:get('system_gluon-old', name, 'value') | ||
if value then | ||
uci:set('system', name, 'value', value) | ||
end | ||
end) | ||
|
||
-- No other sections are migrated, so updated LED and RSSI configs can take effect | ||
|
||
uci:save('system') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
package/gluon-core/luasrc/lib/gluon/upgrade/021-interface-roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/lua | ||
|
||
local site = require 'gluon.site' | ||
local sysconfig = require 'gluon.sysconfig' | ||
local uci = require('simple-uci').cursor() | ||
local util = require 'gluon.util' | ||
|
||
-- Defaults from site.conf | ||
local roles = { | ||
lan = site.interfaces.lan.roles({'client'}), | ||
wan = site.interfaces.wan.roles({'uplink'}), | ||
} | ||
roles.single = site.interfaces.single.roles(roles.wan) | ||
|
||
-- Migration of Mesh-on-WAN/LAN setting from Gluon 2021.1 and older (to be removed in 2024) | ||
-- | ||
-- Wired meshing is enabled for single interfaces if either of the settings | ||
-- was previously enabled | ||
local mesh_lan_disabled = uci:get('network_gluon-old', 'mesh_lan', 'disabled') | ||
local mesh_wan_disabled = uci:get('network_gluon-old', 'mesh_wan', 'disabled') | ||
if mesh_wan_disabled == '0' then | ||
util.add_to_set(roles.wan, 'mesh') | ||
util.add_to_set(roles.single, 'mesh') | ||
elseif mesh_wan_disabled == '1' then | ||
util.remove_from_set(roles.wan, 'mesh') | ||
util.remove_from_set(roles.single, 'mesh') | ||
end | ||
if mesh_lan_disabled == '0' then | ||
util.add_to_set(roles.lan, 'mesh') | ||
util.add_to_set(roles.single, 'mesh') | ||
elseif mesh_lan_disabled == '1' then | ||
util.remove_from_set(roles.lan, 'mesh') | ||
util.remove_from_set(roles.single, 'mesh') | ||
end | ||
|
||
-- Migration of single to WAN/LAN or vice-versa (an interface was added or removed) | ||
-- We identify the WAN with the single interface in this case | ||
-- | ||
-- These settings only take effect when the section that is the target of the | ||
-- migration does not exist yet. | ||
if uci:get('gluon', 'iface_wan') then | ||
roles.single = uci:get_list('gluon', 'iface_wan', 'role') | ||
end | ||
if uci:get('gluon', 'iface_single') then | ||
roles.wan = uci:get_list('gluon', 'iface_single', 'role') | ||
end | ||
|
||
-- Non-existing interfaces are nil, so they will not be added to the table | ||
local interfaces = { | ||
lan = sysconfig.lan_ifname, | ||
wan = sysconfig.wan_ifname, | ||
single = sysconfig.single_ifname, | ||
} | ||
|
||
for iface in pairs(interfaces) do | ||
local section_name = 'iface_' .. iface | ||
if not uci:get('gluon', section_name) then | ||
uci:section('gluon', 'interface', section_name, { | ||
-- / prefix refers to sysconfig ifnames | ||
name = '/' .. iface, | ||
role = roles[iface], | ||
}) | ||
end | ||
end | ||
|
||
uci:save('gluon') |
Oops, something went wrong.