Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / servers / nextcloud / packages / generate.sh
blob3ae55d829bc4019e510df2cfcea930e69ba1ae0c
1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p jq gnused curl
4 set -e
5 set -u
6 set -o pipefail
7 set -x
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")
18 MAJOR=${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
29 echo "Fetching $a"
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
40 "${a}": {
41 "hash": "$HASH",
42 "url": "$URL",
43 "version": "$VERSION",
44 "description": $DESCRIPTION,
45 "homepage": "$HOMEPAGE"
47 EOF
49 # If we can't find the app, then don't try to process it.
50 else
51 true
53 done
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
58 # Beautify file
59 jq '.' "$MAJOR_FILE".tmp >"$MAJOR_FILE"
60 # Remove the temporary files
61 rm "$APPS_PER_VERSION"
62 rm "$MAJOR_FILE".tmp
63 rm "$MAJOR_FILE".bak
64 done