spotify: add macOS support to update script

+82 -54
+82 -54
pkgs/by-name/sp/spotify/update.sh
··· 1 #!/usr/bin/env nix-shell 2 - #! nix-shell -i bash -p curl jq git gnused gnugrep 3 4 5 # executing this script without arguments will ··· 20 21 channel="${1:-stable}" # stable/candidate/edge 22 nixpkgs="$(git rev-parse --show-toplevel)" 23 - spotify_nix="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix" 24 25 26 - # 27 - # find the newest stable spotify version avaiable on snapcraft 28 - # 29 30 - # create bash array from snap info 31 - snap_info=($( 32 - curl -s -H 'X-Ubuntu-Series: 16' \ 33 - "https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \ 34 - | jq --raw-output \ 35 - '.revision,.download_sha512,.version,.last_updated' 36 - )) 37 38 - # "revision" is the actual version identifier on snapcraft, the "version" is 39 - # just for human consumption. Revision is just an integer that gets increased 40 - # by one every (stable or unstable) release. 41 - revision="${snap_info[0]}" 42 - # We need to escape the slashes 43 - hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')" 44 - upstream_version="${snap_info[2]}" 45 - last_updated="${snap_info[3]}" 46 - echo "Latest $channel release is $upstream_version from $last_updated." 47 - # 48 - # read the current spotify version from the currently *committed* nix expression 49 - # 50 51 - current_nix_version=$( 52 - grep 'version\s*=' "$spotify_nix" \ 53 - | sed -Ene 's/.*"(.*)".*/\1/p' 54 - ) 55 56 - echo "Current nix version: $current_nix_version" 57 58 - # 59 - # update the nix expression if the versions differ 60 - # 61 62 - if [[ "$current_nix_version" = "$upstream_version" ]]; then 63 - echo "Spotify is already up-to-date" 64 - exit 0 65 - fi 66 67 - echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}" 68 69 - # search-and-replace revision, hash and version 70 - sed --regexp-extended \ 71 - -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \ 72 - -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \ 73 - -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \ 74 - -i "$spotify_nix" 75 76 - # 77 - # try to build the updated version 78 - # 79 80 - export NIXPKGS_ALLOW_UNFREE=1 81 - if ! nix-build -A spotify "$nixpkgs"; then 82 - echo "The updated spotify failed to build." 83 - exit 1 84 - fi 85 86 - # Commit changes 87 - git add "$spotify_nix" 88 - git commit -m "spotify: ${current_nix_version} -> ${upstream_version}"
··· 1 #!/usr/bin/env nix-shell 2 + #! nix-shell -i bash -p common-updater-scripts curl jq git gnused gnugrep libplist undmg 3 + set -euo pipefail 4 5 6 # executing this script without arguments will ··· 21 22 channel="${1:-stable}" # stable/candidate/edge 23 nixpkgs="$(git rev-parse --show-toplevel)" 24 25 + update_linux() { 26 + nix_file="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix" 27 + # 28 + # find the newest stable spotify version available on snapcraft 29 + # 30 31 + # create bash array from snap info 32 + snap_info=($( 33 + curl -s -H 'X-Ubuntu-Series: 16' \ 34 + "https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \ 35 + | jq --raw-output \ 36 + '.revision,.download_sha512,.version,.last_updated' 37 + )) 38 39 + # "revision" is the actual version identifier on snapcraft, the "version" is 40 + # just for human consumption. Revision is just an integer that gets increased 41 + # by one every (stable or unstable) release. 42 + revision="${snap_info[0]}" 43 + # We need to escape the slashes 44 + hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')" 45 + upstream_version="${snap_info[2]}" 46 + last_updated="${snap_info[3]}" 47 + echo "Latest $channel release for Spotify on Linux is $upstream_version from $last_updated." 48 + # 49 + # read the current spotify version from the currently *committed* nix expression 50 + # 51 52 + current_nix_version=$( 53 + grep 'version\s*=' "$nix_file" \ 54 + | sed -Ene 's/.*"(.*)".*/\1/p' 55 + ) 56 57 + echo "Current Spotify for Linux version in Nixpkgs: $current_nix_version" 58 59 + # 60 + # update the nix expression if the versions differ 61 + # 62 63 + if [[ "$current_nix_version" = "$upstream_version" ]]; then 64 + echo "Spotify on Linux is already up-to-date" 65 + return 66 + fi 67 68 + echo "Updating Spotify on Linux from ${current_nix_version} to ${upstream_version}, released on ${last_updated}" 69 70 + # search-and-replace revision, hash and version 71 + sed --regexp-extended \ 72 + -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \ 73 + -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \ 74 + -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \ 75 + -i "$nix_file" 76 + } 77 78 + update_macos() { 79 + nix_file="$nixpkgs/pkgs/by-name/sp/spotify/darwin.nix" 80 81 + tmp_dir=$(mktemp -d) 82 + trap 'rm -rf "$tmp_dir"' EXIT 83 84 + pushd $tmp_dir 85 86 + x86_64_url="https://download.scdn.co/Spotify.dmg" 87 + aarch64_url="https://download.scdn.co/SpotifyARM64.dmg" 88 + 89 + curl -OL $aarch64_url 90 + undmg SpotifyARM64.dmg 91 + upstream_version=$(plistutil -i Spotify.app/Contents/Info.plist -f json -o - | jq -r '.CFBundleVersion') 92 + 93 + popd 94 + 95 + current_nix_version=$( 96 + grep 'version\s*=' "$nix_file" \ 97 + | sed -Ene 's/.*"(.*)".*/\1/p' 98 + ) 99 + 100 + if [[ "$current_nix_version" != "$upstream_version" ]]; then 101 + archive_url="https://web.archive.org/save" 102 + archived_x86_64_url=$(curl -s -I -L -o /dev/null "$archive_url/$x86_64_url" -w '%{url_effective}') 103 + archived_aarch64_url=$(curl -s -I -L -o /dev/null "$archive_url/$aarch64_url" -w '%{url_effective}') 104 + 105 + update-source-version "pkgsCross.x86_64-darwin.spotify" "$upstream_version" "" "$archived_x86_64_url" \ 106 + --file=$nix_file \ 107 + --ignore-same-version 108 + 109 + update-source-version "pkgsCross.aarch64-darwin.spotify" "$upstream_version" "" "$archived_aarch64_url" \ 110 + --file=$nix_file \ 111 + --ignore-same-version 112 + fi 113 + } 114 + 115 + update_linux 116 + update_macos