1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=./. -i bash -p jq nix-prefetch-scripts
6 DEFAULT_NIX
="$(realpath ".
/pkgs
/applications
/editors
/android-studio
/default.nix
")"
7 RELEASES_JSON
="$(curl --silent -L https://jb.gg/android-studio-releases-list.json)"
9 # Available channels: Release/Patch (stable), Beta, Canary
14 "stable") local select='.channel == "Release" or .channel == "Patch"' ;;
15 "beta") local select='.channel == "Beta" or .channel == "RC"' ;;
16 *) local select=".channel == \"${channel^}\"" ;;
18 local result
="$(echo "$RELEASES_JSON" \
19 | jq -r ".content.item
[] |
select(${select}) |
[.version
, .
${attribute}] |
join(\" \")" \
20 | sort --version-sort \
24 if [[ -n "$result" ]]; then
27 echo "could not find the latest $attribute for $channel"
34 local latestVersion
="$(getLatest "version
" "$channel")"
36 local localVersion
="$(nix --extra-experimental-features nix-command eval --raw --file . androidStudioPackages."${channel}".version)"
37 if [[ "${latestVersion}" == "${localVersion}" ]]; then
38 echo "$channel is already up to date at $latestVersion"
41 echo "updating $channel from $localVersion to $latestVersion"
43 local latestHash
="$(nix-prefetch-url "https
://dl.google.com
/dl
/android
/studio
/ide-zips
/${latestVersion}/android-studio-
${latestVersion}-linux.
tar.gz
")"
44 local latestSri
="$(nix --extra-experimental-features nix-command hash to-sri --type sha256 "$latestHash")"
45 local localHash
="$(nix --extra-experimental-features nix-command eval --raw --file . androidStudioPackages."${channel}".unwrapped.src.drvAttrs.outputHash)"
46 sed -i "s~${localHash}~${latestSri}~g" "${DEFAULT_NIX}"
48 # Match the formatting of default.nix: `version = "2021.3.1.14"; # "Android Studio Dolphin (2021.3.1) Beta 5"`
49 local versionString
="${latestVersion}\"; # \"$(getLatest "name
" "${channel}")\""
50 sed -i "s~${localVersion}.*~${versionString}~g" "${DEFAULT_NIX}"
51 echo "updated ${channel} to ${latestVersion}"
54 if (( $# == 0 )); then
55 for channel
in "beta" "canary" "stable"; do
56 updateChannel
"$channel"
64 echo "unknown channel: $1" && exit 1 ;;