[bin] Fix build script for snapclient
This commit is contained in:
170
bin/.local/bin/build_snapclient.sh
Normal file → Executable file
170
bin/.local/bin/build_snapclient.sh
Normal file → Executable file
@ -1,64 +1,138 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
log() { printf "\n==> %s\n" "$*"; }
|
||||
have() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
REPO_URL="https://github.com/badaix/snapcast.git"
|
||||
WORKDIR="${WORKDIR:-$HOME/tmp/snapcast}"
|
||||
PREFIX="$HOME/.local"
|
||||
PREFIX="${PREFIX:-$HOME/.local}"
|
||||
|
||||
# Ensure ~/.local/bin exists
|
||||
mkdir -p "$PREFIX/bin"
|
||||
mkdir -p "$(dirname "$WORKDIR")"
|
||||
|
||||
# --- Detect distro ---
|
||||
if [ -r /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
if [[ -r /etc/os-release ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/os-release
|
||||
else
|
||||
echo "Cannot read /etc/os-release; unsupported system." >&2
|
||||
exit 1
|
||||
echo "Cannot read /etc/os-release; unsupported system." >&2
|
||||
exit 1
|
||||
fi
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
log() { printf "\n==> %s\n" "$*"; }
|
||||
|
||||
REPO_URL="https://github.com/badaix/snapcast.git"
|
||||
WORKDIR="${WORKDIR:-$HOME/tmp/snapcast}"
|
||||
PREFIX="${PREFIX:-$HOME/.local}"
|
||||
|
||||
mkdir -p "$PREFIX/bin"
|
||||
mkdir -p "$(dirname "$WORKDIR")"
|
||||
|
||||
# --- Detect distro ---
|
||||
if [[ -r /etc/os-release ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/os-release
|
||||
else
|
||||
echo "Cannot read /etc/os-release; unsupported system." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Normalize Arch-like (EndeavourOS is Arch-based)
|
||||
IS_ARCH=0
|
||||
case "${ID:-}" in
|
||||
arch | endeavouros) IS_ARCH=1 ;;
|
||||
arch|endeavouros) IS_ARCH=1 ;;
|
||||
esac
|
||||
if [ "$IS_ARCH" -eq 0 ] && [ -n "${ID_LIKE:-}" ]; then
|
||||
echo "$ID_LIKE" | grep -qi arch && IS_ARCH=1 || true
|
||||
if [[ $IS_ARCH -eq 0 && -n "${ID_LIKE:-}" ]] && echo "$ID_LIKE" | grep -qi arch; then
|
||||
IS_ARCH=1
|
||||
fi
|
||||
|
||||
IS_FEDORA=0
|
||||
case "${ID:-}" in
|
||||
fedora) IS_FEDORA=1 ;;
|
||||
esac
|
||||
if [[ $IS_FEDORA -eq 0 && -n "${ID_LIKE:-}" ]] && echo "$ID_LIKE" | grep -qiE 'fedora|rhel'; then
|
||||
IS_FEDORA=1
|
||||
fi
|
||||
|
||||
if [[ $IS_ARCH -eq 0 && $IS_FEDORA -eq 0 ]]; then
|
||||
echo "Unsupported distro (ID=${ID:-unknown}, ID_LIKE=${ID_LIKE:-unknown})." >&2
|
||||
echo "This script supports Fedora and Arch/EndeavourOS." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Install dependencies ---
|
||||
if [ "$IS_ARCH" -eq 1 ]; then
|
||||
echo "Detected Arch/EndeavourOS. Installing dependencies with pacman..."
|
||||
sudo pacman -Sy --needed --noconfirm \
|
||||
base-devel cmake boost flac libvorbis opus alsa-lib libsoxr avahi
|
||||
if [[ $IS_ARCH -eq 1 ]]; then
|
||||
log "Detected Arch/EndeavourOS. Installing build deps with pacman..."
|
||||
sudo pacman -Sy --needed --noconfirm \
|
||||
base-devel git cmake pkgconf \
|
||||
boost flac libogg libvorbis opus alsa-lib libsoxr avahi \
|
||||
openssl expat
|
||||
else
|
||||
IS_FEDORA=0
|
||||
case "${ID:-}" in
|
||||
fedora) IS_FEDORA=1 ;;
|
||||
esac
|
||||
if [ "$IS_FEDORA" -eq 0 ] && [ -n "${ID_LIKE:-}" ]; then
|
||||
echo "$ID_LIKE" | grep -qi 'fedora\|rhel' && IS_FEDORA=1 || true
|
||||
fi
|
||||
log "Detected Fedora. Installing build deps with dnf..."
|
||||
sudo dnf install -y \
|
||||
git cmake make gcc gcc-c++ \
|
||||
pkgconf-pkg-config \
|
||||
boost-devel \
|
||||
alsa-lib-devel \
|
||||
avahi-devel \
|
||||
flac-devel \
|
||||
libogg-devel \
|
||||
libvorbis-devel \
|
||||
opus-devel \
|
||||
soxr-devel \
|
||||
expat-devel \
|
||||
openssl-devel
|
||||
fi
|
||||
|
||||
if [ "$IS_FEDORA" -eq 1 ]; then
|
||||
echo "Detected Fedora. Installing dependencies with dnf..."
|
||||
sudo dnf -y install \
|
||||
cmake gcc-c++ make git \
|
||||
boost-devel flac-devel libvorbis-devel opus-devel alsa-lib-devel libsoxr-devel avahi-devel
|
||||
else
|
||||
echo "Unsupported distro (ID=${ID:-unknown}, ID_LIKE=${ID_LIKE:-unknown})." >&2
|
||||
exit 1
|
||||
fi
|
||||
# --- Prefer system pkg-config when available (avoid linuxbrew/pkg-config issues) ---
|
||||
PKG_CONFIG_BIN="pkg-config"
|
||||
if [[ -x /usr/bin/pkg-config ]]; then
|
||||
PKG_CONFIG_BIN="/usr/bin/pkg-config"
|
||||
fi
|
||||
|
||||
# Clear env that commonly breaks pkg-config discovery (esp. with linuxbrew)
|
||||
unset PKG_CONFIG_PATH PKG_CONFIG_LIBDIR CMAKE_PREFIX_PATH CPATH LIBRARY_PATH LD_LIBRARY_PATH
|
||||
|
||||
# Force known-good pkg-config search dirs on Linux (Fedora/Arch)
|
||||
if [[ "$(uname -s)" == "Linux" ]]; then
|
||||
# Arch uses /usr/lib/pkgconfig; Fedora uses /usr/lib64/pkgconfig
|
||||
export PKG_CONFIG_LIBDIR="/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig"
|
||||
fi
|
||||
|
||||
log "Using pkg-config at: $PKG_CONFIG_BIN"
|
||||
"$PKG_CONFIG_BIN" --version || true
|
||||
|
||||
# --- Show which pkg-config modules are available ---
|
||||
log "Checking required pkg-config modules..."
|
||||
REQ_MODULES=(alsa avahi-client flac ogg vorbis vorbisenc opus soxr)
|
||||
missing=()
|
||||
for m in "${REQ_MODULES[@]}"; do
|
||||
if "$PKG_CONFIG_BIN" --exists "$m"; then
|
||||
printf " [OK] %s\n" "$m"
|
||||
else
|
||||
printf " [MISSING] %s\n" "$m"
|
||||
missing+=("$m")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing[@]} -ne 0 ]]; then
|
||||
echo
|
||||
echo "Missing pkg-config modules: ${missing[*]}" >&2
|
||||
echo "If you're on Fedora, double-check the devel packages installed:" >&2
|
||||
echo " sudo dnf install -y alsa-lib-devel avahi-devel flac-devel libogg-devel libvorbis-devel opus-devel soxr-devel pkgconf-pkg-config" >&2
|
||||
echo "Also ensure you're not using linuxbrew's pkg-config (which pkg-config should be /usr/bin/pkg-config)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Fetch source ---
|
||||
mkdir -p "$(dirname "$WORKDIR")"
|
||||
|
||||
if [ -d "$WORKDIR/.git" ]; then
|
||||
echo "Updating existing Snapcast repo..."
|
||||
git -C "$WORKDIR" pull --rebase
|
||||
if [[ -d "$WORKDIR/.git" ]]; then
|
||||
log "Repo exists. Updating..."
|
||||
git -C "$WORKDIR" pull --rebase
|
||||
else
|
||||
echo "Cloning Snapcast..."
|
||||
git clone "$REPO_URL" "$WORKDIR"
|
||||
log "Cloning Snapcast..."
|
||||
git clone "$REPO_URL" "$WORKDIR"
|
||||
fi
|
||||
|
||||
# --- Build snapclient only ---
|
||||
@ -66,19 +140,17 @@ cd "$WORKDIR"
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
echo "Configuring with prefix=$PREFIX"
|
||||
log "Configuring (install prefix: $PREFIX)"
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DBUILD_SERVER=OFF \
|
||||
-DBUILD_CLIENT=ON
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DBUILD_SERVER=OFF \
|
||||
-DBUILD_CLIENT=ON
|
||||
|
||||
echo "Building..."
|
||||
log "Building..."
|
||||
make -j"$(nproc)"
|
||||
|
||||
echo "Installing to $PREFIX/bin (no sudo)..."
|
||||
log "Installing to $PREFIX/bin (no sudo)..."
|
||||
make install
|
||||
|
||||
echo
|
||||
echo "Done 🎧"
|
||||
echo "Make sure ~/.local/bin is on your PATH."
|
||||
echo "Test with: snapclient --version"
|
||||
log "Done."
|
||||
echo "Try: $PREFIX/bin/snapclient --version"
|
||||
|
||||
12
systemd/.config/systemd/user/localsnapclient.service
Normal file
12
systemd/.config/systemd/user/localsnapclient.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Snapclient
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile="/etc/snapclient.env"
|
||||
ExecStart=/home/powellc/.local/bin/snapclient -h snapcast.service $EXTRA_ARGS -s 3
|
||||
ExecStop=kill $(pidof snapclient)
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Reference in New Issue
Block a user