-
Notifications
You must be signed in to change notification settings - Fork 3
/
raspberrypi
288 lines (226 loc) · 8.7 KB
/
raspberrypi
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
WAYLAND_SESSION_NAME="LXDE-pi-labwc"
log() {
if [[ $2 != "" ]]; then
printf "\n[ERRO] $1\n"
cat <<EOF
The program has stopped due to the above error
If you believe this is a bug, please report it.
If you are having issues please ask for help from Geckoboard support
Press any key to exit
EOF
# Give the user time to see this message
read
exit 127
else
printf "\n[INFO] $1\n"
fi
}
upgrade_system() {
sudo apt -qq upgrade -y
sudo apt -qq autoremove -y > /dev/null
}
install_color_emoji() {
NOTOEMOJI_ZIPFILE=noto_color_emoji.zip
FONT_STORE=$HOME/.local/share/fonts
NOTOEMOJI_DIR=noto_color_emoji
curl -o $NOTOEMOJI_ZIPFILE https://noto-website-2.storage.googleapis.com/pkgs/NotoColorEmoji-unhinted.zip
unzip $NOTOEMOJI_ZIPFILE -d $NOTOEMOJI_DIR
mkdir -p $FONT_STORE
mv $NOTOEMOJI_DIR/*.ttf $FONT_STORE/
rm -r $NOTOEMOJI_DIR || true
rm $NOTOEMOJI_ZIPFILE || true
}
install_hide_cursor() {
if [[ $DESKTOP_SESSION = $WAYLAND_SESSION_NAME ]]; then
echo "Hide cursor for labwc not supported yet"
# This is not yet supported we need to either write something to use
# wayland client to hide the cursor or use libinput to move the cursor
else
# Unclutter is only applicable to non-wayland setups
sudo apt install -y unclutter
fi
}
check_raspberrypi() {
if ! `lsb_release -a | grep -Eq "Raspbian|Debian"`; then
log "this device appears not to be running raspbian os" 1
fi
if ! `uname -m | grep -Eq "armv|aarch64"` ; then
log "this device doesn't appear to be a raspberry pi" 1
fi
if [[ `echo $DESKTOP_SESSION | grep -Eq "^(LXDE-pi|LXDE-pi-labwc)$"` ]]; then
log "this device isn't running a supported desktop environment", 1
fi
}
install_kiosk_script_for_labwc_compositor() {
GECKOBOARD_KIOSK_FILE=$HOME/.local/geckoboard_kiosk_mode
LABWC_CONFIG_PATH=$HOME/.config/labwc
LABWC_AUTOSTART=$LABWC_CONFIG_PATH/autostart
cat > $GECKOBOARD_KIOSK_FILE <<EOF
#!/bin/bash
# Ensure that if we have a power cut or bad shutdown that
# the chromium preferences are reset to a "good" state so we
# don't get the restore previous session dialog
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' $HOME/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' $HOME/.config/chromium/Default/Preferences
# Disable any installed extentions and the default browser check and error dialogs
# We need to add the switch start-maximized otherwise on wayland it will
# start as a pixel size and not displayed using start-maximized fixes that
chromium-browser \
--disable-extensions \
--start-maximized \
--start-fullscreen \
--no-default-browser-check \
https://app.geckoboard.com/tv
EOF
mkdir -p $LABWC_CONFIG_PATH
chmod +x $GECKOBOARD_KIOSK_FILE
if grep -Fxq "$GECKOBOARD_KIOSK_FILE" $LABWC_AUTOSTART; then
echo "[SKIP] kiosk mode already setup"
else
echo "$GECKOBOARD_KIOSK_FILE &" >> $LABWC_AUTOSTART
fi
}
install_kiosk_script() {
AUTOSTART_PATH=$HOME/.config/lxsession/LXDE-pi
AUTOSTART_FILE=$AUTOSTART_PATH/autostart
GECKOBOARD_KIOSK_FILE=$AUTOSTART_PATH/geckoboard_kiosk_mode
mkdir -p $AUTOSTART_PATH
cat > $GECKOBOARD_KIOSK_FILE <<EOF
#!/bin/bash
# Turn off screensaver stuff and disable energysaver stuff
xset -dpms
xset s noblank
xset s off
# Remove the mouse cursor after 10 seconds of idleness
# This uses grab to remove focus from the browser in case of link hover
unclutter -idle 10 -grab &
# Ensure that if we have a power cut or bad shutdown that
# the chromium preferences are reset to a "good" state so we
# don't get the restore previous session dialog
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' $HOME/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' $HOME/.config/chromium/Default/Preferences
# Disable any installed extentions and the default browser check
chromium-browser \
--disable-extensions \
--start-fullscreen \
--no-default-browser-check \
https://app.geckoboard.com/tv
EOF
chmod +x $GECKOBOARD_KIOSK_FILE
if [[ ! -f $AUTOSTART_FILE ]]; then
# We are clear to clone the current autostart
echo "[INFO] cloning system lxde autostart"
cp /etc/xdg/lxsession/LXDE-pi/autostart $AUTOSTART_FILE
log "adding kiosk mode to autostart"
echo "@$GECKOBOARD_KIOSK_FILE" >> $AUTOSTART_FILE
else
if grep -Fxq "@$GECKOBOARD_KIOSK_FILE" $AUTOSTART_FILE; then
echo "[SKIP] kiosk mode already setup"
else
log "adding kiosk mode to autostart"
echo "@$GECKOBOARD_KIOSK_FILE" >> $AUTOSTART_FILE
fi
fi
}
disable_underscan() {
# Create a backup file before modifying
sudo cp /boot/config.txt /boot/config.txt.bkp
sudo sed -i 's/#disable_overscan=1/disable_overscan=1/' /boot/config.txt
}
# Ensure for bookworm that when turning off the connected display instead of it
# disconnecting and causing Chrome to come out of fullscreen due to re-assessing
# the display, we now we enforce a permanent display when HDMI is "disconnected"
# We need to check which HDMI port is connected and inject to the boot cmdlines
# 1) Is HDMI port nearest to power
# 2) next one
# 3) we don't use here, but means both are connected
# This means that if we setup on 1 and connect to port 2 we will get a seperate
# display instead of the "main" one. Re-running this script will always update.
force_hdmi_display() {
ACTIVE_HDMI_PORT=`wlr-randr | grep HDMI | grep -v null`
BOOT_CMD_FILE=/boot/firmware/cmdline.txt
sudo cp "$BOOT_CMD_FILE" "$BOOT_CMD_FILE".bkp
HDMI_PORT=1
HOTPLUG_CMD=vc4.force_hotplug
if [[ "$ACTIVE_HDMI_PORT" =~ "HDMI-A-2" ]]; then
HDMI_PORT=2
fi
if grep -q "$HOTPLUG_CMD" $BOOT_CMD_FILE; then
echo "Amending existing HDMI hot plug setting"
sed "s/$HOTPLUG_CMD=[1-3]/$HOTPLUG_CMD=$HDMI_PORT/" $BOOT_CMD_FILE | xargs echo -n | sudo tee $BOOT_CMD_FILE
else
echo "Setting up HDMI hotplug"
echo -n " $HOTPLUG_CMD=$HDMI_PORT" | sudo tee -a $BOOT_CMD_FILE
fi
}
# Display logo and intro to user
# ASCII display generated at https://www.ascii-art-generator.org/
cat <<EOF
_____ ______ _____ _ ______ ____ ____ _____ _____
/ ____| ____/ ____| |/ / __ \| _ \ / __ \ /\ | __ \| __ \
| | __| |__ | | ' / | | | |_| | | | | / \ | |__| | | | |
| | |_ | __| | | < | | | _ <| | | |/ /\ \ | _ /| | | |
| |__| | |___ |____| ' \ |__| | |_| | |__| / ____ \| | \ \| |__| |
\_____|______\_____|_|\_\____/|____/ \____/_/ \_\_| \_\_____/
We will guide you through setting up your device optimized to display Geckoboard.
Along the way you will have the option to not do some things for which you can just press enter
The questions which will be asked will be just require either y for Yes or n for No
by default the answer will assume No (y/N) declared by the capital N in these cases you can just press enter
We will do the following;
- Turn off any underscan if necessary
- Upgrade your raspbian OS with the latest updates
- Ensure Chromium is installed and the latest version available
- Install color emoji support
- Install Microsoft core fonts
- Install a script which will disable screensaver/power settings and
start chromium at Geckoboard on each startup
This process should only take a few minutes
If you are ready press any key to start
EOF
read
check_raspberrypi
log "getting latest packages"
sudo apt update -y
# Only ask about underscan for non-wayland instances
if [[ $DESKTOP_SESSION != $WAYLAND_SESSION_NAME ]]; then
printf "do you see black border around the screen [y/N]:"
read blkbrd
if [[ $blkbrd == "y" ]]; then
log "disabling underscan"
disable_underscan
fi
fi
printf "do you want to install latest updates (it might take 10+ mins) [y/N]:"
read upgr
if [[ $upgr == "y" ]]; then
log "updating os packages"
upgrade_system
fi
log "installing latest chromium browser and tools"
sudo apt install -y chromium-browser > /dev/null
install_hide_cursor > /dev/null
log "installing mscore fonts"
sudo apt install -y ttf-mscorefonts-installer > /dev/null
log "installing color emoji support"
install_color_emoji > /dev/null
log "setting up Geckoboard kiosk mode"
# Wayfire compositor handles autostart so check the session
# and use the wayland installation as we can't support any X11 stuff
if [[ $DESKTOP_SESSION = $WAYLAND_SESSION_NAME ]]; then
force_hdmi_display
install_kiosk_script_for_labwc_compositor
else
install_kiosk_script
fi
cat <<EOF
************ Setup complete ***********
Check out the send to TV support article on how to pair your device with Geckoboard
Now you are ready to reboot the raspberry pi.
When raspberry pi next starts up it should display the TV pin code
http://bit.ly/gbontvdoc
You'll be empowering your team to be the best in no time
When you are ready press any key to reboot.
EOF
read
sudo reboot