11#! /bin/sh
2-
3- # Handle PUID/PGID
4- if [ " $PUID " != " 0" ] && [ " $PGID " != " 0" ]; then
5- echo " [setup] Setting up user with PUID=$PUID and PGID=$PGID "
6-
7- # Create group if it doesn't exist
8- if ! getent group explo > /dev/null 2>&1 ; then
9- groupadd -g " $PGID " explo
10- fi
11-
12- # Create user if it doesn't exist
13- if ! getent passwd explo > /dev/null 2>&1 ; then
14- useradd -u " $PUID " -g " $PGID " -d /opt/explo -s /bin/sh explo
15- fi
16-
17- # Ensure explo user owns the working directory and data directory
18- chown -R explo:explo /opt/explo
19- [ -d /data ] && chown -R explo:explo /data
20-
21- # Set timezone for non-root user
22- ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
23- echo " $TZ " > /etc/timezone
24- fi
25-
262echo " [setup] Initializing cron jobs..."
273
28- # Determine which user to run cron jobs as
29- CRON_USER=" root"
30- if [ " $PUID " != " 0" ] && [ " $PGID " != " 0" ]; then
31- CRON_USER=" explo"
32- # Create crontab directory for explo user if it doesn't exist
33- mkdir -p /var/spool/cron/crontabs
34- touch " /var/spool/cron/crontabs/$CRON_USER "
35- chown " $CRON_USER :$CRON_USER " " /var/spool/cron/crontabs/$CRON_USER "
36- fi
374
38- # If block for older versions of Explo ($CRON_SCHEDULE was deprecated in v0.11.0)
5+ # $CRON_SHCEDULE was deprecated in v0.11.0, keeping this block for backwards compatibility
396if [ -n " $CRON_SCHEDULE " ]; then
40- cmd=" apk add --upgrade yt-dlp && cd /opt/explo && ./explo >> /proc/1/fd/1 2>&1"
41- echo " $CRON_SCHEDULE $cmd " > " /var/spool/cron/crontabs/$CRON_USER "
42- chmod 600 " /var/spool/cron/crontabs/$CRON_USER "
7+ echo " $CRON_SCHEDULE apk add --upgrade yt-dlp && cd /opt/explo && ./explo >> /proc/1/fd/1 2>&1" > /etc/crontabs/root
8+ chmod 600 /etc/crontabs/root
439 echo " [setup] Registered single CRON_SCHEDULE job: $CRON_SCHEDULE "
4410 crond -f -l 2
4511fi
@@ -59,19 +25,13 @@ for var in $(env | grep "_SCHEDULE=" | cut -d= -f1); do
5925 # Default: just run explo if flags are empty
6026 cmd=" apk add --upgrade yt-dlp && cd /opt/explo && ./explo $flags >> /proc/1/fd/1 2>&1"
6127
62- echo " $schedule $cmd " >> " /var/spool/cron/ crontabs/$CRON_USER "
28+ echo " $schedule $cmd " >> /etc/ crontabs/root
6329 echo " [setup] Registered job: $job "
6430 echo " Schedule: $schedule "
6531 echo " Command : ./explo $flags "
6632done
6733
68- chmod 600 " /var/spool/cron/crontabs/$CRON_USER "
69-
34+ chmod 600 /etc/crontabs/root
7035
7136echo " [setup] Starting cron..."
72- # Drop privileges after cron setup is done
73- if [ " $( id -u) " = " 0" ]; then
74- exec su-exec explo crond -f -l 2
75- fi
76-
7737crond -f -l 2
0 commit comments