device os-update: Add handling for updates that require takeover

Change-type: minor
This commit is contained in:
myarmolinsky 2024-11-11 08:13:07 -05:00
parent 602e63c8a9
commit 703dbd01c9

View File

@ -20,6 +20,7 @@ import * as cf from '../../utils/common-flags';
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
import type { Device } from 'balena-sdk'; import type { Device } from 'balena-sdk';
import { ExpectedError } from '../../errors'; import { ExpectedError } from '../../errors';
import { getExpandedProp } from '../../utils/pine';
export default class DeviceOsUpdateCmd extends Command { export default class DeviceOsUpdateCmd extends Command {
public static description = stripIndent` public static description = stripIndent`
@ -126,20 +127,46 @@ export default class DeviceOsUpdateCmd extends Command {
); );
} }
} else { } else {
const choices = await Promise.all(
hupVersionInfo.versions.map(async (version) => {
const takeoverRequired =
(await sdk.models.os.getOsUpdateType(
getExpandedProp(is_of__device_type, 'slug')!,
currentOsVersion,
version,
)) === 'takeover';
return {
name: `${version}${hupVersionInfo.recommended === version ? ' (recommended)' : ''}${takeoverRequired ? ' ADVANCED UPDATE: Requires disk re-partitioning with no rollback option' : ''}`,
value: version,
};
}),
);
targetOsVersion = await getCliForm().ask({ targetOsVersion = await getCliForm().ask({
message: 'Target OS version', message: 'Target OS version',
type: 'list', type: 'list',
choices: hupVersionInfo.versions.map((version) => ({ choices,
name:
hupVersionInfo.recommended === version
? `${version} (recommended)`
: version,
value: version,
})),
}); });
} }
const takeoverRequired =
(await sdk.models.os.getOsUpdateType(
getExpandedProp(is_of__device_type, 'slug')!,
currentOsVersion,
targetOsVersion,
)) === 'takeover';
const patterns = await import('../../utils/patterns'); const patterns = await import('../../utils/patterns');
// Warn the user if the update requires a takeover
if (takeoverRequired) {
await patterns.confirm(
options.yes || false,
stripIndent`Before you proceed, note that this update process is different from a regular HostOS Update:
DATA LOSS: This update requires disk re-partitioning, which will erase all data stored on the device.
NO ROLLBACK: Unlike our HostOS update mechanism, this process does not allow reverting to a previous version in case of failure.
Make sure to back up all important data before continuing. For more details, check our documentation: https://docs.balena.io/reference/OS/updates/update-process/
`,
);
}
// Confirm and start update // Confirm and start update
await patterns.confirm( await patterns.confirm(
options.yes || false, options.yes || false,