#!/bin/bash set -e # Function to build the command based on environment variables build_command() { local cmd="/usr/local/bin/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 # Handle --debug-tags mode (takes precedence) if [ "${DEBUG_TAGS:-false}" = "true" ]; then cmd="$cmd --debug-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. Schedule: $CRON_SCHEDULE" 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