Files
sonos-aux-recordplayer-pi/install.sh
Geert Rademakers 9529f1b0e1 Add one-command install script and stability fixes
- Add install.sh for automated setup
- Add all component files (wrapper, service, config, verify)
- Add stability fixes section (WiFi PowerSave disable + Watchdog)
- Update README with new installation instructions
2026-02-17 23:17:38 +01:00

163 lines
4.4 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -euo pipefail
# Master installation script for Record Player Pi → Sonos AUX
# Usage: curl -fsSL https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi/raw/branch/master/install.sh | bash
# Or: wget -qO- https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi/raw/branch/master/install.sh | bash
REPO_URL="https://git.geertrademakers.nl/master/sonos-aux-recordplayer-pi.git"
INSTALL_DIR="/home/pi/sonos-aux-recordplayer-pi"
USER_HOME="/home/pi"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >&2
}
error() {
log "❌ ERROR: $*"
exit 1
}
success() {
log "$*"
}
info() {
log " $*"
}
# Check if running as root for certain operations
check_sudo() {
if ! sudo -n true 2>/dev/null; then
info "This script requires sudo privileges. You may be prompted for your password."
fi
}
# Detect if we're on a Raspberry Pi
check_pi() {
if [ ! -f /proc/device-tree/model ] || ! grep -q "Raspberry Pi" /proc/device-tree/model 2>/dev/null; then
info "⚠️ Warning: This doesn't appear to be a Raspberry Pi. Continuing anyway..."
fi
}
# Install prerequisites
install_prerequisites() {
info "Installing prerequisites..."
sudo apt-get update -qq
sudo apt-get install -y darkice icecast2 alsa-utils curl wget git || error "Failed to install prerequisites"
success "Prerequisites installed"
}
# Clone or update repository
setup_repo() {
if [ -d "$INSTALL_DIR" ]; then
info "Repository exists, updating..."
cd "$INSTALL_DIR"
git pull || error "Failed to update repository"
else
info "Cloning repository..."
git clone "$REPO_URL" "$INSTALL_DIR" || error "Failed to clone repository"
cd "$INSTALL_DIR"
fi
success "Repository ready"
}
# Fix USB audio to always be card 0
fix_usb_audio() {
info "Configuring USB audio as card 0..."
# Blacklist built-in audio
if ! grep -q "blacklist snd_bcm2835" /etc/modprobe.d/raspi-blacklist.conf 2>/dev/null; then
echo "blacklist snd_bcm2835" | sudo tee -a /etc/modprobe.d/raspi-blacklist.conf >/dev/null
fi
# Fix USB audio index
if [ -f /lib/modprobe.d/aliases.conf ]; then
sudo sed -i 's/^options snd-usb-audio index=-2/#options snd-usb-audio index=-2/' /lib/modprobe.d/aliases.conf
fi
success "USB audio configuration updated (reboot required for full effect)"
}
# Deploy files
deploy_files() {
info "Deploying files..."
# Copy wrapper script
sudo cp "$INSTALL_DIR/03-darkice-wrapper.sh" "$USER_HOME/darkice-wrapper.sh"
sudo chmod +x "$USER_HOME/darkice-wrapper.sh"
sudo chown root:audio "$USER_HOME/darkice-wrapper.sh"
sudo chmod 755 "$USER_HOME/darkice-wrapper.sh"
# Copy systemd service
sudo cp "$INSTALL_DIR/04-sonos-aux.service" /etc/systemd/system/sonos-aux.service
# Copy config if it doesn't exist
if [ ! -f "$USER_HOME/darkice.cfg" ]; then
cp "$INSTALL_DIR/darkice.cfg.example" "$USER_HOME/darkice.cfg"
info "📝 Created darkice.cfg - please edit password and mountPoint!"
else
info "darkice.cfg already exists, skipping..."
fi
success "Files deployed"
}
# Setup Icecast
setup_icecast() {
info "Setting up Icecast2..."
sudo systemctl enable icecast2 || true
sudo systemctl start icecast2 || true
success "Icecast2 configured"
}
# Setup systemd service
setup_service() {
info "Setting up systemd service..."
sudo systemctl daemon-reload
sudo systemctl enable sonos-aux.service
success "Systemd service enabled"
}
# Main installation
main() {
log "🚀 Starting Record Player Pi → Sonos AUX installation..."
check_sudo
check_pi
install_prerequisites
setup_repo
fix_usb_audio
deploy_files
setup_icecast
setup_service
echo ""
success "Installation complete!"
echo ""
info "Next steps:"
echo " 1. Edit darkice.cfg: nano $USER_HOME/darkice.cfg"
echo " - Change 'password' to your Icecast source password"
echo " - Change 'mountPoint' if desired"
echo ""
echo " 2. Reboot: sudo reboot"
echo ""
echo " 3. After reboot, verify:"
echo " - journalctl -u sonos-aux.service -f"
echo " - Or run: $INSTALL_DIR/verify.sh"
echo ""
echo " 4. Add to Sonos: http://<pi-ip>:8000/rapi.mp3"
echo ""
}
# Run main function
main "$@"