2020-04-02 13:26:52 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2016-2020 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
import { Args } from '@oclif/core';
|
2020-04-02 13:26:52 +00:00
|
|
|
import Command from '../../command';
|
2020-05-04 14:57:23 +00:00
|
|
|
import { stripIndent } from '../../utils/lazy';
|
2020-04-02 13:26:52 +00:00
|
|
|
import { CommandHelp } from '../../utils/oclif-utils';
|
|
|
|
|
|
|
|
// 'Internal' commands are called during the execution of other commands.
|
|
|
|
// `osinit` is called during `os initialize`
|
|
|
|
// TODO: These should be refactored to modules/functions, and removed
|
|
|
|
// See previous `internal sudo` refactor:
|
|
|
|
// - https://github.com/balena-io/balena-cli/pull/1455/files
|
|
|
|
// - https://github.com/balena-io/balena-cli/pull/1455#discussion_r334308357
|
|
|
|
// - https://github.com/balena-io/balena-cli/pull/1455#discussion_r334308526
|
|
|
|
|
|
|
|
export default class OsinitCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
|
|
|
Do actual init of the device with the preconfigured os image.
|
|
|
|
|
|
|
|
Don't use this command directly!
|
|
|
|
Use \`balena os initialize <image>\` instead.
|
|
|
|
`;
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static args = {
|
|
|
|
image: Args.string({
|
2020-04-02 13:26:52 +00:00
|
|
|
required: true,
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
type: Args.string({
|
2020-04-02 13:26:52 +00:00
|
|
|
required: true,
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
config: Args.string({
|
2020-04-02 13:26:52 +00:00
|
|
|
required: true,
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
};
|
2020-04-02 13:26:52 +00:00
|
|
|
|
|
|
|
public static usage = (
|
|
|
|
'internal osinit ' +
|
|
|
|
new CommandHelp({ args: OsinitCmd.args }).defaultUsage()
|
|
|
|
).trim();
|
|
|
|
|
|
|
|
public static hidden = true;
|
|
|
|
public static root = true;
|
2021-11-12 16:03:29 +00:00
|
|
|
public static offlineCompatible = true;
|
2020-04-02 13:26:52 +00:00
|
|
|
|
|
|
|
public async run() {
|
2023-09-06 14:39:31 +00:00
|
|
|
const { args: params } = await this.parse(OsinitCmd);
|
2020-04-02 13:26:52 +00:00
|
|
|
|
2020-07-08 17:21:37 +00:00
|
|
|
const config = JSON.parse(params.config);
|
|
|
|
|
2020-04-02 13:26:52 +00:00
|
|
|
const { getManifest, osProgressHandler } = await import(
|
|
|
|
'../../utils/helpers'
|
|
|
|
);
|
|
|
|
const manifest = await getManifest(params.image, params.type);
|
|
|
|
|
2020-07-08 17:21:37 +00:00
|
|
|
const { initialize } = await import('balena-device-init');
|
2020-04-02 13:26:52 +00:00
|
|
|
const initializeEmitter = await initialize(params.image, manifest, config);
|
|
|
|
await osProgressHandler(initializeEmitter);
|
|
|
|
}
|
|
|
|
}
|