opus/sys/autorun/version.lua

54 lines
1.7 KiB
Lua
Raw Normal View History

2020-05-01 02:22:44 +00:00
local Config = require('opus.config')
local Util = require('opus.util')
local fs = _G.fs
local shell = _ENV.shell
local URL = 'https://raw.githubusercontent.com/kepler155c/opus/%s/.opus_version'
if fs.exists('.opus_version') then
2020-05-01 04:05:23 +00:00
local f = fs.open('.opus_version', 'r')
2020-05-01 02:22:44 +00:00
local date = f.readLine()
f.close()
2020-05-01 03:27:07 +00:00
date = type(date) == 'string' and Util.split(date)[1]
2020-05-01 02:22:44 +00:00
2020-05-02 05:09:46 +00:00
local today = os.date('%j')
local config = Config.load('version', {
packages = date,
checked = today,
})
2020-05-01 02:22:44 +00:00
2020-05-02 05:09:46 +00:00
-- check if packages need an update
if date ~= config.packages then
config.packages = date
Config.update('version', config)
print('Updating packages')
shell.run('package updateall')
os.reboot()
end
2020-05-01 02:22:44 +00:00
2020-05-02 05:09:46 +00:00
if type(date) == 'string' and #date > 0 then
2020-05-01 02:22:44 +00:00
if config.checked ~= today then
config.checked = today
Config.update('version', config)
print('Checking for new version')
pcall(function()
local c = Util.httpGet(string.format(URL, _G.OPUS_BRANCH))
if c then
2020-05-02 04:26:15 +00:00
local lines = Util.split(c)
local revdate = table.remove(lines, 1)
2020-05-02 05:09:46 +00:00
if date ~= revdate and config.skip ~= revdate then
2020-05-02 04:26:15 +00:00
config.current = revdate
config.details = table.concat(lines, '\n')
2020-05-01 02:22:44 +00:00
Config.update('version', config)
2020-05-01 03:27:07 +00:00
print('New version available')
if _ENV.multishell then
2020-05-01 04:13:03 +00:00
shell.openForegroundTab('sys/apps/Version.lua')
2020-05-01 03:27:07 +00:00
end
2020-05-01 02:22:44 +00:00
end
end
end)
end
end
end