radio/scripts/setup.sh
profit 3d635b742c Initial commit: self-hosted personal radio station
Flask + React web UI with audio player, podcast queue, feed management,
episode browser, music library, schedule viewer, and log tail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 19:01:33 -07:00

115 lines
4.3 KiB
Bash

#!/usr/bin/env bash
# =============================================================================
# Local Radio Station — Initial Setup Script
# Run as root on Debian 13
# =============================================================================
set -euo pipefail
INSTALL_DIR="/opt/localradio"
RADIO_USER="localradio"
RADIO_GROUP="localradio"
echo "=== Local Radio Station Setup ==="
# --- Install system packages --------------------------------------------------
echo "[1/7] Installing system packages..."
apt-get update
apt-get install -y \
icecast2 \
liquidsoap \
python3 \
python3-venv \
python3-pip \
ffmpeg \
sqlite3
# --- Create system user ------------------------------------------------------
echo "[2/7] Creating system user..."
if ! id "$RADIO_USER" &>/dev/null; then
useradd --system --home-dir "$INSTALL_DIR" --shell /usr/sbin/nologin "$RADIO_USER"
echo " Created user: $RADIO_USER"
else
echo " User $RADIO_USER already exists"
fi
# --- Create directory structure -----------------------------------------------
echo "[3/7] Creating directory structure..."
mkdir -p "$INSTALL_DIR"/{config,scripts,state/queue,media/music/{morning,day,night,weekend},media/podcasts,media/fallback,logs}
# --- Copy project files -------------------------------------------------------
echo "[4/7] Copying project files..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cp "$SCRIPT_DIR/config/station.liq" "$INSTALL_DIR/config/"
cp "$SCRIPT_DIR/config/icecast.xml" "$INSTALL_DIR/config/"
cp "$SCRIPT_DIR/config/station.yaml" "$INSTALL_DIR/config/"
cp "$SCRIPT_DIR/config/localradio.env" "$INSTALL_DIR/config/"
# Only copy feeds.yaml if it doesn't already exist (preserve user edits)
if [ ! -f "$INSTALL_DIR/config/feeds.yaml" ]; then
cp "$SCRIPT_DIR/config/feeds.yaml" "$INSTALL_DIR/config/"
fi
cp "$SCRIPT_DIR/scripts/"*.py "$INSTALL_DIR/scripts/"
cp "$SCRIPT_DIR/scripts/"*.sh "$INSTALL_DIR/scripts/" 2>/dev/null || true
cp "$SCRIPT_DIR/requirements.txt" "$INSTALL_DIR/"
# Copy web UI
cp -r "$SCRIPT_DIR/web" "$INSTALL_DIR/"
# --- Set up Python virtual environment ----------------------------------------
echo "[5/7] Setting up Python virtual environment..."
python3 -m venv "$INSTALL_DIR/venv"
"$INSTALL_DIR/venv/bin/pip" install --upgrade pip
"$INSTALL_DIR/venv/bin/pip" install -r "$INSTALL_DIR/requirements.txt"
# --- Build frontend -----------------------------------------------------------
echo "[5b/7] Building frontend..."
if command -v npm &>/dev/null; then
cd "$INSTALL_DIR/web/frontend"
npm install
npm run build
cd -
echo " Frontend built successfully"
else
echo " WARNING: npm not found. Install Node.js and run:"
echo " cd $INSTALL_DIR/web/frontend && npm install && npm run build"
fi
# --- Initialize database ------------------------------------------------------
echo "[6/7] Initializing database..."
PYTHONPATH="$INSTALL_DIR/scripts" "$INSTALL_DIR/venv/bin/python" \
"$INSTALL_DIR/scripts/init_db.py" "$INSTALL_DIR/state/radio.db"
# --- Set ownership ------------------------------------------------------------
echo "[7/7] Setting file ownership..."
chown -R "$RADIO_USER:$RADIO_GROUP" "$INSTALL_DIR"
# Make scripts executable
chmod +x "$INSTALL_DIR/scripts/"*.sh 2>/dev/null || true
chmod +x "$INSTALL_DIR/scripts/"*.py
# --- Install systemd services -------------------------------------------------
echo ""
echo "=== Installing systemd services ==="
cp "$SCRIPT_DIR/systemd/"*.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable localradio-icecast localradio-stream localradio-poller localradio-web
echo ""
echo "=== Setup Complete ==="
echo ""
echo "Next steps:"
echo " 1. Add music files to $INSTALL_DIR/media/music/{morning,day,night,weekend}/"
echo " 2. Add at least one audio file to $INSTALL_DIR/media/fallback/"
echo " 3. Edit $INSTALL_DIR/config/feeds.yaml to add your podcast RSS feeds"
echo " 4. Review $INSTALL_DIR/config/icecast.xml passwords"
echo " 5. Start services:"
echo " systemctl start localradio-icecast"
echo " systemctl start localradio-stream"
echo " systemctl start localradio-poller"
echo " systemctl start localradio-web"
echo " 6. Listen at: http://localhost:8000/stream"
echo " 7. Web dashboard: http://localhost:5000"
echo ""