Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / by-name / tr / tradingview / update.sh
blob863521bfde920be272f73170d3e27eb9740b38a8
1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p curl jq git gnused gnugrep
5 # Get latest version of TradingView from Snapcraft.
8 snap_info=($(
9 curl -s -H 'X-Ubuntu-Series: 16' \
10 'https://api.snapcraft.io/api/v1/snaps/details/tradingview' \
11 | jq --raw-output \
12 '.revision,.download_sha512,.version,.last_updated'
15 # "revision" is the actual version identifier; "version" is for human consumption.
16 revision="${snap_info[0]}"
17 sha512="${snap_info[1]}"
18 sri=$(nix hash to-sri --type "sha512" $sha512)
19 upstream_version="${snap_info[2]}"
20 last_updated="${snap_info[3]}"
22 echo "Latest release is $upstream_version from $last_updated."
25 # Read the current TradingView version.
28 nixpkgs="$(git rev-parse --show-toplevel)"
29 tradingview_nix="$nixpkgs/pkgs/applications/finance/tradingview/default.nix"
30 current_nix_version=$(
31 grep 'version\s*=' "$tradingview_nix" \
32 | sed -Ene 's/.*"(.*)".*/\1/p'
35 echo "Current nix version: $current_nix_version"
37 if [[ "$current_nix_version" = "$upstream_version" ]]; then
38 echo "TradingView is already up-to-date"
39 exit 0
43 # Find and replace.
46 echo "Updating from ${current_nix_version} to ${upstream_version}, released ${last_updated}"
48 sed --regexp-extended \
49 -e 's/revision\s*=\s*"[0-9]+"\s*;/revision = "'"${revision}"'";/' \
50 -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${sri}"'";/' \
51 -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
52 -i "$tradingview_nix"
55 # Attempt a build.
58 export NIXPKGS_ALLOW_UNFREE=1
60 if ! nix-build -A tradingview "$nixpkgs"; then
61 echo "The updated TradingView failed to build."
62 exit 1
66 # Commit changes.
68 git add "$tradingview_nix"
69 git commit -m "tradingview: ${current_nix_version} -> ${upstream_version}"