forked from PiNet/PiNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinet
executable file
·2682 lines (2305 loc) · 94.3 KB
/
pinet
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
#!/bin/bash
# Part of PiNet https://github.com/PiNet/PiNet
#
# See LICENSE file for copyright and license details
version=1.3.5
#PiNet (Previously RaspberryPi-LTSP)
#Written by Andrew Mulholland, based off the fantastic work by vagrantc and alksig from the LTSP community
#Initial guide available at http://cascadia.debian.net/trenza/Documentation/raspberrypi-ltsp-howto/
#Spindle was used to figure out needed changes to generate Raspbian image https://github.com/asb/spindle
#
#PiNet is a utility for setting up and configuring a Linux Terminal Server Project (LTSP) network for Raspberry Pi's
#Constants
#------------------------
ConfigFileLoc=/etc/pinet
Timeout=1
PythonFunctions="/usr/local/bin/pinet_functions_python.py"
PythonStart="python3"
p="$PythonStart $PythonFunctions"
RepositoryBase="https://github.com/PiNet/"
RepositoryName="PiNet"
BootRepositoryName="PiNet-Boot"
RawRepositoryBase="https://raw.github.com/PiNet/"
Repository="$RepositoryBase$RepositoryName"
BootRepository="$RepositoryBase$BootRepositoryName"
RawRepository="$RawRepositoryBase$RepositoryName"
ReleaseBranch="stretch-alpha" #Overwriten later on in SetupRepositories()
ltspBase="/opt/ltsp/"
cpuArch="armhf"
#------------------------
SetupRepositories(){
ReleaseChannel=$(echo "$ReleaseChannel" | tr '[:upper:]' '[:lower:]')
case "$ReleaseChannel" in
stable)
ReleaseBranch="stable"
;;
beta)
ReleaseBranch="beta"
;;
dev)
ReleaseBranch="beta"
;;
alpha)
ReleaseBranch="alpha"
;;
development)
ReleaseBranch="development"
;;
"custom:*")
ReleaseBranch=${ReleaseChannel:7:channelLength}
;;
*)
ReleaseBranch="stable"
;;
esac
}
LegacyFixes() {
#Runs a number of legacy code checks, making sure everything is configured correctly.
if [ -d "/home/shared" ]; then
CheckSharedFolderIntegrity
fi
CheckDesktopShortcut
teacherSudoCheck
CheckRaspberryPiUIMods
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf "NFS_HOME=/home" ""
if [ -f "/etc/default/epoptes" ]; then
ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP=staff" "SOCKET_GROUP=teacher"
fi
if [ ! -f "/opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh" ]; then
AddScreenshot
UpdateConfig NBDBuildNeeded true
fi
if [ ! -f "/usr/local/bin/changePassword.sh" ]; then
AddPasswordReset
UpdateConfig NBDBuildNeeded true
fi
CheckPipSymbolicLinkBug
local passwdVersion=$(cat /home/$SUDO_USER/Desktop/pinet-password.desktop | sed -n '2p')
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
exitcode=$?
sed -i '/^[[:blank:]]*$/d' /opt/ltsp/armhf/etc/lts.conf
if [ "$exitcode" = "1" ]; then
UpdateConfig NBDBuildNeeded true
fi
CheckDebianVersion
CheckBackupScriptVersion
if [ -f "/usr/local/bin/pinet-functions-python.py" ]; then
mv "/usr/local/bin/pinet-functions-python.py" "/usr/local/bin/pinet_functions_python.py"
fi
if grep -Fxq "cutdown_menus=1" "/opt/ltsp/armhf/etc/xdg/libfm/libfm.conf"; then
$p replaceLineOrAdd "/opt/ltsp/armhf/etc/xdg/libfm/libfm.conf" "cutdown_menus=1" "cutdown_menus=0"
UpdateConfig NBDBuildNeeded true
fi
# Make sure that all the required Python libraries are installed
$PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
$PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
$PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
echo $"A required system update has been found. The Raspbian operating system will now be recompressed to apply this update"
NBDRun
else
UpdateConfig NBDBuildNeeded false
fi
$p "checkStatsNotification"
}
ConfigFileRead(){
#Reads the config file and loads in data as variables
#Taken from - http://wiki.bash-hackers.org/howto/conffile
configfile_secured="/tmp/pinet-config"
if egrep -q -v '^#|^[^ ]*=[^;]*' "$ConfigFileLoc"; then
# filter the original to a new file
egrep '^#|^[^ ]*=[^;&]*' "$ConfigFileLoc" > "$configfile_secured"
ConfigFileLoc="$configfile_secured"
source "$ConfigFileLoc"
else
source "$ConfigFileLoc"
fi
}
ReplaceTextLine(){
# ReplaceTextLine /textfile bob brian
egrep -i "^$2" $1 >> /dev/null
if [ $? = 0 ]; then
sed -i "s/$2.*/$3/g" $1
else
echo "$3" >> $1
fi
}
ReplaceAnyTextOnLine(){
# ReplaceTextLine /textfile bob brian
#REMEMBER!! The & symbol can't be in any of the strings as SED is using it for separating. Can change it if need be
egrep -i "$2" $1 >> /dev/null
if [ $? -eq 0 ]; then
sed -i "s&.*$2.*&$3&g" $1
return 0
else
echo "$3" >> $1
return 1
fi
}
UpdateConfig(){
#Updates the PiNet config file with provided values
#Example - UpdateConfig bob false
local configName=$1
local configValue=$2
egrep -i "^$configName" $ConfigFileLoc >> /dev/null
if [ $? = 0 ]; then
sed -i "s/$configName.*/$configName=$configValue/g" $ConfigFileLoc
else
echo "$configName=$configValue" >> $ConfigFileLoc
fi
ConfigFileRead
}
gp(){
#Part of the Python functions code. As Python functions uses a text file to communicate back and forth, this reads it and echos to console.
if [ -f /tmp/ltsptmp ]; then
echo $(head -n 1 /tmp/ltsptmp)
fi
}
installLTSP() {
#Installs main packages required by LTSP
apt-get update && apt-get upgrade -y
apt-get install -y ltsp-server qemu-user-static binfmt-support ldm-server sed git gnome-control-center nfs-kernel-server xml2 openssh-server inotify-tools bindfs net-tools terminator
update-alternatives --set x-terminal-emulator /usr/bin/gnome-terminal.wrapper
exitstatus=$?
if ! [ $exitstatus = 0 ]; then
whiptail --title $"ERROR!" --msgbox $"No internet connection detected or other software is already being installed! Please wait 5-10 minutes and try again or connect to the internet " 10 78
exit 1
fi
}
buildClient() {
#Creates the custom config file needed to build Raspbian and grabs keychain. Then starts the build
wget http://raspbian.raspberrypi.org/raspbian.public.key -O - | gpg --import
gpg --export 90FDDD2E >> /etc/ltsp/raspbian.public.key.gpg
rm /etc/ltsp/ltsp-raspbian.conf
cat <<EOF > /etc/ltsp/ltsp-raspbian.conf
DEBOOTSTRAP_KEYRING=/etc/ltsp/raspbian.public.key.gpg
DIST=stretch
MIRROR=http://raspbian.raspberrypi.org/raspbian
SECURITY_MIRROR=none
UPDATES_MIRROR=none
LOCALE="$LANG UTF-8"
KERNEL_PACKAGES=linux-image-rpf
EOF
VENDOR=Debian ltsp-build-client --arch armhf --config /etc/ltsp/ltsp-raspbian.conf
}
OneTimeFixes(){
#A number of one off fixes needed to be run
echo "/opt/ltsp *(ro,no_root_squash,async,no_subtree_check)" >> /etc/exports #sets up OS exporting for NFS
echo "/home *(rw,sync,no_subtree_check)" >> /etc/exports #Sets up home folder exporting for NFS
mkdir /etc/skel/handin
echo '#!/bin/sh' >> /etc/network/if-up.d/tftpd-hpa #Script to make sure tftpd-hpa autostarts
echo "service tftpd-hpa restart" >> /etc/network/if-up.d/tftpd-hpa
chmod 755 /etc/network/if-up.d/tftpd-hpa
service tftpd-hpa restart
groupadd -g 628 pupil
groupadd -g 629 teacher
}
configFixes() {
#Configuration file changes required after the client is built. These are not once off as they reside inside the Raspberry Pi OS
sed -i -e 's,/bin/plymouth quit --retain-splash.*,/bin/plymouth quit --retain-splash || true,g' /opt/ltsp/armhf/etc/init.d/ltsp-client-core
#echo 'LTSP_FATCLIENT=true' >> /opt/ltsp/armhf/etc/lts.conf
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf LTSP_FATCLIENT LTSP_FATCLIENT=true
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf INIT_COMMAND_RM_NBD_CHECKUPDATE 'INIT_COMMAND_RM_NBD_CHECKUPDATE="rm -rf /usr/share/ldm/rc.d/I01-nbd-checkupdate"'
DuplicateLTSConf
ltsp-chroot --arch armhf groupadd -g 628 pupil
ltsp-chroot --arch armhf groupadd -g 629 teacher
AddUdevRules
ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/modules 'snd-bcm2835' 'snd-bcm2835'
#printf 'snd-bcm2835\n' >> /opt/ltsp/armhf/etc/modules
echo "exit 0" > /opt/ltsp/armhf/etc/rc.local
addSoundcardDefault
}
addSoundcardDefault(){
#Adds the soundcard settings for Raspbian
grep -q mmap_emul "/opt/ltsp/armhf/etc/asound.conf" > /dev/null 2>&1
checkSound=$?
if [ ! $checkSound = 1 ]; then
cat <<\EOF1 > /opt/ltsp/armhf/etc/asound.conf
pcm.!default {
type hw;
card 0;
}
ctl.!default {
type hw
card 0
}
EOF1
return 1
else
return 0
fi
}
checkInternet(){
#Checks if the internet is connected. Mainly passes off to CheckInternet Python programme in Python functions
if [ ! "$CheckInternetConnection" = "false" ]; then
$p CheckInternet $Timeout
result=$(gp)
return $result
else
return 0
fi
}
checkInternetDetailed(){
#Does a more detailed internet connection check than checkInternet, uses internetFullStatusCheck()
if [ ! "$CheckInternetConnection" = "false" ]; then
$p internetFullStatusCheck
status=$(gp)
return $status
else
return 0
fi
}
UpdateSD() {
#Function for updating the SD card images
$p updateSD
ConfigFileRead # Grab updated $NBDBuildNeeded
if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ]; then
echo $"A required system update has been found. The Raspbian operating system will now be recompressed to apply this update."
NBDRun
fi
return
}
EnableNBDswap(){
#Enables NBD swap system. Allows the Raspberry Pis to use NBD partition as swap
rm /etc/nbd-server/conf.d/swap.conf
cat <<EOF > /etc/nbd-server/conf.d/swap.conf
[swap]
exportname = /tmp/nbd-swap/%s
prerun = nbdswapd %s
postrun = rm -f %s
EOF
service nbd-server restart
}
FixRepo() {
#Adds the repositories used by Raspbian. The public keys are included
# Adds PiNet repo
echo "Adding PiNet repository key."
echo deb http://apt.pinet.org.uk stretch main > /opt/ltsp/armhf/etc/apt/sources.list.d/pinet.list
wget http://apt.pinet.org.uk/pinet.public.key -O /opt/ltsp/armhf/tmp/pinet.public.key
sudo ltsp-chroot --arch armhf apt-key add /tmp/pinet.public.key
rm -rf /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
echo "Adding Raspberry Pi Foundation repository key."
echo "deb http://archive.raspberrypi.org/debian/ stretch main ui staging" > /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
ltsp-chroot --arch armhf apt-key add - <<EOF1
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
mQENBE/d7o8BCACrwqQacGJfn3tnMzGui6mv2lLxYbsOuy/+U4rqMmGEuo3h9m92
30E2EtypsoWczkBretzLUCFv+VUOxaA6sV9+puTqYGhhQZFuKUWcG7orf7QbZRuu
TxsEUepW5lg7MExmAu1JJzqM0kMQX8fVyWVDkjchZ/is4q3BPOUCJbUJOsE+kK/6
8kW6nWdhwSAjfDh06bA5wvoXNjYoDdnSZyVdcYCPEJXEg5jfF/+nmiFKMZBraHwn
eQsepr7rBXxNcEvDlSOPal11fg90KXpy7Umre1UcAZYJdQeWcHu7X5uoJx/MG5J8
ic6CwYmDaShIFa92f8qmFcna05+lppk76fsnABEBAAG0IFJhc3BiZXJyeSBQaSBB
cmNoaXZlIFNpZ25pbmcgS2V5iQE4BBMBAgAiBQJP3e6PAhsDBgsJCAcDAgYVCAIJ
CgsEFgIDAQIeAQIXgAAKCRCCsSmSf6MwPk6vB/9pePB3IukU9WC9Bammh3mpQTvL
OifbkzHkmAYxzjfK6D2I8pT0xMxy949+ThzJ7uL60p6T/32ED9DR3LHIMXZvKtuc
mQnSiNDX03E2p7lIP/htoxW2hDP2n8cdlNdt0M9IjaWBppsbO7IrDppG2B1aRLni
uD7v8bHRL2mKTtIDLX42Enl8aLAkJYgNWpZyPkDyOqamjijarIWjGEPCkaURF7g4
d44HvYhpbLMOrz1m6N5Bzoa5+nq3lmifeiWKxioFXU+Hy5bhtAM6ljVb59hbD2ra
X4+3LXC9oox2flmQnyqwoyfZqVgSQa0B41qEQo8t1bz6Q1Ti7fbMLThmbRHiuQEN
BE/d7o8BCADNlVtBZU63fm79SjHh5AEKFs0C3kwa0mOhp9oas/haDggmhiXdzeD3
49JWz9ZTx+vlTq0s+I+nIR1a+q+GL+hxYt4HhxoA6vlDMegVfvZKzqTX9Nr2VqQa
S4Kz3W5ULv81tw3WowK6i0L7pqDmvDqgm73mMbbxfHD0SyTt8+fk7qX6Ag2pZ4a9
ZdJGxvASkh0McGpbYJhk1WYD+eh4fqH3IaeJi6xtNoRdc5YXuzILnp+KaJyPE5CR
qUY5JibOD3qR7zDjP0ueP93jLqmoKltCdN5+yYEExtSwz5lXniiYOJp8LWFCgv5h
m8aYXkcJS1xVV9Ltno23YvX5edw9QY4hABEBAAGJAR8EGAECAAkFAk/d7o8CGwwA
CgkQgrEpkn+jMD5Figf/dIC1qtDMTbu5IsI5uZPX63xydaExQNYf98cq5H2fWF6O
yVR7ERzA2w33hI0yZQrqO6pU9SRnHRxCFvGv6y+mXXXMRcmjZG7GiD6tQWeN/3wb
EbAn5cg6CJ/Lk/BI4iRRfBX07LbYULCohlGkwBOkRo10T+Ld4vCCnBftCh5x2OtZ
TOWRULxP36y2PLGVNF+q9pho98qx+RIxvpofQM/842ZycjPJvzgVQsW4LT91KYAE
4TVf6JjwUM6HZDoiNcX6d7zOhNfQihXTsniZZ6rky287htsWVDNkqOi5T3oTxWUo
m++/7s3K3L0zWopdhMVcgg6Nt9gcjzqN1c0gy55L/g==
=mNSj
-----END PGP PUBLIC KEY BLOCK-----
EOF1
ltsp-chroot --arch armhf debconf-set-selections <<SELEOF
wolfram-engine shared/accepted-wolfram-eula boolean true
SELEOF
#Auto accepts wolfram eula
echo deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi > /opt/ltsp/armhf/etc/apt/sources.list
ltsp-chroot --arch armhf apt-get update
#Fetches most recent package lists
}
Finished() {
#Function performing any actions that should happen after the boot image has been created
whiptail --title $"Install complete" --msgbox $"The client install is complete, a boot.img file has been placed in /root folder, write this to an sd card" 16 78
}
RaspiTheme(){
#Grabs a copy of the PiNet desktop/login theme and installs
$p InstallPiNetTheme
}
NBDRun() {
#Checks if it should be auto NBD compressing or not, if it should be, it recompresses the image
ConfigFileRead
if [ "$NBD" = "true" ]; then #If NBD is enabled on the system overall
if [ "$NBDuse" = "true" ]; then #If temporarily NBD is disable
echo "--------------------------------------------------------"
echo $"Compressing the image, this will take roughly 5 minutes"
echo "--------------------------------------------------------"
ltsp-update-image /opt/ltsp/armhf #If NBD is enabled, recompress the image
UpdateConfig NBDBuildNeeded false
else
echo $"Auto recompression of Raspbian OS is disabled. To enable, run NBD-recompress from the Other menu."
fi
fi
}
NBDSetup() {
#Setup function for NBD, asks user if they wish to use it, if not it defaults to NFS
whiptail --title $"Network technology" --yesno $"2 network technologies are available for PiNet. NBD and NFS. NBD uses compression dramatically improving application loading times. The tradeoff though is after every modification to the operating system, the image must be recompressed which can take around 5 minutes. NFS is slower but does not need compressed, all changes run live. If in doubt, select NBD." --yes-button "NBD" --no-button "NFS" 11 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
EnableNBD
else
UpdateConfig NBD false
UpdateConfig NBDuse false
UpdateConfig NBDBuildNeeded false
ConfigFileRead
fi
}
EnableNBD() {
/usr/sbin/ltsp-update-image --config-nbd /opt/ltsp/armhf
service nbd-server restart
UpdateConfig NBD true
UpdateConfig NBDuse true
UpdateConfig NBDBuildNeeded false
ConfigFileRead
}
AddSoftware(){
#All the software not included in normal base Debian that has been added to Raspbian normally by Spindle
#------------------------------------------------------------------------------------------
#******************************************************************************************
$p installChrootSoftware
return 0
}
AddUdevRules(){
ltsp-chroot --arch armhf printf 'ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/40-scratch.rules
ltsp-chroot --arch armhf printf "SUBSYSTEM==\"gpio*\", PROGRAM=\"/bin/sh -c 'chown -R root:pupil /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:pupil /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; chown -R root:pupil /sys/devices/platform/soc/*.gpio/gpio && chmod -R 770 /sys/devices/platform/soc/*.gpio/gpio'\"\n" > /etc/udev/rules.d/99-com.rules
ltsp-chroot --arch armhf printf 'SUBSYSTEM=="input", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
ltsp-chroot --arch armhf printf 'SUBSYSTEM=="i2c-dev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
ltsp-chroot --arch armhf printf 'SUBSYSTEM=="spidev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
ltsp-chroot --arch armhf printf 'SUBSYSTEM=="bcm2835-gpiomem", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
}
PiConfigFixes(){
#Configuration changes to Raspberry Pi files, mostly to do with LXDE instead of Raspbian itself
ltsp-chroot --arch armhf sed /etc/xdg/lxsession/LXDE/desktop.conf -i -e "s|sNet/ThemeName.*|sNet/ThemeName=Mist|"
ltsp-chroot --arch armhf sed /etc/xdg/openbox/LXDE/rc.xml -i -e "s|<drawContents>yes</drawContents>|<drawContents>no</drawContents>|"
ltsp-chroot --arch armhf update-alternatives --install /usr/share/images/desktop-base/desktop-background desktop-background /usr/share/raspberrypi-artwork/raspberry-pi-logo.png 100
PCMANFMCFG=/etc/xdg/pcmanfm/LXDE/pcmanfm.conf
ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^wallpaper_mode.*/wallpaper_mode=3/'
ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^desktop_bg.*/desktop_bg=#ffffff/'
ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^su_cmd.*/su_cmd=gksu %s/'
}
EpoptesInstaller() {
#Installs Epoptes classroom managment software
apt-get update
apt-get install -y epoptes
gpasswd -a root staff
ltsp-chroot --arch armhf apt-get update
ltsp-chroot --arch armhf apt-get install -y epoptes-client --no-install-recommends
ltsp-chroot --arch armhf epoptes-client -c
ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP" "SOCKET_GROUP=teacher"
}
EpoptesRun() {
#Launches Epoptes classroom management software. Makes sure it is being run as the user, not as root.
su -c "epoptes &" $SUDO_USER > /dev/null 2>&1 &
}
fixGroups(){
# Verify correct groups exist, then make sure all users are in correct groups.
$p verifyCorrectGroupUsers
ConfigFileRead
if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
NBDRun
# whiptail --title $"Reboot required" --msgbox $"A group ID change has taken place to correct an ID mismatch. This is nothing to worry about unless you are seeing repeatedly. Please reboot your PiNet server as soon as possible." 9 78
fi
}
fixGroupsSingle() {
#Check a single user is in the correct groups
$p verifyCorrectGroupSingleUser $1
}
AddTeacher() {
#Adds a new teacher user to the system
whiptail --title $"Teacher" --msgbox $"Teachers have full admin access on the server (so can run PiNet), full read/write access to all shared folders and Epoptes teacher level (so can control students computers)." 9 78
username=$(SelectUser $"to add to the teacher group.")
if [ ! $username = 1 ]; then
INIT=""
AddUserToTeacher $username
whiptail --title $"Success" --msgbox "The user $username has been added to the teacher group." 8 78
fi
}
AddUserToTeacher() {
#Adds the user to the teacher group
usermod -a -G teacher $1
AddDesktopShortcutToUser $1
}
FixDesktopIcons(){
#Adds all the correct desktop icons for PiNet
rm -rf /etc/skel/Desktop
cd /opt/ltsp/armhf/usr/share/applications
mkdir /etc/skel/Desktop
sudo cp -a scratch.desktop idle.desktop idle3.desktop lxterminal.desktop debian-reference-common.desktop wolfram-mathematica.desktop epiphany-browser.desktop wolfram-language.desktop sonic-pi.desktop minecraft-pi.desktop /etc/skel/Desktop
cd /etc/skel
wget "https://github.com/KenT2/python-games/tarball/master" -O python_games.tar.gz
tar -xvf python_games.tar.gz
mv KenT2-python-games* python_games
chmod +x python_games/launcher.sh
rm python_games.tar.gz
cd /etc/skel/Desktop
cat <<\EOF2 > python-games.desktop
[Desktop Entry]
Name=Python Games
Comment=From http://inventwithpython.com/pygame/
Exec=sh -c $HOME/python_games/launcher.sh
Icon=/usr/share/pixmaps/python.xpm
Terminal=false
Type=Application
Categories=Application;Games;
StartupNotify=true
EOF2
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
do
mkdir /home/$user/Desktop
cd /home/$user/Desktop/
cp -R /etc/skel/Desktop/* /home/$user/Desktop/
chown -R "$user" *
cp -R /etc/skel/python_games /home/$user/python_games
done
AddScreenshot
AddPasswordReset
}
CollectWork(){
#A work collection system. It grabs files from students "handin" folders, copies them to "submitted" folder on the server and changes their owner
INIT="$SUDO_USER"
USERHAND=$(whiptail --inputbox $"Enter the username of the user account you want to save the collected work to. This is usually your own account name" 8 78 $INIT --title $"User selection" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
whiptail --title $"WARNING" --yesno $"The current submitted folder will be deleted, are you sure?" 8 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
rm -rf /home/"$USERHAND"/submitted
mkdir /home/"$USERHAND"/submitted
exitstatus=$?
if [ $exitstatus = 0 ]; then
if [ "$USERHAND" != "" ]; then
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
do
if groups "$user" | grep -q -E ' pupil(\s|$)'; then
if [ -d "/home/$user/handin" ]; then
echo $"The user $user has a handin folder"
cp -r "/home/$user/handin/" "/home/$USERHAND/submitted/$user/"
fi
else
echo $"The user $user does not have a handin folder"
fi
done
chown -R "$USERHAND" /home/"$USERHAND"/submitted
whiptail --title $"Complete" --msgbox $"Students work has been collected and can be found in /home/$USERHAND/submitted/" 8 78
else
whiptail --title $"ERROR" --msgbox $"The username can't be blank!" 8 78
fi
else
whiptail --title $"ERROR" --msgbox $"The user $USERHAND was not found!" 8 78
fi
fi
fi
}
CopyToUsers(){ #(Path-to-folder, path-in-home, skel? warning?)
#Used to copy files out to every user, plus to the skel folder for new users
if [ $4 == "True" ]; then
whiptail --title "WARNING" --yesno "This involves copying a folder to the users home folder, if it already exists should we delete it?" 8 78
local delete=$?
else
local delete=0
fi
local CurrentFilepath=$1
local NewFilepath=$2
local filename=$(basename "$NewFilepath")
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
do
if [ $delete = 0 ] ; then
rm -rf "/home/$user/$NewFilepath"
fi
mkdir -p "/home/$user/"$(dirname ${NewFilepath})
cp -r "$CurrentFilepath" "/home/$user/$NewFilepath"
chown -R "$user" "/home/$user/$NewFilepath"
done
if [ $3 == "True" ]; then
mkdir -p "/etc/skel/"$(dirname ${NewFilepath})
cp -r "$CurrentFilepath" "/etc/skel/$NewFilepath"
fi
}
SudoMenu(){
#Used to enable Sudo on pupil accounts
whiptail --title $"Sudo access" --yesno $"Would you like to give students access to the sudo command on their Raspberry Pi? Sudo (equivalent to run as administrator on Windows) is enabled by default on Raspbian, so disabling it can cause issues with some software. It is required for some GPIO activities as well. Enabling it though does in theory introduce the possibility of students bypassing the built in PiNet tampering safeguards. You can change your mind later the in Manage-Users submenu." 13 78
exitstatus=$?
rm -f /opt/ltsp/armhf/etc/sudoers.d/01pupil
touch /opt/ltsp/armhf/etc/sudoers.d/01pupil
chmod 440 /opt/ltsp/armhf/etc/sudoers.d/01pupil
if [ $exitstatus = 0 ]; then
echo '%pupil ALL=NOPASSWD: ALL' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
fi
echo '%pupil ALL = NOPASSWD: /sbin/shutdown' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
echo '%pupil ALL = NOPASSWD: /sbin/reboot' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
echo '%pupil ALL = NOPASSWD: /sbin/poweroff' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
echo '%pupil ALL = NOPASSWD: /sbin/halt' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
UpdateConfig NBDBuildNeeded true
}
fileSelect(){
#Selects a folder using some BASH/Whiptail trickery
results=$(whiptail --title $"Current location $(pwd)" --menu $"Select a folder. To select this folder, select ./ and to go up a folder, select ../ " 20 80 10 `for x in $(ls -pa | grep "/"); do echo $x "-"; done` 2>&1 >/dev/tty)
exitstatus=$?
if [ "$exitstatus" = "1" ]; then
echo "The user canceled :( "
return "1"
else
if [ "$results" = "./" ]; then
location=$(pwd)
echo $"chosen location is $location"
else
cd "$results"
fileSelect
fi
fi
}
SingleFileSelect(){
#Selects a folder using some BASH/Whiptail trickery
results=$(whiptail --title $"Current location $(pwd)" --menu $"Select a folder. To select this folder, select ./ and to go up a folder, select ../ " 20 80 10 `echo "../ -"; for x in $(ls -p); do echo $x "-"; done` 2>&1 >/dev/tty)
exitstatus=$?
if [ "$exitstatus" = "1" ]; then
echo "The user canceled :("
return "1"
else
if [ -f "$results" ]; then
location=$(pwd)/$results
echo "$location"
else
cd "$results"
SingleFileSelect
fi
fi
}
removeAnacronLines() {
#Removes anacrontab lines which can cause issues. Used for backup scheduling
sed --in-place '/PiNet.backup/d' /etc/anacrontab
sed --in-place '/PiNet.backup/d' /etc/anacrontab
sed --in-place '/PiNet.backup/d' /etc/anacrontab
}
createBackupScript(){
#Adds the backup script to the system to auto backup user data
rm -rf /usr/local/bin/pinet-backup.sh
echo '#!/bin/sh
version=2
#PiNet backup utility script
ConfigFileLoc=/etc/pinet
ConfigFileRead(){
if egrep -q -v "^#|^[^ ]*=[^;]*" "$ConfigFileLoc"; then
# filter the original to a new file
egrep "^#|^[^ ]*=[^;&]*" "$ConfigFileLoc" > "$configfile_secured"
ConfigFileLoc="$configfile_secured"
source "$ConfigFileLoc"
else
source "$ConfigFileLoc"
fi
#echo config read
}
ConfigFileRead
currentDate=`date +"%d-%m-%y"`
currentTime=`date +"%H_%M"`
if [ ! $backupLoc = "" ]; then
LOCATION=$backupLoc
if [ -d "$LOCATION" ]; then
find "$LOCATION" -name "*PiNet-Users-Backup.tar.gz" -ctime +"$DELETETIME" | xargs rm -rf
tar -zcvf "$LOCATION$currentDate--$currentTime--PiNet-Users-Backup.tar.gz" /home
exitstatus=$?
if [ $exitstatus = 0 ]; then
logger -s "$currentDate $currentTime - Backup of users files was successful" 2>> /var/log/PiNet-backup.log
else
logger -s "$currentDate $currentTime - Backup failed with tar errorcode $exitstatus" 2>> /var/log/PiNet-backup.log
fi
else
logger -s "$currentDate $currentTime - Backup folder unavailable!" 2>> /var/log/PiNet-backup.log
fi
else
logger -s "$currentDate $currentTime - No backup location specified!" 2>> /var/log/PiNet-backup.log
fi' >> /usr/local/bin/pinet-backup.sh
chmod +x /usr/local/bin/pinet-backup.sh
}
AddUsers(){
#Add users to the system. Manually adds the user hash instead of using adduser
username=$(whiptail --inputbox $"Enter new username" 8 78 $INIT --title $"Username" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ "$exitstatus" = "0" ]; then
password=$(whiptail --inputbox $"Enter new password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ "$exitstatus" = "0" ]; then
egrep "^$username:" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
whiptail --title "Error" --msgbox $"Username already exists!" 8 78
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -s /bin/bash -p $pass $username
[ $? -eq 0 ] && echo $"$username has been added to system!" || echo $"Failed to add a user!"
fixGroupsSingle $username
whiptail --title $"Permission level" --yesno $"Is $username a pupil or a teacher? Teachers have a lot more permissions including write access to all shared folders, Epoptes teacher access and the ability to run PiNet control software." --yes-button $"Pupil" --no-button $"Teacher" 8 78 ############
if [ ! $? -eq 0 ]; then
AddUserToTeacher $username
whiptail --title $"Success" --msgbox $"A new teacher user has been added to the system successfully with the name - $username" 8 78
else
whiptail --title $"Success" --msgbox $"A new student user has been added to the system successfully with the name - $username" 8 78
fi
fi
whiptail --title $"Another user" --yesno $"Would you like to add another user?" 8 78
if [ $? -eq 0 ]; then
AddUsers
fi
fi
fi
}
RemoveUser(){
#Removes user from list
username=$(SelectUser "to remove.")
if [ ! $username = 1 ]; then
whiptail --title $"Are you sure?" --yesno $"Are you sure you want to delete $username and all $username's user files?" 8 78
if [ $? -eq 0 ]; then
userdel -rf $username
whiptail --title $"Successful" --msgbox $"User successfully removed" 8 78
fi
fi
whiptail --title $"Another user" --yesno $"Would you like to delete another user?" 8 78
if [ $? -eq 0 ]; then
RemoveUser
fi
}
ChangeUserPassword(){
#Change a users password
username=$(SelectUser $"to change the password of.")
if [ ! $username = 1 ]; then
password=$(whiptail --inputbox $"Enter the new password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
if ! [ "$password" = "" ]; then
echo -e "$password\n$password" | passwd $username
whiptail --title $"Successful" --msgbox $"Password successfully changed" 8 78
else
whiptail --title $"Error" --msgbox $"Password not valid" 8 78
fi
fi
whiptail --title $"Another user" --yesno $"Would you like to change another users password?" 8 78
if [ $? -eq 0 ]; then
ChangeUserPassword
fi
}
RestoreBackup() { #Currently incomplete
whiptail --title $"Select backup" --msgbox $"Please select a backup file. They are normally the date, time followed by Raspi-Users-Backup.tar.gz" 8 78
}
SelectUser(){
#Using some BASH/Whiptail magic, builds a list of users, formats it perfectly and hads it to whiptail
users=$(cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | sort | awk -F':' '{ print $1"\na"}')
user=$(whiptail --title $"Users" --menu $"Select a user $1" 16 78 5 $users --noitem 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
echo $user
else
echo 1
fi
}
TroubleShooter(){
#PiNet troubleshooter - Needs some more answers built in
whiptail --title $"Troubleshooter" --msgbox $"Welcome to PiNet troubleshooter. The troubleshooter goes over a few possible issues you may be having with your setup and offers advice. WARNING - This troubleshooter is experimental, feel free to open issue reports at $Repository/issues if you have any additional issues." 16 78
whiptail --title $"Boot" --yesno $"Have you got as far as your Raspberry Pi starting up?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Login screen" --yesno $"Have you got as far as the login screen displaying?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Login screen" --yesno $"Are you having login issues?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Login" --msgbox $"LDM (login screen) does not handle incorrect passwords very well. If you enter an incorrect set of credentials, it just restarts itself. Don't worry about this.
If you are unsure about your password, remember you can easily change it in the Manage-users submenu" 16 78
else
whiptail --title $"USB drivers" --yesno $"Is your keyboard working?" 8 78
if [ ! $? -eq 0 ]; then
whiptail --title $"Kernel misaligned" --msgbox $"9/10 times, this means your kernels are misaligned. Basically there is a kernel on the SD card and as it boots and connects to the PiNet server, it loads the required additional modules (for stuff like USB) from the server. If the server has modules compiled for a more recent kernel, they are misaligned and don't work. To fix this, make sure you are running the most recent version of PiNet, also hit the update-sd option and reflash your SD card to see if that fixes it. If not, a patched set of boot files may not be available yet (they have to be prepared by hand). Best thing you can do is drop support an email and let them know that you are having keyboard/mouse issues. Visit http://pinet.org.uk/articles/support.html" 17 78
else
whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
fi
fi
else
resetAndCleanup
whiptail --title $"Fixed?" --yesno $"Is it fixed now? I just reset some of the networking services." 8 78
if [ ! $? -eq 0 ]; then
whiptail --title $"Connection refused" --yesno $"Are you getting connection refused or connection timed out error?" 8 78
if [ $? -eq 0 ]; then
GetInternalIPAddress #Get the current main IP address
whiptail --title $"Troubleshooter" --msgbox $"This is a common error, it occurs when the IP address of the server on the SD card is incorrect. Insert the SD card into a computer and open the cmdline.txt file. Find NBDRoot= (or NFSRoot=) and make sure the address that follows it is $IP If it isn't, change it so it is. If it is currently 1.1.1.1 the server was unable to get your current address when it created the SD card. If it is a different address, your server may have been assigned a new IP address. It would be a good idea to assign a static IP address to your server. Talk to your technician about this." 16 78
else
whiptail --title $"Giving up" --yesno $"Are you getting a number of 'giving up' errors?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Giving up" --msgbox $"This usually means the Raspberry Pi isn't physically connected to the network, check the ethernet cable is correctly plugged in (wifi is not supported) and is connected to your main switch." 16 78
else
whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
fi
fi
fi
fi
else
whiptail --title $"SD card" --yesno $"Are you having issues with loading the files onto the SD card?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Partitions" --yesno $"Are you having issues with there being 2-3 partitions on the SD card?" 8 78
if [ $? -eq 0 ]; then
whiptail --title $"Formating partitions" --msgbox $"When flashing Raspbian or another Raspberry Pi operating system onto SD cards, a number of partitions are created. PiNet only needs a single partition, the boot partition. This is usually a small (~50mb) partition which is formatted as fat32. If you wish to format the entire SD card (which if you are having issues, you may want to), please refer to the userguide section on formatting SD cards. " 16 78
else
whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
fi
else
whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
fi
fi
}
DisplayUsers(){
#Displays system users onto the terminal
clear
local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
echo "-------------------"
echo $"Current Linux users"
echo "-------------------"
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
do
echo "$user"
done
echo "---------------"
echo $"Current Linux users in the teacher group"
echo "$TEACHER"
echo "---------------"
echo $"Press enter to continue"
read
}
SetupSambaServer(){
#Unused
apt-get install samba libpam-smbpass -y
}
SetupSambaPi(){
#Unused
mkdir /opt/ltsp/armhf/media/school-share
ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf FSTAB 'FSTAB_0="//server/School-Share /media/school-share cifs guest,uid=1000,iocharset=utf8 0 0"'
echo "file:///media/school-share School-Share" >>/tmp/.gtk-bookmarks
CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
rm -rf /tmp/.gtk-bookmarks
}
AfterUpdate(){
#Code run after a successful update on the BASH side, given that most update code is handled via Python
ConfigFileRead
whiptail --title $"Update complete" --msgbox $"The update succeeded. PiNet is now up to date on $ReleaseBranch." 8 78
whiptail --title $"Update-all" --yesno $"After a software update it is recommended you do a system update. This will update all packages to their most recent version and add any new ones added in the update, do you want to?" 9 78
exitstatus=$?
if [ $exitstatus = 0 ]; then
exec /bin/bash pinet Update-All
exit
else
exec /bin/bash pinet
exit
fi
}
Updater(){
#Main updater, most of it is handed by updatePiNet on the Python side or by AfterUpdate on BASH side
$p updatePiNet
exitstatus=$(gp)
if [ $exitstatus = 0 ] && [ "$1" = "IgnoreAfterUpdate" ]; then
if [ ! "$2" = "NoRestart" ]; then
whiptail --title $"Restarting PiNet" --msgbox $"Restarting PiNet to guarantee is running the correct branch version." 8 78
exec /bin/bash pinet
exit
fi
else
if [ $exitstatus = 0 ]; then
AfterUpdate
else
whiptail --title $"Update failed" --msgbox $"The auto update failed. This usually means you aren't connected to the internet" 8 78
exec /bin/bash pinet
fi
fi
}
VerifyPythonPackages(){
#Verify needed Python packages are installed. If not installed, install them.
$PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
$PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
$PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
}