38 lines
1.6 KiB
Bash
38 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Mopidy entrypoint — runs as root, fixes permissions, then drops to mopidy user.
|
|
set -e
|
|
|
|
# Fix ownership of the data volume (may be stale from a previous container build
|
|
# with a different mopidy uid, or from Docker initialising a new volume as root).
|
|
chown -R mopidy:audio /var/lib/mopidy 2>/dev/null || true
|
|
|
|
FIFO=/audio/mopidy.fifo
|
|
|
|
# Create FIFO if missing (init-pipes.sh should have done this, but be safe)
|
|
if [[ ! -p "$FIFO" ]]; then
|
|
echo "[mopidy] Creating FIFO: $FIFO"
|
|
mkfifo "$FIFO"
|
|
chmod 666 "$FIFO"
|
|
fi
|
|
|
|
echo "[mopidy] FIFO ready: $FIFO"
|
|
|
|
# Load Spotify credentials from shared config volume (written by the settings UI).
|
|
# Values here take precedence over env vars from docker-compose / .env.
|
|
_SPOTIFY_JSON=/config/shared/spotify.json
|
|
if [[ -f "$_SPOTIFY_JSON" ]]; then
|
|
_ID=$(python3 -c "import json; d=json.load(open('$_SPOTIFY_JSON')); print(d.get('client_id',''))" 2>/dev/null || true)
|
|
_SEC=$(python3 -c "import json; d=json.load(open('$_SPOTIFY_JSON')); print(d.get('client_secret',''))" 2>/dev/null || true)
|
|
[[ -n "$_ID" ]] && export SPOTIFY_CLIENT_ID="$_ID"
|
|
[[ -n "$_SEC" ]] && export SPOTIFY_CLIENT_SECRET="$_SEC"
|
|
echo "[mopidy] Spotify credentials loaded from shared config"
|
|
fi
|
|
|
|
# Expand only our own vars — leave Mopidy's $XDG_* vars untouched
|
|
envsubst '${SPOTIFY_CLIENT_ID}${SPOTIFY_CLIENT_SECRET}${SNAPSERVER_HOST}${BEETS_HOST}' \
|
|
< /config/mopidy.conf > /tmp/mopidy.conf
|
|
echo "[mopidy] Config expanded from template"
|
|
|
|
# Drop from root → mopidy user for the actual Mopidy process
|
|
exec gosu mopidy "$@"
|