mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-04 08:40:49 +00:00
Create config.txt if there isn't one already
Change-type: patch Signed-off-by: Theodor Gherzan <theodor@balena.io>
This commit is contained in:
parent
c46c1e04d3
commit
1570fd424b
@ -106,51 +106,58 @@ export class RPiConfigBackend extends DeviceConfigBackend {
|
|||||||
return _.startsWith(deviceType, 'raspberry') || deviceType === 'fincm3';
|
return _.startsWith(deviceType, 'raspberry') || deviceType === 'fincm3';
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBootConfig(): Promise<ConfigOptions> {
|
public async getBootConfig(): Promise<ConfigOptions> {
|
||||||
return Promise.resolve(
|
let configContents = '';
|
||||||
fs.readFile(RPiConfigBackend.bootConfigPath, 'utf-8'),
|
|
||||||
).then(confStr => {
|
|
||||||
const conf: ConfigOptions = {};
|
|
||||||
const configStatements = confStr.split(/\r?\n/);
|
|
||||||
|
|
||||||
for (const configStr of configStatements) {
|
if (await fs.exists(RPiConfigBackend.bootConfigPath)) {
|
||||||
// Don't show warnings for comments and empty lines
|
configContents = await fs.readFile(
|
||||||
const trimmed = _.trimStart(configStr);
|
RPiConfigBackend.bootConfigPath,
|
||||||
if (_.startsWith(trimmed, '#') || trimmed === '') {
|
'utf-8',
|
||||||
continue;
|
);
|
||||||
}
|
} else {
|
||||||
let keyValue = /^([^=]+)=(.*)$/.exec(configStr);
|
await fs.writeFile(RPiConfigBackend.bootConfigPath, '');
|
||||||
if (keyValue != null) {
|
}
|
||||||
const [, key, value] = keyValue;
|
|
||||||
if (!_.includes(RPiConfigBackend.arrayConfigKeys, key)) {
|
|
||||||
conf[key] = value;
|
|
||||||
} else {
|
|
||||||
if (conf[key] == null) {
|
|
||||||
conf[key] = [];
|
|
||||||
}
|
|
||||||
const confArr = conf[key];
|
|
||||||
if (!_.isArray(confArr)) {
|
|
||||||
throw new Error(
|
|
||||||
`Expected '${key}' to have a config array but got ${typeof confArr}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
confArr.push(value);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try the next regex instead
|
const conf: ConfigOptions = {};
|
||||||
keyValue = /^(initramfs) (.+)/.exec(configStr);
|
const configStatements = configContents.split(/\r?\n/);
|
||||||
if (keyValue != null) {
|
|
||||||
const [, key, value] = keyValue;
|
for (const configStr of configStatements) {
|
||||||
|
// Don't show warnings for comments and empty lines
|
||||||
|
const trimmed = _.trimStart(configStr);
|
||||||
|
if (_.startsWith(trimmed, '#') || trimmed === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let keyValue = /^([^=]+)=(.*)$/.exec(configStr);
|
||||||
|
if (keyValue != null) {
|
||||||
|
const [, key, value] = keyValue;
|
||||||
|
if (!_.includes(RPiConfigBackend.arrayConfigKeys, key)) {
|
||||||
conf[key] = value;
|
conf[key] = value;
|
||||||
} else {
|
} else {
|
||||||
log.warn(`Could not parse config.txt entry: ${configStr}. Ignoring.`);
|
if (conf[key] == null) {
|
||||||
|
conf[key] = [];
|
||||||
|
}
|
||||||
|
const confArr = conf[key];
|
||||||
|
if (!_.isArray(confArr)) {
|
||||||
|
throw new Error(
|
||||||
|
`Expected '${key}' to have a config array but got ${typeof confArr}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
confArr.push(value);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf;
|
// Try the next regex instead
|
||||||
});
|
keyValue = /^(initramfs) (.+)/.exec(configStr);
|
||||||
|
if (keyValue != null) {
|
||||||
|
const [, key, value] = keyValue;
|
||||||
|
conf[key] = value;
|
||||||
|
} else {
|
||||||
|
log.warn(`Could not parse config.txt entry: ${configStr}. Ignoring.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setBootConfig(opts: ConfigOptions): Promise<void> {
|
public setBootConfig(opts: ConfigOptions): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user