From e721eb68b6f3b3b8c96eefda297c598971c2d23f Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Thu, 30 Apr 2020 20:22:44 -0600 Subject: [PATCH] update notification --- .github/workflows/main.yml | 3 ++- sys/autorun/upgraded.lua | 9 ------- sys/autorun/version.lua | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) delete mode 100644 sys/autorun/upgraded.lua create mode 100644 sys/autorun/version.lua diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 017607a..f6d3458 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,11 +24,12 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: echo date > .opus_version + run: echo `date` > .opus_version - name: Update version file uses: alexesprit/action-update-file@master with: + branch: develop-1.8 file-path: .opus_version commit-msg: Update version date github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/sys/autorun/upgraded.lua b/sys/autorun/upgraded.lua deleted file mode 100644 index 67d3da5..0000000 --- a/sys/autorun/upgraded.lua +++ /dev/null @@ -1,9 +0,0 @@ -local fs = _G.fs -local shell = _ENV.shell - -if fs.exists('.opus_upgrade') then - fs.delete('.opus_upgrade') - print('Updating packages') - shell.run('package updateall') - os.reboot() -end diff --git a/sys/autorun/version.lua b/sys/autorun/version.lua new file mode 100644 index 0000000..8acf87d --- /dev/null +++ b/sys/autorun/version.lua @@ -0,0 +1,53 @@ +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' + +local function notifyUpdate(config) + print('Opus has been updated to: ' .. config.current) + read() +end + +if fs.exists('.opus_version') then + local f = fs.open('.opus_version') + local date = f.readLine() + f.close() + + if type(date) == 'string' and #date > 0 then + local today = os.date('%j') + local config = Config.load('version', { + opus = date, + packages = date, + checked = today, + }) + + -- check if packages need an update + if config.opus ~= config.packages then + config.packages = config.opus + Config.update('version', config) + print('Updating packages') + shell.run('package updateall') + os.reboot() + end + + 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 + c = Util.split(c)[1] + if config.opus ~= c and config.skip ~= c then + config.current = c + Config.update('version', config) + notifyUpdate(config) + end + end + end) + end + end +end