···1#!/usr/bin/env nix-shell
2-#! nix-shell -i bash -p curl jq git gnused gnugrep
0345# executing this script without arguments will
···2021channel="${1:-stable}" # stable/candidate/edge
22nixpkgs="$(git rev-parse --show-toplevel)"
23-spotify_nix="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix"
24000002526-#
27-# find the newest stable spotify version avaiable on snapcraft
28-#
00002930-# 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-))
000003738-# "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-#
5051-current_nix_version=$(
52- grep 'version\s*=' "$spotify_nix" \
53- | sed -Ene 's/.*"(.*)".*/\1/p'
54-)
5556-echo "Current nix version: $current_nix_version"
005758-#
59-# update the nix expression if the versions differ
60-#
06162-if [[ "$current_nix_version" = "$upstream_version" ]]; then
63- echo "Spotify is already up-to-date"
64- exit 0
65-fi
6667-echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
0000006869-# 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"
7576-#
77-# try to build the updated version
78-#
7980-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
8586-# Commit changes
87-git add "$spotify_nix"
88-git commit -m "spotify: ${current_nix_version} -> ${upstream_version}"
0000000000000000000000000000
···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
456# executing this script without arguments will
···2122channel="${1:-stable}" # stable/candidate/edge
23nixpkgs="$(git rev-parse --show-toplevel)"
02425+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+ #
3031+ # 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+ ))
3839+ # "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+ #
5152+ current_nix_version=$(
53+ grep 'version\s*=' "$nix_file" \
54+ | sed -Ene 's/.*"(.*)".*/\1/p'
55+ )
000000005657+ echo "Current Spotify for Linux version in Nixpkgs: $current_nix_version"
0005859+ #
60+ # update the nix expression if the versions differ
61+ #
6263+ if [[ "$current_nix_version" = "$upstream_version" ]]; then
64+ echo "Spotify on Linux is already up-to-date"
65+ return
66+ fi
6768+ echo "Updating Spotify on Linux from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
0006970+ # 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+}
7778+update_macos() {
79+ nix_file="$nixpkgs/pkgs/by-name/sp/spotify/darwin.nix"
00008081+ tmp_dir=$(mktemp -d)
82+ trap 'rm -rf "$tmp_dir"' EXIT
08384+ pushd $tmp_dir
00008586+ 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