#!/bin/bash # Entrypoint script for YouTube Sync Docker container set -e echo "==========================================" echo "YouTube Channel Sync Docker" echo "==========================================" echo "Download Directory: $DOWNLOAD_DIR" echo "Config Directory: $CONFIG_DIR" echo "Sync Schedule: $SYNC_SCHEDULE" echo "Max Quality: ${MAX_QUALITY}p" echo "Sleep Interval: ${SLEEP_INTERVAL}s" echo "Timezone: $TZ" echo "==========================================" # Create example channels file if it doesn't exist if [ ! -f "$CONFIG_DIR/channels.txt" ]; then echo "[INFO] Creating example channels.txt..." cat > "$CONFIG_DIR/channels.txt" << 'EOF' # YouTube Channel Configuration # Format: CHANNEL_ID|Channel Name # One channel per line. Lines starting with # are ignored. # # Examples: # UCfDNi1aEljAQ17mUrfUjkvg|Alton Brown # UCoq2qlWgvvKJzW_hBkLIE8w|Flavour Trip # # To find a channel ID: # 1. Go to the channel's main page # 2. View page source (Ctrl+U or Cmd+U) # 3. Search for "channelId" or look in the URL EOF fi # Set up cron job if SYNC_SCHEDULE is provided if [ "$SYNC_SCHEDULE" != "manual" ]; then echo "[INFO] Setting up cron schedule: $SYNC_SCHEDULE" echo "$SYNC_SCHEDULE /app/sync.sh >> /var/log/youtube-sync.log 2>&1" > /etc/crontabs/root # Start crond in the background crond -f -l 2 & CRON_PID=$! echo "[INFO] Cron daemon started (PID: $CRON_PID)" # Run initial sync echo "[INFO] Running initial sync..." /app/sync.sh || true # Keep container running and monitor cron echo "[INFO] Container ready. Watching for scheduled syncs..." wait $CRON_PID else echo "[INFO] Manual mode enabled. Running sync once..." /app/sync.sh fi