#!/ffp/bin/sh

# PROVIDE: uwmirrorfolderservice
# REQUIRE: LOGIN

. /ffp/etc/ffp.subr

name="uwmirrorfolderservice"
start_cmd="uwmirrorfolderservice_start"
stop_cmd="uwmirrorfolderservice_stop"

CRONTXT=/tmp/crontab.txt

uwmirrorfolderservice_start() {
    # start with existing crontab
    /bin/crontab -l > $CRONTXT

    # Add CronJob
    /bin/echo "0 3 * * * /ffp/var/opt/uwmirrorfolderrsync/uwmirrorfolderrsync.sh &" >> $CRONTXT
    /bin/echo "0 15 * * * /ffp/var/opt/uwmirrorfolderrsync/uwmirrorfolderrsync.sh &" >> $CRONTXT
    #          * * * * *
    #          - - - - -
    #          | | | | |
    #          | | | | +---- Weekday (0-7) (Sunday =0 oder =7)
    #          | | | +------ Month (1-12)
    #          | | +-------- Day (1-31)
    #          | +---------- Hour (0-23)
    #          +--------------- Minute (0-59)

    # install the new crontab
    /bin/crontab $CRONTXT

    # clean up tmp crontab
    /bin/rm $CRONTXT
}
uwmirrorfolderservice_stop() {
    # start with existing crontab
    /bin/crontab -l|grep -v "uwmirrorfolderrsync" > $CRONTXT
    # install the new crontab
    /bin/crontab $CRONTXT
    # clean up tmp crontab
    /bin/rm $CRONTXT
    echo "root">> /var/spool/cron/crontabs/cron.update
}

run_rc_command "$1"
