#!/usr/bin/env bash # SpotX-Bash + spicetify (Marketplace) on Gentoo's media-sound/spotify. # Run as your regular user after the first setup and after every Spotify update. # Write access must be configured explicitly before opting in. set -euo pipefail client=/opt/spotify/spotify-client spotx_url=https://raw.githubusercontent.com/SpotX-Official/SpotX-Bash/main/spotx.sh spicetify=$HOME/.spicetify/spicetify [[ -w $client/Apps/xpui.spa && -w $client/spotify ]] || { echo "No write access to $client. Review docs/spotify.md and configure client write access explicitly before opting in." >&2 exit 1 } echo "Closing Spotify..." pkill -TERM -x spotify 2>/dev/null || true for _ in {1..40}; do pgrep -x spotify >/dev/null || break; sleep 0.25; done pgrep -x spotify >/dev/null && { echo "Spotify is still running, close it and retry." >&2; exit 1; } if [[ -f $client/Apps/xpui.spa ]]; then # A Spotify update puts stock *.spa back but leaves the unowned dirs of the old # spicetify apply. Spicetify's backup is from the old build too: never restore it. rm -rf -- "$client/Apps/xpui" "$client/Apps/login" else # Undo spicetify first, so xpui.spa is stock or SpotX-only again. "$spicetify" restore >/dev/null 2>&1 /dev/null | awk '{print $3}') old=$("$bak" --version 2>/dev/null | awk '{print $3}' || true) if [[ ! -f $bak || ! -f $xbak || $cur != "$old" ]]; then arch=${XDG_STATE_HOME:-$HOME/.local/state}/spotify-patch/stale-$(date +%Y%m%d-%H%M%S) mkdir -p "$arch" mv -f -- "$bak" "$xbak" "$arch/" 2>/dev/null || true echo "Moved stale SpotX backups to $arch" fi fi # SpotX asks for sudo on files you do not own, and an update leaves them # root-owned. The directory ACL lets you swap them for copies you own. for f in "$client/spotify" "$client/Apps/xpui.spa"; do [[ -O $f ]] || { cp -p -- "$f" "$f.fiw" && mv -f -- "$f.fiw" "$f"; } done tmp=$(mktemp --tmpdir spotx.XXXXXXXX.sh) trap 'rm -f -- "$tmp"' EXIT curl --proto '=https' --tlsv1.2 -fsSL "$spotx_url" -o "$tmp" echo "SpotX-Bash sha256: $(sha256sum "$tmp" | cut -d' ' -f1)" bash "$tmp" -f -P "$client" "$@" # Fresh spicetify backup of the SpotX-patched client, then apply. "$spicetify" clear >/dev/null 2>&1 || true "$spicetify" backup apply --no-restart # spicetify patches custom apps (Marketplace) into xpui-modules.js only "$HOME/.local/bin/spicetify-snapshotfix" nohup spotify --enable-features=UseOzonePlatform --ozone-platform=wayland >/dev/null 2>&1 & echo "Done."