Browse Source

ffho-autoupdater-wifi-fallback: parse arg -b

determine the update branch with 'autoupdater-wifi-fallback -b <branch>'
Karsten Böddeker 8 years ago
parent
commit
fc66f2eb7d

+ 4 - 6
ffho/ffho-autoupdater-wifi-fallback/files/usr/lib/lua/autoupdater-wifi-fallback/util.lua

@@ -27,15 +27,13 @@ function get_available_wifi_networks()
   return false
 end
 
-function get_update_hosts()
+function get_update_hosts(branch)
   local hosts = {}
-  local branch = uci:get('autoupdater', 'settings', 'branch')
   local mirrors = uci:get_list('autoupdater', branch, 'mirror')
 
-  while #mirrors > 0 do
-    local m = table.remove(mirrors)
-    mirror = m:match("://%[?([a-zA-Z0-9\:\.]+)%]?/")
-    table.insert(hosts, 1, mirror)
+  for _, mirror in ipairs(mirrors) do
+    local host = mirror:match("://%[?([a-zA-Z0-9\:\.]+)%]?/")
+    table.insert(hosts, 1, host)
   end
   return hosts
 end

+ 8 - 2
ffho/ffho-autoupdater-wifi-fallback/files/usr/sbin/autoupdater-wifi-fallback

@@ -9,6 +9,7 @@ local gluon = require 'gluon.util'
 local configname = 'autoupdater-wifi-fallback'
 local force = false
 local min_uptime_secs = 3600
+local branch_name = uci:get('autoupdater','settings','branch')
 
 local function parse_args()
 local i = 1
@@ -57,7 +58,7 @@ local function connectivity_check()
   end
   
   -- connectivity check against updateserver
-  for _, host in ipairs(get_update_hosts()) do
+  for _, host in ipairs(get_update_hosts(branch_name)) do
     if os.execute("ping -w2 -c1 " .. host .. " > /dev/null 2>&1") == 0 then
       return true
     end
@@ -67,7 +68,7 @@ local function connectivity_check()
 end
 
 local function run_autoupdater()
-  os.execute("/usr/sbin/autoupdater -f")
+  os.execute("/usr/sbin/autoupdater -f -b " .. branch_name)
 end
 
 local function switch_to_fallback_mode(wifiNetwork, radio)
@@ -103,6 +104,11 @@ end
 
 parse_args()
 
+if not uci:get('autoupdater', branch_name) then
+  io.stderr:write("Can't find configuration for branch '" .. branch_name .. "'\n")
+  os.exit(1)
+end
+
 if (force or preflight_check()) and not connectivity_check() then
   local offset = 2 * 3600
   local unreachable_since = os.time()