forked from tosca07/picochess
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkiosk.sh
More file actions
executable file
·167 lines (149 loc) · 4.31 KB
/
Copy pathkiosk.sh
File metadata and controls
executable file
·167 lines (149 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
is_wayland() {
[ "${XDG_SESSION_TYPE:-}" = "wayland" ] || [ -n "${WAYLAND_DISPLAY:-}" ]
}
if is_wayland; then
echo "kiosk.sh: Wayland session detected"
else
echo "kiosk.sh: X11 session detected"
xset s noblank
xset s off
xset -dpms
# Uncomment this to rotate the DSI display to portrait
# xrandr --output DSI-1 --rotate right
unclutter -idle 0.5 -root &
fi
if [ -d "/home/$USER/.config/chromium/Default" ]; then
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/$USER/.config/chromium/'Local State'
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/$USER/.config/chromium/Default/Preferences
fi
display_ready() {
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
return 0
fi
if [ -z "${DISPLAY:-}" ]; then
return 1
fi
if [ -n "${XDG_SESSION_TYPE:-}" ]; then
return 0
fi
ls /tmp/.X11-unix/X* >/dev/null 2>&1
}
terminal_cmd() {
if command -v lxterminal >/dev/null 2>&1; then
echo "lxterminal --title=Updating... -e sh -c 'tail -F /var/log/picochess-update.log'"
elif command -v xfce4-terminal >/dev/null 2>&1; then
echo "xfce4-terminal --disable-server --title=Updating... -e 'sh -c \"tail -F /var/log/picochess-update.log\"'"
elif command -v xterm >/dev/null 2>&1; then
echo "xterm -fullscreen -bg black -fg white -title Updating... -e sh -c 'tail -F /var/log/picochess-update.log'"
else
echo ""
fi
}
notify_no_terminal() {
local msg="Updating PicoChess... please wait (this can take 10-15 minutes)."
if [ -w /dev/console ]; then
printf '%s\n' "$msg" >/dev/console 2>/dev/null
fi
if command -v logger >/dev/null 2>&1; then
logger -t picochess-kiosk "$msg"
fi
}
update_pending() {
[ -f "${HOME}/run_picochess_update.flag" ]
}
close_update_terminal() {
if [ -n "${UPDATE_TERM_PID:-}" ] && kill -0 "$UPDATE_TERM_PID" 2>/dev/null; then
kill "$UPDATE_TERM_PID" 2>/dev/null
fi
if command -v pkill >/dev/null 2>&1; then
pkill -u "$USER" -f "lxterminal --title=Updating..." 2>/dev/null
pkill -u "$USER" -f "xfce4-terminal .*--title=Updating..." 2>/dev/null
pkill -u "$USER" -f "xterm -fullscreen.*-title Updating..." 2>/dev/null
pkill -u "$USER" -f "tail -F /var/log/picochess-update.log" 2>/dev/null
fi
UPDATE_TERM_PID=""
}
configured_web_port() {
awk -F= '
/^[[:space:]]*#/ { next }
/^[[:space:]]*web-server[[:space:]]*=/ {
value = $2
sub(/#.*/, "", value)
gsub(/[[:space:]]/, "", value)
print value
}
' /opt/picochess/picochess.ini 2>/dev/null | tail -n 1
}
port_open() {
local port="$1"
[ -n "$port" ] || return 1
(: >/dev/tcp/127.0.0.1/"$port") >/dev/null 2>&1
}
picochess_url() {
local port
port="$(configured_web_port)"
[ -n "$port" ] || port=80
case "$port" in
*[!0-9]*)
port=80
;;
esac
for _ in 1 2 3 4 5; do
if port_open "$port"; then
break
fi
if [ "$port" = "80" ] && port_open 8080; then
port=8080
break
fi
sleep 1
done
if [ "$port" = "80" ]; then
printf '%s\n' "http://127.0.0.1"
else
printf '%s\n' "http://127.0.0.1:$port"
fi
}
# This will wait for PicoChess to start before launching the browser
while true; do
if display_ready; then
if update_pending || systemctl is-active --quiet picochess-update.service; then
if [ -z "${UPDATE_TERM_PID:-}" ] || ! kill -0 "$UPDATE_TERM_PID" 2>/dev/null; then
TERM_CMD="$(terminal_cmd)"
if [ -n "$TERM_CMD" ]; then
eval "$TERM_CMD" &
UPDATE_TERM_PID=$!
NO_TERM_NOTICE_SENT=""
else
if [ -z "${NO_TERM_NOTICE_SENT:-}" ]; then
notify_no_terminal
NO_TERM_NOTICE_SENT="1"
fi
fi
fi
else
close_update_terminal
NO_TERM_NOTICE_SENT=""
fi
fi
systemctl is-active --quiet picochess
if [ $? -eq 0 ]; then
close_update_terminal
PICOCHESS_URL="$(picochess_url)"
if is_wayland; then
/usr/bin/chromium --password-store=basic --kiosk "$PICOCHESS_URL" &
else
/usr/bin/chromium --enable-features=OverlayScrollbar --password-store=basic --display=:0 --noerrdialogs --disable-infobars --kiosk "$PICOCHESS_URL" &
fi
exit 0
else
/bin/sleep 5
fi
done
# This section will enable a refresh by chromium every 'sleep xx' seconds.
#
#while true; do
# xdotool keydown ctrl+r; xdotool keyup ctrl+r;
# sleep 20
#done