From f81d3f0fdd9e6dfd0a984631513eb4633e1a1d71 Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 6 Nov 2024 16:33:53 +0000 Subject: [PATCH 1/5] refactor: extract `isLMX()`/`getOSUser()` to top level --- deploy/codebase/lamassu-machine-manager.js | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/deploy/codebase/lamassu-machine-manager.js b/deploy/codebase/lamassu-machine-manager.js index 8912c9177..953359f5f 100644 --- a/deploy/codebase/lamassu-machine-manager.js +++ b/deploy/codebase/lamassu-machine-manager.js @@ -37,6 +37,19 @@ function command(cmd, cb) { }); } +const isLMX = () => + fs.readFileSync('/etc/os-release', { encoding: 'utf8' }) + .split('\n') + .includes('IMAGE_ID=lamassu-machine-xubuntu') + +const getOSUser = () => { + try { + return (!machineWithMultipleCodes.includes(hardwareCode) || isLMX()) ? 'lamassu' : 'ubilinux' + } catch (err) { + return 'ubilinux' + } +} + function updateUdev (cb) { LOG("Updating udev rules") if (hardwareCode !== 'aaeon') return cb() @@ -54,19 +67,6 @@ function updateSupervisor (cb) { LOG("Updating Supervisor services") if (hardwareCode === 'aaeon') return cb() - const isLMX = () => - fs.readFileSync('/etc/os-release', { encoding: 'utf8' }) - .split('\n') - .includes('IMAGE_ID=lamassu-machine-xubuntu') - - const getOSUser = () => { - try { - return (!machineWithMultipleCodes.includes(hardwareCode) || isLMX()) ? 'lamassu' : 'ubilinux' - } catch (err) { - return 'ubilinux' - } - } - const getServices = () => { const extractServices = stdout => { const services = stdout From 8d147b7b2365869f0dc021c8c1e0d5e0a81d9472 Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 6 Nov 2024 17:36:18 +0000 Subject: [PATCH 2/5] refactor: rename variable to avoid collision with `path` --- deploy/codebase/lamassu-machine-manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/codebase/lamassu-machine-manager.js b/deploy/codebase/lamassu-machine-manager.js index 953359f5f..8328823ed 100644 --- a/deploy/codebase/lamassu-machine-manager.js +++ b/deploy/codebase/lamassu-machine-manager.js @@ -14,7 +14,7 @@ const packagePath = `${basePath}/package/subpackage` const machineWithMultipleCodes = ['upboard', 'up4000', 'coincloud', 'generalbytes', 'genmega'] -const path = machineWithMultipleCodes.includes(hardwareCode) ? +const hardwarePath = machineWithMultipleCodes.includes(hardwareCode) ? `${packagePath}/hardware/${hardwareCode}/${machineCode}` : `${packagePath}/hardware/${hardwareCode}` @@ -121,8 +121,8 @@ function updateAcpChromium (cb) { LOG("Updating ACP Chromium") if (hardwareCode !== 'aaeon') return cb() return async.series([ - async.apply(command, `cp ${path}/sencha-chrome.conf /home/iva/.config/upstart/`), - async.apply(command, `cp ${path}/start-chrome /home/iva/`), + async.apply(command, `cp ${hardwarePath}/sencha-chrome.conf /home/iva/.config/upstart/`), + async.apply(command, `cp ${hardwarePath}/start-chrome /home/iva/`), ], function(err) { if (err) throw err; cb() @@ -133,7 +133,7 @@ function installDeviceConfig (cb) { LOG("Installing `device_config.json`") try { const currentDeviceConfigPath = `${applicationParentFolder}/lamassu-machine/device_config.json` - const newDeviceConfigPath = `${path}/device_config.json` + const newDeviceConfigPath = `${hardwarePath}/device_config.json` // Updates don't necessarily need to carry a device_config.json file if (!fs.existsSync(newDeviceConfigPath)) return cb() From d3a62ad87b8f4939acce1f50197b8c353af00a68 Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 6 Nov 2024 16:42:53 +0000 Subject: [PATCH 3/5] feat: make `supervisor` start after X11 --- deploy/codebase/lamassu-machine-manager.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/deploy/codebase/lamassu-machine-manager.js b/deploy/codebase/lamassu-machine-manager.js index 8328823ed..ffb276007 100644 --- a/deploy/codebase/lamassu-machine-manager.js +++ b/deploy/codebase/lamassu-machine-manager.js @@ -1,8 +1,10 @@ 'use strict'; +const cp = require('child_process'); const fs = require('fs'); +const { mkdir, writeFile } = require('fs/promises'); +const path = require('path'); const async = require('./async'); -const cp = require('child_process'); const report = require('./report').report; const hardwareCode = process.argv[2]; @@ -107,6 +109,22 @@ function updateSupervisor (cb) { }) } +const updateSystemd = cb => { + LOG("Make Supervisor start after X") + const override = dm => `[Unit]\nAfter=${dm}.service\nWants=${dm}.service\n` + const SUPERVISOR_OVERRIDE = "/etc/systemd/system/supervisor.service.d/override.conf" + return mkdir(path.dirname(SUPERVISOR_OVERRIDE), { recursive: true }) + .then(() => isLMX() ? 'lightdm' : 'sddm') // Assume Ubilinux if not l-m-x + .then(dm => writeFile(SUPERVISOR_OVERRIDE, override(dm), { mode: 0o600, flush: true })) + .then(() => new Promise((resolve, reject) => + cp.execFile('systemctl', ['daemon-reload'], { timeout: 10000 }, + (error, _stdout, _stderr) => error ? reject(error) : resolve() + ) + )) + .then(() => cb()) + .catch(err => cb(err)) +} + function restartWatchdogService (cb) { async.series([ async.apply(command, 'supervisorctl update lamassu-watchdog'), @@ -204,6 +222,7 @@ const upgrade = () => { async.apply(command, `mv ${applicationParentFolder}/lamassu-machine/camera-streamer/camera-streamer.${arch} ${applicationParentFolder}/lamassu-machine/camera-streamer/camera-streamer`), async.apply(installDeviceConfig), async.apply(updateSupervisor), + async.apply(updateSystemd), async.apply(updateUdev), async.apply(updateAcpChromium), async.apply(report, null, 'finished.'), From cc308d0e659796412759eb61a9b9d04104d8e96e Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 6 Nov 2024 17:37:38 +0000 Subject: [PATCH 4/5] fix: don't crash if `connection_info.json` is missing --- lib/update/updater.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/update/updater.js b/lib/update/updater.js index 1f14895fd..a5893de9e 100644 --- a/lib/update/updater.js +++ b/lib/update/updater.js @@ -191,14 +191,21 @@ Updater.prototype._update = function _update () { function noop () {} +const readConnectionInfo = dataPath => { + try { + const connectionInfoPath = path.resolve(dataPath, 'connection_info.json') + return JSON.parse(fs.readFileSync(connectionInfoPath)) + } catch (err) { + return {} + } +} + Updater.prototype.updateHeaders = function updateHeaders (options) { var dataPath = path.resolve(__dirname, '..', '..', this.config.dataPath) var machineInfo = machineInfoLoader.load(dataPath) var watchdogInfo = watchdogInfoLoader.load(dataPath) - var connectionInfoPath = path.resolve(dataPath, 'connection_info.json') - const connectionInfo = JSON.parse(fs.readFileSync(connectionInfoPath)) - + const connectionInfo = readConnectionInfo(dataPath) if (connectionInfo.host) { options = _.assign(options, { 'device-host': crypto.createHash('sha256').update(connectionInfo.host).digest('hex') From e9ce8d0fdc0a89797e79364213c30309023a13b7 Mon Sep 17 00:00:00 2001 From: siiky Date: Wed, 6 Nov 2024 19:00:19 +0000 Subject: [PATCH 5/5] feat: it's not l-m-x if `/etc/os-release` doesn't exist --- deploy/codebase/lamassu-machine-manager.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/deploy/codebase/lamassu-machine-manager.js b/deploy/codebase/lamassu-machine-manager.js index ffb276007..a09ad65d3 100644 --- a/deploy/codebase/lamassu-machine-manager.js +++ b/deploy/codebase/lamassu-machine-manager.js @@ -39,10 +39,15 @@ function command(cmd, cb) { }); } -const isLMX = () => - fs.readFileSync('/etc/os-release', { encoding: 'utf8' }) - .split('\n') - .includes('IMAGE_ID=lamassu-machine-xubuntu') +const isLMX = () => { + try { + return fs.readFileSync('/etc/os-release', { encoding: 'utf8' }) + .split('\n') + .includes('IMAGE_ID=lamassu-machine-xubuntu') + } catch (err) { + return false + } +} const getOSUser = () => { try {