1
0
Files
emby-tv-logo-tools/entrypoint.sh
Seth Van Niekerk e1acd126a7
All checks were successful
Build & Push Docker Image / build-and-publish (push) Successful in 13s
containerize & enhance filtering
2026-02-08 12:07:35 -05:00

143 lines
3.6 KiB
Bash

#!/bin/bash
set -e
# Function to build the command based on environment variables
build_command() {
local cmd="python3 /app/update_channel_logos.py"
# Required parameters
cmd="$cmd --server \"$EMBY_SERVER_URL\""
cmd="$cmd --api-key \"$EMBY_API_KEY\""
# Handle --list-tags mode (takes precedence)
if [ "${LIST_TAGS:-false}" = "true" ]; then
cmd="$cmd --list-tags"
echo "$cmd"
return
fi
# Optional parameters
if [ "${MODE:-copy}" = "clear" ]; then
cmd="$cmd --clear"
fi
if [ "${DRY_RUN:-true}" != "true" ]; then
cmd="$cmd --execute"
fi
if [ "${FIRST_ONLY:-false}" = "true" ]; then
cmd="$cmd --first-only"
fi
if [ "${FORCE:-false}" = "true" ] && [ "${MODE:-copy}" = "copy" ]; then
cmd="$cmd --force"
fi
# Add tags if specified
if [ -n "${TAGS:-}" ]; then
cmd="$cmd --tags \"$TAGS\""
fi
# Add non-interactive flag
cmd="$cmd --non-interactive"
echo "$cmd"
}
# Validate required environment variables
if [ -z "$EMBY_SERVER_URL" ]; then
echo "ERROR: EMBY_SERVER_URL environment variable is required"
exit 1
fi
if [ -z "$EMBY_API_KEY" ]; then
echo "ERROR: EMBY_API_KEY environment variable is required"
exit 1
fi
# Get the cron schedule (default: daily at 3 AM)
CRON_SCHEDULE="${CRON_SCHEDULE:-0 3 * * *}"
# Build the command
COMMAND=$(build_command)
# Log the configuration
echo "=========================================="
echo "Emby TV Logo Tools - Docker Container"
echo "=========================================="
echo "Emby Server: $EMBY_SERVER_URL"
echo "Mode: ${MODE:-copy}"
echo "Dry Run: ${DRY_RUN:-true}"
echo "First Only: ${FIRST_ONLY:-false}"
echo "Force: ${FORCE:-false}"
echo "Tags: ${TAGS:-(none)}"
echo "Cron Schedule: $CRON_SCHEDULE"
echo "Timezone: ${TZ:-UTC}"
echo "=========================================="
echo ""
# If RUN_ONCE is set, just run the command once and exit
if [ "${RUN_ONCE:-false}" = "true" ]; then
echo "Running once (RUN_ONCE=true)..."
eval "$COMMAND"
exit 0
fi
# Create cron job
echo "Setting up cron job..."
echo "$CRON_SCHEDULE $COMMAND >> /var/log/cron.log 2>&1" > /etc/cron.d/emby-logo-update
# Give execution rights on the cron job
chmod 0644 /etc/cron.d/emby-logo-update
# Create the log file
touch /var/log/cron.log
# Apply cron job
crontab /etc/cron.d/emby-logo-update
# Print next scheduled run times
echo ""
echo "Cron job installed. Next 5 scheduled runs:"
echo "=========================================="
# Calculate next run times (this is approximate)
python3 - <<EOF
from datetime import datetime, timedelta
import sys
schedule = "${CRON_SCHEDULE}"
parts = schedule.split()
if len(parts) != 5:
print("Invalid cron schedule format")
sys.exit(1)
minute, hour = parts[0], parts[1]
# Simple calculation for daily cron jobs
if parts[2] == '*' and parts[3] == '*' and parts[4] == '*':
now = datetime.now()
target_hour = int(hour) if hour != '*' else now.hour
target_minute = int(minute) if minute != '*' else 0
next_run = now.replace(hour=target_hour, minute=target_minute, second=0, microsecond=0)
if next_run <= now:
next_run += timedelta(days=1)
for i in range(5):
print(next_run.strftime("%Y-%m-%d %H:%M:%S"))
next_run += timedelta(days=1)
else:
print("(Schedule calculation only supports simple daily jobs)")
print("Your schedule: $CRON_SCHEDULE")
EOF
echo "=========================================="
echo ""
echo "Starting cron daemon..."
echo "Container is running. Logs will appear below."
echo ""
# Start cron in foreground and tail the log
cron && tail -f /var/log/cron.log