ripasso-cursive: cosmetic changes (#361736)
[NixPkgs.git] / pkgs / by-name / ca / castopod / update.sh
blob742788dc8ddfddfb27631a3b4ec0c53a169c40f0
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p curl jq
3 set -euo pipefail
5 nixpkgs="$(git rev-parse --show-toplevel)"
6 castopod_nix="$nixpkgs/pkgs/applications/audio/castopod/default.nix"
8 # https://www.meetup.com/api/guide/#p02-querying-section
9 query='
10 query allReleases($fullPath: ID!, $first: Int, $last: Int, $before: String, $after: String, $sort: ReleaseSort) {
11 project(fullPath: $fullPath) {
13 releases(
14 first: $first
15 last: $last
16 before: $before
17 after: $after
18 sort: $sort
19 ) {
20 nodes {
21 ...Release
22 __typename
24 __typename
26 __typename
30 fragment Release on Release {
32 name
33 tagName
34 releasedAt
35 createdAt
36 upcomingRelease
37 historicalRelease
38 assets {
39 links {
40 nodes {
42 name
43 url
44 directAssetUrl
45 linkType
46 __typename
48 __typename
50 __typename
52 __typename
55 variables='{
56 "fullPath": "adaures/castopod",
57 "first": 1,
58 "sort": "RELEASED_AT_DESC"
61 post=$(cat <<EOF
62 {"query": "$(echo $query)", "variables": $(echo $variables)}
63 EOF
66 json="$(curl -s -X POST https://code.castopod.org/api/graphql \
67 -H 'Content-Type: application/json' \
68 -d "$post")"
70 echo "$json"
71 TAG=$(echo $json | jq -r '.data.project.releases.nodes[].tagName')
72 ASSET_URL=$(echo $json | jq -r '.data.project.releases.nodes[].assets.links.nodes[].url' | grep .tar.gz$)
74 CURRENT_VERSION=$(nix eval -f "$nixpkgs" --raw castopod.version)
75 VERSION=${TAG:1}
77 if [[ "$CURRENT_VERSION" == "$VERSION" ]]; then
78 echo "castopod is up-to-date: ${CURRENT_VERSION}"
79 exit 0
82 SHA256=$(nix-prefetch-url "$ASSET_URL")
84 URL=$(echo $ASSET_URL | sed -e 's/[\/&]/\\&/g')
86 sed -e "s/version =.*;/version = \"$VERSION\";/g" \
87 -e "s/url =.*;/url = \"$URL\";/g" \
88 -e "s/sha256 =.*;/sha256 = \"$SHA256\";/g" \
89 -i "$castopod_nix"