UNPKG

balena-cli

Version:

The official balena Command Line Interface

126 lines (120 loc) 6.07 kB
"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); const { downloadOSImage, isESR } = await Promise.resolve().then(() => require('../../utils/os')); const balena = (0, lazy_1.getBalenaSdk)(); const dtManifest = await balena.models.config.getDeviceTypeManifestBySlug(params.type); const defaultImageType = /^(resin|balena)-image-flasher\b/.test(dtManifest.yocto.deployArtifact) ? 'installation-media' : 'disk-image'; if (options.type === 'installation-media' || (defaultImageType === 'installation-media' && !options.type)) { console.warn("WARNING: balenaOS installation media automatically and without confirmation erases and formats the target device's internal storage when booted."); } if (options.version) { 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; } } } try { await downloadOSImage(params.type, options.output, options.version, defaultImageType === options.type ? undefined : options.type); } catch (e) { e.deviceTypeSlug = params.type; (_a = e.message) !== null && _a !== void 0 ? _a : (e.message = ''); const { OSVersionNotFoundError } = await Promise.resolve().then(() => require('../../errors')); if (e instanceof OSVersionNotFoundError) { 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 '--type' to specify the type of OS download If omitted, the default type for the specified device type-version combination is used. Some OS download types may not be available for certain device types and versions. 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 menu', '$ balena os download raspberrypi3 -o ../foo/bar/raspberrypi3.img --version menu-esr', '$ balena os download generic-amd64 -o ../foo/bar/generic-amd64.img --type installation-media', ]; 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' (excludes invalidated & pre-releases), or 'menu' (interactive menu, non-ESR versions), or 'menu-esr' (interactive menu, ESR versions) `, }), type: core_1.Flags.string({ options: ['installation-media', 'disk-image'], description: (0, lazy_1.stripIndent) ` 'disk-image' (for flashing onto device system disk/storage) or 'installation-media' (for creating installation media to automatically erase, format, and install balenaOS on a device) `, }), }; exports.default = OsDownloadCmd; //# sourceMappingURL=download.js.map