gluon-core: convert all initial scripts to invariant scripts

This commit is contained in:
Matthias Schiffer 2015-01-23 05:51:13 +01:00
parent 71c498edd2
commit 6f11279438
15 changed files with 103 additions and 68 deletions

View File

@ -1,38 +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 lan_ifname = uci:get('network', 'lan', 'ifname')
local wan_ifname = uci:get('network', 'wan', 'ifname')
if platform.match('ar71xx', 'generic', {'cpe510', 'nanostation-m', 'nanostation-m-xw'}) then
lan_ifname, wan_ifname = wan_ifname, lan_ifname
end
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

View File

@ -1,14 +0,0 @@
#!/usr/bin/lua
local site = require 'gluon.site_config'
local util = require 'gluon.util'
local uci = require 'luci.model.uci'
local c = uci.cursor()
local system = c:get_first('system', 'system')
c:set('system', system, 'hostname', site.hostname_prefix .. '-' .. util.node_id())
c:set('system', system, 'timezone', site.timezone)
c:save('system')
c:commit('system')

View File

@ -1,9 +0,0 @@
#!/usr/bin/lua
local uci = require('luci.model.uci').cursor()
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:save('network')
uci:commit('network')

View File

@ -1,7 +0,0 @@
#!/usr/bin/lua
local uci = require('luci.model.uci').cursor()
uci:delete_all('wireless', 'wifi-iface')
uci:save('wireless')
uci:commit('wireless')

View File

@ -0,0 +1,10 @@
#!/usr/bin/lua
local fs = require 'luci.fs'
local sysconfig = require 'gluon.sysconfig'
if fs.isfile('/lib/gluon/version/core') and not sysconfig.gluon_version then
-- This isn't an initial upgrade, so set gluon_version
sysconfig.gluon_version = ''
end

View File

@ -0,0 +1,16 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform'
local fs = require 'luci.fs'
local util = require 'luci.util'
if not sysconfig.primary_mac then
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
end

View File

@ -0,0 +1,36 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local gluon_util = require 'gluon.util'
local platform = require 'gluon.platform'
local uci = require('luci.model.uci').cursor()
if not (sysconfig.lan_ifname or sysconfig.wan_ifname) then
local function iface_exists(name)
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
end
local lan_ifname = uci:get('network', 'lan', 'ifname')
local wan_ifname = uci:get('network', 'wan', 'ifname')
if platform.match('ar71xx', 'generic', {'cpe510', 'nanostation-m', 'nanostation-m-xw'}) then
lan_ifname, wan_ifname = wan_ifname, lan_ifname
end
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', 'lan')
uci:delete('network', 'wan')
uci:save('network')
uci:commit('network')
end

View File

@ -0,0 +1,18 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
-- Initial
if not sysconfig.gluon_version then
local site = require 'gluon.site_config'
local util = require 'gluon.util'
local uci = require('luci.model.uci').cursor()
local system = uci:get_first('system', 'system')
uci:set('system', system, 'hostname', site.hostname_prefix .. '-' .. util.node_id())
uci:set('system', system, 'timezone', site.timezone)
uci:save('system')
uci:commit('system')
end

View File

@ -0,0 +1,12 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
-- Initial
if not sysconfig.gluon_version then
local uci = require('luci.model.uci').cursor()
uci:delete_all('wireless', 'wifi-iface')
uci:save('wireless')
uci:commit('wireless')
end

View File

@ -0,0 +1,11 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local fs = require 'luci.fs'
local util = require 'luci.util'
-- Save the Gluon version in the sysconfig so we know which version we
-- upgraded from after the next upgrade
sysconfig.gluon_version = util.trim(fs.readfile('/lib/gluon/gluon-version'))