#!/bin/bash # Stop on any error set -e echo "Starting Librespot installation and setup..." # Step 1: Update and Install Dependencies echo "Updating system and installing required dependencies..." sudo apt update && sudo apt upgrade -y sudo apt install -y build-essential git libasound2-dev libavahi-client-dev avahi-daemon avahi-utils cargo # Step 2: Clone or Update Librespot Repository if [ ! -d "librespot" ]; then echo "Cloning Librespot repository..." git clone https://github.com/librespot-org/librespot.git else echo "Updating Librespot repository..." cd librespot && git pull && cd .. fi # Step 3: Build Librespot with ALSA and Zeroconf Discovery echo "Building Librespot with ALSA and Avahi support..." cd librespot cargo clean cargo build --release --no-default-features --features "alsa-backend with-avahi" # Step 4: Move Binary to Secured Location echo "Moving Librespot binary to /opt/librespot..." sudo mkdir -p /opt/librespot sudo cp target/release/librespot /opt/librespot/ sudo chmod 755 /opt/librespot/librespot # Step 5: Protect Binary from Updates echo "Protecting Librespot binary from accidental modifications..." sudo chattr +i /opt/librespot/librespot # Step 6: Create and Configure Systemd Service echo "Setting up Librespot as a systemd service..." sudo bash -c 'cat > /etc/systemd/system/librespot.service' <