gluon-legacy: convert gluon-core legacy scripts to invariant scripts
This also fixes a long-broken legacy upgrade script which would leave the sysconfig variable lan_ifname unset and the LAN ports unusable.
This commit is contained in:
parent
ecfcb4dd6b
commit
5e0bad2f25
11
package/gluon-legacy/files/lib/gluon/upgrade/core/invariant/000-legacy
Executable file
11
package/gluon-legacy/files/lib/gluon/upgrade/core/invariant/000-legacy
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
|
||||
for _, file in ipairs(site.legacy.version_files) do
|
||||
if os.remove(file) then
|
||||
-- Set version being upgraded from to 'legacy'
|
||||
sysconfig.gluon_version = 'legacy'
|
||||
end
|
||||
end
|
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local gluon_util = require 'gluon.util'
|
||||
local platform = require 'gluon.platform'
|
||||
local site = require 'gluon.site_config'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
|
||||
local uci = require('luci.model.uci').cursor()
|
||||
local util = require 'luci.util'
|
||||
|
||||
|
||||
if sysconfig.gluon_version == 'legacy' then
|
||||
local function iface_exists(name)
|
||||
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
|
||||
end
|
||||
|
||||
local function remove_bat0(iface)
|
||||
return util.trim(string.gsub(' ' .. iface .. ' ', ' bat0 ', ' '))
|
||||
end
|
||||
|
||||
|
||||
local lan_ifname = remove_bat0(uci:get('network', site.legacy.mesh_ifname, 'ifname'))
|
||||
local wan_ifname = uci:get('network', 'wan', 'ifname')
|
||||
|
||||
if wan_ifname and iface_exists(wan_ifname) then
|
||||
sysconfig.wan_ifname = wan_ifname
|
||||
sysconfig.lan_ifname = lan_ifname
|
||||
else
|
||||
sysconfig.wan_ifname = lan_ifname
|
||||
end
|
||||
|
||||
|
||||
uci:delete('network', site.legacy.mesh_ifname)
|
||||
uci:delete('network', 'wan')
|
||||
|
||||
uci:save('network')
|
||||
uci:commit('network')
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
|
||||
local uci = require('luci.model.uci').cursor()
|
||||
|
||||
|
||||
if sysconfig.gluon_version == 'legacy' then
|
||||
function delete_legacy_iface(iface)
|
||||
for _, wifi in pairs(site.legacy.wifi_names) do
|
||||
if wifi == iface['.name'] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
uci:delete_all('wireless', 'wifi-iface', delete_legacy_iface)
|
||||
|
||||
uci:save('wireless')
|
||||
uci:commit('wireless')
|
||||
end
|
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
local gluon_util = require 'gluon.util'
|
||||
local platform = require 'gluon.platform'
|
||||
|
||||
local fs = require 'luci.fs'
|
||||
local uci = require('luci.model.uci').cursor()
|
||||
local util = require 'luci.util'
|
||||
|
||||
|
||||
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then
|
||||
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy1/macaddress'))
|
||||
else
|
||||
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy0/macaddress'))
|
||||
end
|
||||
|
||||
|
||||
local function iface_exists(name)
|
||||
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
|
||||
end
|
||||
|
||||
local function remove_bat0(iface)
|
||||
return util.trim(string.gsub(' ' .. iface .. ' ', ' bat0 ', ' '))
|
||||
end
|
||||
|
||||
|
||||
local lan_ifname = remove_bat0(uci:get('network', site.legacy.mesh_ifname, 'ifname'))
|
||||
local wan_ifname = uci:get('network', 'wan', 'ifname')
|
||||
|
||||
|
||||
if wan_ifname and iface_exists(wan_ifname) then
|
||||
sysconfig.wan_ifname = wan_ifname
|
||||
sysconfig.lan_ifname = lan_ifname
|
||||
else
|
||||
sysconfig.wan_ifname = lan_ifname
|
||||
end
|
@ -1,24 +0,0 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local uci = require 'luci.model.uci'
|
||||
|
||||
|
||||
local c = uci.cursor()
|
||||
|
||||
|
||||
function delete_legacy_iface(iface)
|
||||
for _, wifi in pairs(site.legacy.wifi_names) do
|
||||
if wifi == iface['.name'] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
c:delete_all('wireless', 'wifi-iface', delete_legacy_iface)
|
||||
|
||||
c:save('wireless')
|
||||
c:commit('wireless')
|
@ -1,22 +0,0 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
|
||||
local site = require 'gluon.site_config'
|
||||
local uci = require 'luci.model.uci'
|
||||
|
||||
local c = uci.cursor()
|
||||
|
||||
|
||||
local s = c:get_all('network', site.legacy.mesh_ifname)
|
||||
c:delete('network', site.legacy.mesh_ifname)
|
||||
|
||||
s.auto = nil
|
||||
s.accept_ra = nil
|
||||
s.defaultroute = nil
|
||||
s.proto = 'dhcpv6'
|
||||
s.reqprefix = 'no'
|
||||
|
||||
c:section('network', 'interface', 'client', s)
|
||||
|
||||
c:save('network')
|
||||
c:commit('network')
|
Loading…
Reference in New Issue
Block a user