1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p jq gnused curl
9 cd $
(dirname -- "${BASH_SOURCE[0]}")
11 export NEXTCLOUD_VERSIONS
=$
(nix-instantiate
--eval -E 'import ./nc-versions.nix {}' -A e
)
13 APPS
=$
(jq
-r 'keys|.[]' nextcloud-apps.json |
sed -z 's/\n/,/g;s/,$/\n/')
15 for v
in ${NEXTCLOUD_VERSIONS//,/ }; do
16 # Get major version and back up previous major version apps file
17 v
=$
(sed -e 's/^"//' -e 's/"$//' <<<"$v")
19 MAJOR_FILE
="$MAJOR".json
20 mv "$MAJOR_FILE" "$MAJOR_FILE".bak
22 # Download current apps file from Nextcloud's official servers
23 APPS_PER_VERSION
=${v}.json
24 curl
"https://apps.nextcloud.com/api/v1/platform/${v}/apps.json" -o "$APPS_PER_VERSION"
26 # Add a starting bracket to the apps file for this version
27 echo '{' >"$MAJOR_FILE".tmp
28 for a
in ${APPS//,/ }; do
30 # Ensure the app exists in the file
31 if [ "$(jq -r ".
[] |
select(.id
== \"${a}\")" "$APPS_PER_VERSION")" != "" ]; then
32 # Get all of our variables
33 VERSION
=$
(jq
-r ".[] | select(.id == \"${a}\") | .releases[0].version" "$APPS_PER_VERSION")
34 URL
=$
(jq
-r ".[] | select(.id == \"${a}\") | .releases[0].download" "$APPS_PER_VERSION")
35 HASH
=$
(nix
--extra-experimental-features nix-command store prefetch-file
--json --hash-type sha256
--unpack "$URL" | jq
-r .
hash)
36 HOMEPAGE
=$
(jq
-r ".[] | select(.id == \"${a}\") | .website" "$APPS_PER_VERSION")
37 DESCRIPTION
=$
(jq
".[] | select(.id == \"${a}\") | .translations.en.description" "$APPS_PER_VERSION")
38 # Add all variables to the file
39 cat >>"$MAJOR_FILE".tmp
<<EOF
43 "version": "$VERSION",
44 "description": $DESCRIPTION,
45 "homepage": "$HOMEPAGE"
49 # If we can't find the app, then don't try to process it.
54 # clean up by removing last trailing comma
55 sed -i '$s/,$//' "$MAJOR_FILE".tmp
56 # Add final closing bracket
57 echo '}' >>"$MAJOR_FILE".tmp
59 jq
'.' "$MAJOR_FILE".tmp
>"$MAJOR_FILE"
60 # Remove the temporary files
61 rm "$APPS_PER_VERSION"