#!/usr/bin/env bash # install.sh — Update Tdarr plugins from Gitea raw file URLs. # # Usage: # ./install.sh # latest version of ALL plugins # ./install.sh --latest # latest version of ALL plugins # ./install.sh --all # every available plugin version # ./install.sh --all p1 p2 # every version of selected plugins # ./install.sh --latest p1 p2 # latest version of selected plugins # # Or pipe directly from Gitea (no clone needed): # curl -fsSL https://git.cdtech.freeddns.org/PickleRick/Tdarr-plugin/raw/branch/main/install.sh \ # | bash -s -- /your/tdarr/plugins/FlowPlugins # # Environment overrides: # GITEA_URL — base URL of the Gitea instance (default below) # GITEA_BRANCH — branch to pull from (default: main) set -euo pipefail # ── Config ──────────────────────────────────────────────────────────────────── GITEA_URL="${GITEA_URL:-https://git.cdtech.freeddns.org}" GITEA_REPO="PickleRick/Tdarr-plugin" BRANCH="${GITEA_BRANCH:-main}" RAW="${GITEA_URL}/${GITEA_REPO}/raw/branch/${BRANCH}" # Map: plugin-name → category declare -A PLUGIN_CATEGORY=( [mediaAnalyzerGOP]=utility [setAnimationFlag]=utility [extractChaptersXml]=utility [finalizeMedia]=utility [copyToWorkDir]=utility [replaceOriginalFile]=utility [audioSelectorClamping]=audio [backupSourceAudio]=audio [extractSubtitlesAndOcr]=subtitles [transcode2PassX265]=video ) # ── Args ────────────────────────────────────────────────────────────────────── if [[ $# -lt 1 ]]; then echo "Usage: $0 [plugin1 plugin2 ...]" echo "" echo " PLUGIN_DIR — path that contains LocalFlowPlugins/" echo " (e.g. /docker/tdarr/data/Tdarr/Plugins/FlowPlugins)" exit 1 fi PLUGIN_DIR="$1" shift # Version mode defaults to the latest version only. VERSION_MODE="latest" if [[ "${1:-}" == "--all" || "${1:-}" == "--latest" ]]; then VERSION_MODE="${1#--}" shift fi # If no specific plugins requested, update all. if [[ $# -eq 0 ]]; then TARGETS=("${!PLUGIN_CATEGORY[@]}") else TARGETS=("$@") fi # ── Download helper ─────────────────────────────────────────────────────────── download_plugin() { local name="$1" local category="${PLUGIN_CATEGORY[$name]:-}" if [[ -z "$category" ]]; then echo " ✗ Unknown plugin '${name}' — skipping." return 1 fi local versions="1.0.0" for version in $versions; do local dest="${PLUGIN_DIR}/LocalFlowPlugins/${category}/${name}/${version}" local url="${RAW}/LocalFlowPlugins/${category}/${name}/${version}/index.js" mkdir -p "$dest" if curl -fsSL "$url" -o "${dest}/index.js"; then echo " ✓ ${name} ${version} → ${dest}/index.js" else echo " ✗ Failed to download ${name} ${version} from ${url}" return 1 fi done } download_flow_helpers() { local dest="${PLUGIN_DIR}/FlowHelpers/1.0.0" mkdir -p "$dest" # Restore official Tdarr fileUtils.js if it was previously overwritten by a mock local official_fu="https://raw.githubusercontent.com/HaveAGitGat/Tdarr_Plugins/master/FlowPlugins/FlowHelpers/1.0.0/fileUtils.js" if [[ -f "${dest}/fileUtils.js" ]]; then if grep -q "Local mock of Tdarr" "${dest}/fileUtils.js" || ! grep -q "getFileAbsoluteDir" "${dest}/fileUtils.js"; then echo " 🔄 Restoring official Tdarr fileUtils.js..." curl -fsSL "$official_fu" -o "${dest}/fileUtils.js" || true fi else curl -fsSL "$official_fu" -o "${dest}/fileUtils.js" || true fi # Download our custom copyWithProgress helper local url="${RAW}/FlowHelpers/1.0.0/copyWithProgress.js" if curl -fsSL "$url" -o "${dest}/copyWithProgress.js"; then echo " ✓ FlowHelper copyWithProgress.js → ${dest}/copyWithProgress.js" else echo " ✗ Failed to download copyWithProgress.js from ${url}" return 1 fi } clean_deprecated_plugins() { for deprecated in copyToWorkDir replaceOriginalFile; do local dep_dir="${PLUGIN_DIR}/LocalFlowPlugins/utility/${deprecated}/2.0.0" if [[ -d "$dep_dir" ]]; then rm -rf "$dep_dir" echo " 🗑️ Removed deprecated ${deprecated} 2.0.0" fi done } # ── Run ─────────────────────────────────────────────────────────────────────── echo "=== Tdarr Plugin Updater ===" echo " Source : ${GITEA_URL}/${GITEA_REPO} (branch: ${BRANCH})" echo " Target : ${PLUGIN_DIR}" echo "" ERRORS=0 clean_deprecated_plugins for plugin in "${TARGETS[@]}"; do download_plugin "$plugin" || ERRORS=$((ERRORS + 1)) done download_flow_helpers || ERRORS=$((ERRORS + 1)) echo "" if [[ $ERRORS -eq 0 ]]; then echo "✅ Done. Restart Tdarr server to pick up changes:" echo " docker restart tdarr-server" else echo "⚠️ Done with ${ERRORS} error(s). Check output above." exit 1 fi