-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-Updater may fail for signed electron apps #116
* add typescript script to update the checksum metadata for an installer and also include the version number in the installer filename path * change build process so that the windows installer gets a fixed checksum after signing and create a link to the installer including the version number * also build zip for mac because required for updates
- Loading branch information
1 parent
2a6de5e
commit 8db6609
Showing
4 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import * as crypto from 'crypto'; | ||
import * as fs from 'fs'; | ||
import * as jsyaml from 'js-yaml'; | ||
import * as path from 'path'; | ||
import { hideBin } from 'yargs/helpers'; | ||
import yargs from 'yargs/yargs'; | ||
|
||
|
||
const argv = yargs(hideBin(process.argv)) | ||
.option('executable', { alias: 'e', type: 'string', default: '../dist/TheiaBlueprint.AppImage', desription: 'The executable for which the checksum needs to be updated' }) | ||
.option('yaml', { alias: 'y', type: 'string', default: '../dist/latest-linux.yml', desription: 'The yaml file where the checksum needs to be updated' }) | ||
.version(false) | ||
.wrap(120) | ||
.parseSync(); | ||
|
||
execute(); | ||
|
||
async function execute(): Promise<void> { | ||
const executable = argv.executable; | ||
const yaml = argv.yaml; | ||
|
||
const executablePath = path.resolve( | ||
__dirname, | ||
executable | ||
); | ||
|
||
const yamlPath = path.resolve( | ||
__dirname, | ||
yaml | ||
); | ||
|
||
console.log('Exe: ' + executablePath + '; Yaml: ' + yamlPath) | ||
|
||
const hash = await hashFile(executablePath, 'sha512', 'base64', {}); | ||
const size = fs.statSync(executablePath).size | ||
|
||
const yamlContents: string = fs.readFileSync(yamlPath, { encoding: 'utf8' }) | ||
const latestYaml: any = jsyaml.safeLoad(yamlContents); | ||
latestYaml.sha512 = hash; | ||
latestYaml.path = updatedPath(latestYaml.path, latestYaml.version) | ||
for (const file of latestYaml.files) { | ||
file.sha512 = hash; | ||
file.size = size; | ||
file.url = updatedPath(file.url, latestYaml.version) | ||
} | ||
|
||
//line width -1 to avoid adding >- on long strings like a hash | ||
const newYamlContents = jsyaml.dump(latestYaml, { lineWidth: -1 }); | ||
fs.writeFileSync(yamlPath, newYamlContents); | ||
} | ||
|
||
function hashFile(file: fs.PathLike, algorithm = 'sha512', encoding: BufferEncoding = 'base64', options: string | { | ||
flags?: string; | ||
encoding?: BufferEncoding; | ||
fd?: number; | ||
mode?: number; | ||
autoClose?: boolean; | ||
emitClose?: boolean; | ||
start?: number; | ||
end?: number; | ||
highWaterMark?: number; | ||
}): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
const hash = crypto.createHash(algorithm); | ||
hash.on('error', reject).setEncoding(encoding); | ||
fs.createReadStream( | ||
file, | ||
Object.assign({}, options, { | ||
highWaterMark: 1024 * 1024, | ||
}) | ||
) | ||
.on('error', reject) | ||
.on('end', () => { | ||
hash.end(); | ||
resolve(hash.read()); | ||
}) | ||
.pipe( | ||
hash, | ||
{ | ||
end: false, | ||
} | ||
); | ||
}); | ||
} | ||
|
||
function updatedPath(path: string, version: string): string { | ||
const extensionIndex = path.lastIndexOf('.'); | ||
return path.substring(0, extensionIndex) + '-' + version + path.substring(extensionIndex); | ||
} |