balena-cli
Version:
The official balena Command Line Interface
110 lines (107 loc) • 4.72 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const cf = require("../../utils/common-flags");
const lazy_1 = require("../../utils/lazy");
const errors_1 = require("../../errors");
class DeviceOsUpdateCmd extends core_1.Command {
async run() {
const { args: params, flags: options } = await this.parse(DeviceOsUpdateCmd);
const sdk = (0, lazy_1.getBalenaSdk)();
const { uuid, is_of__device_type, os_version, os_variant } = (await sdk.models.device.get(params.uuid, {
$select: ['uuid', 'os_version', 'os_variant'],
$expand: {
is_of__device_type: {
$select: 'slug',
},
},
}));
const currentOsVersion = sdk.models.device.getOsVersion({
os_version,
os_variant,
});
if (!currentOsVersion) {
throw new errors_1.ExpectedError('The current os version of the device is not available');
}
let includeDraft = options['include-draft'];
if (!includeDraft && options.version != null) {
const bSemver = await Promise.resolve().then(() => require('balena-semver'));
const parsedVersion = bSemver.parse(options.version);
includeDraft =
parsedVersion != null && parsedVersion.prerelease.length > 0;
}
const hupVersionInfo = await sdk.models.os.getSupportedOsUpdateVersions(is_of__device_type[0].slug, currentOsVersion, {
includeDraft,
});
if (hupVersionInfo.versions.length === 0) {
throw new errors_1.ExpectedError('There are no available Host OS update targets for this device');
}
let targetOsVersion = options.version;
if (targetOsVersion != null) {
const { normalizeOsVersion } = await Promise.resolve().then(() => require('../../utils/normalization'));
targetOsVersion = normalizeOsVersion(targetOsVersion);
if (!hupVersionInfo.versions.includes(targetOsVersion)) {
throw new errors_1.ExpectedError(`The provided version ${targetOsVersion} is not in the Host OS update targets for this device`);
}
}
else {
targetOsVersion = await (0, lazy_1.getCliForm)().ask({
message: 'Target OS version',
type: 'list',
choices: hupVersionInfo.versions.map((version) => ({
name: hupVersionInfo.recommended === version
? `${version} (recommended)`
: version,
value: version,
})),
});
}
const patterns = await Promise.resolve().then(() => require('../../utils/patterns'));
await patterns.confirm(options.yes || false, 'Host OS updates require a device restart when they complete. Are you sure you want to proceed?');
await sdk.models.device
.startOsUpdate(uuid, targetOsVersion, {
runDetached: true,
})
.then(() => {
console.log(`The balena OS update has started. You can keep track of the progress via the dashboard.\n` +
`To open the dashboard page related to a device via the CLI, you can use \`balena device UUID --view\``);
})
.catch((error) => {
console.error(`Failed to start OS update for device ${uuid}:`, error);
});
}
}
DeviceOsUpdateCmd.description = (0, lazy_1.stripIndent) `
Start a Host OS update for a device.
Start a Host OS update for a device.
Note this command will ask for confirmation interactively.
This can be avoided by passing the \`--yes\` option.
Requires balenaCloud; will not work with openBalena or standalone balenaOS.
`;
DeviceOsUpdateCmd.examples = [
'$ balena device os-update 23c73a1',
'$ balena device os-update 23c73a1 --version 2.101.7',
'$ balena device os-update 23c73a1 --version 2.31.0+rev1.prod',
'$ balena device os-update 23c73a1 --include-draft',
];
DeviceOsUpdateCmd.args = {
uuid: core_1.Args.string({
description: 'the uuid of the device to update',
required: true,
}),
};
DeviceOsUpdateCmd.flags = {
version: core_1.Flags.string({
description: 'a balenaOS version',
exclusive: ['include-draft'],
}),
'include-draft': core_1.Flags.boolean({
description: 'include pre-release balenaOS versions',
default: false,
exclusive: ['version'],
}),
yes: cf.yes,
};
DeviceOsUpdateCmd.authenticated = true;
exports.default = DeviceOsUpdateCmd;
//# sourceMappingURL=os-update.js.map
;