Initial import: Music_Server, MusicFree, catalog-sync

This commit is contained in:
2026-05-23 16:51:14 +08:00
commit 069af30dba
847 changed files with 179878 additions and 0 deletions
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_HOME="$(cd "${SCRIPT_DIR}/.." && pwd)"
CONFIG_FILE="${APP_HOME}/config/catalogsync.env"
# shellcheck source=./load_env.sh
source "${SCRIPT_DIR}/load_env.sh"
fail() {
echo "[install_runtime.sh] ERROR: $*" >&2
exit 1
}
require_var() {
local var_name="$1"
if [[ -z "${!var_name:-}" ]]; then
fail "Missing required config variable: ${var_name} (from ${CONFIG_FILE})"
fi
}
require_requirement() {
local requirement_name="$1"
if ! grep -Eq "^${requirement_name}([<>=!~].*)?$" "${NAS_REQUIREMENTS_FILE}"; then
fail "Missing required runtime dependency in requirements.txt: ${requirement_name}"
fi
}
if [[ -f "${CONFIG_FILE}" ]]; then
load_env_file "${CONFIG_FILE}"
else
fail "Config file not found: ${CONFIG_FILE}. Copy catalogsync.env.example to catalogsync.env first."
fi
for required_var in APP_HOME DB_PATH LOG_DIR PYTHON_BIN VENV_DIR; do
require_var "${required_var}"
done
if ! command -v "${PYTHON_BIN}" >/dev/null 2>&1; then
fail "PYTHON_BIN is not executable or not found in PATH: ${PYTHON_BIN}"
fi
APP_DIR="${APP_HOME}/app"
REQUIREMENTS_FILE="${APP_DIR}/requirements.txt"
SETUP_FILE="${APP_DIR}/setup.py"
if [[ ! -f "${REQUIREMENTS_FILE}" ]]; then
fail "requirements.txt not found: ${REQUIREMENTS_FILE}"
fi
if [[ ! -f "${SETUP_FILE}" ]]; then
fail "setup.py not found: ${SETUP_FILE}"
fi
mkdir -p "${APP_HOME}" "${APP_DIR}" "${LOG_DIR}" "$(dirname "${DB_PATH}")"
export PYTHONPATH="${APP_DIR}${PYTHONPATH:+:${PYTHONPATH}}"
LOG_FILE="${LOG_DIR}/install_runtime_$(date +%Y%m%d_%H%M%S).log"
exec > >(tee -a "${LOG_FILE}") 2>&1
echo "[install_runtime.sh] logging to ${LOG_FILE}"
if [[ ! -d "${VENV_DIR}" ]]; then
"${PYTHON_BIN}" -m venv "${VENV_DIR}"
fi
RUNTIME_PYTHON_BIN="${VENV_DIR}/bin/python"
if [[ ! -x "${RUNTIME_PYTHON_BIN}" ]]; then
fail "Virtualenv python not found after setup: ${RUNTIME_PYTHON_BIN}"
fi
"${RUNTIME_PYTHON_BIN}" -m pip install --upgrade pip setuptools wheel
NAS_REQUIREMENTS_FILE="${APP_DIR}/requirements.nas.txt"
grep -v '^nodejs-wheel$' "${REQUIREMENTS_FILE}" > "${NAS_REQUIREMENTS_FILE}"
for runtime_requirement in fastapi uvicorn python-multipart; do
require_requirement "${runtime_requirement}"
done
"${RUNTIME_PYTHON_BIN}" -m pip install -r "${NAS_REQUIREMENTS_FILE}"
"${RUNTIME_PYTHON_BIN}" -m pip install --no-deps -e "${APP_DIR}"
echo "[install_runtime.sh] runtime ready: ${RUNTIME_PYTHON_BIN}"