diff --git a/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector b/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector index 9de3ce69b4458514f4c369396bb18284f015b256..df109b6b0b4606f480f4e1f5753351cdb5e5f531 100755 --- a/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector +++ b/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector @@ -103,31 +103,48 @@ local function getWifiDevices() return radios end +local function getDefaultHood(jhood) + for _, h in pairs(jhood) do + if h.defaulthood then + return h + end + end + return nil +end + -- START HERE if not uci:get('hoodselector', 'hoodselector') then os.execute("touch /etc/config/hoodselector") end +local hoodfile = '' local hoodname = uci:get('hoodselector', 'hoodselector', 'hood') -if hoodname == nil then - hoodname = 'default' -end +local static = uci:get('hoodselector', 'hoodselector', 'static') +local enabled = uci:get('hoodselector', 'hoodselector', 'enabled') -local hoodfile = '' if site.hoodselector.hoodfile then hoodfile = site.hoodselector.hoodfile end -local static = uci:get('hoodselector', 'hoodselector', 'static') if static == nil then static = '0' end -local enabled = uci:get('hoodselector', 'hoodselector', 'enabled') if enabled == nil then enabled = '1' end +local jhood = readHoodfile(hoodfile) +if jhood == nil then + enabled = 0 +end + +if hoodname == nil then + if jhood ~= nil then + hoodname = (getDefaultHood(jhood)).name + end +end + uci:section('hoodselector', 'settings', 'hoodselector', { hood = hoodname, hoodfile = hoodfile, @@ -136,11 +153,6 @@ uci:section('hoodselector', 'settings', 'hoodselector', { }) uci:save('hoodselector') -local jhood = readHoodfile(hoodfile) -if jhood == nil then - os.exit(1) -end - local hood = getHoodByName(jhood,hoodname) if hood == nil then os.exit(1)