balena-cli
Version:
The official balena Command Line Interface
107 lines (102 loc) • 5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const lazy_1 = require("../../utils/lazy");
class OsDownloadCmd extends core_1.Command {
async run() {
var _a, _b;
const { args: params, flags: options } = await this.parse(OsDownloadCmd);
if (options.version) {
const { isESR } = await Promise.resolve().then(() => require('../../utils/image-manager'));
if (options.version === 'menu-esr' || isESR(options.version)) {
try {
const { checkLoggedIn } = await Promise.resolve().then(() => require('../../utils/patterns'));
await checkLoggedIn();
}
catch (e) {
const { ExpectedError, NotLoggedInError } = await Promise.resolve().then(() => require('../../errors'));
if (e instanceof NotLoggedInError) {
throw new ExpectedError((0, lazy_1.stripIndent) `
${e.message}
User authentication is required to download balenaOS ESR versions.`);
}
throw e;
}
}
}
const { downloadOSImage } = await Promise.resolve().then(() => require('../../utils/cloud'));
try {
await downloadOSImage(params.type, options.output, options.version);
}
catch (e) {
e.deviceTypeSlug = params.type;
(_a = e.message) !== null && _a !== void 0 ? _a : (e.message = '');
if (e.code === 'BalenaRequestError' ||
e.message.toLowerCase().includes('no such version')) {
const version = (_b = options.version) !== null && _b !== void 0 ? _b : '';
if (!version.endsWith('.dev') &&
!version.endsWith('.prod') &&
/^v?\d+\.\d+\.\d+/.test(version)) {
e.message += `
** Hint: some OS releases require specifying the full OS version including
** the '.prod' or '.dev' suffix, e.g. '--version 2021.10.2.prod'`;
}
}
throw e;
}
}
}
OsDownloadCmd.description = (0, lazy_1.stripIndent) `
Download an unconfigured OS image.
Download an unconfigured OS image for the specified device type.
Check available device types with 'balena device-type list'.
Note: Currently this command only works with balenaCloud, not openBalena.
If using openBalena, please download the OS from: https://www.balena.io/os/
The '--version' option is used to select the balenaOS version. If omitted,
the latest released version is downloaded (and if only pre-release versions
exist, the latest pre-release version is downloaded).
Use '--version menu' or '--version menu-esr' to interactively select the
OS version. The latter lists ESR versions which are only available for
download on Production and Enterprise plans. See also:
https://www.balena.io/docs/reference/OS/extended-support-release/
Development images can be selected by appending \`.dev\` to the version.
`;
OsDownloadCmd.examples = [
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version 2.101.7',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version 2022.7.0',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version ^2.90.0',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version 2.60.1+rev1',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version 2.60.1+rev1.dev',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version 2021.10.2.prod',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version latest',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version default',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version menu',
'$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version menu-esr',
];
OsDownloadCmd.args = {
type: core_1.Args.string({
description: 'the device type',
required: true,
}),
};
OsDownloadCmd.flags = {
output: core_1.Flags.string({
description: 'output path',
char: 'o',
required: true,
}),
version: core_1.Flags.string({
description: (0, lazy_1.stripIndent) `
version number (ESR or non-ESR versions),
or semver range (non-ESR versions only),
or 'latest' (includes pre-releases),
or 'default' (excludes pre-releases if at least one released version is available),
or 'recommended' (excludes pre-releases, will fail if only pre-release versions are available),
or 'menu' (interactive menu, non-ESR versions),
or 'menu-esr' (interactive menu, ESR versions)
`,
}),
};
exports.default = OsDownloadCmd;
//# sourceMappingURL=download.js.map