2020-07-28 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* @license
|
2021-04-13 21:44:58 +00:00
|
|
|
* Copyright 2016-2021 Balena Ltd.
|
2020-07-28 12:40:47 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { flags } from '@oclif/command';
|
|
|
|
import Command from '../../command';
|
|
|
|
import * as cf from '../../utils/common-flags';
|
|
|
|
import { getVisuals, stripIndent } from '../../utils/lazy';
|
|
|
|
|
|
|
|
interface FlagsDef {
|
2021-11-24 23:00:38 +00:00
|
|
|
type?: string;
|
2020-07-28 12:40:47 +00:00
|
|
|
drive?: string;
|
|
|
|
advanced: boolean;
|
|
|
|
help: void;
|
2021-11-24 23:00:38 +00:00
|
|
|
version?: string;
|
2020-07-28 12:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class ConfigReconfigureCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2021-11-24 23:00:38 +00:00
|
|
|
Interactively reconfigure a balenaOS image file or attached media.
|
2020-07-28 12:40:47 +00:00
|
|
|
|
2021-11-24 23:00:38 +00:00
|
|
|
Interactively reconfigure a balenaOS image file or attached media.
|
|
|
|
|
|
|
|
This command extracts the device UUID from the 'config.json' file of the
|
|
|
|
chosen balenaOS image file or attached media, and then passes the UUID as
|
|
|
|
the '--device' argument to the 'balena os configure' command.
|
|
|
|
|
|
|
|
For finer-grained or scripted control of the operation, use the
|
|
|
|
'balena config read' and 'balena os configure' commands separately.
|
2020-07-28 12:40:47 +00:00
|
|
|
`;
|
|
|
|
public static examples = [
|
2021-11-24 23:00:38 +00:00
|
|
|
'$ balena config reconfigure',
|
|
|
|
'$ balena config reconfigure --drive /dev/disk3',
|
|
|
|
'$ balena config reconfigure --drive balena.img --advanced',
|
2020-07-28 12:40:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public static usage = 'config reconfigure';
|
|
|
|
|
|
|
|
public static flags: flags.Input<FlagsDef> = {
|
2021-04-13 21:44:58 +00:00
|
|
|
drive: cf.driveOrImg,
|
2020-07-28 12:40:47 +00:00
|
|
|
advanced: flags.boolean({
|
|
|
|
description: 'show advanced commands',
|
|
|
|
char: 'v',
|
|
|
|
}),
|
|
|
|
help: cf.help,
|
2021-11-24 23:00:38 +00:00
|
|
|
version: flags.string({
|
|
|
|
description: 'balenaOS version, for example "2.32.0" or "2.44.0+rev1"',
|
|
|
|
}),
|
2020-07-28 12:40:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public static authenticated = true;
|
|
|
|
public static root = true;
|
|
|
|
|
|
|
|
public async run() {
|
|
|
|
const { flags: options } = this.parse<FlagsDef, {}>(ConfigReconfigureCmd);
|
|
|
|
|
2021-07-20 21:38:39 +00:00
|
|
|
const { safeUmount } = await import('../../utils/umount');
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
const drive =
|
|
|
|
options.drive || (await getVisuals().drive('Select the device drive'));
|
2021-04-13 21:44:58 +00:00
|
|
|
await safeUmount(drive);
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
const config = await import('balena-config-json');
|
2021-11-24 23:00:38 +00:00
|
|
|
const { uuid } = await config.read(drive, '');
|
2021-04-13 21:44:58 +00:00
|
|
|
await safeUmount(drive);
|
2020-07-28 12:40:47 +00:00
|
|
|
|
2021-11-24 23:00:38 +00:00
|
|
|
if (!uuid) {
|
|
|
|
const { ExpectedError } = await import('../../errors');
|
|
|
|
throw new ExpectedError(
|
|
|
|
`Error: UUID not found in 'config.json' file for '${drive}'`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-28 12:40:47 +00:00
|
|
|
const configureCommand = ['os', 'configure', drive, '--device', uuid];
|
2021-11-24 23:00:38 +00:00
|
|
|
if (options.version) {
|
|
|
|
configureCommand.push('--version', options.version);
|
|
|
|
}
|
2020-07-28 12:40:47 +00:00
|
|
|
if (options.advanced) {
|
|
|
|
configureCommand.push('--advanced');
|
|
|
|
}
|
|
|
|
|
|
|
|
const { runCommand } = await import('../../utils/helpers');
|
|
|
|
await runCommand(configureCommand);
|
|
|
|
|
|
|
|
console.info('Done');
|
|
|
|
}
|
|
|
|
}
|