Mercurial > bottledash
annotate contrib/dashboardctl @ 38:3fc74bcbd2cf
Fix indentation; add Vim modeline
author | Gernot Schulz <gernot@intevation.de> |
---|---|
date | Tue, 20 Oct 2015 08:24:56 +0200 |
parents | 58ca5b1d33a5 |
children | c3955e5cf3b3 |
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 | 3 # ------------------------------------------------------------------- |
4 # Copyright (C) 2015 by Intevation GmbH | |
5 # Author(s): | |
6 # Gernot Schulz <gernot.schulz@intevation.de> | |
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 () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
43 kill $(cat $BOTTLEDASH_PID) |
33
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 start_chromium () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
47 # taken from show-dashboard |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
48 rm -R $HOME/.cache/chromium/Default/Cache/ |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
49 DISPLAY=:0.0 nohup chromium --new --noerrdialogs --kiosk \ |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
50 http://localhost:8080 2>&1 > $CHROMIUM_LOG & |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
51 echo $! > $CHROMIUM_PID |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
52 } |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
53 |
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 stop_chromium () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
56 kill $(cat $CHROMIUM_PID) |
33
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 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
59 xdo_reload_chromium () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
60 # Start Chromium if necessary |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
61 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
|
62 # Send F5 to Chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
63 WID=$(xdotool search --onlyvisible --class chromium | head -1) |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
64 xdotool windowactivate ${WID} |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
65 xdotool key F5 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
66 else |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
67 start_chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
68 fi |
33
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 check_new_db () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
72 if [ ! -f "$NEWDB" ]; then |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
73 echo 0 ; return |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
74 fi |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
75 OLDSIZE=$(md5sum $OLDDB | awk '{print $1}') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
76 NEWSIZE=$(md5sum $NEWDB | awk '{print $1}') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
77 if [ "$OLDSIZE" != "$NEWSIZE" ]; then |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
78 echo 1 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
79 else |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
80 echo 0 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
81 fi |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
82 } |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
83 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
84 update_db () { |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
85 if [ $(check_new_db) -eq 1 ]; then |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
86 mv "$NEWDB" "$OLDDB" |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
87 fi |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
88 } |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
89 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
90 case $1 in |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
91 '--start') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
92 start_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
93 start_chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
94 ;; |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
95 '--stop') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
96 stop_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
97 stop_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 '--restart-bd') |
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 start_bottledash |
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 '--reload-browser') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
104 xdo_reload_chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
105 ;; |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
106 '--reload') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
107 stop_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
108 start_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
109 xdo_reload_chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
110 ;; |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
111 '--check-db') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
112 check_new_db |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
113 ;; |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
114 '--smart-reload') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
115 if [ $(check_new_db) -eq 1 ]; then |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
116 update_db |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
117 stop_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
118 start_bottledash |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
119 sleep 10 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
120 xdo_reload_chromium |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
121 fi |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
122 ;; |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
123 '-h'|'--help') |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
124 usage |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
125 exit 0 |
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 *) |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
128 echo "ERROR: unknown command: $1" >&2 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
129 usage |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
130 exit 2 |
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
131 ;; |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
132 esac |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
133 |
38
3fc74bcbd2cf
Fix indentation; add Vim modeline
Gernot Schulz <gernot@intevation.de>
parents:
37
diff
changeset
|
134 # vim: set ft=sh ts=4 sw=4 expandtab : |