Merge pull request #1576 from balena-io/add-gsm-configuration-action

configure: Allow passing system-connection files to `os configure` command
This commit is contained in:
Rich Bayliss 2020-01-21 21:44:07 +00:00 committed by GitHub
commit 5cf407b483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 2 deletions

View File

@ -1300,6 +1300,13 @@ following sources, in precedence order:
The --device-type option may be used to override the application's default The --device-type option may be used to override the application's default
device type, in case of an application with mixed device types. device type, in case of an application with mixed device types.
The --system-connection (-c) option can be used to inject NetworkManager connection
profiles for additional network interfaces, such as cellular/GSM or additional
WiFi or ethernet connections. This option may be passed multiple times in case there
are multiple files to inject. See connection profile examples and reference at:
https://www.balena.io/docs/reference/OS/network/2.x/
https://developer.gnome.org/NetworkManager/stable/nm-settings.html
The --device-api-key option is deprecated and will be removed in a future release. The --device-api-key option is deprecated and will be removed in a future release.
A suitable key is automatically generated or fetched if this option is omitted. A suitable key is automatically generated or fetched if this option is omitted.
@ -1368,6 +1375,10 @@ device type slug (e.g. "raspberrypi3") to override the application device type
balenaOS version, for example "2.32.0" or "2.44.0+rev1" balenaOS version, for example "2.32.0" or "2.44.0+rev1"
#### -c, --system-connection SYSTEM-CONNECTION
paths to local files to place into the 'system-connections' directory
## os initialize <image> ## os initialize <image>
Use this command to initialize a device with previously configured operating system image. Use this command to initialize a device with previously configured operating system image.

View File

@ -17,13 +17,18 @@
import { Command, flags } from '@oclif/command'; import { Command, flags } from '@oclif/command';
import BalenaSdk = require('balena-sdk'); import BalenaSdk = require('balena-sdk');
import Bluebird = require('bluebird');
import { stripIndent } from 'common-tags'; import { stripIndent } from 'common-tags';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as path from 'path';
import { ExpectedError } from '../../errors'; import { ExpectedError } from '../../errors';
import * as cf from '../../utils/common-flags'; import * as cf from '../../utils/common-flags';
import { CommandHelp } from '../../utils/oclif-utils'; import { CommandHelp } from '../../utils/oclif-utils';
const BOOT_PARTITION = 1;
const CONNECTIONS_FOLDER = '/system-connections';
interface FlagsDef { interface FlagsDef {
advanced?: boolean; advanced?: boolean;
app?: string; app?: string;
@ -38,6 +43,7 @@ interface FlagsDef {
'device-type'?: string; 'device-type'?: string;
help?: void; help?: void;
version?: string; version?: string;
'system-connection': string[];
} }
interface ArgsDef { interface ArgsDef {
@ -77,6 +83,13 @@ export default class OsConfigureCmd extends Command {
The --device-type option may be used to override the application's default The --device-type option may be used to override the application's default
device type, in case of an application with mixed device types. device type, in case of an application with mixed device types.
The --system-connection (-c) option can be used to inject NetworkManager connection
profiles for additional network interfaces, such as cellular/GSM or additional
WiFi or ethernet connections. This option may be passed multiple times in case there
are multiple files to inject. See connection profile examples and reference at:
https://www.balena.io/docs/reference/OS/network/2.x/
https://developer.gnome.org/NetworkManager/stable/nm-settings.html
${deviceApiKeyDeprecationMsg.split('\n').join('\n\t\t')} ${deviceApiKeyDeprecationMsg.split('\n').join('\n\t\t')}
`; `;
public static examples = [ public static examples = [
@ -144,6 +157,13 @@ export default class OsConfigureCmd extends Command {
version: flags.string({ version: flags.string({
description: 'balenaOS version, for example "2.32.0" or "2.44.0+rev1"', description: 'balenaOS version, for example "2.32.0" or "2.44.0+rev1"',
}), }),
'system-connection': flags.string({
multiple: true,
char: 'c',
required: false,
description:
"paths to local files to place into the 'system-connections' directory",
}),
}; };
public async run() { public async run() {
@ -163,6 +183,7 @@ export default class OsConfigureCmd extends Command {
'../../utils/config' '../../utils/config'
); );
const helpers = await import('../../utils/helpers'); const helpers = await import('../../utils/helpers');
const imagefs = await require('resin-image-fs');
let app: BalenaSdk.Application | undefined; let app: BalenaSdk.Application | undefined;
let device: BalenaSdk.Device | undefined; let device: BalenaSdk.Device | undefined;
let deviceTypeSlug: string; let deviceTypeSlug: string;
@ -213,14 +234,42 @@ export default class OsConfigureCmd extends Command {
console.info('Configuring operating system image'); console.info('Configuring operating system image');
const image = params.image;
await helpers.osProgressHandler( await helpers.osProgressHandler(
await devInit.configure( await devInit.configure(
params.image, image,
deviceTypeManifest, deviceTypeManifest,
configJson || {}, configJson || {},
answers, answers,
), ),
); );
if (options['system-connection']) {
const files = await Bluebird.map(
options['system-connection'],
async filePath => {
const content = await fs.readFile(filePath, 'utf8');
const name = path.basename(filePath);
return {
name,
content,
};
},
);
await Bluebird.each(files, async ({ name, content }) => {
await imagefs.writeFile(
{
image,
partition: BOOT_PARTITION,
path: path.join(CONNECTIONS_FOLDER, name),
},
content,
);
console.info(`Copied system-connection file: ${name}`);
});
}
} }
} }