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