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.
|
|
|
|
*/
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
import { Args } from '@oclif/core';
|
2020-07-28 12:40:47 +00:00
|
|
|
import Command from '../../command';
|
|
|
|
import * as cf from '../../utils/common-flags';
|
|
|
|
import { getVisuals, stripIndent } from '../../utils/lazy';
|
|
|
|
|
|
|
|
export default class ConfigInjectCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2021-11-24 23:00:38 +00:00
|
|
|
Inject a config.json file to a balenaOS image or attached media.
|
2020-07-28 12:40:47 +00:00
|
|
|
|
2021-11-24 23:00:38 +00:00
|
|
|
Inject a 'config.json' file to a balenaOS image file or attached SD card or
|
|
|
|
USB stick.
|
2021-09-16 11:15:53 +00:00
|
|
|
|
2021-11-24 23:00:38 +00:00
|
|
|
Documentation for the balenaOS 'config.json' file can be found at:
|
|
|
|
https://www.balena.io/docs/reference/OS/configuration/
|
2020-07-28 12:40:47 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
public static examples = [
|
2021-11-24 23:00:38 +00:00
|
|
|
'$ balena config inject my/config.json',
|
|
|
|
'$ balena config inject my/config.json --drive /dev/disk2',
|
2020-07-28 12:40:47 +00:00
|
|
|
];
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static args = {
|
|
|
|
file: Args.string({
|
2020-07-28 12:40:47 +00:00
|
|
|
description: 'the path to the config.json file to inject',
|
|
|
|
required: true,
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
};
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
public static usage = 'config inject <file>';
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static flags = {
|
2021-04-13 21:44:58 +00:00
|
|
|
drive: cf.driveOrImg,
|
2020-07-28 12:40:47 +00:00
|
|
|
help: cf.help,
|
|
|
|
};
|
|
|
|
|
|
|
|
public static root = true;
|
2021-11-12 16:03:29 +00:00
|
|
|
public static offlineCompatible = true;
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
public async run() {
|
2023-09-06 14:39:31 +00:00
|
|
|
const { args: params, flags: options } = await this.parse(ConfigInjectCmd);
|
2020-07-28 12:40:47 +00:00
|
|
|
|
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/OS drive'));
|
2021-04-13 21:44:58 +00:00
|
|
|
await safeUmount(drive);
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
const fs = await import('fs');
|
|
|
|
const configJSON = JSON.parse(
|
|
|
|
await fs.promises.readFile(params.file, 'utf8'),
|
|
|
|
);
|
|
|
|
|
|
|
|
const config = await import('balena-config-json');
|
2021-11-24 23:00:38 +00:00
|
|
|
await config.write(drive, '', configJSON);
|
2020-07-28 12:40:47 +00:00
|
|
|
|
|
|
|
console.info('Done');
|
|
|
|
}
|
|
|
|
}
|