#!/bin/bash

OCCURANCE=$1
REPO=$2
BRANCH=$3
CNAME=$4


if [ -z $CNAME ]; then
echo "Usage: droneCreateRandomCron.sh <occurance> <repository> <branch> <crontab name>"
echo -e "\t occurance = 1 = Daily  | 0 = Weekly"
exit 1
fi



HOUR=$(($RANDOM % 24))

if [ $1 -eq 1 ]; then

DAY='*' 

else

DAY=$(($RANDOM % 6))

fi

CRONTAB="0 0 ${HOUR} * * ${DAY}"
echo "Crontab: ${CRONTAB}"

drone cron add --branch $BRANCH $REPO $CNAME "${CRONTAB}"


