From 1c097b8ee8358bd0b6405e1cee4830ffc4d38132 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph <johannes.rudolph@gmx.com> Date: Mon, 20 Mar 2017 19:09:07 +0100 Subject: [PATCH] reorder get Default Hood Name from hood file --- .../lib/gluon/upgrade/540-ffnw-hoodselector | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector b/hoodselector/luasrc/lib/gluon/upgrade/540-ffnw-hoodselector index 9de3ce6..df109b6 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) -- GitLab