mirror of
https://github.com/mistergibson/radio.git
synced 2026-09-09 06:19:52 -07:00
fixed python venv (installer)
This commit is contained in:
parent
7a57591820
commit
30aeaa4b21
1 changed files with 27 additions and 11 deletions
|
|
@ -2,8 +2,9 @@
|
||||||
#
|
#
|
||||||
# install_for_python.sh - Installs the Python-based radio automation stack.
|
# install_for_python.sh - Installs the Python-based radio automation stack.
|
||||||
# Derives its service name from the directory it lives in, prompts for a
|
# Derives its service name from the directory it lives in, prompts for a
|
||||||
# storage path (kept out of the boot drive), writes config.json, creates
|
# storage path (kept out of the boot drive), creates a virtualenv for
|
||||||
# the systemd unit, and sets up cron entries.
|
# dependencies, writes config.json, creates the systemd unit, and sets up
|
||||||
|
# cron entries.
|
||||||
#
|
#
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
@ -12,6 +13,8 @@ DIR_NAME="$(basename "$SCRIPT_DIR")"
|
||||||
SERVICE_NAME="${DIR_NAME}"
|
SERVICE_NAME="${DIR_NAME}"
|
||||||
SYSTEMD_UNIT="/etc/systemd/system/${SERVICE_NAME}.service"
|
SYSTEMD_UNIT="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||||
CONFIG_FILE="${SCRIPT_DIR}/config.json"
|
CONFIG_FILE="${SCRIPT_DIR}/config.json"
|
||||||
|
VENV_DIR="${SCRIPT_DIR}/.venv"
|
||||||
|
PYBIN="${VENV_DIR}/bin/python3"
|
||||||
|
|
||||||
echo "=== ${SERVICE_NAME} installer (Python) ==="
|
echo "=== ${SERVICE_NAME} installer (Python) ==="
|
||||||
echo "Install dir: ${SCRIPT_DIR}"
|
echo "Install dir: ${SCRIPT_DIR}"
|
||||||
|
|
@ -25,8 +28,8 @@ mkdir -p "${STORAGE_PATH}"/{music,podcasts,jingles,announcements,state,playlists
|
||||||
chown -R liquidsoap:liquidsoap "${STORAGE_PATH}" 2>/dev/null || true
|
chown -R liquidsoap:liquidsoap "${STORAGE_PATH}" 2>/dev/null || true
|
||||||
|
|
||||||
# --- Collect Icecast credentials ------------------------------------------
|
# --- Collect Icecast credentials ------------------------------------------
|
||||||
read -rp "Icecast source port [8000]: " IC_PORT
|
read -rp "Icecast source port [7777]: " IC_PORT
|
||||||
IC_PORT="${IC_PORT:-8000}"
|
IC_PORT="${IC_PORT:-7777}"
|
||||||
read -rp "Icecast mount [/radio.mp3]: " IC_MOUNT
|
read -rp "Icecast mount [/radio.mp3]: " IC_MOUNT
|
||||||
IC_MOUNT="${IC_MOUNT:-/radio.mp3}"
|
IC_MOUNT="${IC_MOUNT:-/radio.mp3}"
|
||||||
read -rp "Icecast source username [sourceadmin]: " IC_USER
|
read -rp "Icecast source username [sourceadmin]: " IC_USER
|
||||||
|
|
@ -40,8 +43,12 @@ case "${GPODDER_ENABLE,,}" in
|
||||||
y|yes)
|
y|yes)
|
||||||
read -rp "gPodder host [https://gpodder.net]: " GP_HOST
|
read -rp "gPodder host [https://gpodder.net]: " GP_HOST
|
||||||
GP_HOST="${GP_HOST:-https://gpodder.net}"
|
GP_HOST="${GP_HOST:-https://gpodder.net}"
|
||||||
|
# Strip trailing slash if the user typed one
|
||||||
|
GP_HOST="${GP_HOST%/}"
|
||||||
read -rp "gPodder username: " GP_USER
|
read -rp "gPodder username: " GP_USER
|
||||||
|
GP_USER="${GP_USER:?gPodder username required}"
|
||||||
read -rsp "gPodder password: " GP_PASS; echo
|
read -rsp "gPodder password: " GP_PASS; echo
|
||||||
|
GP_PASS="${GP_PASS:?gPodder password required}"
|
||||||
GP_JSON=$(jq -n --arg h "$GP_HOST" --arg u "$GP_USER" --arg p "$GP_PASS" \
|
GP_JSON=$(jq -n --arg h "$GP_HOST" --arg u "$GP_USER" --arg p "$GP_PASS" \
|
||||||
'{enable:true, host:$h, username:$u, password:$p}')
|
'{enable:true, host:$h, username:$u, password:$p}')
|
||||||
;;
|
;;
|
||||||
|
|
@ -67,9 +74,16 @@ EOF
|
||||||
chmod 600 "$CONFIG_FILE"
|
chmod 600 "$CONFIG_FILE"
|
||||||
echo "Wrote ${CONFIG_FILE}"
|
echo "Wrote ${CONFIG_FILE}"
|
||||||
|
|
||||||
# --- Dependencies -----------------------------------------------------------
|
# --- Virtualenv + dependencies ----------------------------------------------
|
||||||
echo "Installing Python dependencies..."
|
echo "Creating virtual environment at ${VENV_DIR} ..."
|
||||||
pip3 install feedparser requests 2>/dev/null || pip install feedparser requests
|
if [ ! -x "$PYBIN" ]; then
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq python3-venv python3-pip jq >/dev/null
|
||||||
|
fi
|
||||||
|
python3 -m venv "$VENV_DIR"
|
||||||
|
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
|
||||||
|
"$VENV_DIR/bin/pip" install --quiet feedparser requests
|
||||||
|
echo "Installed feedparser + requests into ${VENV_DIR}"
|
||||||
|
|
||||||
# --- Systemd unit ------------------------------------------------------------
|
# --- Systemd unit ------------------------------------------------------------
|
||||||
cat > "$SYSTEMD_UNIT" <<EOF
|
cat > "$SYSTEMD_UNIT" <<EOF
|
||||||
|
|
@ -92,8 +106,8 @@ systemctl enable "${SERVICE_NAME}"
|
||||||
echo "Enabled systemd unit: ${SERVICE_NAME}"
|
echo "Enabled systemd unit: ${SERVICE_NAME}"
|
||||||
|
|
||||||
# --- Cron --------------------------------------------------------------------
|
# --- Cron --------------------------------------------------------------------
|
||||||
CRON_FETCH="0 * * * * cd ${SCRIPT_DIR} && /usr/bin/python3 fetch_podcasts.py >> ${STORAGE_PATH}/logs/cron.log 2>&1"
|
CRON_FETCH="0 * * * * cd ${SCRIPT_DIR} && ${PYBIN} fetch_podcasts.py >> ${STORAGE_PATH}/logs/cron.log 2>&1"
|
||||||
CRON_PLAYLISTS="30 * * * * cd ${SCRIPT_DIR} && /usr/bin/python3 update_playlists.py >> ${STORAGE_PATH}/logs/cron.log 2>&1"
|
CRON_PLAYLISTS="30 * * * * cd ${SCRIPT_DIR} && ${PYBIN} update_playlists.py >> ${STORAGE_PATH}/logs/cron.log 2>&1"
|
||||||
|
|
||||||
(crontab -l 2>/dev/null | grep -v "fetch_podcasts.py\|update_playlists.py"; echo "$CRON_FETCH"; echo "$CRON_PLAYLISTS") | crontab -
|
(crontab -l 2>/dev/null | grep -v "fetch_podcasts.py\|update_playlists.py"; echo "$CRON_FETCH"; echo "$CRON_PLAYLISTS") | crontab -
|
||||||
echo "Installed cron jobs:"
|
echo "Installed cron jobs:"
|
||||||
|
|
@ -102,5 +116,7 @@ echo " $CRON_PLAYLISTS"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Installation complete ==="
|
echo "=== Installation complete ==="
|
||||||
echo "Storage root: ${STORAGE_PATH}"
|
echo "Storage root: ${STORAGE_PATH}"
|
||||||
echo "Start with: systemctl start ${SERVICE_NAME}"
|
echo "Virtualenv: ${VENV_DIR}"
|
||||||
|
echo "Start with: systemctl start ${SERVICE_NAME}"
|
||||||
|
echo "Test fetcher: ${PYBIN} fetch_podcasts.py --list-shows"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue