summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-04-02 01:14:38 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-04-02 01:14:38 +0200
commite7b2200152c95009292121876a5d5c37f7fbfeec (patch)
treeedc5aed3a900fe86c037c029069cf7e25d92be79
parent3f05033858e98fab16713df5abacde3dd494bab1 (diff)
downloadimpressive-display-e7b2200152c95009292121876a5d5c37f7fbfeec.tar.gz
impressive-display-e7b2200152c95009292121876a5d5c37f7fbfeec.tar.bz2
impressive-display-e7b2200152c95009292121876a5d5c37f7fbfeec.zip
Add support for RUSH_HOURS and SLEEP_HOURS to the PDF download loop.
-rwxr-xr-xbin/impressive-display107
1 files changed, 105 insertions, 2 deletions
diff --git a/bin/impressive-display b/bin/impressive-display
index 3cff9ac..3a786e4 100755
--- a/bin/impressive-display
+++ b/bin/impressive-display
@@ -72,12 +72,23 @@ HTTP_PROXY_URL=""
# interval of PDF continuous downloads
DOWNLOAD_INTERVAL="600"
+# During rush hours check PDF file on remote URL more often
+RUSH_HOURS="07-11"
+RUSH_HOURS_DOWNLOAD_INTERVAL="180"
+
+# Disable PDF downloads at night time completely...
+SLEEP_HOURS="22-06"
+SLEEP_HOURS_DOWNLOAD_INTERVAL="0"
+
# show each slide for 20 seconds by default
SLIDE_DURATION="20"
# option for impressive fading...
IMPRESSIVE_OPTIONS="--transition None"
+# write some debugging output to stdout when downloading a remote PDF
+DEBUG_DOWNLOADS=""
+
if [ -r $HOME/.impressive-display-secrets ] && [ ! -d $HOME/.impressive-display-secrets ]; then
. $HOME/.impressive-display-secrets
fi
@@ -159,6 +170,11 @@ if [ -n "$HTTP_PROXY_URL" ]; then
export ftp_proxy="$HTTP_PROXY_URL"
fi
+rush_hours_start=`echo $RUSH_HOURS | grep -E '^[0-9]{2}-[0-9]{2}$' | sed -n -r -e 's/^([0-9]{2})-([0-9]{2})$/\1/p'`
+rush_hours_end=`echo $RUSH_HOURS | grep -E '^[0-9]{2}-[0-9]{2}$' | sed -n -r -e 's/^([0-9]{2})-([0-9]{2})$/\2/p'`
+sleep_hours_start=`echo $SLEEP_HOURS | grep -E '^[0-9]{2}-[0-9]{2}$' | sed -n -r -e 's/^([0-9]{2})-([0-9]{2})$/\1/p'`
+sleep_hours_end=`echo $SLEEP_HOURS | grep -E '^[0-9]{2}-[0-9]{2}$' | sed -n -r -e 's/^([0-9]{2})-([0-9]{2})$/\2/p'`
+
function cleanup {
if [ -r "$impressive_lock" ]; then
@@ -243,6 +259,64 @@ function local_pdffile {
}
+function is_rush_hour {
+
+ if [ -n "$rush_hours_start" ] && [ -n "$rush_hours_end" ]; then
+
+ current_hour=`date +%H`
+ if [ $rush_hours_end -gt $rush_hours_start ]; then
+
+ if [ $rush_hours_start -le $current_hour ] && [ $current_hour -lt $rush_hours_end ]; then
+ echo "true"
+ return 0
+ fi
+
+ else
+
+ if [ $rush_hours_end -le $current_hour ] && [ $current_hour -lt $rush_hours_start ]; then
+ :
+ else
+ echo "true"
+ return 0
+ fi
+
+ fi
+
+ fi
+ echo "false"
+ return -1
+
+}
+
+function is_sleep_hour {
+
+ if [ -n "$sleep_hours_start" ] && [ -n "$sleep_hours_end" ]; then
+
+ current_hour=`date +%H`
+ if [ $sleep_hours_end -gt $sleep_hours_start ]; then
+
+ if [ $sleep_hours_start -le $current_hour ] && [ $current_hour -lt $sleep_hours_end ]; then
+ echo "true"
+ return 0
+ fi
+
+ else
+
+ if [ $sleep_hours_end -le $current_hour ] && [ $current_hour -lt $sleep_hours_start ]; then
+ :
+ else
+ echo "true"
+ return 0
+ fi
+
+ fi
+
+ fi
+ echo "false"
+ return -1
+
+}
+
function download_pdffile {
if [ -r "$pdffile_downloaded" ]; then
@@ -279,10 +353,39 @@ function download_loop {
if [ "x$DOWNLOAD_INTERVAL" != "x0" ]; then
(
+ #set -x
while [ -e "$session_lock" ]; do
- sleep $DOWNLOAD_INTERVAL
- download_pdffile
+
+ if [ -n "$DEBUG_DOWNLOADS" ]; then
+ echo "DEBUG: rush hour: `is_rush_hour` (interval: $RUSH_HOURS_DOWNLOAD_INTERVAL), sleep hour: `is_sleep_hour` (interval: $SLEEP_HOURS_DOWNLOAD_INTERVAL). Normal interval: $DOWNLOAD_INTERVAL."
+ fi
+
+ if is_rush_hour 1>/dev/null && [ "x$RUSH_HOURS_DOWNLOAD_INTERVAL" != "x0" ]; then
+ sleep $RUSH_HOURS_DOWNLOAD_INTERVAL
+ if [ -n "$DEBUG_DOWNLOADS" ]; then
+ echo "RUSH HOUR download, URL: $PDF_URL"
+ fi
+ download_pdffile
+ elif is_sleep_hour 1>/dev/null && [ "x$SLEEP_HOURS_DOWNLOAD_INTERVAL" != "x0" ]; then
+ sleep $SLEEP_HOURS_DOWNLOAD_INTERVAL
+ if [ -n "$DEBUG_DOWNLOADS" ]; then
+ echo "SLEEP HOUR download, URL: $PDF_URL"
+ fi
+ download_pdffile
+ elif (! is_rush_hour 1>/dev/null ) && (! is_sleep_hour 1>/dev/null) && [ "x$DOWNLOAD_INTERVAL" != "x0" ]; then
+ sleep $DOWNLOAD_INTERVAL
+ if [ -n "$DEBUG_DOWNLOADS" ]; then
+ echo "NORMAL HOUR download, URL: $PDF_URL"
+ fi
+ download_pdffile
+ else
+ if [ -n "$DEBUG_DOWNLOADS" ]; then
+ echo "DEBUG: Not doing any download."
+ fi
+ sleep 60
+ fi
done
+ #set +x
) &
fi