-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient-install-raspberry-pi.sh
executable file
·492 lines (364 loc) · 12.8 KB
/
client-install-raspberry-pi.sh
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
#!/bin/bash
# Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
# Copyright (C) 2019-2022 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Original Authors : Debayan Sutradhar (@rnayabed), Jordan Duabe (@j4ckofalltrades)
# Installer Script for Raspberry Pi
VERSION=2.3
DOWNLOAD_LINK=https://github.com/stream-pi/client/releases/download/1.0.0-EA%2B3/stream-pi-client-linux-arm32-1.0.0-EA+3-executable.zip
CONFIG=/boot/config.txt
NINE_NINE_RULES_FILE=/etc/udev/rules.d/99-com.rules
BACKLIGHT_PERMISSIONS_RULES_FILE=/etc/udev/rules.d/backlight-permissions.rules
INSTALL_DIRECTORY=$HOME # current user's home dir as default
FOLDER_NAME=stream-pi-client/
DESKTOP_SHORTCUT="${HOME}/Desktop/Stream-Pi Client.desktop"
CREATE_SHORTCUT=true
SLEEP_DURATION=10
GPU_MEM=128
DEBUG=0
CHANGE_BACKLIGHT_PERMISSIONS=true
AXEL_THREADS=4
DOWNLOAD=true
ZIP_FILE="spi.zip"
PRESERVE_DATA=false
ADD_TOUCH_SUPPORT=true
USE_WGET=false
SKIP_KMS_PROMPT=0
# SKIP_KMS_PROMPT details
# 0 = Do not skip
# 1 = Skip and enable
# 2 = Skip and do not enable
SKIP_REBOOT_PROMPT=0
# SKIP_REBOOT_PROMPT details
# 0 = Do not skip
# 1 = Skip and reboot
# 2 = Skip and do not reboot
# Necessary Methods
is_pi() {
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
return true
else
return false
fi
}
usage() {
cat << EOF
Usage: [-h | --help] [-v | --verbose]
[-d | --download-link] [-g | --gpu-mem]
[-i | --install-dir] [-c | --client-dir]
[-s | --skip-shortcut] [-b | --backlight-no]
[-ky | --enable-kms] [-kn | --dont-enable-kms]
[-ry | --reboot-after-install] [-rn | --dont-reboot-after-install]
[-z | --zip] [-p | --preserve-old-data]
[-t | --dont-add-touch] [-at | --axel-threads]
[-uw | --use-wget]
If no arguments are provided, installation will continue using the default
values.
-h --help Print this message.
-v --verbose Print debug information.
-d --download-link Set custom download link for Stream-Pi client.
Defaults to the latest stable release.
-g --gpu-mem Set custom GPU memory split, defaults to 128.
-i --install-dir Set custom root installation directory.
Defaults to user's home directory.
-c --client-dir Set custom directory for the client application.
This will be a sub-directory under 'install-dir',
defaults to 'stream-pi-client'.
-s --skip-shortcut Does not create shortcut in Desktop.
-b --backlight-no Does not modify Official Screen backlight persmissions.
-ky --enable-kms Skips user prompt and turns on KMS driver.
-kn --dont-enable-kms Skips user prompt and does not turn on KMS driver.
-ry --reboot-after-install Skip reboot prompt and reboot automatically after installation.
-rn --dont-reboot-after-install Skips reboot prompt and does NOT perform reboot after installation.
Not Recommended with fresh installs.
-z --zip-file Use custom zip instead of downloading.
-p --preserve-old-data Skips user data and preserve previous Stream-Pi data (if found).
Not recommended for upgrading to different versions.
-t --dont-add-touch Does not add touch support.
Not recommended if Client is to be used in Console mode.
-at --axel-threads Specify number of axel threads while downloading. Default is 4.
-uw --use-wget Use wget instead of axel to download.
EOF
}
parse_params() {
while :; do
case "${1-}" in
-v | --verbose) DEBUG=1 ;;
-d | --download-link)
DOWNLOAD_LINK="${2-}"
shift
;;
-g | --gpu-mem)
GPU_MEM="${2-}"
shift
;;
-i | --install-dir)
INSTALL_DIRECTORY="${2-}"
shift
;;
-c | --client-dir)
FOLDER_NAME="${2-}"
shift
;;
-s | --skip-shortcut)
CREATE_SHORTCUT=false
;;
-b | --backlight-no)
CHANGE_BACKLIGHT_PERMISSIONS=false
;;
-ky | --enable-kms)
SKIP_KMS_PROMPT=1
;;
-kn | --dont-enable-kms)
SKIP_KMS_PROMPT=2
;;
-ry | --reboot-after-install)
SKIP_REBOOT_PROMPT=1
;;
-rn | --dont-reboot-after-install)
SKIP_REBOOT_PROMPT=2
;;
-z | --zip-file)
DOWNLOAD=false
ZIP_FILE="${2-}"
shift
;;
-p | --preserve-old-data)
PRESERVE_DATA=true
;;
-t | --dont-add-touch)
ADD_TOUCH_SUPPORT=false
;;
-at | --axel-threads)
AXEL_THREADS=${2-}
shift
;;
-uw | --use-wget)
USE_WGET=true
;;
*)
if [ ! -z "${1-}" -a "${1-}" != " " ]; then
usage
exit 0
else
break
fi
;;
esac
shift
done
}
print_params() {
cat << EOF
Installation params:
---
DOWNLOAD_LINK=$DOWNLOAD_LINK
GPU_MEM=$GPU_MEM
INSTALL_DIRECTORY=$INSTALL_DIRECTORY
FOLDER_NAME=$FOLDER_NAME
CREATE_SHORTCUT=$CREATE_SHORTCUT
CHANGE_BACKLIGHT_PERMISSIONS=$CHANGE_BACKLIGHT_PERMISSIONS
SKIP_KMS_PROMPT=$SKIP_KMS_PROMPT
SKIP_REBOOT_PROMPT=$SKIP_REBOOT_PROMPT
DOWNLOAD=$DOWNLOAD
ZIP_FILE=$ZIP_FILE
ADD_TOUCH_SUPPORT=$ADD_TOUCH_SUPPORT
AXEL_THREADS=$AXEL_THREADS
USE_WGET=$USE_WGET
---
EOF
}
# Check whether this is a pi or not
if [ ! is_pi ]; then
echo This script is only for Raspberry Pi Devices.
exit 1
fi
parse_params "$@"
if [ "$DEBUG" -eq 1 ]; then
print_params
fi
# Print intro
cat << EOF
,***///****. ,****///***,
.*//*,,*//////, *//////*,**//*.
,//////**,,*/* */*,,**/////*.
,////////. ,////////,
..,,.. (/ .,,,..
.(@@@@/.
*&@@@&(*,. .,*(&@@@&/
/@@@/ /@@@/
*&@( .,. .,. /@&*
,&@@/ #@&#&@%%@&(, /@@&,
(@@&. #@* &@. ,#@&( .&@@(
#@@. #@* &@. ,#&&(. .&@#
(@# /@@&%@@@&/. #@(
%@%. .%@%
*&@&* *&@&*
,#&&%(/****/(%&&#,
.(@@@@@&(.
Stream-Pi Client Installer For Raspberry Pi
v$VERSION
EOF
# Update ...
echo -e "\nUpdate ..."
sudo apt-get update
if [ $? -ne 0 ]; then
echo Unable to run apt update. Check internet connection / permissions. Quitting ...
exit 1
fi
# Installing required dependencies ...
echo -e "\nInstalling required dependencies ..."
sudo apt-get -y install unzip axel libegl-mesa0 libegl1 libgbm1 libgles2 libpango1.0-0 libpangoft2-1.0.0 libgl1-mesa-dri gldriver-test libgtk-3-0
if [ $? -ne 0 ]; then
echo Unable to install required dependencies. Quitting ...
exit 1
fi
# Delete old client
if [ -d "$INSTALL_DIRECTORY/$FOLDER_NAME" ]; then
echo -e "\nDeleting existing Stream-Pi Client ..."
rm -rf "$INSTALL_DIRECTORY/$FOLDER_NAME"
fi
# Delete old data
if [ -d "${HOME}/Stream-Pi/" ]; then
if [ "$PRESERVE_DATA" == false ]; then
echo -e "\nDelete old data ..."
rm -rf "${HOME}/Stream-Pi/"
fi
fi
# Finally Download and extract
if [ "$DOWNLOAD" == true ]; then
echo -e "\nDownloading Client ..."
cd "$HOME"
if [ "$USE_WGET" == true ]; then
if ! wget $DOWNLOAD_LINK -O "$ZIP_FILE" ; then
echo Unable to Download. Quitting ...
exit 1
fi
else
if ! axel -k -a -n $AXEL_THREADS --output="$ZIP_FILE" $DOWNLOAD_LINK ; then
echo Unable to Download. Quitting ...
exit 1
fi
fi
fi
echo -e "\nExtracting ..."
unzip "$ZIP_FILE" -d "$FOLDER_NAME"
if [ "$DOWNLOAD" == true ]; then
echo -e "\nClean up ..."
rm -rf "$ZIP_FILE"
fi
echo -e "\nSetting permissions ..."
cd "$FOLDER_NAME"
chmod +x run_console
chmod +x run_desktop
if [ -f jre/bin/java ]; then
chmod +x jre/bin/java
fi
# Add support for touch
grep -q -E "chown -R root:input /sys/class/input/\*/ && chmod -R 770 /sys/class/input/\*/;" "$NINE_NINE_RULES_FILE"
if [ $? -ne 0 ] && [ "$ADD_TOUCH_SUPPORT" == true ]; then
echo -e "\nAdding touch support ..."
sudo tee -a "$NINE_NINE_RULES_FILE" > /dev/null <<EOT
SUBSYSTEM=="input*", PROGRAM="/bin/sh -c '\
chown -R root:input /sys/class/input/*/ && chmod -R 770 /sys/class/input/*/;\
'"
EOT
fi
# Allow non-root change of backlight power
if [ "$CHANGE_BACKLIGHT_PERMISSIONS" == true ]; then
echo -e "\nAdding backlight power change permission ..."
sudo tee -a "$BACKLIGHT_PERMISSIONS_RULES_FILE" > /dev/null <<EOT
SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"
EOT
fi
# Turn on FAKE KMS Driver
enable_kms() {
echo -e "\nTurning ON KMS Driver ..."
sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/g"
sed $CONFIG -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/g"
if ! sed -n "/\[pi4\]/,/\[/ !p" $CONFIG | grep -q "^dtoverlay=vc4-kms-v3d" ; then
printf "[all]\ndtoverlay=vc4-kms-v3d\n" >> $CONFIG
fi
}
if [ ! -d "/dev/dri" ]; then
if [ "$SKIP_KMS_PROMPT" == 0 ]; then
cat << EOF
===================================
ATTENTION! PLEASE READ CAREFULLY!
Stream-Pi Client can run either in Console Mode or Desktop Mode.
It is recommended to use console mode as Stream-Pi Client can then leverage Hardware acceleration and offer a smooth experience.
Stream-Pi Client CANNOT run in console mode with the KMS Driver turned OFF.
To ensure maximum compatibility, Stream-Pi Client can also run in Desktop Mode in case KMS is not available/disabled.
However, certain screens like the HyperPixel for Raspberry Pi conflicts with the KMS driver.
Stream-Pi Client can still run on these screens using desktop mode.
Fortunately, most screens like the Official 7" Raspberry Pi Display, Waveshare screens (including clones) work well with the KMS Driver.
You can later disable or enable the KMS driver using the "raspi-config" tool, or by modifying /boot/config.txt
Do you want to turn on the KMS Driver ? [Y/N]
EOF
read -n 1 -r </dev/tty
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
enable_kms
fi
elif [ "$SKIP_KMS_PROMPT" == 1 ]; then
enable_kms
fi
fi
# Add GPU MEM
echo -e "\nSetting gpu_mem to $GPU_MEM MB ..."
sudo sed "$CONFIG" -i -e "s/^gpu_mem=/#gpu_mem=/g"
sudo sed "$CONFIG" -i -e "s/^#gpu_mem=$GPU_MEM/gpu_mem=$GPU_MEM/g"
if ! sudo sed -n "/\[pi4\]/,/\[/ !p" "$CONFIG" | grep -q "^gpu_mem=$GPU_MEM" ; then
sudo sh -c "printf 'gpu_mem=$GPU_MEM\n' >> $CONFIG"
fi
# Create desktop shortcut
if [ ! -d "${HOME}/Desktop" ] && [ "$CREATE_SHORTCUT" == true ]; then
CREATE_SHORTCUT=false
fi
if [ "${CREATE_SHORTCUT}" == true ]; then
sudo rm -rf "${DESKTOP_SHORTCUT}"
echo -e "\nCreating desktop shortcut : $DESKTOP_SHORTCUT"
tee -a "${DESKTOP_SHORTCUT}" > /dev/null <<EOT
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Stream-Pi Client (Desktop Mode)
Comment=Cross Platform Macropad Software
Icon=$INSTALL_DIRECTORY/$FOLDER_NAME/app-icon.png
Exec=$INSTALL_DIRECTORY/$FOLDER_NAME/run_desktop
Terminal=false
EOT
chmod +x "${DESKTOP_SHORTCUT}"
fi
# Finish Message
cat << EOF
===================================
Stream-Pi Client is now successfully installed. However your Pi needs to be restarted.
After Restart, You may cd to "$INSTALL_DIRECTORY/$FOLDER_NAME"
and run './run_console' to run in Console mode using KMS Driver (Recommended)
or run './run_desktop' to run in Desktop Mode without hardware acceleration.
WARNING: You cannot run Stream-Pi Client as desktop mode while you are in console mode, and vice versa.
EOF
if [ "$CREATE_SHORTCUT" == true ]; then
echo -e "A desktop shortcut has also been created in $HOME/Desktop for ease of use."
fi
if [ "$SKIP_REBOOT_PROMPT" == 0 ]; then
echo -e "\nRestart now? [Y/N]\n"
read -n 1 -r </dev/tty
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
SKIP_REBOOT_PROMPT=1
fi
fi
if [ "$SKIP_REBOOT_PROMPT" == 1 ]; then
echo Rebooting ...
sudo reboot
fi