Strip down factory-update.js to its essentials.

This commit is contained in:
László Monda
2018-04-02 00:11:35 +02:00
parent 533c2f13d2
commit 01fcf9053a

View File

@@ -1,9 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs'); const fs = require('fs');
const program = require('commander'); const program = require('commander');
const tmp = require('tmp');
const decompress = require('decompress');
const decompressTarbz = require('decompress-tarbz2');
const uhk = require('./uhk') const uhk = require('./uhk')
require('shelljs/global'); require('shelljs/global');
@@ -13,7 +10,6 @@ require('shelljs/global');
program program
.usage(`firmwarePath`) .usage(`firmwarePath`)
.option('-u, --overwrite-user-config', 'Overwrite the user configuration with the one that is bundled with the firmware')
.parse(process.argv); .parse(process.argv);
if (program.args.length == 0) { if (program.args.length == 0) {
@@ -21,26 +17,19 @@ require('shelljs/global');
exit(1); exit(1);
} }
let firmwarePath = program.args[0];
// If a tarball is specified then extract it and override firmwarePath with the target directory name.
if (test('-f', firmwarePath)) {
const tmpObj = tmp.dirSync();
await decompress(firmwarePath, tmpObj.name, {plugins: [decompressTarbz()]});
firmwarePath = tmpObj.name;
}
config.verbose = true; config.verbose = true;
const firmwarePath = program.args[0];
await uhk.updateFirmwares(firmwarePath); await uhk.updateFirmwares(firmwarePath);
const device = uhk.getUhkDevice();
if (program.overwriteUserConfig) { const configBuffer = fs.readFileSync(`${firmwarePath}/devices/uhk60-right/config.bin`);
const device = uhk.getUhkDevice(); console.log('write config');
const configBuffer = fs.readFileSync(`${firmwarePath}/devices/uhk60-right/config.bin`); await uhk.writeConfig(device, configBuffer, false);
await uhk.writeConfig(device, configBuffer, false); console.log('apply config');
await uhk.applyConfig(device); await uhk.applyConfig(device);
await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeUserConfig); console.log('lanuch eeprom transfer');
} await uhk.launchEepromTransfer(device, uhk.eepromOperations.write, uhk.eepromTransfer.writeUserConfig);
config.verbose = false; config.verbose = false;
} catch (exception) { } catch (exception) {
console.error(exception.message); console.error(exception.message);
exit(1); exit(1);