From a02968af2236a66f381d3e43f2176a2e5edbdc43 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 17 Sep 2012 09:16:13 +0200 Subject: [PATCH] [scripts] iso_build.sh: implement --sleepnight switch logic --- scripts/iso_build.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/iso_build.sh b/scripts/iso_build.sh index 6beb183..d0b336e 100755 --- a/scripts/iso_build.sh +++ b/scripts/iso_build.sh @@ -15,6 +15,7 @@ for arg in "$@" do [[ "${arg}" = "--push" ]] && DO_PUSH="1" [[ "${arg}" = "--stdout" ]] && DO_STDOUT="1" + [[ "${arg}" = "--sleepnight" ]] && DO_SLEEPNIGHT="1" if [ "${arg}" = "--pushonly" ]; then DO_PUSH="1" DRY_RUN="1" @@ -37,6 +38,7 @@ export BUILDING_DAILY echo "DO_PUSH=${DO_PUSH}" echo "DRY_RUN=${DRY_RUN}" +echo "DO_SLEEPNIGHT=${DO_SLEEPNIGHT}" echo "LOG_FILE=${LOG_FILE}" # setup default language, cron might not do that @@ -44,6 +46,28 @@ export LC_ALL="en_US.UTF-8" export LANG="en_US.UTF-8" export LANGUAGE="en_US.UTF-8" +# Sleep until 22pm? +if [ "${DO_SLEEPNIGHT}" = "1" ] && [ "${DO_PUSH}" = "1" ]; then + target_h=22 # 22pm + current_h=$(date +%H) + current_h=${current_h/0} # remove leading 0 + delta_h=$(( target_h - current_h )) + if [ ${current_h} -ge 0 ] && [ ${current_h} -le 6 ]; then + # If it's past midnight and no later than 7am + # just push + echo "Just pusing out now" + elif [ ${delta_h} -gt 0 ]; then + delta_s=$(( delta_h * 3600 )) + echo "Sleeping for ${delta_h} hours..." + sleep ${delta_s} || exit 1 + elif [ ${delta_h} -lt 0 ]; then + # between 22 and 24, run! + echo "I'm after 22pm, running" + else + echo "No need to sleep" + fi +fi + ARM_SOURCE_SPECS=() ARM_SOURCE_SPECS_IMG=()