forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the-unarchiver: init at 4.3.8 (NixOS#371773)
- Loading branch information
Showing
4 changed files
with
158 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "4.3.8", | ||
"url": "https://dl.devmate.com/com.macpaw.site.theunarchiver/146/1715865652/TheUnarchiver-146.zip", | ||
"hash": "sha256-VcgNT7z7KtdAZxya8DS4Kuk323AAh3Mv/2L7LpUS2NU=" | ||
} |
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,41 @@ | ||
{ | ||
lib, | ||
stdenvNoCC, | ||
fetchurl, | ||
unzip, | ||
}: | ||
let | ||
info = lib.importJSON ./info.json; | ||
in | ||
stdenvNoCC.mkDerivation (finalAttrs: { | ||
pname = "the-unarchiver"; | ||
inherit (info) version; | ||
|
||
src = fetchurl { inherit (info) url hash; }; | ||
|
||
sourceRoot = "."; | ||
nativeBuildInputs = [ unzip ]; | ||
|
||
installPhase = '' | ||
runHook preInstall | ||
mkdir -p $out/Applications | ||
mv "The Unarchiver.app" $out/Applications | ||
runHook postInstall | ||
''; | ||
|
||
passthru.updateScript = ./update/update.mjs; | ||
|
||
meta = { | ||
description = "Unpacks archive files"; | ||
homepage = "https://theunarchiver.com/"; | ||
license = lib.licenses.unfree; | ||
maintainers = with lib.maintainers; [ xiaoxiangmoe ]; | ||
platforms = [ | ||
"aarch64-darwin" | ||
"x86_64-darwin" | ||
]; | ||
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; | ||
}; | ||
}) |
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,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"module": "NodeNext", | ||
"noEmit": true, | ||
"strict": true | ||
} | ||
} |
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,103 @@ | ||
#!/usr/bin/env nix-shell | ||
/* | ||
#!nix-shell -i node --pure --packages cacert nodejs yq-go nix | ||
*/ | ||
import * as assert from "node:assert/strict"; | ||
import * as child_process from "node:child_process"; | ||
import * as fsPromises from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
|
||
const __dirname = import.meta.dirname; | ||
|
||
/** @typedef {{ | ||
rss: { | ||
channel: { | ||
item: Array<{ | ||
pubDate: string; | ||
enclosure: { | ||
"+@url": string; | ||
"+@length": string; | ||
"+@type": string; | ||
"+@sparkle:version": string; | ||
"+@sparkle:shortVersionString": string; | ||
}; | ||
}> | ||
} | ||
} | ||
}} UpdatesXmlInfo */ | ||
|
||
/** @typedef {{ | ||
version: string; | ||
url: string; | ||
hash: string; | ||
}} Info */ | ||
|
||
const UPDATE_URL = | ||
"https://updateinfo.devmate.com/com.macpaw.site.theunarchiver/updates.xml"; | ||
|
||
async function main() { | ||
const filePath = path.join(__dirname, "../info.json"); | ||
/** @type {Info} */ | ||
const oldInfo = JSON.parse( | ||
await fsPromises.readFile(filePath, { encoding: "utf-8" }) | ||
); | ||
|
||
const response = await fetch(UPDATE_URL); | ||
assert.ok(response.ok, `Failed to fetch ${UPDATE_URL}`); | ||
/** @type {UpdatesXmlInfo} */ | ||
const updatesXmlInfo = JSON.parse( | ||
child_process | ||
.execSync(`yq eval --input-format=xml --output-format=json`, { | ||
input: Buffer.from(await response.arrayBuffer()), | ||
}) | ||
.toString() | ||
); | ||
const items = updatesXmlInfo?.rss?.channel?.item; | ||
assert.ok(Array.isArray(items), "items is required"); | ||
const item = items.sort( | ||
(a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime() | ||
)[0]; | ||
const { | ||
"+@url": url, | ||
"+@sparkle:shortVersionString": version, | ||
"+@length": fileSize, | ||
} = item.enclosure; | ||
assert.ok(url, "url is required"); | ||
assert.ok(version, "version is required"); | ||
assert.ok(fileSize, "fileSize is required"); | ||
|
||
if (oldInfo.url === url && oldInfo.version === version) { | ||
console.log("[update] No updates found"); | ||
return; | ||
} | ||
|
||
const [prefetchHash, prefetchStorePath] = child_process | ||
.execSync(`nix-prefetch-url --print-path ${url}`) | ||
.toString() | ||
.split("\n"); | ||
|
||
const downloadedFileSize = (await fsPromises.stat(prefetchStorePath)).size; | ||
if (Number(fileSize) !== downloadedFileSize) { | ||
console.error( | ||
`File size mismatch: expected ${fileSize}, got ${downloadedFileSize}` | ||
); | ||
process.exit(1); | ||
} | ||
const hash = child_process | ||
.execSync(`nix hash convert --hash-algo sha256 --to sri ${prefetchHash}`) | ||
.toString() | ||
.trim(); | ||
/** @type {Info} */ | ||
const info = { | ||
version, | ||
url, | ||
hash, | ||
}; | ||
console.log(`[update] Updating Notion ${oldInfo.version} -> ${info.version}`); | ||
await fsPromises.writeFile(filePath, JSON.stringify(info, null, 2) + "\n", { | ||
encoding: "utf-8", | ||
}); | ||
console.log("[update] Updating Notion complete"); | ||
} | ||
|
||
main(); |