spotify: add macOS support to update script
This commit is contained in:
parent
d1578f3c7e
commit
cbeeccddb0
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#! nix-shell -i bash -p curl jq git gnused gnugrep
|
#! nix-shell -i bash -p common-updater-scripts curl jq git gnused gnugrep libplist undmg
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
||||||
# executing this script without arguments will
|
# executing this script without arguments will
|
||||||
@ -20,69 +21,96 @@
|
|||||||
|
|
||||||
channel="${1:-stable}" # stable/candidate/edge
|
channel="${1:-stable}" # stable/candidate/edge
|
||||||
nixpkgs="$(git rev-parse --show-toplevel)"
|
nixpkgs="$(git rev-parse --show-toplevel)"
|
||||||
spotify_nix="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix"
|
|
||||||
|
|
||||||
|
update_linux() {
|
||||||
|
nix_file="$nixpkgs/pkgs/by-name/sp/spotify/linux.nix"
|
||||||
|
#
|
||||||
|
# find the newest stable spotify version available on snapcraft
|
||||||
|
#
|
||||||
|
|
||||||
#
|
# create bash array from snap info
|
||||||
# find the newest stable spotify version avaiable on snapcraft
|
snap_info=($(
|
||||||
#
|
curl -s -H 'X-Ubuntu-Series: 16' \
|
||||||
|
"https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \
|
||||||
|
| jq --raw-output \
|
||||||
|
'.revision,.download_sha512,.version,.last_updated'
|
||||||
|
))
|
||||||
|
|
||||||
# create bash array from snap info
|
# "revision" is the actual version identifier on snapcraft, the "version" is
|
||||||
snap_info=($(
|
# just for human consumption. Revision is just an integer that gets increased
|
||||||
curl -s -H 'X-Ubuntu-Series: 16' \
|
# by one every (stable or unstable) release.
|
||||||
"https://api.snapcraft.io/api/v1/snaps/details/spotify?channel=$channel" \
|
revision="${snap_info[0]}"
|
||||||
| jq --raw-output \
|
# We need to escape the slashes
|
||||||
'.revision,.download_sha512,.version,.last_updated'
|
hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
|
||||||
))
|
upstream_version="${snap_info[2]}"
|
||||||
|
last_updated="${snap_info[3]}"
|
||||||
|
echo "Latest $channel release for Spotify on Linux is $upstream_version from $last_updated."
|
||||||
|
#
|
||||||
|
# read the current spotify version from the currently *committed* nix expression
|
||||||
|
#
|
||||||
|
|
||||||
# "revision" is the actual version identifier on snapcraft, the "version" is
|
current_nix_version=$(
|
||||||
# just for human consumption. Revision is just an integer that gets increased
|
grep 'version\s*=' "$nix_file" \
|
||||||
# by one every (stable or unstable) release.
|
| sed -Ene 's/.*"(.*)".*/\1/p'
|
||||||
revision="${snap_info[0]}"
|
)
|
||||||
# We need to escape the slashes
|
|
||||||
hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
|
|
||||||
upstream_version="${snap_info[2]}"
|
|
||||||
last_updated="${snap_info[3]}"
|
|
||||||
echo "Latest $channel release is $upstream_version from $last_updated."
|
|
||||||
#
|
|
||||||
# read the current spotify version from the currently *committed* nix expression
|
|
||||||
#
|
|
||||||
|
|
||||||
current_nix_version=$(
|
echo "Current Spotify for Linux version in Nixpkgs: $current_nix_version"
|
||||||
grep 'version\s*=' "$spotify_nix" \
|
|
||||||
| sed -Ene 's/.*"(.*)".*/\1/p'
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Current nix version: $current_nix_version"
|
#
|
||||||
|
# update the nix expression if the versions differ
|
||||||
|
#
|
||||||
|
|
||||||
#
|
if [[ "$current_nix_version" = "$upstream_version" ]]; then
|
||||||
# update the nix expression if the versions differ
|
echo "Spotify on Linux is already up-to-date"
|
||||||
#
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$current_nix_version" = "$upstream_version" ]]; then
|
echo "Updating Spotify on Linux from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
|
||||||
echo "Spotify is already up-to-date"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Updating from ${current_nix_version} to ${upstream_version}, released on ${last_updated}"
|
# search-and-replace revision, hash and version
|
||||||
|
sed --regexp-extended \
|
||||||
|
-e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
|
||||||
|
-e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
|
||||||
|
-e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
|
||||||
|
-i "$nix_file"
|
||||||
|
}
|
||||||
|
|
||||||
# search-and-replace revision, hash and version
|
update_macos() {
|
||||||
sed --regexp-extended \
|
nix_file="$nixpkgs/pkgs/by-name/sp/spotify/darwin.nix"
|
||||||
-e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
|
|
||||||
-e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
|
|
||||||
-e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
|
|
||||||
-i "$spotify_nix"
|
|
||||||
|
|
||||||
#
|
tmp_dir=$(mktemp -d)
|
||||||
# try to build the updated version
|
trap 'rm -rf "$tmp_dir"' EXIT
|
||||||
#
|
|
||||||
|
|
||||||
export NIXPKGS_ALLOW_UNFREE=1
|
pushd $tmp_dir
|
||||||
if ! nix-build -A spotify "$nixpkgs"; then
|
|
||||||
echo "The updated spotify failed to build."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Commit changes
|
x86_64_url="https://download.scdn.co/Spotify.dmg"
|
||||||
git add "$spotify_nix"
|
aarch64_url="https://download.scdn.co/SpotifyARM64.dmg"
|
||||||
git commit -m "spotify: ${current_nix_version} -> ${upstream_version}"
|
|
||||||
|
curl -OL $aarch64_url
|
||||||
|
undmg SpotifyARM64.dmg
|
||||||
|
upstream_version=$(plistutil -i Spotify.app/Contents/Info.plist -f json -o - | jq -r '.CFBundleVersion')
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
current_nix_version=$(
|
||||||
|
grep 'version\s*=' "$nix_file" \
|
||||||
|
| sed -Ene 's/.*"(.*)".*/\1/p'
|
||||||
|
)
|
||||||
|
|
||||||
|
if [[ "$current_nix_version" != "$upstream_version" ]]; then
|
||||||
|
archive_url="https://web.archive.org/save"
|
||||||
|
archived_x86_64_url=$(curl -s -I -L -o /dev/null "$archive_url/$x86_64_url" -w '%{url_effective}')
|
||||||
|
archived_aarch64_url=$(curl -s -I -L -o /dev/null "$archive_url/$aarch64_url" -w '%{url_effective}')
|
||||||
|
|
||||||
|
update-source-version "pkgsCross.x86_64-darwin.spotify" "$upstream_version" "" "$archived_x86_64_url" \
|
||||||
|
--file=$nix_file \
|
||||||
|
--ignore-same-version
|
||||||
|
|
||||||
|
update-source-version "pkgsCross.aarch64-darwin.spotify" "$upstream_version" "" "$archived_aarch64_url" \
|
||||||
|
--file=$nix_file \
|
||||||
|
--ignore-same-version
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_linux
|
||||||
|
update_macos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user