Rework LuCI build system
[project/luci.git] / modules / luci-mod-freifunk / luasrc / controller / freifunk / remote_update.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 ]]--
13
14 module("luci.controller.freifunk.remote_update", package.seeall)
15
16 function index()
17         if not nixio.fs.access("/usr/sbin/remote-update") then
18                 return
19         end
20
21         entry({"admin", "system", "remote_update"}, call("act_remote_update"),
22                 _("Freifunk Remote Update"), 90)
23 end
24
25 function act_remote_update()
26         if luci.http.formvalue("flash") == "1" then
27                 if luci.http.formvalue("confirm") == "1" then
28                         local nobackup = ( luci.http.formvalue("keepcfg") ~= "1" )
29                         local noverify = ( luci.http.formvalue("verify")  ~= "1" )
30
31                         luci.http.redirect("/luci-static/flashing.html")
32
33                         os.execute("start-stop-daemon -S -b -x /usr/sbin/remote-update -- %s%s-s 5 -y" % {
34                                 noverify and "-v " or "",
35                                 nobackup and "-n " or ""
36                         })
37                 else
38                         luci.template.render("freifunk/remote_update", {confirm=1})
39                 end
40         else
41                 local fd = io.popen("remote-update -c")
42                 local update = { }
43
44                 if fd then
45                         while true do
46                                 local ln=fd:read("*l")
47
48                                 if not ln                  then break
49                                 elseif ln:find("Local: ")  then update.locvar = ln:match("Local: (%d+)")
50                                 elseif ln:find("Remote: ") then update.remver = ln:match("Remote: (%d+)")
51                                 elseif ln == "--"          then update.info   = ""
52                                 elseif update.info ~= nil  then
53                                         update.info = update.info .. ln .. "\n"
54                                 end
55                         end
56
57                         fd:close()
58                 end
59
60                 luci.template.render("freifunk/remote_update", {update=update})
61         end
62 end