From 4103e1be656577494fdf35f771caf30ab70207cc Mon Sep 17 00:00:00 2001 From: FailedProxy Date: Sun, 19 Apr 2026 17:39:40 -0400 Subject: [PATCH] icorp host profiles into scripts that needed it --- Master.conf | 14 +++++++++++--- Monitors/emby_session_report.sh | 13 +++++++++++++ Transcodes/transcode_manager.sh | 11 +++++++++++ git_pull_execute.sh | 32 +++++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Master.conf b/Master.conf index 8aca32a..6b6792d 100644 --- a/Master.conf +++ b/Master.conf @@ -104,10 +104,18 @@ # Gitea self-hosted repository settings used by git_pull_execute.sh. # Running git_pull_execute.sh on either server pulls the latest scripts and sets # executable permissions automatically — keeps both servers in sync with one command. - REPO_SSH="git@192.168.50.2:FailedProxy/Unraid_Scripts.git" +# +# git_pull_execute.sh detects where the Gitea container is running at runtime: +# Gitea running locally → connects via local IP +# Gitea running remotely → connects via remote server's Tailscale IP +# No hardcoded assumptions about which server hosts Gitea — works through failover. +# If Gitea fails over to HOST2, HOST1 automatically finds it there and vice versa. + + GITEA_CONTAINER="Gitea" # exact Docker container name + GITEA_REPO_PATH="FailedProxy/Unraid_Scripts.git" # repo path on Gitea TARGET_DIR="/mnt/user/appdata/unraid_scripts" - GITEA_SSH_KEY="/root/.ssh/unraid_gitea" # SSH key for authenticating to Gitea - SSH_PORT=221 # Gitea SSH port — default Gitea uses 22 + GITEA_SSH_KEY="/root/.ssh/unraid_gitea" # SSH key for authenticating to Gitea + SSH_PORT=221 # Gitea SSH port # ============================================================================================== # ── RSYNC ───────────────────────────────────────────────────────────────────────────────────── diff --git a/Monitors/emby_session_report.sh b/Monitors/emby_session_report.sh index cfbe6ce..c62cf56 100644 --- a/Monitors/emby_session_report.sh +++ b/Monitors/emby_session_report.sh @@ -43,6 +43,19 @@ if ! command -v jq >/dev/null 2>&1; then exit 1 fi +# Select correct Emby instance based on which server is running this script +detect_hosts + +if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then + EMBY_URL="$HOST1_EMBY_URL" + EMBY_API_KEY="$HOST1_EMBY_API_KEY" +else + EMBY_URL="$HOST2_EMBY_URL" + EMBY_API_KEY="$HOST2_EMBY_API_KEY" +fi + +info "Emby instance: $LOCAL_SERVER_NAME → $EMBY_URL" + require_var EMBY_URL require_var EMBY_API_KEY diff --git a/Transcodes/transcode_manager.sh b/Transcodes/transcode_manager.sh index 47b1c71..88afd4a 100644 --- a/Transcodes/transcode_manager.sh +++ b/Transcodes/transcode_manager.sh @@ -47,6 +47,17 @@ fi success "Running as root" +# Select correct Emby instance for session display +detect_hosts + +if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then + EMBY_URL="${HOST1_EMBY_URL}" + EMBY_API_KEY="${HOST1_EMBY_API_KEY}" +else + EMBY_URL="${HOST2_EMBY_URL}" + EMBY_API_KEY="${HOST2_EMBY_API_KEY}" +fi + case "$TRANSCODE_MANAGER_MODE" in smart|ramdisk|ssd) info "$ICON_GEAR Mode: $TRANSCODE_MANAGER_MODE" ;; *) diff --git a/git_pull_execute.sh b/git_pull_execute.sh index ac5fd80..c17ad91 100644 --- a/git_pull_execute.sh +++ b/git_pull_execute.sh @@ -4,7 +4,13 @@ # ----------------------------------------------------------------------------------------------- # Pulls latest scripts from Gitea repo via SSH and sets executable permissions. # Lives at the repo root — sources Master.conf and common.sh from the same directory. -# Uses GITEA_SSH_KEY, SSH_PORT and REPO_SSH from Master.conf. +# Uses GITEA_SSH_KEY, SSH_PORT, GITEA_CONTAINER and GITEA_REPO_PATH from Master.conf. +# +# Detects where the Gitea container is running at runtime: +# Gitea running locally → connects via local IP +# Gitea running remotely → connects via remote server's Tailscale IP +# Works correctly through failover — no hardcoded assumptions about which server hosts Gitea. +# # Supports --dry-run, --log, --status flags via common.sh parse_args. # ----------------------------------------------------------------------------------------------- @@ -22,7 +28,6 @@ parse_args "$@" echo "" echo "━━━ $ICON_GEAR Setup ━━━" -# ROOT CHECK if [[ "$EUID" -ne 0 ]]; then error "Must be run as root" exit 1 @@ -30,7 +35,28 @@ fi success "Running as root" -# VALIDATION +# Detect which server we're on and where Gitea is running +detect_hosts + +# Check if Gitea container is running locally +if docker ps --format "{{.Names}}" 2>/dev/null | grep -q "^${GITEA_CONTAINER}$"; then + # Gitea is running on this server — use local IP + GITEA_IP=$(hostname -I | awk '{print $1}') + info "$ICON_CONTAINERS Gitea running locally — connecting via $GITEA_IP" +else + # Gitea is not running locally — find it on the remote server via Tailscale + info "$ICON_CONTAINERS Gitea not running locally — checking remote server" + GITEA_IP=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null) + if [[ -z "$GITEA_IP" ]]; then + error "Cannot resolve Tailscale IP for $REMOTE_SERVER_NAME — is Tailscale running?" + notify "Git pull failed on $(hostname) — cannot find Gitea container or resolve remote IP" "Git Sync" "alert" + exit 1 + fi + info "$ICON_NET Gitea on $REMOTE_SERVER_NAME — connecting via $GITEA_IP" +fi + +REPO_SSH="git@${GITEA_IP}:${GITEA_REPO_PATH}" + require_var REPO_SSH require_var TARGET_DIR require_var GITEA_SSH_KEY