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:
Theodor Gherzan 2019-11-16 18:43:23 +00:00
parent c46c1e04d3
commit 1570fd424b
No known key found for this signature in database
GPG Key ID: FE24E396B42287CE

View File

@ -106,12 +106,20 @@ 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 => { if (await fs.exists(RPiConfigBackend.bootConfigPath)) {
configContents = await fs.readFile(
RPiConfigBackend.bootConfigPath,
'utf-8',
);
} else {
await fs.writeFile(RPiConfigBackend.bootConfigPath, '');
}
const conf: ConfigOptions = {}; const conf: ConfigOptions = {};
const configStatements = confStr.split(/\r?\n/); const configStatements = configContents.split(/\r?\n/);
for (const configStr of configStatements) { for (const configStr of configStatements) {
// Don't show warnings for comments and empty lines // Don't show warnings for comments and empty lines
@ -150,7 +158,6 @@ export class RPiConfigBackend extends DeviceConfigBackend {
} }
return conf; return conf;
});
} }
public setBootConfig(opts: ConfigOptions): Promise<void> { public setBootConfig(opts: ConfigOptions): Promise<void> {