Skip to content

Commit

Permalink
device os-update: Add handling for updates that require takeover
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
myarmolinsky committed Nov 18, 2024
1 parent d3a8b5b commit 44b09b8
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/commands/device/os-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as cf from '../../utils/common-flags';
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
import type { Device } from 'balena-sdk';
import { ExpectedError } from '../../errors';
import { getExpandedProp } from '../../utils/pine';

export default class DeviceOsUpdateCmd extends Command {
public static description = stripIndent`
Expand Down Expand Up @@ -115,6 +116,10 @@ export default class DeviceOsUpdateCmd extends Command {
);
}

const { HUPActionHelper, actionsConfig } = await import(
'balena-hup-action-utils'
);
const hupActionHelper = new HUPActionHelper(actionsConfig);
// Get target OS version
let targetOsVersion = options.version;
if (targetOsVersion != null) {
Expand All @@ -129,17 +134,40 @@ export default class DeviceOsUpdateCmd extends Command {
targetOsVersion = await getCliForm().ask({
message: 'Target OS version',
type: 'list',
choices: hupVersionInfo.versions.map((version) => ({
name:
hupVersionInfo.recommended === version
? `${version} (recommended)`
: version,
value: version,
})),
choices: hupVersionInfo.versions.map((version) => {
const takeoverRequired =
hupActionHelper.getHUPActionType(
getExpandedProp(is_of__device_type, 'slug')!,
currentOsVersion,
version,
) === 'takeover';

return {
name: `${
hupVersionInfo.recommended === version
? `${version} (recommended)`
: version
}${takeoverRequired ? ' WARNING: No rollback mechanism' : ''}`,
value: version,
};
}),
});
}

const takeoverRequired =
hupActionHelper.getHUPActionType(
getExpandedProp(is_of__device_type, 'slug')!,
currentOsVersion,
targetOsVersion,
) === 'takeover';
const patterns = await import('../../utils/patterns');
// Warn the user if the update requires a takeover
if (takeoverRequired) {
await patterns.confirm(
options.yes || false,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
);
}
// Confirm and start update
await patterns.confirm(
options.yes || false,
Expand Down

0 comments on commit 44b09b8

Please sign in to comment.