Mercurial > bottledash
diff contrib/dashboardctl @ 33:70d50b6312e2
Initial commit of dashboardctl
author | Gernot Schulz <gernot@intevation.de> |
---|---|
date | Fri, 16 Oct 2015 16:16:33 +0200 |
parents | |
children | 7162616389a5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/dashboardctl Fri Oct 16 16:16:33 2015 +0200 @@ -0,0 +1,114 @@ +#!/usr/bin/env sh + +export DISPLAY=":0.0" + +OLDDB=/home/pi/incoming_dbs/tech_intern.db +NEWDB=/home/pi/incoming_dbs/tech_intern.db.new + +usage () { +cat << EOF +Usage: $0 [COMMAND] + +Commands: + --restart-bd Restart Bottledash + --reload-browser Reload dashboard/browser + --reload Restart Bottledash and reload the dashboard/browser + --check-db Check if a new DB is available + --smart-reload If a new DB is available, restart Bottledash and reload + the dashboard/browser + -h, --help This help +EOF +} + +start_bottledash () { + # taken from start-bottledash-hohup + nohup python3 /home/pi/bottledash/dash.py 2>&1 > $HOME/bottledash.log & + echo $! > $HOME/pid_bottledash +} + +stop_bottledash () { + kill $(cat $HOME/pid_bottledash) +} + +start_chromium () { + # taken from show-dashboard + rm -R $HOME/.cache/chromium/Default/Cache/ + DISPLAY=:0.0 nohup chromium --new --noerrdialogs --kiosk \ + http://localhost:8080 2>&1 > $HOME/show-dashboard.log & + echo $! > $HOME/pid_chromium +} + + +stop_chromium () { + kill $(cat pid_chromium) +} + +xdo_reload_chromium () { + # Start Chromium if necessary + if [ -f "$HOME/pid_bottledash" ] && [ -d /proc/$(cat "$HOME/pid_chromium") ]; then + # Send F5 to Chromium + WID=$(xdotool search --onlyvisible --class chromium | head -1) + xdotool windowactivate ${WID} + xdotool key F5 + else + start_chromium + fi +} + +check_new_db () { + if [ ! -f "$NEWDB" ]; then + echo 0 ; return + fi + OLDSIZE=$(md5sum $OLDDB | awk '{print $1}') + NEWSIZE=$(md5sum $NEWDB | awk '{print $1}') + if [ "$OLDSIZE" != "$NEWSIZE" ]; then + echo 1 + else + echo 0 + fi +} + +update_db () { + if [ $(check_new_db) -eq 1 ]; then + mv "$NEWDB" "$OLDDB" + fi +} + +case $1 in + '--restart-bd') + stop_bottledash + start_bottledash + ;; + '--reload-browser') + xdo_reload_chromium + ;; + '--reload') + stop_bottledash + start_bottledash + sleep 10 + xdo_reload_chromium + ;; + '--check-db') + check_new_db + ;; + '--smart-reload') + if [ $(check_new_db) -eq 1 ]; then + update_db + stop_bottledash + start_bottledash + sleep 10 + xdo_reload_chromium + fi + ;; + '-h'|'--help') + usage + exit 0 + ;; + *) + echo "ERROR: unknown command: $1" >&2 + usage + exit 2 + ;; +esac + +# vim: set ft=sh :