@@ -1,8 +1,31 @@
1−channel="stable" # stable/candidate/edge
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
6+# - find the newest stable spotify version avaiable on snapcraft (https://snapcraft.io/spotify)
7+# - read the current spotify version from the current nix expression
8+# - update the nix expression if the versions differ
9+# - try to build the updated version, exit if that fails
10+# - give instructions for upstreaming
11+
12+# Please test the update manually before pushing. There have been errors before
13+# and because the service is proprietary and a paid account is necessary to do
14+# anything with spotify automatic testing is not possible.
15+
16+# As an optional argument you can specify the snapcraft channel to update to.
17+# Default is `stable` and only stable updates should be pushed to nixpkgs. For
18+# testing you may specify `candidate` or `edge`.
19+
20+
21+channel="${1:-stable}" # stable/candidate/edge
222nixpkgs="$(git rev-parse --show-toplevel)"
323spotify_nix="$nixpkgs/pkgs/applications/audio/spotify/default.nix"
424
525
26+#
27+# find the newest stable spotify version avaiable on snapcraft
28+#
629
730# create bash array from snap info
831snap_info=($(
@@ -12,38 +35,62 @@ snap_info=($(
1235 '.revision,.download_sha512,.version,.last_updated'
1336))
1437
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.
1541revision="${snap_info[0]}"
1642sha512="${snap_info[1]}"
17−version="${snap_info[2]}"
43+upstream_version="${snap_info[2]}"
1844last_updated="${snap_info[3]}"
1945
20−# find the last commited version
21−version_pre=$(
22− git grep 'version\s*=' HEAD "$spotify_nix" \
46+echo "Latest $channel release is $upstream_version from $last_updated."
47+
48+#
49+# read the current spotify version from the currently *committed* nix expression
50+#
51+
52+current_nix_version=$(
53+ grep 'version\s*=' "$spotify_nix" \
2354 | sed -Ene 's/.*"(.*)".*/\1/p'
2455)
2556
26−if [[ "$version_pre" = "$version" ]]; then
57+echo "Current nix version: $current_nix_version"
58+
59+#
60+# update the nix expression if the versions differ
61+#
62+
63+if [[ "$current_nix_version" = "$upstream_version" ]]; then
2764 echo "Spotify is already up ot date"
2865 exit 0
2966fi
3067
31−echo "Updating from ${version_pre} to ${version}, released on ${last_updated}"
68+echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
3269
33−# search-andreplace revision, hash and version
70+# search-and-replace revision, hash and version
3471sed --regexp-extended \
3572 -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
36− -e 's/sha512\s*=\s*".{128}"\s*;/sha512 = "'"${sha512}"'";/' \
37− -e 's/version\s*=\s*".*"\s*;/version = "'"${version}"'";/' \
73+ -e 's/sha512\s*=\s*"[^"]*"\s*;/sha512 = "'"${sha512}"'";/' \
74+ -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
3875 -i "$spotify_nix"
3976
77+#
78+# try to build the updated version
79+#
80+
4081if ! nix-build -A spotify "$nixpkgs"; then
4182 echo "The updated spotify failed to build."
4283 exit 1
4384fi
4485
86+#
87+# give instructions for upstreaming
88+#
89+
4590git add "$spotify_nix"
46−# show diff for review
47−git diff HEAD
48−# prepare commit message, but allow edit
49−git commit --edit --message "spotify: $version_pre -> $version"
91+# show changes for review
92+git status
93+echo 'Please review and test the changes (./result/bin/spotify).'
94+echo 'Then stage the changes with `git add` and commit with:'
95+# prepare commit message
96+echo "git commit -m 'spotify: $current_nix_version -> $upstream_version'"