39 lines
1.3 KiB
Bash
Executable File
39 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Convenience runner for the Discord netradio relay.
|
|
#
|
|
# On first run it creates a local virtualenv and installs dependencies; on
|
|
# every run it starts the bot, which streams for the configured duration and
|
|
# then exits. Safe to call directly from cron.
|
|
#
|
|
# Cron example — transmit for 5 minutes every day at 18:00:
|
|
# 0 18 * * * /path/to/run.sh >> /path/to/radio.log 2>&1
|
|
#
|
|
# The bot token can be provided via the DISCORD_BOT_TOKEN environment variable
|
|
# or the "token" field in radioconfig.json.
|
|
|
|
set -euo pipefail
|
|
|
|
# Resolve the directory this script lives in, so cron's cwd doesn't matter.
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
VENV_DIR="$SCRIPT_DIR/.venv"
|
|
PYTHON="${PYTHON:-python3}"
|
|
|
|
# Require ffmpeg — discord.py shells out to it for audio.
|
|
if ! command -v ffmpeg >/dev/null 2>&1; then
|
|
echo "ERROR: ffmpeg not found on PATH. Install it (e.g. 'sudo pacman -S ffmpeg')." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Create the virtualenv and install deps on first run.
|
|
if [[ ! -d "$VENV_DIR" ]]; then
|
|
echo "Setting up virtualenv in $VENV_DIR ..."
|
|
"$PYTHON" -m venv "$VENV_DIR"
|
|
"$VENV_DIR/bin/pip" install --upgrade pip >/dev/null
|
|
"$VENV_DIR/bin/pip" install -r "$SCRIPT_DIR/requirements.txt"
|
|
fi
|
|
|
|
exec "$VENV_DIR/bin/python" "$SCRIPT_DIR/radio_bot.py" "$@"
|