balena-cli
Version:
The official balena Command Line Interface
68 lines (66 loc) • 2.67 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 INIT_WARNING_MESSAGE = `
Note: Initializing the device may ask for administrative permissions
because we need to access the raw devices directly.\
`;
class OsInitializeCmd extends core_1.Command {
async run() {
var _a, _b;
const { args: params, flags: options } = await this.parse(OsInitializeCmd);
const { getManifest, sudo } = await Promise.resolve().then(() => require('../../utils/helpers'));
console.info(`Initializing device ${INIT_WARNING_MESSAGE}`);
const manifest = await getManifest(params.image, options.type);
const answers = await (0, lazy_1.getCliForm)().run((_b = (_a = manifest.initialization) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : [], {
override: {
drive: options.drive,
},
});
if (answers.drive != null) {
const { confirm } = await Promise.resolve().then(() => require('../../utils/patterns'));
await confirm(options.yes, `This will erase ${answers.drive}. Are you sure?`, `Going to erase ${answers.drive}.`);
const { safeUmount } = await Promise.resolve().then(() => require('../../utils/umount'));
await safeUmount(answers.drive);
}
await sudo([
'internal',
'osinit',
params.image,
options.type,
JSON.stringify(answers),
]);
if (answers.drive != null) {
const { safeUmount } = await Promise.resolve().then(() => require('../../utils/umount'));
await safeUmount(answers.drive);
console.info(`You can safely remove ${answers.drive} now`);
}
}
}
OsInitializeCmd.description = (0, lazy_1.stripIndent) `
Initialize an os image for a device.
Initialize an os image for a device with a previously
configured operating system image and flash the
an external storage drive or the device's storage
medium depending on the device type.
${INIT_WARNING_MESSAGE}
`;
OsInitializeCmd.examples = [
'$ balena os initialize ../path/rpi.img --type raspberry-pi',
];
OsInitializeCmd.args = {
image: core_1.Args.string({
description: 'path to OS image',
required: true,
}),
};
OsInitializeCmd.flags = {
type: cf.deviceType,
drive: cf.drive,
yes: cf.yes,
};
OsInitializeCmd.authenticated = true;
exports.default = OsInitializeCmd;
//# sourceMappingURL=initialize.js.map