gluon-mesh-vpn: fix fastd <-> tunneldigger migration

The generic upgrade script is moved to run after the more specific scripts.
In addition, the script will now remove the configuration sections of
uninstalled VPN packages, so both positive and negative changes of the
default enable state can be migrated correctly.

Based-on-patch-by: Cyrus Fox <cyrus@lambdacore.de>
Fixes: #1187
This commit is contained in:
Matthias Schiffer 2017-08-08 01:28:53 +02:00
parent 23a8947628
commit 952439885e
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
3 changed files with 36 additions and 22 deletions

View File

@ -62,15 +62,36 @@ uci:save('firewall')
-- VPN migration -- VPN migration
local has_fastd = fs.access('/lib/gluon/mesh-vpn/fastd') local has_fastd = fs.access('/lib/gluon/mesh-vpn/fastd')
local fastd_enabled = uci:get_bool("fastd", "mesh_vpn", "enabled") local fastd_enabled = uci:get('fastd', 'mesh_vpn', 'enabled')
local has_tunneldigger = fs.access('/lib/gluon/mesh-vpn/tunneldigger') local has_tunneldigger = fs.access('/lib/gluon/mesh-vpn/tunneldigger')
local tunneldigger_enabled = uci:get_bool("tunneldigger", "mesh_vpn", "enabled") local tunneldigger_enabled = uci:get('tunneldigger', 'mesh_vpn', 'enabled')
local enabled = fastd_enabled or tunneldigger_enabled or false local enabled
uci:set("fastd", "mesh_vpn", "enabled", has_fastd and enabled) -- If the installed VPN package has its enabled state set, keep the value
uci:save("fastd") if has_fastd and fastd_enabled then
enabled = fastd_enabled == '1'
elseif has_tunneldigger and tunneldigger_enabled then
enabled = tunneldigger_enabled == '1'
-- Otherwise, migrate the other package's value if any is set
elseif fastd_enabled or tunneldigger_enabled then
enabled = fastd_enabled == '1' or tunneldigger_enabled == '1'
-- If nothing is set, use the default
else
enabled = site.mesh_vpn.enabled or false
end
uci:set("tunneldigger", "mesh_vpn", "enabled", has_tunneldigger and enabled) if has_fastd then
uci:save("tunneldigger") uci:set('fastd', 'mesh_vpn', 'enabled', enabled)
else
uci:delete('fastd', 'mesh_vpn')
end
uci:save('fastd')
if has_tunneldigger then
uci:set('tunneldigger', 'mesh_vpn', 'enabled', enabled)
else
uci:delete('tunneldigger', 'mesh_vpn')
end
uci:save('tunneldigger')

View File

@ -6,11 +6,6 @@ local util = require 'gluon.util'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local enabled = uci:get('fastd', 'mesh_vpn', 'enabled')
if enabled == nil then
enabled = site.mesh_vpn.enabled or false
end
local syslog_level = uci:get('fastd', 'mesh_vpn', 'syslog_level') or 'verbose' local syslog_level = uci:get('fastd', 'mesh_vpn', 'syslog_level') or 'verbose'
local methods local methods
@ -40,7 +35,6 @@ end
uci:section('fastd', 'fastd', 'mesh_vpn', { uci:section('fastd', 'fastd', 'mesh_vpn', {
enabled = enabled,
group = 'gluon-mesh-vpn', group = 'gluon-mesh-vpn',
syslog_level = syslog_level, syslog_level = syslog_level,
interface = 'mesh-vpn', interface = 'mesh-vpn',

View File

@ -6,18 +6,17 @@ local util = require 'gluon.util'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local enabled = uci:get('tunneldigger', 'mesh_vpn', 'enabled') local enabled
if enabled == nil then
if uci:get_first('tunneldigger', 'broker', 'interface') == "mesh-vpn" then -- Delete old broker config section (remove in 2019)
if not uci:get('tunneldigger', 'mesh_vpn') then
if uci:get_first('tunneldigger', 'broker', 'interface') == 'mesh-vpn' then
enabled = uci:get_first('tunneldigger', 'broker', 'enabled') enabled = uci:get_first('tunneldigger', 'broker', 'enabled')
end end
end
if enabled == nil then
enabled = site.mesh_vpn.enabled or false
end
-- Delete old broker config section -- In the usual case (no migration from old tunneldigger package), the
if not uci:get('tunneldigger', 'mesh_vpn') then -- enabled state is set in the 500-mesh-vpn script
uci:delete_all('tunneldigger', 'broker') uci:delete_all('tunneldigger', 'broker')
end end