#!/bin/sh set -e # Function to grab EPG data for a site grab_epg() { site=$1 echo "Grabbing EPG data for site: $site" # Build command with optional parameters cmd="npm run grab -- --site=$site --output=output/${site}.xml --maxConnections=${MAX_CONNECTIONS}" # Add optional parameters if they are set if [ -n "$DAYS" ]; then cmd="$cmd --days=${DAYS}" fi if [ -n "$TIMEOUT" ]; then cmd="$cmd --timeout=${TIMEOUT}" fi if [ -n "$DELAY" ]; then cmd="$cmd --delay=${DELAY}" fi if [ -n "$LANG" ]; then cmd="$cmd --lang=${LANG}" fi if [ "$GZIP" = "true" ]; then cmd="$cmd --gzip" fi # Execute the command eval $cmd } # Function to grab EPG data for all sites grab_all_sites() { # Split the SITES environment variable by comma - POSIX sh compatible echo "$SITES" | tr ',' '\n' >/tmp/sites.txt # Process each site while read site; do grab_epg "$site" done /app/grab-sites.js < { try { console.log(\`Grabbing EPG data for site: \${site}\`); let cmd = \`npm run grab -- --site=\${site} --output=output/\${site}.xml --maxConnections=\${process.env.MAX_CONNECTIONS || 1}\`; // Add optional parameters if (process.env.DAYS) cmd += \` --days=\${process.env.DAYS}\`; if (process.env.TIMEOUT) cmd += \` --timeout=\${process.env.TIMEOUT}\`; if (process.env.DELAY) cmd += \` --delay=\${process.env.DELAY}\`; if (process.env.LANG) cmd += \` --lang=\${process.env.LANG}\`; if (process.env.GZIP === 'true') cmd += \` --gzip\`; execSync(cmd, { stdio: 'inherit' }); } catch (error) { console.error(\`Error grabbing EPG data for site: \${site}\`, error); } }); EOL chmod +x /app/grab-sites.js # Start the cron job pm2 start --name epg-grabber /app/grab-sites.js --no-autorestart --cron-restart="$CRON_SCHEDULE" fi # Start the server to serve the guide files cd /app echo "Starting server on port 3000" npx serve -p 3000 # Keep the container running tail -f /dev/null