diff options
Diffstat (limited to 'scripts/http.lua')
-rw-r--r-- | scripts/http.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/http.lua b/scripts/http.lua new file mode 100644 index 0000000..adc565e --- /dev/null +++ b/scripts/http.lua @@ -0,0 +1,40 @@ + + +cl_latestRelease = cvar.new("cl_latestRelease") + +dlurl = "" + +Releases = { + url='https://api.github.com/repos/GrangerHub/tremulous/releases' + + refresh = function() + r = http.get(url) + if r.code != 200 then + cl_latestRelease = "ERROR:\n Server did not return OK status code" + return false + end + releases = rapidjson.decode(r.body) + most_recent = releases[1] + cl_latestRelease = most_recent.tag; + for i,asset in ipairs(most_recent.assets) do + dlurl = cvar.new("download_url", "", 256) + dlurl = asset.browser_download_url + end + return true + end + + download = function() + r = http.get(download_url) + if r.code != 200 then + cvar.new("com_error") = "Download failed" + return false + end + + io.open(path, "w+") + io.write(r.body) + io.close() + + args = "path-to-tremulous-binary" + os.execute(path .. args) + end +} |