[scripts] iso_build.sh: implement --sleepnight switch logic

This commit is contained in:
Fabio Erculiani 2012-09-17 09:16:13 +02:00
parent 2cc772056e
commit a02968af22
1 changed files with 24 additions and 0 deletions

View File

@ -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=()