annotate contrib/dashboardctl @ 40:bef9105f2d28

Merge dashboardctl repository
author Gernot Schulz <gernot@intevation.de>
date Tue, 10 Nov 2015 11:47:46 +0100
parents c3955e5cf3b3
children
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
37
58ca5b1d33a5 Add copyright info
Gernot Schulz <gernot@intevation.de>
parents: 36
diff changeset
3 # -------------------------------------------------------------------
58ca5b1d33a5 Add copyright info
Gernot Schulz <gernot@intevation.de>
parents: 36
diff changeset
4 # Copyright (C) 2015 by Intevation GmbH
58ca5b1d33a5 Add copyright info
Gernot Schulz <gernot@intevation.de>
parents: 36
diff changeset
5 # Author(s):
58ca5b1d33a5 Add copyright info
Gernot Schulz <gernot@intevation.de>
parents: 36
diff changeset
6 # Gernot Schulz <gernot.schulz@intevation.de>
58ca5b1d33a5 Add copyright info
Gernot Schulz <gernot@intevation.de>
parents: 36
diff changeset
7
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
8 export DISPLAY=":0.0"
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
9
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
10 OLDDB=/home/pi/incoming_dbs/tech_intern.db
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
11 NEWDB=/home/pi/incoming_dbs/tech_intern.db.new
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
12
34
7162616389a5 Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents: 33
diff changeset
13 BOTTLEDASH_PID="$HOME/bottledash.pid"
7162616389a5 Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents: 33
diff changeset
14 BOTTLEDASH_LOG="$HOME/bottledash.log"
7162616389a5 Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents: 33
diff changeset
15 CHROMIUM_PID="$HOME/chromium.pid"
7162616389a5 Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents: 33
diff changeset
16 CHROMIUM_LOG="$HOME/chromium.log"
7162616389a5 Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents: 33
diff changeset
17
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
18 usage () {
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
19 cat << EOF
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
20 Usage: $0 [COMMAND]
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 Commands:
36
1e084c23d101 Add --start/--stop commands
Gernot Schulz <gernot@intevation.de>
parents: 35
diff changeset
23 --start Start Bottledash and the dashboard/browser
1e084c23d101 Add --start/--stop commands
Gernot Schulz <gernot@intevation.de>
parents: 35
diff changeset
24 --stop Stop Bottledash and the dashboard/browser
1e084c23d101 Add --start/--stop commands
Gernot Schulz <gernot@intevation.de>
parents: 35
diff changeset
25 --reload Restart Bottledash and reload the dashboard/browser
1e084c23d101 Add --start/--stop commands
Gernot Schulz <gernot@intevation.de>
parents: 35
diff changeset
26 --smart-reload If a new DB is available, restart Bottledash and reload
1e084c23d101 Add --start/--stop commands
Gernot Schulz <gernot@intevation.de>
parents: 35
diff changeset
27 the dashboard/browser
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
28 --restart-bd Restart Bottledash
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
29 --reload-browser Reload dashboard/browser
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
30 --check-db Check if a new DB is available
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
31 -h, --help This help
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
32 EOF
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
33 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
34
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
35 start_bottledash () {
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
36 # taken from start-bottledash-hohup
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
37 nohup python3 /home/pi/bottledash/dash.py 2>&1 > $BOTTLEDASH_LOG &
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
38 echo $! > $BOTTLEDASH_PID
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
39 sleep 10
33
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_bottledash () {
39
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
43 if [ -f "$BOTTLEDASH_PID" ]; then
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
44 kill $(cat "$BOTTLEDASH_PID") && rm "$BOTTLEDASH_PID"
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
45 fi
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
46 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
47
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
48 start_chromium () {
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
49 # taken from show-dashboard
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
50 rm -R $HOME/.cache/chromium/Default/Cache/
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
51 DISPLAY=:0.0 nohup chromium --new --noerrdialogs --kiosk \
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
52 http://localhost:8080 2>&1 > $CHROMIUM_LOG &
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
53 echo $! > $CHROMIUM_PID
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
54 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
55
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 stop_chromium () {
39
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
58 if [ -f "$CHROMIUM_PID" ]; then
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
59 kill $(cat "$CHROMIUM_PID") && rm "$CHROMIUM_PID"
c3955e5cf3b3 Improve stop functions
Gernot Schulz <gernot@intevation.de>
parents: 38
diff changeset
60 fi
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
61 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
62
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
63 xdo_reload_chromium () {
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
64 # Start Chromium if necessary
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
65 if [ -f "$BOTTLEDASH_PID" ] && [ -d /proc/$(cat "$CHROMIUM_PID") ]; then
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
66 # Send F5 to Chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
67 WID=$(xdotool search --onlyvisible --class chromium | head -1)
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
68 xdotool windowactivate ${WID}
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
69 xdotool key F5
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
70 else
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
71 start_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
72 fi
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
73 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
74
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
75 check_new_db () {
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
76 if [ ! -f "$NEWDB" ]; then
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
77 echo 0 ; return
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
78 fi
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
79 OLDSIZE=$(md5sum $OLDDB | awk '{print $1}')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
80 NEWSIZE=$(md5sum $NEWDB | awk '{print $1}')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
81 if [ "$OLDSIZE" != "$NEWSIZE" ]; then
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
82 echo 1
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
83 else
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
84 echo 0
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
85 fi
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
86 }
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
87
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
88 update_db () {
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
89 if [ $(check_new_db) -eq 1 ]; then
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
90 mv "$NEWDB" "$OLDDB"
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
91 fi
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
92 }
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 case $1 in
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
95 '--start')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
96 start_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
97 start_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
98 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
99 '--stop')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
100 stop_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
101 stop_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
102 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
103 '--restart-bd')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
104 stop_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
105 start_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
106 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
107 '--reload-browser')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
108 xdo_reload_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
109 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
110 '--reload')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
111 stop_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
112 start_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
113 xdo_reload_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
114 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
115 '--check-db')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
116 check_new_db
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
117 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
118 '--smart-reload')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
119 if [ $(check_new_db) -eq 1 ]; then
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
120 update_db
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
121 stop_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
122 start_bottledash
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
123 sleep 10
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
124 xdo_reload_chromium
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
125 fi
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
126 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
127 '-h'|'--help')
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
128 usage
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
129 exit 0
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
130 ;;
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
131 *)
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
132 echo "ERROR: unknown command: $1" >&2
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
133 usage
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
134 exit 2
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
135 ;;
33
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
136 esac
70d50b6312e2 Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff changeset
137
38
3fc74bcbd2cf Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents: 37
diff changeset
138 # vim: set ft=sh ts=4 sw=4 expandtab :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)