87 lines
4 KiB
Shell
Executable file
87 lines
4 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# Mulberry installer for Linux (per-user, no root needed).
|
|
#
|
|
# ./install.sh build the release binary from source and install it (or update)
|
|
# ./install.sh --uninstall remove the app, menu entry and icon (keeps your library/settings)
|
|
# ./install.sh --purge uninstall AND delete your library, playlists, settings and caches
|
|
# ./install.sh --help
|
|
set -euo pipefail
|
|
|
|
SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
|
|
CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
|
|
BIN="$HOME/.local/bin"
|
|
APPS="$DATA_HOME/applications"
|
|
ICON="$DATA_HOME/icons/hicolor/scalable/apps/mulberry.svg"
|
|
|
|
bold() { printf '\033[1m%s\033[0m\n' "$*"; }
|
|
ok() { printf ' \033[32m✓\033[0m %s\n' "$*"; }
|
|
warn() { printf ' \033[33m!\033[0m %s\n' "$*"; }
|
|
die() { printf ' \033[31m✗ %s\033[0m\n' "$*" >&2; exit 1; }
|
|
|
|
refresh_menus() {
|
|
command -v update-desktop-database >/dev/null && update-desktop-database "$APPS" 2>/dev/null || true
|
|
command -v kbuildsycoca6 >/dev/null && kbuildsycoca6 >/dev/null 2>&1 || true
|
|
command -v gtk-update-icon-cache >/dev/null && gtk-update-icon-cache -q "$DATA_HOME/icons/hicolor" 2>/dev/null || true
|
|
}
|
|
|
|
uninstall() {
|
|
bold "==> Uninstalling Mulberry"
|
|
pkill -x mulberry 2>/dev/null || true
|
|
rm -f "$BIN/mulberry" && ok "removed $BIN/mulberry"
|
|
rm -f "$APPS/mulberry.desktop" && ok "removed menu entry"
|
|
rm -f "$ICON" && ok "removed icon"
|
|
refresh_menus
|
|
if [[ "${1:-}" == "purge" ]]; then
|
|
rm -rf "$DATA_HOME/mulberry" "$CONFIG_HOME/mulberry" "$CACHE_HOME/mulberry"
|
|
ok "deleted library, playlists, settings and caches"
|
|
else
|
|
echo " Your library, playlists and settings were kept in:"
|
|
echo " $DATA_HOME/mulberry and $CONFIG_HOME/mulberry"
|
|
echo " (run ./install.sh --purge to delete them too)"
|
|
fi
|
|
bold "Done."
|
|
}
|
|
|
|
case "${1:-}" in
|
|
-h|--help) sed -n '2,7p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
--uninstall|uninstall) uninstall; exit 0 ;;
|
|
--purge|purge) uninstall purge; exit 0 ;;
|
|
""|--install|install|--update|update) ;;
|
|
*) die "unknown option: $1 (try --help)" ;;
|
|
esac
|
|
|
|
bold "==> Checking requirements"
|
|
command -v cargo >/dev/null || die "cargo not found — install Rust (https://rustup.rs, or: sudo pacman -S rust)"
|
|
ok "$(cargo --version)"
|
|
(/sbin/ldconfig -p 2>/dev/null || ldconfig -p 2>/dev/null) | grep 'libmpv.so' >/dev/null || die "libmpv not found — Arch: sudo pacman -S mpv · Debian/Ubuntu: sudo apt install libmpv-dev · Fedora: sudo dnf install mpv-libs-devel"
|
|
ok "libmpv"
|
|
missing=()
|
|
command -v ffmpeg >/dev/null || missing+=("ffmpeg — visualizer analysis and CD rip encoding")
|
|
command -v cdparanoia >/dev/null || missing+=("cdparanoia — CD ripping")
|
|
command -v yt-dlp >/dev/null || missing+=("yt-dlp — YouTube / SoundCloud / Bandcamp links")
|
|
command -v parec >/dev/null || missing+=("parec (pulseaudio-utils / pipewire-pulse) — visualizer for radio streams")
|
|
if ((${#missing[@]})); then
|
|
warn "Optional tools not found:"
|
|
for m in "${missing[@]}"; do echo " - $m"; done
|
|
echo " Arch: sudo pacman -S ffmpeg cdparanoia yt-dlp libpulse"
|
|
fi
|
|
|
|
bold "==> Building (release)"
|
|
(cd "$SRC" && cargo build --release)
|
|
ok "built $SRC/target/release/mulberry"
|
|
|
|
bold "==> Installing"
|
|
mkdir -p "$BIN" "$APPS" "$(dirname "$ICON")"
|
|
if [[ -L "$BIN/mulberry" ]]; then
|
|
mv "$BIN/mulberry" "$BIN/mulberry.old" && warn "kept your previous launcher as $BIN/mulberry.old"
|
|
elif [[ -e "$BIN/mulberry" ]] && ! cmp -s "$BIN/mulberry" "$SRC/target/release/mulberry"; then
|
|
mv "$BIN/mulberry" "$BIN/mulberry.old" && warn "kept your previous launcher as $BIN/mulberry.old"
|
|
fi
|
|
install -m755 "$SRC/target/release/mulberry" "$BIN/mulberry" && ok "installed $BIN/mulberry"
|
|
install -m644 "$SRC/packaging/mulberry.svg" "$ICON" && ok "installed icon"
|
|
install -m644 "$SRC/packaging/mulberry.desktop" "$APPS/mulberry.desktop" && ok "installed menu entry"
|
|
refresh_menus
|
|
case ":$PATH:" in *":$BIN:"*) ;; *) warn "$BIN is not on your PATH" ;; esac
|
|
bold "Done. Start it from the app menu or with: mulberry"
|