From 62d76145914c04ec9b022fc384f9e65d22d56f77 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Wed, 28 Apr 2021 09:45:52 +0200 Subject: [PATCH] Added update system [WIP] --- apolloui | 2 +- backend/os_stats | 2 +- package.json | 1 + src/graphql/graphqlModules/Mcu/McuStats.js | 1 + src/graphql/graphqlModules/Mcu/mcuUpdate.js | 13 +++++++++++++ src/store/api/mcu/mcuStats.js | 3 +++ src/store/api/mcu/mcuUpdate.js | 13 +++++++++++++ yarn.lock | 12 ++++++++++++ 8 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/graphql/graphqlModules/Mcu/mcuUpdate.js create mode 100644 src/store/api/mcu/mcuUpdate.js diff --git a/apolloui b/apolloui index 9419d5e..25c121f 160000 --- a/apolloui +++ b/apolloui @@ -1 +1 @@ -Subproject commit 9419d5e6c8ac2f221b1d043fd1fdd0c4b719de29 +Subproject commit 25c121f447d40aabe58b5df8891aca3004f0eb8f diff --git a/backend/os_stats b/backend/os_stats index e3f4d64..c2637eb 100755 --- a/backend/os_stats +++ b/backend/os_stats @@ -29,7 +29,7 @@ OS=$(lsb_release -s -i -c -r | sed ':a;N;$!ba;s/\n/ /g') UPTIME=$(uptime -s) LOADAVG=$(cat /proc/loadavg) ARCHITECTURE=$(uname -m) -if [ -f /sys/devices/virtual/thermal/thermal_zone0/temp ]; then +if [ -f "/sys/devices/virtual/thermal/thermal_zone0/temp" ]; then TEMP=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp) else TEMP="0" diff --git a/package.json b/package.json index 4ef7d3c..aa0225b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "run-container": "docker run --rm -it -v \"$(pwd)\":/hostdir --entrypoint=/bin/bash orange" }, "dependencies": { + "axios": "^0.21.1", "backend-helpers": "^0.5.0", "backend-store": "^0.7.0", "bcryptjs": "^2.4.3", diff --git a/src/graphql/graphqlModules/Mcu/McuStats.js b/src/graphql/graphqlModules/Mcu/McuStats.js index e7c9518..112bee6 100644 --- a/src/graphql/graphqlModules/Mcu/McuStats.js +++ b/src/graphql/graphqlModules/Mcu/McuStats.js @@ -13,6 +13,7 @@ module.exports.typeDefs = ` } type McuStats { + currentAppVersion: String, timestamp: String! hostname: String, operatingSystem: String diff --git a/src/graphql/graphqlModules/Mcu/mcuUpdate.js b/src/graphql/graphqlModules/Mcu/mcuUpdate.js new file mode 100644 index 0000000..66ef638 --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/mcuUpdate.js @@ -0,0 +1,13 @@ +module.exports.typeDefs = ` + type McuActions { + update: EmptyOutput! + } +` + +module.exports.resolvers = { + McuActions: { + update (root, args, { dispatch }) { + return dispatch('api/mcu/update') + } + } +} diff --git a/src/store/api/mcu/mcuStats.js b/src/store/api/mcu/mcuStats.js index 4658870..e9ac214 100644 --- a/src/store/api/mcu/mcuStats.js +++ b/src/store/api/mcu/mcuStats.js @@ -1,9 +1,12 @@ const { join } = require('path') const { exec } = require('child_process') +const axios = require('axios') module.exports = ({ define }) => { define('stats', async (payload, { knex, errors, utils }) => { const stats = await getOsStats() + const gitAppVersion = await axios.get('https://raw.githubusercontent.com/CryptofyCH/apolloui/dev-BTC/package.json'); + stats.currentAppVersion = (gitAppVersion && gitAppVersion.data) ? gitAppVersion.data.version : null; stats.timestamp = new Date().toISOString() return { stats } }, { diff --git a/src/store/api/mcu/mcuUpdate.js b/src/store/api/mcu/mcuUpdate.js new file mode 100644 index 0000000..5061524 --- /dev/null +++ b/src/store/api/mcu/mcuUpdate.js @@ -0,0 +1,13 @@ +const { join } = require('path') +const { exec } = require('child_process') + +module.exports = ({ define }) => { + define('update', async (payload, { knex, errors, utils }) => { + const updateScript = join(__dirname, '..', '..', '..', '..', 'backend', 'update') + if (process.env.NODE_ENV === 'production') return exec(`bash ${updateScript}`) + else console.log(updateScript) + return; + }, { + auth: true + }) +} diff --git a/yarn.lock b/yarn.lock index bf61e6e..8cef5ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -219,6 +219,13 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== + dependencies: + follow-redirects "^1.10.0" + babel-polyfill@^6.23.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" @@ -1116,6 +1123,11 @@ finalhandler@~1.1.2: statuses "~1.5.0" unpipe "~1.0.0" +follow-redirects@^1.10.0: + version "1.14.0" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.0.tgz#f5d260f95c5f8c105894491feee5dc8993b402fe" + integrity sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg== + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"