Skip to content

Commit

Permalink
Remove reg code from config blob and format config blob as json
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Feb 3, 2025
1 parent 648d5b4 commit 4c7177c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/cmd/setup-tachyon.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,41 @@ Welcome to the Particle Tachyon setup! This interactive command:
);

let configBlobPath = loadConfig;
let configBlob = null;
if (configBlobPath) {
try {
const data = fs.readFileSync(configBlobPath, 'utf8');
configBlob = JSON.parse(data);
const res = await this._createConfigBlob({
registrationCode,
systemPassword: configBlob.system_password,
wifi: configBlob.wifi,
sshKey: configBlob.ssh_key
});
configBlobPath = res.path;
} catch (error) {
throw new Error(`The configuration file is not a valid JSON file: ${error.message}`);
}
this.ui.write(
`${os.EOL}${os.EOL}Skipping Step 6 - Using configuration file: ` + loadConfig + `${os.EOL}`
);
} else {
configBlobPath = await this._runStepWithTiming(
const res = await this._runStepWithTiming(
'Creating the configuration file to write to the Tachyon device...',
6,
() => this._createConfigBlob({ registrationCode, ...config })
);
configBlobPath = res.path;
configBlob = res.configBlob;
}

const xmlPath = await this._createXmlFile(configBlobPath);

if (saveConfig) {
this.ui.write(`${os.EOL}${os.EOL}Configuration file written here: ${saveConfig}${os.EOL}`);
fs.copyFileSync(configBlobPath, saveConfig);
fs.writeFileSync(saveConfig, JSON.stringify(configBlob, null, 2));
this.ui.write(`${os.EOL}Configuration file written here: ${saveConfig}${os.EOL}`);
}

//what files to flash?
// const filesToFlash = skipFlashingOs ? [xmlPath] : [packagePath, xmlPath];

const flashSuccessful = await this._runStepWithTiming(
`Okay—last step! We're now flashing the device with the configuration, including the password, Wi-Fi settings, and operating system.${os.EOL}` +
`Heads up: this is a large image and will take around 10 minutes to complete. Don't worry—we'll show a progress bar as we go!${os.EOL}${os.EOL}` +
Expand Down Expand Up @@ -487,7 +501,7 @@ Welcome to the Particle Tachyon setup! This interactive command:

// Write config JSON to a temporary file (generate a filename with the temp npm module)
// prefixed by the JSON string length as a 32 bit integer
let jsonString = JSON.stringify(config);
let jsonString = JSON.stringify(config, null, 2);
const buffer = Buffer.alloc(4 + Buffer.byteLength(jsonString));
buffer.writeUInt32BE(Buffer.byteLength(jsonString), 0);
buffer.write(jsonString, 4);
Expand All @@ -496,7 +510,7 @@ Welcome to the Particle Tachyon setup! This interactive command:
fs.writeSync(tempFile.fd, buffer);
fs.closeSync(tempFile.fd);

return tempFile.path;
return { path: tempFile.path, configBlob: config };
}

_generateShadowCompatibleHash(password) {
Expand Down

0 comments on commit 4c7177c

Please sign in to comment.