#!/bin/sh
set -e

CRONJOB="$CRON_SCHEDULE $COMMAND $RCLONE_OPTS"

echo "Configuring..."

echo "This cron job will be added :"
echo "$CRONJOB"

echo "Installing the cron job..."
echo "$CRONJOB > /proc/1/fd/1 2>/proc/1/fd/2" > /var/spool/cron/crontabs/root
chown root:root /var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root

echo "We run the command once (initial check)..."
#eval "$COMMAND"

# run the CMD
echo "First sync was successful, starting cron !"
exec "$@"
