forked from PiSCSI/piscsi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyinstall.sh
executable file
·1386 lines (1227 loc) · 50.7 KB
/
easyinstall.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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# BSD 3-Clause License
# Author @sonique6784
# Copyright (c) 2020, sonique6784
function showRaSCSILogo(){
logo="""
.~~. .~~.\n
'. \ ' ' / .'\n
.╔═══════╗.\n
: ║|¯¯¯¯¯|║ :\n
~ (║|_____|║) ~\n
( : ║ . __ ║ : )\n
~ .╚╦═════╦╝. ~\n
( ¯¯¯¯¯¯¯ ) RaSCSI Reloaded Assistant\n
'~ .~~~. ~'\n
'~'\n
"""
echo -e $logo
}
function showMacNetworkWired(){
logo="""
.-~-.-~~~-.~-.\n
╔═══════╗ .( )\n
║|¯¯¯¯¯|║ / \`.\n
║|_____|║>--------------<~ . )\n
║ . __ ║ ( :'-'\n
╚╦═════╦╝ ~-.________.:'\n
¯¯¯¯¯¯¯\n
"""
echo -e $logo
}
function showMacNetworkWireless(){
logo="""
.-~-.-~~~-.~-.\n
╔═══════╗ .( .( )\n
║|¯¯¯¯¯|║ .( .( / \`.\n
║|_____|║ .o o ~ . )\n
║ . __ ║ '( '( ( :'-'\n
╚╦═════╦╝ '( ~-.________.:'\n
¯¯¯¯¯¯¯\n
"""
echo -e $logo
}
USER=$(whoami)
BASE=$(dirname "$(readlink -f "${0}")")
VIRTUAL_DRIVER_PATH="$HOME/images"
CFG_PATH="$HOME/.config/rascsi"
WEB_INSTALL_PATH="$BASE/python/web"
OLED_INSTALL_PATH="$BASE/python/oled"
CTRLBOARD_INSTALL_PATH="$BASE/python/ctrlboard"
PYTHON_COMMON_PATH="$BASE/python/common"
SYSTEMD_PATH="/etc/systemd/system"
SSL_CERTS_PATH="/etc/ssl/certs"
SSL_KEYS_PATH="/etc/ssl/private"
HFS_FORMAT=/usr/bin/hformat
HFDISK_BIN=/usr/bin/hfdisk
LIDO_DRIVER=$BASE/lido-driver.img
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_REMOTE=${GIT_REMOTE:-origin}
TOKEN=""
SECRET_FILE="$HOME/.config/rascsi/rascsi_secret"
set -e
# checks to run before entering the script main menu
function initialChecks() {
if [ "root" == "$USER" ]; then
echo "Do not run this script as $USER or with 'sudo'."
exit 1
fi
}
# checks that the current user has sudoers privileges
function sudoCheck() {
echo "Input your password to allow this script to make the above changes."
sudo -v
}
# install all dependency packages for RaSCSI Service
function installPackages() {
sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y -qq \
build-essential \
git \
libspdlog-dev \
libpcap-dev \
libprotobuf-dev \
genisoimage \
python3 \
python3-dev \
python3-pip \
python3-venv \
python3-setuptools \
python3-wheel \
nginx-light \
protobuf-compiler \
bridge-utils \
libev-dev \
libevdev2 \
unzip \
unar \
disktype \
libgmock-dev
}
# install Debian packges for RaSCSI standalone
function installPackagesStandalone() {
sudo apt-get update && sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y -qq \
build-essential \
libspdlog-dev \
libpcap-dev \
libprotobuf-dev \
protobuf-compiler \
disktype \
libgmock-dev
}
# cache the pip packages
function cachePipPackages(){
pushd $WEB_INSTALL_PATH
# Refresh the sudo authentication, which shouldn't trigger another password prompt
sudo -v
sudo pip3 install -r ./requirements.txt
popd
}
# compile the RaSCSI binaries
function compileRaScsi() {
cd "$BASE/src/raspberrypi" || exit 1
echo "Compiling with ${CORES:-1} simultaneous cores..."
make clean </dev/null
# Refresh the sudo authentication, which shouldn't trigger another password prompt
sudo -v
make -j "${CORES:-1}" all CONNECT_TYPE="${CONNECT_TYPE:-FULLSPEC}" </dev/null
}
function cleanupOutdatedManPage() {
OUTDATED_MAN_PAGE_DIR=/usr/share/man/man1/
if [ -f "${OUTDATED_MAN_PAGE_DIR}/$1" ]; then
sudo rm "${OUTDATED_MAN_PAGE_DIR}/$1"
fi
}
# install the RaSCSI binaries and modify the service configuration
function installRaScsi() {
# clean up outdated man pages if they exist
cleanupOutdatedManPage "rascsi.1"
cleanupOutdatedManPage "rasctl.1"
cleanupOutdatedManPage "scsimon.1"
cleanupOutdatedManPage "rasdump.1"
cleanupOutdatedManPage "sasidump.1"
# install
sudo make install CONNECT_TYPE="${CONNECT_TYPE:-FULLSPEC}" </dev/null
}
function preparePythonCommon() {
if [ -f "$WEB_INSTALL_PATH/src/rascsi_interface_pb2.py" ]; then
sudo rm "$WEB_INSTALL_PATH/src/rascsi_interface_pb2.py"
echo "Deleting old Python protobuf library $WEB_INSTALL_PATH/src/rascsi_interface_pb2.py"
fi
if [ -f "$OLED_INSTALL_PATH/src/rascsi_interface_pb2.py" ]; then
sudo rm "$OLED_INSTALL_PATH/src/rascsi_interface_pb2.py"
echo "Deleting old Python protobuf library $OLED_INSTALL_PATH/src/rascsi_interface_pb2.py"
fi
if [ -f "$PYTHON_COMMON_PATH/src/rascsi_interface_pb2.py" ]; then
sudo rm "$PYTHON_COMMON_PATH/src/rascsi_interface_pb2.py"
echo "Deleting old Python protobuf library $PYTHON_COMMON_PATH/src/rascsi_interface_pb2.py"
fi
echo "Compiling the Python protobuf library rascsi_interface_pb2.py..."
protoc -I="$BASE/src/raspberrypi/" --python_out="$PYTHON_COMMON_PATH/src" rascsi_interface.proto
}
# install everything required to run an HTTP server (Nginx + Python Flask App)
function installRaScsiWebInterface() {
sudo cp -f "$WEB_INSTALL_PATH/service-infra/nginx-default.conf" /etc/nginx/sites-available/default
sudo cp -f "$WEB_INSTALL_PATH/service-infra/502.html" /var/www/html/502.html
sudo usermod -a -G $USER www-data
if [ -f "$SSL_CERTS_PATH/rascsi-web.crt" ]; then
echo "SSL certificate $SSL_CERTS_PATH/rascsi-web.crt already exists."
else
echo "SSL certificate $SSL_CERTS_PATH/rascsi-web.crt does not exist; creating self-signed certificate..."
sudo mkdir -p "$SSL_CERTS_PATH" || true
sudo mkdir -p "$SSL_KEYS_PATH" || true
sudo openssl req -x509 -nodes -sha256 -days 3650 \
-newkey rsa:4096 \
-keyout "$SSL_KEYS_PATH/rascsi-web.key" \
-out "$SSL_CERTS_PATH/rascsi-web.crt" \
-subj '/CN=rascsi' \
-addext 'subjectAltName=DNS:rascsi' \
-addext 'extendedKeyUsage=serverAuth'
fi
sudo systemctl reload nginx || true
}
# Creates the dir that RaSCSI uses to store image files
function createImagesDir() {
if [ -d "$VIRTUAL_DRIVER_PATH" ]; then
echo "The $VIRTUAL_DRIVER_PATH directory already exists."
else
echo "The $VIRTUAL_DRIVER_PATH directory does not exist; creating..."
mkdir -p "$VIRTUAL_DRIVER_PATH"
chmod -R 775 "$VIRTUAL_DRIVER_PATH"
fi
}
# Creates the dir that the Web Interface uses to store configuration files
function createCfgDir() {
if [ -d "$CFG_PATH" ]; then
echo "The $CFG_PATH directory already exists."
else
echo "The $CFG_PATH directory does not exist; creating..."
mkdir -p "$CFG_PATH"
chmod -R 775 "$CFG_PATH"
fi
}
# Stops the rascsi-web and apache2 processes
function stopOldWebInterface() {
stopRaScsiWeb
APACHE_STATUS=$(sudo systemctl status apache2 &> /dev/null; echo $?)
if [ "$APACHE_STATUS" -eq 0 ] ; then
echo "Stopping old Apache2 RaSCSI Web..."
sudo systemctl disable apache2
sudo systemctl stop apache2
fi
}
# Checks for upstream changes to the git repo and fast-forwards changes if needed
function updateRaScsiGit() {
cd "$BASE" || exit 1
set +e
git rev-parse --is-inside-work-tree &> /dev/null
if [[ $? -ge 1 ]]; then
echo "Warning: This does not seem to be a valid clone of a git repository. I will not be able to pull the latest code."
return 0
fi
set -e
stashed=0
if [[ $(git diff --stat) != '' ]]; then
echo "There are local changes to the RaSCSI code; we will stash and reapply them."
git -c user.name="${GIT_COMMITTER_NAME-rascsi}" -c user.email="${[email protected]}" stash
stashed=1
fi
if [[ `git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"` != "" ]]; then
echo "Updating checked out git branch $GIT_REMOTE/$GIT_BRANCH"
git pull --ff-only
else
echo "Detected a local git working branch; skipping the remote update step."
fi
if [ $stashed -eq 1 ]; then
echo "Reapplying local changes..."
git stash apply
fi
}
# Takes a backup copy of the rascsi.service file if it exists
function backupRaScsiService() {
if [ -f "$SYSTEMD_PATH/rascsi.service" ]; then
sudo mv "$SYSTEMD_PATH/rascsi.service" "$SYSTEMD_PATH/rascsi.service.old"
SYSTEMD_BACKUP=true
echo "Existing version of rascsi.service detected; Backing up to rascsi.service.old"
else
SYSTEMD_BACKUP=false
fi
}
# Offers the choice of enabling token-based authentication for RaSCSI
function configureTokenAuth() {
if [[ -f "$HOME/.rascsi_secret" ]]; then
sudo rm "$HOME/.rascsi_secret"
echo "Removed (legacy) RaSCSI token file"
fi
if [[ -f $SECRET_FILE ]]; then
sudo rm "$SECRET_FILE"
echo "Removed RaSCSI token file"
fi
if [[ $SKIP_TOKEN ]]; then
echo "Skipping RaSCSI token setup"
return 0
fi
if [[ -z $TOKEN ]]; then
echo ""
echo "Do you want to protect your RaSCSI installation with a password? [y/N]"
read REPLY
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
return 0
fi
echo -n "Enter the password that you want to use: "
read -r TOKEN
fi
echo "$TOKEN" > "$SECRET_FILE"
# Make the secret file owned and only readable by root
sudo chown root:root "$SECRET_FILE"
sudo chmod 600 "$SECRET_FILE"
echo ""
echo "Configured RaSCSI to use $SECRET_FILE for authentication. This file is readable by root only."
echo "Make note of your password: you will need it to use rasctl and other RaSCSI clients."
}
# Modifies and installs the rascsi service
function enableRaScsiService() {
if [ ! -z "$TOKEN" ]; then
sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH -P $SECRET_FILE@" "$SYSTEMD_PATH/rascsi.service"
else
sudo sed -i "s@^ExecStart.*@& -F $VIRTUAL_DRIVER_PATH@" "$SYSTEMD_PATH/rascsi.service"
fi
echo "Configured rascsi.service to use $VIRTUAL_DRIVER_PATH as default image dir."
sudo systemctl daemon-reload
sudo systemctl restart rsyslog
sudo systemctl enable rascsi # optional - start rascsi at boot
sudo systemctl start rascsi
}
# Modifies and installs the rascsi-web service
function installWebInterfaceService() {
echo "Installing the rascsi-web.service configuration..."
sudo cp -f "$WEB_INSTALL_PATH/service-infra/rascsi-web.service" "$SYSTEMD_PATH/rascsi-web.service"
sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/rascsi-web.service"
echo "$TOKEN"
if [ ! -z "$TOKEN" ]; then
sudo sed -i "8 i ExecStart=$WEB_INSTALL_PATH/start.sh --password=$TOKEN" "$SYSTEMD_PATH/rascsi-web.service"
# Make the service file readable by root only, to protect the token string
sudo chmod 600 "$SYSTEMD_PATH/rascsi-web.service"
echo "Granted access to the Web Interface with the token password that you configured for RaSCSI."
else
sudo sed -i "8 i ExecStart=$WEB_INSTALL_PATH/start.sh" "$SYSTEMD_PATH/rascsi-web.service"
fi
sudo systemctl daemon-reload
sudo systemctl enable rascsi-web
sudo systemctl start rascsi-web
}
# Stops the rascsi service if it is running
function stopRaScsi() {
if [[ -f "$SYSTEMD_PATH/rascsi.service" ]]; then
SERVICE_RASCSI_RUNNING=0
sudo systemctl is-active --quiet rascsi.service >/dev/null 2>&1 || SERVICE_RASCSI_RUNNING=$?
if [[ $SERVICE_RASCSI_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi.service
fi
fi
}
# Stops the rascsi-web service if it is running
function stopRaScsiWeb() {
if [[ -f "$SYSTEMD_PATH/rascsi-web.service" ]]; then
SERVICE_RASCSI_WEB_RUNNING=0
sudo systemctl is-active --quiet rascsi-web.service >/dev/null 2>&1 || SERVICE_RASCSI_WEB_RUNNING=$?
if [[ $SERVICE_RASCSI_WEB_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi-web.service
fi
fi
}
# Stops the rascsi-oled service if it is running
function stopRaScsiScreen() {
if [[ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]]; then
SERVICE_MONITOR_RASCSI_RUNNING=0
sudo systemctl is-active --quiet monitor_rascsi.service >/dev/null 2>&1 || SERVICE_MONITOR_RASCSI_RUNNING=$?
if [[ $SERVICE_MONITOR_RASCSI_RUNNING -eq 0 ]]; then
sudo systemctl stop monitor_rascsi.service
fi
fi
if [[ -f "$SYSTEMD_PATH/rascsi-oled.service" ]]; then
SERVICE_RASCSI_OLED_RUNNING=0
sudo systemctl is-active --quiet rascsi-oled.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_RUNNING=$?
if [[ $SERVICE_RASCSI_OLED_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi-oled.service
fi
fi
}
# Stops the rascsi-ctrlboard service if it is running
function stopRaScsiCtrlBoard() {
if [[ -f "$SYSTEMD_PATH/rascsi-ctrlboard.service" ]]; then
SERVICE_RASCSI_CTRLBOARD_RUNNING=0
sudo systemctl is-active --quiet rascsi-ctrlboard.service >/dev/null 2>&1 || SERVICE_RASCSI_CTRLBOARD_RUNNING=$?
if [[ SERVICE_RASCSI_CTRLBOARD_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi-ctrlboard.service
fi
fi
}
# disables and removes the old monitor_rascsi service
function disableOldRaScsiMonitorService() {
if [ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]; then
SERVICE_MONITOR_RASCSI_RUNNING=0
sudo systemctl is-active --quiet monitor_rascsi.service >/dev/null 2>&1 || SERVICE_MONITOR_RASCSI_RUNNING=$?
if [[ $SERVICE_MONITOR_RASCSI_RUNNING -eq 0 ]]; then
sudo systemctl stop monitor_rascsi.service
fi
SERVICE_MONITOR_RASCSI_ENABLED=0
sudo systemctl is-enabled --quiet monitor_rascsi.service >/dev/null 2>&1 || SERVICE_MONITOR_RASCSI_ENABLED=$?
if [[ $SERVICE_MONITOR_RASCSI_ENABLED -eq 0 ]]; then
sudo systemctl disable monitor_rascsi.service
fi
sudo rm $SYSTEMD_PATH/monitor_rascsi.service
fi
}
# disables the rascsi-oled service
function disableRaScsiOledService() {
if [ -f "$SYSTEMD_PATH/rascsi-oled.service" ]; then
SERVICE_RASCSI_OLED_RUNNING=0
sudo systemctl is-active --quiet rascsi-oled.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_RUNNING=$?
if [[ $SERVICE_RASCSI_OLED_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi-oled.service
fi
SERVICE_RASCSI_OLED_ENABLED=0
sudo systemctl is-enabled --quiet rascsi-oled.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_ENABLED=$?
if [[ $SERVICE_RASCSI_OLED_ENABLED -eq 0 ]]; then
sudo systemctl disable rascsi-oled.service
fi
fi
}
# disables the rascsi-ctrlboard service
function disableRaScsiCtrlBoardService() {
if [ -f "$SYSTEMD_PATH/rascsi-ctrlboard.service" ]; then
SERVICE_RASCSI_CTRLBOARD_RUNNING=0
sudo systemctl is-active --quiet rascsi-ctrlboard.service >/dev/null 2>&1 || SERVICE_RASCSI_CTRLBOARD_RUNNING=$?
if [[ $SERVICE_RASCSI_CTRLBOARD_RUNNING -eq 0 ]]; then
sudo systemctl stop rascsi-ctrlboard.service
fi
SERVICE_RASCSI_CTRLBOARD_ENABLED=0
sudo systemctl is-enabled --quiet rascsi-ctrlboard.service >/dev/null 2>&1 || SERVICE_RASCSI_CTRLBOARD_ENABLED=$?
if [[ $SERVICE_RASCSI_CTRLBOARD_ENABLED -eq 0 ]]; then
sudo systemctl disable rascsi-ctrlboard.service
fi
fi
}
# Stops the macproxy service if it is running
function stopMacproxy() {
if [ -f "$SYSTEMD_PATH/macproxy.service" ]; then
sudo systemctl stop macproxy.service
fi
}
# Checks whether the rascsi-oled service is installed
function isRaScsiScreenInstalled() {
SERVICE_RASCSI_OLED_ENABLED=0
if [[ -f "$SYSTEMD_PATH/rascsi-oled.service" ]]; then
sudo systemctl is-enabled --quiet rascsi-oled.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_ENABLED=$?
elif [[ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]]; then
sudo systemctl is-enabled --quiet monitor_rascsi.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_ENABLED=$?
else
SERVICE_RASCSI_OLED_ENABLED=1
fi
echo $SERVICE_RASCSI_OLED_ENABLED
}
# Checks whether the rascsi-ctrlboard service is installed
function isRaScsiCtrlBoardInstalled() {
SERVICE_RASCSI_CTRLBOARD_ENABLED=0
if [[ -f "$SYSTEMD_PATH/rascsi-ctrlboard.service" ]]; then
sudo systemctl is-enabled --quiet rascsi-ctrlboard.service >/dev/null 2>&1 || SERVICE_RASCSI_CTRLBOARD_ENABLED=$?
else
SERVICE_RASCSI_CTRLBOARD_ENABLED=1
fi
echo $SERVICE_RASCSI_CTRLBOARD_ENABLED
}
# Checks whether the rascsi-oled service is running
function isRaScsiScreenRunning() {
SERVICE_RASCSI_OLED_RUNNING=0
if [[ -f "$SYSTEMD_PATH/rascsi-oled.service" ]]; then
sudo systemctl is-active --quiet rascsi-oled.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_RUNNING=$?
elif [[ -f "$SYSTEMD_PATH/monitor_rascsi.service" ]]; then
sudo systemctl is-active --quiet monitor_rascsi.service >/dev/null 2>&1 || SERVICE_RASCSI_OLED_RUNNING=$?
else
SERVICE_RASCSI_OLED_RUNNING=1
fi
echo $SERVICE_RASCSI_OLED_RUNNING
}
# Checks whether the rascsi-oled service is running
function isRaScsiCtrlBoardRunning() {
SERVICE_RASCSI_CTRLBOARD_RUNNING=0
if [[ -f "$SYSTEMD_PATH/rascsi-ctrlboard.service" ]]; then
sudo systemctl is-active --quiet rascsi-ctrlboard.service >/dev/null 2>&1 || SERVICE_RASCSI_CTRLBOARD_RUNNING=$?
else
SERVICE_RASCSI_CTRLBOARD_RUNNING=1
fi
echo $SERVICE_RASCSI_CTRLBOARD_RUNNING
}
# Starts the rascsi-oled service if installed
function startRaScsiScreen() {
if [[ $(isRaScsiScreenInstalled) -eq 0 ]] && [[ $(isRaScsiScreenRunning) -ne 1 ]]; then
sudo systemctl start rascsi-oled.service
showRaScsiScreenStatus
fi
}
# Starts the rascsi-ctrlboard service if installed
function startRaScsiCtrlBoard() {
if [[ $(isRaScsiCtrlBoardInstalled) -eq 0 ]] && [[ $(isRaScsiCtrlBoardRunning) -ne 1 ]]; then
sudo systemctl start rascsi-ctrlboard.service
showRaScsiCtrlBoardStatus
fi
}
# Starts the macproxy service if installed
function startMacproxy() {
if [ -f "$SYSTEMD_PATH/macproxy.service" ]; then
sudo systemctl start macproxy.service
showMacproxyStatus
fi
}
# Shows status for the rascsi service
function showRaScsiStatus() {
systemctl status rascsi | tee
}
# Shows status for the rascsi-web service
function showRaScsiWebStatus() {
systemctl status rascsi-web | tee
}
# Shows status for the rascsi-oled service
function showRaScsiScreenStatus() {
systemctl status rascsi-oled | tee
}
# Shows status for the rascsi-ctrlboard service
function showRaScsiCtrlBoardStatus() {
systemctl status rascsi-ctrlboard | tee
}
# Shows status for the macproxy service
function showMacproxyStatus() {
systemctl status macproxy | tee
}
# Creates a drive image file with specific parameters
function createDrive600MB() {
createDrive 600 "HD600"
}
# Creates a drive image file and prompts for parameters
function createDriveCustom() {
driveSize=-1
until [ $driveSize -ge "10" ] && [ $driveSize -le "4000" ]; do
echo "What drive size would you like (in MB) (10-4000)"
read driveSize
echo "How would you like to name that drive?"
read driveName
done
createDrive "$driveSize" "$driveName"
}
# Creates an HFS file system
function formatDrive() {
diskPath="$1"
volumeName="$2"
if [ ! -x $HFS_FORMAT ]; then
# Install hfsutils to have hformat to format HFS
sudo apt-get install hfsutils --assume-yes </dev/null
fi
if [ ! -x $HFDISK_BIN ]; then
# Clone, compile and install 'hfdisk', partition tool
git clone git://www.codesrc.com/git/hfdisk.git
cd hfdisk || exit 1
make
sudo cp hfdisk /usr/bin/hfdisk
fi
# Inject hfdisk commands to create Drive with correct partitions
# https://www.codesrc.com/mediawiki/index.php/HFSFromScratch
# i initialize partition map
# continue with default first block
# C Create 1st partition with type specified next)
# continue with default
# 32 32 blocks (required for HFS+)
# Driver_Partition Partition Name
# Apple_Driver Partition Type (available types: Apple_Driver, Apple_Driver43, Apple_Free, Apple_HFS...)
# C Create 2nd partition with type specified next
# continue with default first block
# continue with default block size (rest of the disk)
# ${volumeName} Partition name provided by user
# Apple_HFS Partition Type
# w Write partition map to disk
# y Confirm partition table
# p Print partition map
(echo i; echo ; echo C; echo ; echo 32; echo "Driver_Partition"; echo "Apple_Driver"; echo C; echo ; echo ; echo "${volumeName}"; echo "Apple_HFS"; echo w; echo y; echo p;) | $HFDISK_BIN "$diskPath"
partitionOk=$?
if [ $partitionOk -eq 0 ]; then
if [ ! -f "$LIDO_DRIVER" ];then
echo "Lido driver couldn't be found. Make sure RaSCSI is up-to-date with git pull"
return 1
fi
# Burn Lido driver to the disk
dd if="$LIDO_DRIVER" of="$diskPath" seek=64 count=32 bs=512 conv=notrunc
driverInstalled=$?
if [ $driverInstalled -eq 0 ]; then
# Format the partition with HFS file system
$HFS_FORMAT -l "${volumeName}" "$diskPath" 1
hfsFormattedOk=$?
if [ $hfsFormattedOk -eq 0 ]; then
echo "Disk created with success."
else
echo "Unable to format HFS partition."
return 4
fi
else
echo "Unable to install Lido Driver."
return 3
fi
else
echo "Unable to create the partition."
return 2
fi
}
# Creates an image file
function createDrive() {
if [ $# -ne 2 ]; then
echo "To create a Drive, volume size and volume name must be provided"
echo "$ createDrive 600 \"RaSCSI Drive\""
echo "Drive wasn't created."
return
fi
driveSize=$1
driveName=$2
mkdir -p "$VIRTUAL_DRIVER_PATH"
drivePath="${VIRTUAL_DRIVER_PATH}/${driveSize}MB.hda"
if [ ! -f "$drivePath" ]; then
echo "Creating a ${driveSize}MB Drive"
truncate --size "${driveSize}m" "$drivePath"
echo "Formatting drive with HFS"
formatDrive "$drivePath" "$driveName"
else
echo "Error: drive already exists"
fi
}
# Modifies system configurations for a wired network bridge
function setupWiredNetworking() {
echo "Setting up wired network..."
LAN_INTERFACE=eth0
echo "$LAN_INTERFACE will be configured for network forwarding with DHCP."
echo ""
echo "WARNING: If you continue, the IP address of your Pi may change upon reboot."
echo "Please make sure you will not lose access to the Pi system."
echo ""
echo "Do you want to proceed with network configuration using the default settings? [Y/n]"
read REPLY
if [ "$REPLY" == "N" ] || [ "$REPLY" == "n" ]; then
echo "Available wired interfaces on this system:"
echo `ip -o addr show scope link | awk '{split($0, a); print $2}' | grep eth`
echo "Please type the wired interface you want to use and press Enter:"
read SELECTED
LAN_INTERFACE=$SELECTED
fi
if [ "$(grep -c "^denyinterfaces" /etc/dhcpcd.conf)" -ge 1 ]; then
echo "WARNING: Network forwarding may already have been configured. Proceeding will overwrite the configuration."
echo "Press enter to continue or CTRL-C to exit"
read REPLY
sudo sed -i /^denyinterfaces/d /etc/dhcpcd.conf
fi
sudo bash -c 'echo "denyinterfaces '$LAN_INTERFACE'" >> /etc/dhcpcd.conf'
echo "Modified /etc/dhcpcd.conf"
# default config file is made for eth0, this will set the right net interface
sudo bash -c 'sed s/eth0/'"$LAN_INTERFACE"'/g '"$BASE"'/src/raspberrypi/os_integration/rascsi_bridge > /etc/network/interfaces.d/rascsi_bridge'
echo "Modified /etc/network/interfaces.d/rascsi_bridge"
echo "Configuration completed!"
echo "Please make sure you attach a DaynaPORT network adapter to your RaSCSI configuration."
echo "Either use the Web UI, or do this on the command line (assuming SCSI ID 6):"
echo "rasctl -i 6 -c attach -t scdp -f $LAN_INTERFACE"
echo ""
echo "We need to reboot your Pi"
echo "Press Enter to reboot or CTRL-C to exit"
read
echo "Rebooting..."
sleep 3
sudo reboot
}
# Modifies system configurations for a wireless network bridge with NAT
function setupWirelessNetworking() {
NETWORK="10.10.20"
IP=$NETWORK.2 # Macintosh or Device IP
NETWORK_MASK="255.255.255.0"
CIDR="24"
ROUTER_IP=$NETWORK.1
ROUTING_ADDRESS=$NETWORK.0/$CIDR
WLAN_INTERFACE="wlan0"
echo "$WLAN_INTERFACE will be configured for network forwarding with static IP assignment."
echo "Configure your Macintosh or other device with the following:"
echo "IP Address (static): $IP"
echo "Router Address: $ROUTER_IP"
echo "Subnet Mask: $NETWORK_MASK"
echo "DNS Server: Any public DNS server"
echo ""
echo "Do you want to proceed with network configuration using the default settings? [Y/n]"
read REPLY
if [ "$REPLY" == "N" ] || [ "$REPLY" == "n" ]; then
echo "Available wireless interfaces on this system:"
echo `ip -o addr show scope link | awk '{split($0, a); print $2}' | grep wlan`
echo "Please type the wireless interface you want to use and press Enter:"
read -r WLAN_INTERFACE
echo "Base IP address (ex. 10.10.20):"
read -r NETWORK
echo "CIDR for Subnet Mask (ex. '24' for 255.255.255.0):"
read -r CIDR
ROUTER_IP=$NETWORK.1
ROUTING_ADDRESS=$NETWORK.0/$CIDR
fi
if [ "$(grep -c "^net.ipv4.ip_forward=1" /etc/sysctl.conf)" -ge 1 ]; then
echo "WARNING: Network forwarding may already have been configured. Proceeding will overwrite the configuration."
echo "Press enter to continue or CTRL-C to exit"
read REPLY
else
sudo bash -c 'echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf'
echo "Modified /etc/sysctl.conf"
fi
# Check if iptables is installed
if [ `apt-cache policy iptables | grep Installed | grep -c "(none)"` -eq 0 ]; then
echo "iptables is already installed"
else
sudo apt-get install iptables --assume-yes </dev/null
fi
sudo iptables --flush
sudo iptables -t nat -F
sudo iptables -X
sudo iptables -Z
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -t nat -A POSTROUTING -o "$WLAN_INTERFACE" -s "$ROUTING_ADDRESS" -j MASQUERADE
# Check if iptables-persistent is installed
if [ `apt-cache policy iptables-persistent | grep Installed | grep -c "(none)"` -eq 0 ]; then
echo "iptables-persistent is already installed"
sudo iptables-save --file /etc/iptables/rules.v4
else
sudo apt-get install iptables-persistent --assume-yes </dev/null
fi
echo "Modified /etc/iptables/rules.v4"
echo "Configuration completed!"
echo ""
echo "Please make sure you attach a DaynaPORT network adapter to your RaSCSI configuration"
echo "Either use the Web UI, or do this on the command line (assuming SCSI ID 6):"
echo "rasctl -i 6 -c attach -t scdp -f $WLAN_INTERFACE:$ROUTER_IP/$CIDR"
echo ""
echo "We need to reboot your Pi"
echo "Press Enter to reboot or CTRL-C to exit"
read REPLY
echo "Rebooting..."
sleep 3
sudo reboot
}
# Downloads, compiles, and installs Netatalk (AppleShare server)
function installNetatalk() {
NETATALK_VERSION="2-220801"
AFP_SHARE_PATH="$HOME/afpshare"
AFP_SHARE_NAME="Pi File Server"
echo "Downloading netatalk-$NETATALK_VERSION to $HOME"
cd $HOME || exit 1
wget -O "netatalk-$NETATALK_VERSION.tar.gz" "https://github.com/rdmark/Netatalk-2.x/archive/refs/tags/netatalk-$NETATALK_VERSION.tar.gz" </dev/null
tar -xzvf netatalk-$NETATALK_VERSION.tar.gz
cd "$HOME/Netatalk-2.x-netatalk-$NETATALK_VERSION/contrib/shell_utils" || exit 1
./debian_install.sh -j="${CORES:-1}" -n="$AFP_SHARE_NAME" -p="$AFP_SHARE_PATH" || exit 1
}
# Downloads, compiles, and installs Macproxy (web proxy)
function installMacproxy {
PORT=5000
echo "Macproxy is a Web Proxy for all vintage Web Browsers -- not only for Macs!"
echo ""
echo "By default, Macproxy listens to port $PORT, but you can choose any other available port."
echo -n "Enter a port number 1024 - 65535, or press Enter to use the default port: "
read -r CHOICE
if [[ $CHOICE -ge "1024" ]] && [[ $CHOICE -le "65535" ]]; then
PORT=$CHOICE
else
echo "Using the default port $PORT"
fi
( sudo apt-get update && sudo apt-get install python3 python3-venv --assume-yes ) </dev/null
MACPROXY_VER="22.8"
MACPROXY_PATH="$HOME/macproxy-$MACPROXY_VER"
if [ -d "$MACPROXY_PATH" ]; then
echo "The $MACPROXY_PATH directory already exists. Deleting before downloading again..."
sudo rm -rf "$MACPROXY_PATH"
fi
cd "$HOME" || exit 1
wget -O "macproxy-$MACPROXY_VER.tar.gz" "https://github.com/rdmark/macproxy/archive/refs/tags/v$MACPROXY_VER.tar.gz" </dev/null
tar -xzvf "macproxy-$MACPROXY_VER.tar.gz"
sudo cp "$MACPROXY_PATH/macproxy.service" "$SYSTEMD_PATH"
sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/macproxy.service"
sudo sed -i "8 i ExecStart=$MACPROXY_PATH/start_macproxy.sh -p=$PORT" "$SYSTEMD_PATH/macproxy.service"
sudo systemctl daemon-reload
sudo systemctl enable macproxy
startMacproxy
echo -n "Macproxy is now running on IP "
echo -n `ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}'`
echo " port $PORT"
echo "Configure your browser to use the above as http (and https) proxy."
echo ""
}
# updates configuration files and installs packages needed for the OLED screen script
function installRaScsiScreen() {
echo "IMPORTANT: This configuration requires a OLED screen to be installed onto your RaSCSI board."
echo "See wiki for more information: https://github.com/akuker/RASCSI/wiki/OLED-Status-Display-(Optional)"
echo ""
echo "Choose screen rotation:"
echo " 1) 0 degrees"
echo " 2) 180 degrees (default)"
read REPLY
if [ "$REPLY" == "1" ]; then
echo "Proceeding with 0 degrees rotation."
ROTATION="0"
else
echo "Proceeding with 180 degrees rotation."
ROTATION="180"
fi
echo ""
echo "Choose screen resolution:"
echo " 1) 128x32 pixels (default)"
echo " 2) 128x64 pixels"
read REPLY
if [ "$REPLY" == "2" ]; then
echo "Proceeding with 128x64 pixel resolution."
SCREEN_HEIGHT="64"
else
echo "Proceeding with 128x32 pixel resolution."
SCREEN_HEIGHT="32"
fi
if [ -z "$TOKEN" ]; then
echo ""
echo "Did you protect your RaSCSI installation with a token password? [y/N]"
read -r REPLY
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
echo -n "Enter the password that you configured with RaSCSI at the time of installation: "
read -r TOKEN
fi
fi
stopRaScsiScreen
disableRaScsiCtrlBoardService
updateRaScsiGit
sudo apt-get update && sudo apt-get install libjpeg-dev libpng-dev libopenjp2-7-dev i2c-tools raspi-config -y </dev/null
if [[ $(grep -c "^dtparam=i2c_arm=on" /boot/config.txt) -ge 1 ]]; then
echo "NOTE: I2C support seems to have been configured already."
REBOOT=0
else
sudo raspi-config nonint do_i2c 0 </dev/null
echo "Modified the Raspberry Pi boot configuration to enable I2C."
echo "A reboot will be required for the change to take effect."
REBOOT=1
fi
echo "Installing the rascsi-oled.service configuration..."
sudo cp -f "$OLED_INSTALL_PATH/service-infra/rascsi-oled.service" "$SYSTEMD_PATH/rascsi-oled.service"
sudo sed -i /^ExecStart=/d "$SYSTEMD_PATH/rascsi-oled.service"
if [ ! -z "$TOKEN" ]; then
sudo sed -i "8 i ExecStart=$OLED_INSTALL_PATH/start.sh --rotation=$ROTATION --height=$SCREEN_HEIGHT --password=$TOKEN" "$SYSTEMD_PATH/rascsi-oled.service"
# Make the service file readable by root only, to protect the token string
sudo chmod 600 "$SYSTEMD_PATH/rascsi-oled.service"
echo "Granted access to the OLED Monitor with the password that you configured for RaSCSI."
else
sudo sed -i "8 i ExecStart=$OLED_INSTALL_PATH/start.sh --rotation=$ROTATION --height=$SCREEN_HEIGHT" "$SYSTEMD_PATH/rascsi-oled.service"
fi
sudo systemctl daemon-reload
# ensure that the old monitor_rascsi service is disabled and removed before the new one is installed
disableOldRaScsiMonitorService
sudo systemctl daemon-reload
sudo systemctl enable rascsi-oled
if [ $REBOOT -eq 1 ]; then
echo ""
echo "The rascsi-oled service will start on the next Pi boot."
echo "Press Enter to reboot or CTRL-C to exit"
read
echo "Rebooting..."
sleep 3
sudo reboot
fi
sudo systemctl start rascsi-oled
}
# updates configuration files and installs packages needed for the CtrlBoard script
function installRaScsiCtrlBoard() {
echo "IMPORTANT: This configuration requires a RaSCSI Control Board connected to your RaSCSI board."
echo "See wiki for more information: https://github.com/akuker/RASCSI/wiki/RaSCSI-Control-Board"
echo ""
echo "Choose screen rotation:"
echo " 1) 0 degrees"
echo " 2) 180 degrees (default)"
read REPLY
if [ "$REPLY" == "1" ]; then
echo "Proceeding with 0 degrees rotation."
ROTATION="0"
else
echo "Proceeding with 180 degrees rotation."
ROTATION="180"
fi
if [ -z "$TOKEN" ]; then
echo ""
echo "Did you protect your RaSCSI installation with a token password? [y/N]"
read -r REPLY
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
echo -n "Enter the password that you configured with RaSCSI at the time of installation: "
read -r TOKEN
fi
fi
stopRaScsiCtrlBoard
updateRaScsiGit
sudo apt-get update && sudo apt-get install libjpeg-dev libpng-dev libopenjp2-7-dev i2c-tools raspi-config -y </dev/null
# install python packages through apt that need compilation
sudo apt-get install python3-cbor2 -y </dev/null
# enable i2c
if [[ $(grep -c "^dtparam=i2c_arm=on" /boot/config.txt) -ge 1 ]]; then