mirror of
https://github.com/Koenkk/zigbee-OTA.git
synced 2026-09-16 09:38:44 +00:00
Add sha512 checksum to OTA firmwares (#25)
* Add sha512 checksum to OTA firmwares This hashes firmware during download and adds the hash to index.json. Additionally, this PR adds `updateall.js` script which reads all entries and runs `add.js` on each of them (for mass updates, such as the hash algorithm or URL encoding etc). To allow for this to happen, this PR adds the ability to modify entries in-place via `add.js` (if called on an existing path in the repo). Lastly, this normalises the path for the Gledopto firmware to lowercase its file extensions; they were previously `.OTA` in index.json but `.ota` in the repository & in the `url` field -- something picked up by the mass update. * Update README.md Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
co-authored by
Koen Kanters
parent
8e17765e3f
commit
a45b49f4d0
+7
-2
@@ -1,5 +1,6 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const ota = require('../lib/ota');
|
||||
const filenameOrURL = process.argv[2];
|
||||
const modelId = process.argv[3];
|
||||
@@ -65,11 +66,15 @@ const main = async () => {
|
||||
const indexJSON = JSON.parse(fs.readFileSync('index.json'));
|
||||
const destination = path.join('images', manufacturerName, path.basename(file));
|
||||
|
||||
const hash = crypto.createHash('sha512');
|
||||
hash.update(buffer);
|
||||
|
||||
const entry = {
|
||||
fileVersion: parsed.header.fileVersion,
|
||||
fileSize: parsed.header.totalImageSize,
|
||||
manufacturerCode: parsed.header.manufacturerCode,
|
||||
imageType: parsed.header.imageType,
|
||||
sha512: hash.digest('hex'),
|
||||
};
|
||||
|
||||
if (modelId) {
|
||||
@@ -92,7 +97,7 @@ const main = async () => {
|
||||
console.log(`Updated existing entry (${JSON.stringify(entry)})`);
|
||||
indexJSON[index] = entry;
|
||||
|
||||
if (entry.path) {
|
||||
if (entry.path && entry.path !== destination) {
|
||||
fs.unlinkSync(entry.path);
|
||||
}
|
||||
} else {
|
||||
@@ -100,7 +105,7 @@ const main = async () => {
|
||||
indexJSON.push(entry);
|
||||
}
|
||||
|
||||
if (!isURL) {
|
||||
if (!isURL && file !== path.resolve(destination)) {
|
||||
if (!fs.existsSync(path.dirname(destination))) {
|
||||
fs.mkdirSync(path.dirname(destination));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const child_process = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const main = async () => {
|
||||
const indexJSON = JSON.parse(fs.readFileSync('index.json'));
|
||||
indexJSON.forEach(entry => {
|
||||
const result = child_process.execSync(`node ./scripts/add.js "${entry.path || entry.url}" "${entry.modelId || ''}"`, {
|
||||
cwd: path.dirname(__dirname)
|
||||
})
|
||||
console.log(result.toString())
|
||||
})
|
||||
}
|
||||
|
||||
return main();
|
||||
Reference in New Issue
Block a user