annotate 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
rev   line source
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env sh
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
2
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
3 export DISPLAY=":0.0"
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
4
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
5 OLDDB=/home/pi/incoming_dbs/tech_intern.db
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
6 NEWDB=/home/pi/incoming_dbs/tech_intern.db.new
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
7
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
8 usage () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
9 cat << EOF
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
10 Usage: $0 [COMMAND]
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
11
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
12 Commands:
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
13 --restart-bd Restart Bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
14 --reload-browser Reload dashboard/browser
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
15 --reload Restart Bottledash and reload the dashboard/browser
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
16 --check-db Check if a new DB is available
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
17 --smart-reload If a new DB is available, restart Bottledash and reload
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
18 the dashboard/browser
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
19 -h, --help This help
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
20 EOF
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
21 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
22
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
23 start_bottledash () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
24 # taken from start-bottledash-hohup
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
25 nohup python3 /home/pi/bottledash/dash.py 2>&1 > $HOME/bottledash.log &
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
26 echo $! > $HOME/pid_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
27 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
28
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
29 stop_bottledash () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
30 kill $(cat $HOME/pid_bottledash)
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
31 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
32
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
33 start_chromium () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
34 # taken from show-dashboard
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
35 rm -R $HOME/.cache/chromium/Default/Cache/
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
36 DISPLAY=:0.0 nohup chromium --new --noerrdialogs --kiosk \
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
37 http://localhost:8080 2>&1 > $HOME/show-dashboard.log &
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
38 echo $! > $HOME/pid_chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
39 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
40
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
41
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
42 stop_chromium () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
43 kill $(cat pid_chromium)
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
44 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
45
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
46 xdo_reload_chromium () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
47 # Start Chromium if necessary
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
48 if [ -f "$HOME/pid_bottledash" ] && [ -d /proc/$(cat "$HOME/pid_chromium") ]; then
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
49 # Send F5 to Chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
50 WID=$(xdotool search --onlyvisible --class chromium | head -1)
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
51 xdotool windowactivate ${WID}
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
52 xdotool key F5
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
53 else
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
54 start_chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
55 fi
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
56 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
57
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
58 check_new_db () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
59 if [ ! -f "$NEWDB" ]; then
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
60 echo 0 ; return
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
61 fi
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
62 OLDSIZE=$(md5sum $OLDDB | awk '{print $1}')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
63 NEWSIZE=$(md5sum $NEWDB | awk '{print $1}')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
64 if [ "$OLDSIZE" != "$NEWSIZE" ]; then
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
65 echo 1
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
66 else
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
67 echo 0
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
68 fi
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
69 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
70
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
71 update_db () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
72 if [ $(check_new_db) -eq 1 ]; then
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
73 mv "$NEWDB" "$OLDDB"
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
74 fi
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
75 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
76
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
77 case $1 in
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
78 '--restart-bd')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
79 stop_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
80 start_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
81 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
82 '--reload-browser')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
83 xdo_reload_chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
84 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
85 '--reload')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
86 stop_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
87 start_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
88 sleep 10
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
89 xdo_reload_chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
90 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
91 '--check-db')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
92 check_new_db
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
93 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
94 '--smart-reload')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
95 if [ $(check_new_db) -eq 1 ]; then
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
96 update_db
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
97 stop_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
98 start_bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
99 sleep 10
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
100 xdo_reload_chromium
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
101 fi
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
102 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
103 '-h'|'--help')
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
104 usage
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
105 exit 0
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
106 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
107 *)
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
108 echo "ERROR: unknown command: $1" >&2
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
109 usage
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
110 exit 2
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
111 ;;
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
112 esac
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
113
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
114 # vim: set ft=sh :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)