From 7a762ceb123b86914cd3cedef8333f01077818cb Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Mon, 8 Jan 2024 11:54:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Chocolatey=20script=20checks=20h?= =?UTF-8?q?ash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-config/chocolateyInstall.ps1 | 3 +++ utils/prepare-electron-builder.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/build-config/chocolateyInstall.ps1 b/build-config/chocolateyInstall.ps1 index e989d5c4..00059473 100644 --- a/build-config/chocolateyInstall.ps1 +++ b/build-config/chocolateyInstall.ps1 @@ -1,5 +1,6 @@ $packageName = 'electronim' $file = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim-win-x64.zip" +$hash: 1337 $unzipLocation = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\electronim" @@ -7,5 +8,7 @@ Install-ChocolateyZipPackage ` -PackageName $packageName ` -File $file ` -UnzipLocation $unzipLocation ` + -Checksum $hash: AB32A2282C65DBEE325FAE31770CD848B3A3A84FE2798D306FC2EAE2BA0D93B5 + -ChecksumType 'SHA256' ` Install-BinFile -Name $packageName -Path 'electronim.exe' diff --git a/utils/prepare-electron-builder.js b/utils/prepare-electron-builder.js index e21a4110..87fcc000 100755 --- a/utils/prepare-electron-builder.js +++ b/utils/prepare-electron-builder.js @@ -1,5 +1,6 @@ #!/usr/bin/env node /* eslint-disable no-console */ +const crypto = require('crypto'); const fs = require('fs'); const path = require('path'); const errorHandler = require('./error-handler'); @@ -18,9 +19,21 @@ const licenseForChocolatey = () => { fs.copyFileSync(packageLicense, packageLicenseTxt); }; +const calculateHashForChocolatey = () => { + const fileBuffer = fs.readFileSync(path.join(__dirname, '..', 'dist', 'electronim-win-x64.zip')); + const hashSum = crypto.createHash('sha256'); + hashSum.update(fileBuffer); + const hash = hashSum.digest('hex').toUpperCase(); + const chocolateyInstall = path.resolve(__dirname, '..', 'build-config', 'chocolateyInstall.ps1'); + fs.writeFileSync(chocolateyInstall, fs.readFileSync(chocolateyInstall).toString() + .replace(/\$hash.+$/gm, `$hash: ${hash}`) + ); +} + const prepareElectronBuilder = () => { electronToDevDependencies(); licenseForChocolatey(); + calculateHashForChocolatey(); }; process.on('unhandledRejection', errorHandler);