1{
2 writeScript,
3 lib,
4 curl,
5 runtimeShell,
6 jq,
7 coreutils,
8 moreutils,
9 nix,
10 gnused,
11}:
12
13writeScript "update-standardnotes" ''
14 #!${runtimeShell}
15 PATH=${
16 lib.makeBinPath [
17 jq
18 curl
19 nix
20 coreutils
21 moreutils
22 gnused
23 ]
24 }
25
26 set -euo pipefail
27 set -x
28
29 tmpDir=$(mktemp -d)
30 srcJson=pkgs/applications/editors/standardnotes/src.json
31 jsonPath="$tmpDir"/latest
32
33 oldVersion=$(jq -r .version < "$srcJson")
34
35 curl https://api.github.com/repos/standardnotes/app/releases/latest > "$jsonPath"
36
37 tagName=$(jq -r .tag_name < "$jsonPath")
38
39 if [[ ! "$tagName" =~ "desktop" ]]; then
40 echo "latest release '$tagName' not a desktop release"
41 exit 1
42 fi
43
44 newVersion=$(jq -r .tag_name < "$jsonPath" | sed s,@standardnotes/desktop@,,g)
45
46 if [[ "$oldVersion" == "$newVersion" ]]; then
47 echo "version did not change"
48 exit 0
49 fi
50
51 function getDownloadUrl() {
52 jq -r ".assets[] | select(.name==\"standard-notes-$newVersion-$1.deb\") | .browser_download_url" < "$jsonPath"
53 }
54
55 function setJsonKey() {
56 jq "$1 = \"$2\"" "$srcJson" | sponge "$srcJson"
57 }
58
59 function updatePlatform() {
60 nixPlatform="$1"
61 upstreamPlatform="$2"
62 url=$(getDownloadUrl "$upstreamPlatform")
63 hash=$(nix-prefetch-url "$url" --type sha512)
64 sriHash=$(nix --extra-experimental-features nix-command hash to-sri --type sha512 $hash)
65 setJsonKey .deb[\""$nixPlatform"\"].url "$url"
66 setJsonKey .deb[\""$nixPlatform"\"].hash "$sriHash"
67 }
68
69 updatePlatform x86_64-linux linux-amd64
70 updatePlatform aarch64-linux linux-arm64
71 setJsonKey .version "$newVersion"
72''