Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 97.93 KB | None | 0 0
  1. #!/bin/bash
  2. # Part of PiNet https://github.com/PiNet/PiNet
  3. #
  4. # See LICENSE file for copyright and license details
  5.  
  6. version=1.2.10
  7.  
  8. #PiNet (Previously RaspberryPi-LTSP)
  9.  
  10. #Written by Andrew Mulholland, based off the fantastic work by vagrantc and alksig from the LTSP community
  11. #Initial guide available at http://cascadia.debian.net/trenza/Documentation/raspberrypi-ltsp-howto/
  12. #Spindle was used to figure out needed changes to generate Raspbian image https://github.com/asb/spindle
  13. #
  14. #PiNet is a utility for setting up and configuring a Linux Terminal Server Project (LTSP) network for Raspberry Pi's
  15.  
  16. #Constants
  17. #------------------------
  18. ConfigFileLoc=/etc/pinet
  19. Timeout=1
  20. PythonFunctions="/usr/local/bin/pinet_functions_python.py"
  21. PythonStart="python3"
  22. p="$PythonStart $PythonFunctions"
  23. RepositoryBase="https://github.com/PiNet/"
  24. RepositoryName="PiNet"
  25. BootRepositoryName="PiNet-Boot"
  26. RawRepositoryBase="https://raw.github.com/PiNet/"
  27. Repository="$RepositoryBase$RepositoryName"
  28. BootRepository="$RepositoryBase$BootRepositoryName"
  29. RawRepository="$RawRepositoryBase$RepositoryName"
  30. ReleaseBranch="jessie-stable"  #Overwriten later on in SetupRepositories()
  31. ltspBase="/opt/ltsp/"
  32. cpuArch="armhf"
  33.  
  34.  
  35. #------------------------
  36.  
  37. SetupRepositories(){
  38.     ReleaseChannel=$(echo "$ReleaseChannel" | tr '[:upper:]' '[:lower:]')
  39.     case "$ReleaseChannel" in
  40.         stable)
  41.             ReleaseBranch="stable"
  42.         ;;
  43.  
  44.         beta)
  45.             ReleaseBranch="beta"
  46.         ;;
  47.  
  48.         dev)
  49.             ReleaseBranch="beta"
  50.         ;;
  51.  
  52.         alpha)
  53.             ReleaseBranch="alpha"
  54.         ;;
  55.  
  56.         "custom:*")
  57.             ReleaseBranch=${ReleaseChannel:7:channelLength}
  58.         ;;
  59.  
  60.         *)
  61.             ReleaseBranch="stable"
  62.         ;;
  63.     esac
  64.  
  65. }
  66.  
  67. LegacyFixes() {
  68.     #Runs a number of legacy code checks, making sure everything is configured correctly.
  69.     if [ -d "/home/shared" ]; then
  70.         CheckSharedFolderIntegrity
  71.     fi
  72.     CheckDesktopShortcut
  73.     teacherSudoCheck
  74.     CheckRaspberryPiUIMods
  75.     ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf "NFS_HOME=/home" ""
  76.     if [ -f "/etc/default/epoptes" ]; then
  77.         ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP=staff" "SOCKET_GROUP=teacher"
  78.     fi
  79.  
  80.     if [ ! -f "/opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh" ]; then
  81.         AddScreenshot
  82.         UpdateConfig NBDBuildNeeded true
  83.     fi
  84.  
  85.     if [ ! -f "/usr/local/bin/changePassword.sh" ]; then
  86.         AddPasswordReset
  87.         UpdateConfig NBDBuildNeeded true
  88.     fi
  89.     CheckPipSymbolicLinkBug
  90.     local passwdVersion=$(cat /home/$SUDO_USER/Desktop/pinet-password.desktop | sed -n '2p')
  91.     ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
  92.     exitcode=$?
  93.     sed -i '/^[[:blank:]]*$/d' /opt/ltsp/armhf/etc/lts.conf
  94.     if [ "$exitcode" = "1" ]; then
  95.         UpdateConfig NBDBuildNeeded true
  96.     fi
  97.  
  98.     CheckDebianVersion
  99.     CheckBackupScriptVersion
  100.  
  101.     if [ -f "/usr/local/bin/pinet-functions-python.py" ]; then
  102.         mv "/usr/local/bin/pinet-functions-python.py" "/usr/local/bin/pinet_functions_python.py"
  103.     fi
  104.  
  105.     # Make sure that all the required Python libraries are installed
  106.     $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser  )
  107.     $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests  )
  108.     $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces  )
  109.  
  110.     if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
  111.         echo $"A required system update has been found. The Raspbian operating system will now be recompressed to apply this update"
  112.         NBDRun
  113.     else
  114.         UpdateConfig NBDBuildNeeded false
  115.     fi
  116.     $p "checkStatsNotification"
  117.  
  118. }
  119.  
  120.  
  121. ConfigFileRead(){
  122.     #Reads the config file and loads in data as variables
  123.     #Taken from - http://wiki.bash-hackers.org/howto/conffile
  124.     configfile_secured="/tmp/pinet-config"
  125.  
  126.     if egrep -q -v '^#|^[^ ]*=[^;]*' "$ConfigFileLoc"; then
  127.         # filter the original to a new file
  128.         egrep '^#|^[^ ]*=[^;&]*'  "$ConfigFileLoc" > "$configfile_secured"
  129.         ConfigFileLoc="$configfile_secured"
  130.         source "$ConfigFileLoc"
  131.     else
  132.         source "$ConfigFileLoc"
  133.     fi
  134. }
  135.  
  136. ReplaceTextLine(){
  137. # ReplaceTextLine /textfile bob brian
  138.     egrep -i "^$2" $1 >> /dev/null
  139.     if [ $? = 0 ]; then
  140.         sed -i "s/$2.*/$3/g" $1
  141.     else
  142.         echo "$3" >> $1
  143.     fi
  144.  
  145. }
  146.  
  147. ReplaceAnyTextOnLine(){
  148. # ReplaceTextLine /textfile bob brian
  149. #REMEMBER!! The & symbol can't be in any of the strings as SED is using it for separating. Can change it if need be
  150.         egrep -i "$2" $1 >> /dev/null
  151.         if [ $? -eq 0 ]; then
  152.                 sed -i "s&.*$2.*&$3&g" $1
  153.                 return 0
  154.         else
  155.                 echo "$3" >> $1
  156.                 return 1
  157.         fi
  158.  
  159. }
  160.  
  161. UpdateConfig(){
  162.     #Updates the PiNet config file with provided values
  163.     #Example - UpdateConfig bob false
  164.     local configName=$1
  165.     local configValue=$2
  166.     egrep -i "^$configName" $ConfigFileLoc >> /dev/null
  167.     if [ $? = 0 ]; then
  168.         sed -i "s/$configName.*/$configName=$configValue/g" $ConfigFileLoc
  169.     else
  170.         echo "$configName=$configValue" >> $ConfigFileLoc
  171.     fi
  172. ConfigFileRead
  173. }
  174.  
  175.  
  176. gp(){
  177.     #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.
  178.     if [ -f /tmp/ltsptmp ]; then
  179.         echo $(head -n 1 /tmp/ltsptmp)
  180.     fi
  181. }
  182.  
  183. installLTSP() {
  184. #Installs main packages required by LTSP
  185. apt-get update && apt-get upgrade -y
  186.  
  187. 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
  188. exitstatus=$?
  189. if ! [ $exitstatus = 0 ]; then
  190.     whiptail --title $"ERRORE!" --msgbox $"Nessuna connessione a Internet, oppure altro software e' gia' installato nel sistema! Per favore, aspetta 5-10 minuti o connettiti a Internet" 10 78
  191.     exit 1
  192. fi
  193.  
  194. }
  195.  
  196.  
  197.  
  198. buildClient() {
  199. #Creates the custom config file needed to build Raspbian and grabs keychain. Then starts the build
  200.  
  201. wget http://archive.raspbian.org/raspbian.public.key -O - | gpg --import
  202. gpg --export 90FDDD2E >> /etc/ltsp/raspbian.public.key.gpg
  203.  
  204. rm /etc/ltsp/ltsp-raspbian.conf
  205.  
  206. cat <<EOF > /etc/ltsp/ltsp-raspbian.conf
  207. DEBOOTSTRAP_KEYRING=/etc/ltsp/raspbian.public.key.gpg
  208. DIST=jessie
  209. # For alternate raspbian mirrors, see: http://www.raspbian.org/RaspbianMirrors
  210. MIRROR=http://mirrordirector.raspbian.org/raspbian
  211. SECURITY_MIRROR=none
  212. UPDATES_MIRROR=none
  213. LOCALE="$LANG UTF-8"
  214. KERNEL_PACKAGES=linux-image-3.10-3-rpi
  215. EOF
  216.  
  217. VENDOR=Debian ltsp-build-client --arch armhf --config /etc/ltsp/ltsp-raspbian.conf
  218. }
  219.  
  220.  
  221.  
  222. OneTimeFixes(){
  223. #A number of one off fixes needed to be run
  224.  
  225. echo "/opt/ltsp *(ro,no_root_squash,async,no_subtree_check)" >> /etc/exports #sets up OS exporting for NFS
  226. echo "/home   *(rw,sync,no_subtree_check)" >> /etc/exports #Sets up home folder exporting for NFS
  227.  
  228. mkdir /etc/skel/handin
  229.  
  230. echo '#!/bin/sh' >> /etc/network/if-up.d/tftpd-hpa      #Script to make sure tftpd-hpa autostarts
  231. echo "service tftpd-hpa restart" >> /etc/network/if-up.d/tftpd-hpa
  232. chmod 755 /etc/network/if-up.d/tftpd-hpa
  233. service tftpd-hpa restart
  234. groupadd -g 628 pupil
  235. groupadd -g 629 teacher
  236.  
  237. }
  238.  
  239. configFixes() {
  240. #Configuration file changes required after the client is built. These are not once off as they reside inside the Raspberry Pi OS
  241.  
  242. 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
  243. echo 'LTSP_FATCLIENT=true' >> /opt/ltsp/armhf/etc/lts.conf
  244. ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
  245. DuplicateLTSConf
  246.  
  247. ltsp-chroot --arch armhf groupadd -g 628 pupil
  248. ltsp-chroot --arch armhf groupadd -g 629 teacher
  249. AddUdevRules
  250.  
  251. printf 'snd-bcm2835\n' >> /opt/ltsp/armhf/etc/modules
  252.  
  253. addSoundcardDefault
  254.  
  255. }
  256.  
  257. addSoundcardDefault(){
  258. #Adds the soundcard settings for Raspbian
  259. grep -q mmap_emul "/opt/ltsp/armhf/etc/asound.conf" > /dev/null 2>&1
  260. checkSound=$?
  261. if [ ! $checkSound = 1 ]; then
  262. cat <<\EOF1 > /opt/ltsp/armhf/etc/asound.conf
  263. pcm.!default {
  264. type hw;
  265. card 0;
  266. }
  267.  
  268. ctl.!default {
  269.     type hw
  270.     card 0
  271. }
  272.  
  273. EOF1
  274. return 1
  275. else
  276. return 0
  277.  
  278. fi
  279.  
  280. }
  281.  
  282. checkInternet(){
  283. #Checks if the internet is connected. Mainly passes off to CheckInternet Python programme in Python functions
  284. if [ ! "$CheckInternetConnection" = "false" ]; then
  285.     $p CheckInternet $Timeout
  286.     result=$(gp)
  287.     return $result
  288. else
  289.     return 0
  290. fi
  291.  
  292. }
  293.  
  294. checkInternetDetailed(){
  295. #Does a more detailed internet connection check than checkInternet, uses internetFullStatusCheck()
  296. if [ ! "$CheckInternetConnection" = "false" ]; then
  297.     $p internetFullStatusCheck
  298.     status=$(gp)
  299.     return $status
  300. else
  301.     return 0
  302. fi
  303. }
  304.  
  305. UpdateSD() {
  306. #Function for updating the SD card images
  307.  
  308. $p updateSD
  309. ConfigFileRead  # Grab updated $NBDBuildNeeded
  310. if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ]; then
  311.         echo $"È stato trovato un aggiornamento di sistema richiesto. Il sistema operativo Raspbian verrà ora ricompresso per applicare questo aggiornamento."
  312.         NBDRun
  313.     fi
  314. return
  315.  
  316. }
  317.  
  318. EnableNBDswap(){
  319. #Enables NBD swap system. Allows the Raspberry Pis to use NBD partition as swap
  320.  
  321. rm /etc/nbd-server/conf.d/swap.conf
  322. cat <<EOF > /etc/nbd-server/conf.d/swap.conf
  323. [swap]
  324. exportname = /tmp/nbd-swap/%s
  325. prerun = nbdswapd %s
  326. postrun = rm -f %s
  327. EOF
  328. service nbd-server restart
  329.  
  330. }
  331.  
  332.  
  333. FixRepo() {
  334. #Adds the repositories used by Raspbian. The public keys are included
  335.  
  336. # Adds PiNet repo
  337. echo "Aggiunta della chiave del repository PiNet."
  338. echo deb http://apt.pinet.org.uk jessie main > /opt/ltsp/armhf/etc/apt/sources.list.d/pinet.list
  339. wget http://apt.pinet.org.uk/pinet.public.key -O /opt/ltsp/armhf/tmp/pinet.public.key
  340. sudo ltsp-chroot --arch armhf apt-key add /tmp/pinet.public.key
  341.  
  342. rm -rf /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
  343. echo "Sto aggiungendo la chiave del repository della PiNet Foundation."
  344. echo "deb http://archive.raspberrypi.org/debian/ jessie main ui staging" > /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
  345. ltsp-chroot --arch armhf apt-key add - <<EOF1
  346. -----BEGIN PGP PUBLIC KEY BLOCK-----
  347. Version: GnuPG v1.4.12 (GNU/Linux)
  348.  
  349. mQENBE/d7o8BCACrwqQacGJfn3tnMzGui6mv2lLxYbsOuy/+U4rqMmGEuo3h9m92
  350. 30E2EtypsoWczkBretzLUCFv+VUOxaA6sV9+puTqYGhhQZFuKUWcG7orf7QbZRuu
  351. TxsEUepW5lg7MExmAu1JJzqM0kMQX8fVyWVDkjchZ/is4q3BPOUCJbUJOsE+kK/6
  352. 8kW6nWdhwSAjfDh06bA5wvoXNjYoDdnSZyVdcYCPEJXEg5jfF/+nmiFKMZBraHwn
  353. eQsepr7rBXxNcEvDlSOPal11fg90KXpy7Umre1UcAZYJdQeWcHu7X5uoJx/MG5J8
  354. ic6CwYmDaShIFa92f8qmFcna05+lppk76fsnABEBAAG0IFJhc3BiZXJyeSBQaSBB
  355. cmNoaXZlIFNpZ25pbmcgS2V5iQE4BBMBAgAiBQJP3e6PAhsDBgsJCAcDAgYVCAIJ
  356. CgsEFgIDAQIeAQIXgAAKCRCCsSmSf6MwPk6vB/9pePB3IukU9WC9Bammh3mpQTvL
  357. OifbkzHkmAYxzjfK6D2I8pT0xMxy949+ThzJ7uL60p6T/32ED9DR3LHIMXZvKtuc
  358. mQnSiNDX03E2p7lIP/htoxW2hDP2n8cdlNdt0M9IjaWBppsbO7IrDppG2B1aRLni
  359. uD7v8bHRL2mKTtIDLX42Enl8aLAkJYgNWpZyPkDyOqamjijarIWjGEPCkaURF7g4
  360. d44HvYhpbLMOrz1m6N5Bzoa5+nq3lmifeiWKxioFXU+Hy5bhtAM6ljVb59hbD2ra
  361. X4+3LXC9oox2flmQnyqwoyfZqVgSQa0B41qEQo8t1bz6Q1Ti7fbMLThmbRHiuQEN
  362. BE/d7o8BCADNlVtBZU63fm79SjHh5AEKFs0C3kwa0mOhp9oas/haDggmhiXdzeD3
  363. 49JWz9ZTx+vlTq0s+I+nIR1a+q+GL+hxYt4HhxoA6vlDMegVfvZKzqTX9Nr2VqQa
  364. S4Kz3W5ULv81tw3WowK6i0L7pqDmvDqgm73mMbbxfHD0SyTt8+fk7qX6Ag2pZ4a9
  365. ZdJGxvASkh0McGpbYJhk1WYD+eh4fqH3IaeJi6xtNoRdc5YXuzILnp+KaJyPE5CR
  366. qUY5JibOD3qR7zDjP0ueP93jLqmoKltCdN5+yYEExtSwz5lXniiYOJp8LWFCgv5h
  367. m8aYXkcJS1xVV9Ltno23YvX5edw9QY4hABEBAAGJAR8EGAECAAkFAk/d7o8CGwwA
  368. CgkQgrEpkn+jMD5Figf/dIC1qtDMTbu5IsI5uZPX63xydaExQNYf98cq5H2fWF6O
  369. yVR7ERzA2w33hI0yZQrqO6pU9SRnHRxCFvGv6y+mXXXMRcmjZG7GiD6tQWeN/3wb
  370. EbAn5cg6CJ/Lk/BI4iRRfBX07LbYULCohlGkwBOkRo10T+Ld4vCCnBftCh5x2OtZ
  371. TOWRULxP36y2PLGVNF+q9pho98qx+RIxvpofQM/842ZycjPJvzgVQsW4LT91KYAE
  372. 4TVf6JjwUM6HZDoiNcX6d7zOhNfQihXTsniZZ6rky287htsWVDNkqOi5T3oTxWUo
  373. m++/7s3K3L0zWopdhMVcgg6Nt9gcjzqN1c0gy55L/g==
  374. =mNSj
  375. -----END PGP PUBLIC KEY BLOCK-----
  376. EOF1
  377.  
  378. ltsp-chroot --arch armhf debconf-set-selections <<SELEOF
  379. wolfram-engine shared/accepted-wolfram-eula boolean true
  380. SELEOF
  381. #Auto accepts wolfram eula
  382.  
  383. echo deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi > /opt/ltsp/armhf/etc/apt/sources.list
  384.  
  385. ltsp-chroot --arch armhf apt-get update
  386. #Fetches most recent package lists
  387.  
  388. }
  389.  
  390.  
  391. Finished() {
  392. #Function performing any actions that should happen after the boot image has been created
  393. whiptail --title $"Installazione Completata" --msgbox $"L'installazione del client è stata completata, un file boot.img è stato posizionato nella directory /root, scrivilo in una scheda SD" 16 78
  394. }
  395.  
  396.  
  397. RaspiTheme(){
  398. #Grabs a copy of the PiNet desktop/login theme and installs
  399.  
  400. rm -rf /tmp/pinet
  401. git clone --no-single-branch --depth 1 $Repository.git /tmp/pinet #Clones main repository, including boot files
  402. (cd "/tmp/pinet"; git checkout "$ReleaseBranch")
  403. cp -r /tmp/pinet/themes/raspi /opt/ltsp/armhf/usr/share/ldm/themes/raspi
  404. rm /opt/ltsp/armhf/etc/alternatives/ldm-theme
  405. ln -s /usr/share/ldm/themes/raspi /opt/ltsp/armhf/etc/alternatives/ldm-theme
  406. rm -rf /tmp/pinet
  407. cp /opt/ltsp/armhf/usr/share/ldm/themes/raspi/bg.png /opt/ltsp/armhf/usr/share/images/desktop-base/pinet.png
  408. sudo ltsp-chroot --arch armhf update-alternatives --install /usr/share/images/desktop-base/desktop-background desktop-background /usr/share/images/desktop-base/pinet.png 100
  409.  
  410. }
  411.  
  412.  
  413. NBDRun() {
  414. #Checks if it should be auto NBD compressing or not, if it should be, it recompresses the image
  415. ConfigFileRead
  416. if [ "$NBD" = "true" ]; then  #If NBD is enabled on the system overall
  417.     if [ "$NBDuse" = "true" ]; then  #If temporarily NBD is disable
  418.         echo "--------------------------------------------------------"
  419.         echo $"Compressione dell'immagine, questo processo potrebbe durare 5 minuti"
  420.         echo "--------------------------------------------------------"
  421.         ltsp-update-image /opt/ltsp/armhf  #If NBD is enabled, recompress the image
  422.         UpdateConfig NBDBuildNeeded false
  423.     else
  424.         echo $"L'auto recomprissione del Raspbian OS è disabilitata. Per attivarla, avvia il comando NBD-recompress dall'altro menu"
  425.     fi
  426. fi
  427.  
  428. }
  429.  
  430. NBDSetup() {
  431. #Setup function for NBD, asks user if they wish to use it, if not it defaults to NFS
  432.  
  433. whiptail --title $"Tecnologia di rete" --yesno  $"Sono disponibili 2 tecnologie di rete per PiNet. NBD e NFS. NBD utilizza la compressione che migliora drasticamente i tempi di caricamento delle applicazioni. Il compromesso è però dopo ogni modifica al sistema operativo, l'immagine deve essere ricompressa che può richiedere circa 5 minuti. NFS è più lento ma non ha bisogno di essere compresso, tutte le modifiche vengono eseguite dal vivo. In caso di dubbio, selezionare NBD." --yes-button "NBD" --no-button "NFS" 11 78
  434. exitstatus=$?
  435. if [ $exitstatus = 0 ]; then
  436.     EnableNBD
  437. else
  438.     UpdateConfig NBD false
  439.     UpdateConfig NBDuse false
  440.     UpdateConfig NBDBuildNeeded false
  441.     ConfigFileRead
  442. fi
  443. }
  444.  
  445. EnableNBD() {
  446.     /usr/sbin/ltsp-update-image --config-nbd /opt/ltsp/armhf
  447.     service nbd-server restart
  448.     UpdateConfig NBD true
  449.     UpdateConfig NBDuse true
  450.     UpdateConfig NBDBuildNeeded false
  451.     ConfigFileRead
  452.  
  453. }
  454.  
  455. AddSoftware(){
  456. #All the software not included in normal base Debian that has been added to Raspbian normally by Spindle
  457.  
  458. #------------------------------------------------------------------------------------------
  459. #******************************************************************************************
  460.  
  461. $p installChrootSoftware
  462. return 0
  463.  
  464. }
  465.  
  466.  
  467. AddUdevRules(){
  468.  
  469. 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
  470. 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
  471. ltsp-chroot --arch armhf printf 'SUBSYSTEM=="input", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
  472. ltsp-chroot --arch armhf printf 'SUBSYSTEM=="i2c-dev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
  473. ltsp-chroot --arch armhf printf 'SUBSYSTEM=="spidev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
  474. ltsp-chroot --arch armhf printf 'SUBSYSTEM=="bcm2835-gpiomem", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
  475.  
  476. }
  477.  
  478. PiConfigFixes(){
  479. #Configuration changes to Raspberry Pi files, mostly to do with LXDE instead of Raspbian itself
  480.  
  481. ltsp-chroot --arch armhf sed /etc/xdg/lxsession/LXDE/desktop.conf -i -e "s|sNet/ThemeName.*|sNet/ThemeName=Mist|"
  482. ltsp-chroot --arch armhf sed /etc/xdg/openbox/LXDE/rc.xml -i -e \
  483. "s|<drawContents>yes</drawContents>|<drawContents>no</drawContents>|"
  484. ltsp-chroot --arch armhf apt-get install -y raspberrypi-artwork
  485. 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
  486. ltsp-chroot --arch armhf PCMANFMCFG=/etc/xdg/pcmanfm/LXDE/pcmanfm.conf
  487. ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^wallpaper_mode.*/wallpaper_mode=3/'
  488. ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^desktop_bg.*/desktop_bg=#ffffff/'
  489. ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^su_cmd.*/su_cmd=gksu %s/'
  490. }
  491.  
  492.  
  493. EpoptesInstaller() {
  494.     #Installs Epoptes classroom managment software
  495.     apt-get update
  496.     apt-get install -y epoptes
  497.     gpasswd -a root staff
  498.     ltsp-chroot --arch armhf apt-get update
  499.     ltsp-chroot --arch armhf apt-get install -y epoptes-client --no-install-recommends
  500.     ltsp-chroot --arch armhf epoptes-client -c
  501.     ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP" "SOCKET_GROUP=teacher"
  502. }
  503.  
  504. EpoptesRun() {
  505.     #Launches Epoptes classroom management software. Makes sure it is being run as the user, not as root.
  506.     su -c "epoptes &" $SUDO_USER > /dev/null 2>&1 &
  507. }
  508.  
  509. fixGroups(){
  510.     # Verify correct groups exist, then make sure all users are in correct groups.
  511.     $p verifyCorrectGroupUsers
  512.     ConfigFileRead
  513.     if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
  514.         NBDRun
  515.         whiptail --title $"Riavvio richiesto" --msgbox $"È stata apportata una modifica dell'ID di gruppo per correggere una mancata corrispondenza dell'ID. Questo non è nulla di cui preoccuparsi a meno che non si vedano più volte. Riavvia il tuo server PiNet il prima possibile." 9 78
  516.     fi
  517. }
  518.  
  519.  
  520. fixGroupsSingle() {
  521.     #Check a single user is in the correct groups
  522.     $p verifyCorrectGroupSingleUser $1
  523. }
  524.  
  525.  
  526.  
  527. AddTeacher() {
  528.     #Adds a new teacher user to the system
  529.     whiptail --title $"Insegnante" --msgbox $"Gli insegnanti hanno pieno accesso amministrativo sul server (quindi possono eseguire PiNet), accesso completo in lettura / scrittura a tutte le cartelle condivise e al livello di insegnante di Epoptes (in modo da poter controllare i computer degli studenti)." 9 78
  530.     username=$(SelectUser $"per aggiungere al gruppo degli insegnanti")
  531.     if [ ! $username = 1 ]; then
  532.         INIT=""
  533.         AddUserToTeacher $username
  534.         whiptail --title $"Successo!" --msgbox "L'utente $username è stato aggiunto al gruppo insegnanti." 8 78
  535.     fi
  536. }
  537.  
  538. AddUserToTeacher() {
  539.     #Adds the user to the teacher group
  540.     usermod -a -G teacher $1
  541.     AddDesktopShortcutToUser $1
  542. }
  543.  
  544. FixDesktopIcons(){
  545. #Adds all the correct desktop icons for PiNet
  546. rm -rf /etc/skel/Desktop
  547. cd /opt/ltsp/armhf/usr/share/applications
  548. mkdir /etc/skel/Desktop
  549. 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
  550. cd /etc/skel
  551. wget "https://github.com/KenT2/python-games/tarball/master" -O python_games.tar.gz
  552. tar -xvf python_games.tar.gz
  553. mv KenT2-python-games* python_games
  554. chmod +x python_games/launcher.sh
  555. rm python_games.tar.gz
  556. cd /etc/skel/Desktop
  557. cat <<\EOF2 > python-games.desktop
  558. [Desktop Entry]
  559. Name=Python Games
  560. Comment=From http://inventwithpython.com/pygame/
  561. Exec=sh -c $HOME/python_games/launcher.sh
  562. Icon=/usr/share/pixmaps/python.xpm
  563. Terminal=false
  564. Type=Application
  565. Categories=Application;Games;
  566. StartupNotify=true
  567. EOF2
  568.  
  569. cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  570. do
  571.         mkdir /home/$user/Desktop
  572.         cd /home/$user/Desktop/
  573.         cp -R  /etc/skel/Desktop/* /home/$user/Desktop/
  574.         chown -R "$user" *
  575.         cp -R /etc/skel/python_games /home/$user/python_games
  576.  
  577. done
  578.  
  579. AddScreenshot
  580. AddPasswordReset
  581.  
  582. }
  583.  
  584.  
  585. CollectWork(){
  586. #A work collection system. It grabs files from students "handin" folders, copies them to "submitted" folder on the server and changes their owner
  587. INIT="$SUDO_USER"
  588. USERHAND=$(whiptail --inputbox $"Immettere il nome utente dell'account utente su cui si desidera salvare il lavoro raccolto. Questo di solito è il nome del tuo account" 8 78 $INIT --title $"User selection" 3>&1 1>&2 2>&3)
  589.  
  590. exitstatus=$?
  591. if [ $exitstatus = 0 ]; then
  592.     whiptail --title $"AVVERTIMENTO" --yesno $"La cartella attuale scelta verrà eliminata, sei sicuro?" 8 78
  593.     exitstatus=$?
  594.     if [ $exitstatus = 0 ]; then
  595.         rm -rf /home/"$USERHAND"/submitted
  596.         mkdir /home/"$USERHAND"/submitted
  597.         exitstatus=$?
  598.         if [ $exitstatus = 0 ]; then
  599.             if [ "$USERHAND" != "" ]; then
  600.                 cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  601.                 do
  602.                     if groups "$user" | grep -q -E ' pupil(\s|$)'; then
  603.                         if [ -d "/home/$user/handin" ]; then
  604.                             echo $"l'utente $user ha una cartella di handin"
  605.                             cp -r "/home/$user/handin/" "/home/$USERHAND/submitted/$user/"
  606.  
  607.                         fi
  608.  
  609.                         else
  610.                             echo $"L'utente $user non ha una cartella di handin"
  611.  
  612.                     fi
  613.                 done
  614.  
  615.                 chown -R "$USERHAND" /home/"$USERHAND"/submitted
  616.                 whiptail --title $"Completato!" --msgbox $"I lavori degli studenti sono stati raccolti e sono accessibili in : /home/$USERHAND/submitted/" 8 78
  617.             else
  618.             whiptail --title $"ERRORE" --msgbox $"l'username non può essere uno spazio vuoto" 8 78
  619.             fi
  620.         else
  621.             whiptail --title $"ERRORE" --msgbox $"L'utente $USERHAND non è stato trovato" 8 78
  622.  
  623.         fi
  624.     fi
  625. fi
  626.  
  627. }
  628.  
  629. CopyToUsers(){ #(Path-to-folder, path-in-home, skel? warning?)
  630. #Used to copy files out to every user, plus to the skel folder for new users
  631.  
  632. if [ $4 == "True" ]; then
  633.     whiptail --title "ATTENZIONE" --yesno "Questo comporta copiare una cartella alla directory home, se esiste la cancello?" 8 78
  634.     local delete=$?
  635. else
  636.     local delete=0
  637. fi
  638. local CurrentFilepath=$1
  639. local NewFilepath=$2
  640. local filename=$(basename "$NewFilepath")
  641. cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  642. do
  643.     if [ $delete = 0 ] ; then
  644.         rm -rf "/home/$user/$NewFilepath"
  645.     fi
  646.         mkdir -p "/home/$user/"$(dirname ${NewFilepath})
  647.         cp -r  "$CurrentFilepath" "/home/$user/$NewFilepath"
  648.         chown -R "$user" "/home/$user/$NewFilepath"
  649.  
  650. done
  651. if [ $3 == "True" ]; then
  652.     mkdir -p "/etc/skel/"$(dirname ${NewFilepath})
  653.     cp -r  "$CurrentFilepath" "/etc/skel/$NewFilepath"
  654. fi
  655. }
  656.  
  657. SudoMenu(){
  658. #Used to enable Sudo on pupil accounts
  659.  
  660. whiptail --title $"Accesso come amministratore" --yesno $"Vorresti che gli studenti avessero l'accesso al comando sudo?( Sudo equivalente all'esegui come amministratore dli windows) è abilitato di default in Raspbian, quindi disabilitarlo comporterebbe avere dei problemi con alcuni software. Abilitarlo potrebbe dare possibilità agli studenti di eludere le misure di sicurezza PiNet. Puoi cambiare idea più tardi nel submenu Gestisci Utenti." 13 78
  661. exitstatus=$?
  662. rm -f /opt/ltsp/armhf/etc/sudoers.d/01pupil
  663. touch /opt/ltsp/armhf/etc/sudoers.d/01pupil
  664. chmod 440 /opt/ltsp/armhf/etc/sudoers.d/01pupil
  665. if [ $exitstatus = 0 ]; then
  666.     echo '%pupil ALL=NOPASSWD: ALL' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
  667. fi
  668. echo '%pupil ALL = NOPASSWD: /sbin/shutdown' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
  669. echo '%pupil ALL = NOPASSWD: /sbin/reboot' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
  670. echo '%pupil ALL = NOPASSWD: /sbin/poweroff' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
  671. echo '%pupil ALL = NOPASSWD: /sbin/halt' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
  672. UpdateConfig NBDBuildNeeded true
  673. }
  674.  
  675.  
  676. fileSelect(){
  677. #Selects a folder using some BASH/Whiptail trickery
  678. results=$(whiptail --title $"Posizione attuale $(pwd)"  --menu $"Seleziona una cartella. Per selezionare questa cartella, digita ./ e per andare su una cartella, digita ../ " 20 80 10 `for x in $(ls -pa | grep "/"); do echo $x "-"; done` 2>&1 >/dev/tty)
  679. exitstatus=$?
  680. if [ "$exitstatus" = "1" ]; then
  681.         echo "L'utente annullato :( "
  682.         return "1"
  683. else
  684.         if [ "$results" = "./" ]; then
  685.                 location=$(pwd)
  686.                 echo $"la posizione scelta è: $location"
  687.         else
  688.                 cd "$results"
  689.                 fileSelect
  690.         fi
  691. fi
  692.  
  693. }
  694.  
  695. SingleFileSelect(){
  696. #Selects a folder using some BASH/Whiptail trickery
  697. results=$(whiptail --title $"Posizione attuale $(pwd)"  --menu $"Seleziona una cartella. Per selezionare questa cartella, digita ./ e per andare su una cartella, digita ../ " 20 80 10 `echo "../ -"; for x in $(ls -p); do echo $x "-"; done` 2>&1 >/dev/tty)
  698. exitstatus=$?
  699. if [ "$exitstatus" = "1" ]; then
  700.         echo "L'utente annullato :("
  701.         return "1"
  702. else
  703.         if [ -f "$results" ]; then
  704.                 location=$(pwd)/$results
  705.                 echo "$location"
  706.         else
  707.                 cd "$results"
  708.                 SingleFileSelect
  709.         fi
  710. fi
  711.  
  712. }
  713.  
  714. removeAnacronLines() {
  715. #Removes anacrontab lines which can cause issues. Used for backup scheduling
  716. sed --in-place '/PiNet.backup/d' /etc/anacrontab
  717. sed --in-place '/PiNet.backup/d' /etc/anacrontab
  718. sed --in-place '/PiNet.backup/d' /etc/anacrontab
  719.  
  720. }
  721.  
  722. createBackupScript(){
  723. #Adds the backup script to the system to auto backup user data
  724. rm -rf /usr/local/bin/pinet-backup.sh
  725.  
  726. echo '#!/bin/sh
  727. version=2
  728.  
  729. #PiNet backup utility script
  730.  
  731. ConfigFileLoc=/etc/pinet
  732. ConfigFileRead(){
  733.     if egrep -q -v "^#|^[^ ]*=[^;]*" "$ConfigFileLoc"; then
  734.         # filter the original to a new file
  735.         egrep "^#|^[^ ]*=[^;&]*"  "$ConfigFileLoc" > "$configfile_secured"
  736.         ConfigFileLoc="$configfile_secured"
  737.         source "$ConfigFileLoc"
  738.     else
  739.         source "$ConfigFileLoc"
  740.     fi
  741.     #echo config read
  742. }
  743.  
  744. ConfigFileRead
  745.  
  746. currentDate=`date +"%d-%m-%y"`
  747. currentTime=`date +"%H_%M"`
  748. if [ ! $backupLoc = "" ]; then
  749.        LOCATION=$backupLoc
  750.        if [ -d "$LOCATION" ]; then
  751.                 find "$LOCATION" -name "*PiNet-Users-Backup.tar.gz" -ctime +"$DELETETIME" | xargs rm -rf
  752.                tar -zcvf "$LOCATION$currentDate--$currentTime--PiNet-Users-Backup.tar.gz" /home
  753.                exitstatus=$?
  754.                if [ $exitstatus = 0 ]; then
  755.                        logger -s "$currentDate $currentTime - Il backup dei file degli utenti ha avuto successo" 2>> /var/log/PiNet-backup.log
  756.                else
  757.                        logger -s "$currentDate $currentTime - Backup fallito con codice errore tar $exitstatus" 2>> /var/log/PiNet-backup.log
  758.                fi
  759.        else
  760.                logger -s "$currentDate $currentTime - Cartella di backup non disponibile!" 2>> /var/log/PiNet-backup.log
  761.        fi
  762. else
  763.        logger -s "$currentDate $currentTime - Nessuna posizione di backup specificata!" 2>> /var/log/PiNet-backup.log
  764. fi' >> /usr/local/bin/pinet-backup.sh
  765. chmod +x /usr/local/bin/pinet-backup.sh
  766. }
  767.  
  768. AddUsers(){
  769. #Add users to the system. Manually adds the user hash instead of using adduser
  770.     username=$(whiptail --inputbox $"Inserisci un nuovo nome utente" 8 78 $INIT --title $"Nome utente" 3>&1 1>&2 2>&3)
  771.     exitstatus=$?
  772.     if [ "$exitstatus" = "0" ]; then
  773.         password=$(whiptail --inputbox $"Inserire una nuova password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
  774.         exitstatus=$?
  775.         if [ "$exitstatus" = "0" ]; then
  776.             egrep "^$username" /etc/passwd >/dev/null
  777.             if [ $? -eq 0 ]; then
  778.                 whiptail --title "Errore" --msgbox $"Il nome utente esiste già!" 8 78
  779.             else
  780.                 pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
  781.                 useradd -m -s /bin/bash -p $pass $username
  782.             [ $? -eq 0 ] && echo $"$username è stato aggiunto al sistema!" || echo $"Impossibile aggiungere un utente!"
  783.             fixGroupsSingle $username
  784.             whiptail --title $"Livello di autorizzazione" --yesno $"Is $username un allievo o un insegnante? Gli insegnanti hanno molte più autorizzazioni, incluso l'accesso in scrittura a tutte le cartelle condivise, l'accesso agli insegnanti di Epoptes e la possibilità di eseguire il software di controllo PiNet." --yes-button $"Allievo" --no-button $"Insegnante" 8 78  ############
  785.             if [ ! $? -eq 0 ]; then
  786.                 AddUserToTeacher $username
  787.                 whiptail --title $"Successo" --msgbox $"Un nuovo utente insegnante è stato aggiunto al sistema con successo con il nome - $username" 8 78
  788.             else
  789.                 whiptail --title $"Successo" --msgbox $"Un nuovo utente studente è stato aggiunto al sistema con successo con il nome - $username" 8 78
  790.             fi
  791.             fi
  792.             whiptail --title $"Un altro utente" --yesno $"Vorresti aggiungere un altro utente?" 8 78
  793.             if [ $? -eq 0 ]; then
  794.                 AddUsers
  795.             fi
  796.         fi
  797.     fi
  798. }
  799.  
  800. RemoveUser(){
  801.     #Removes user from list
  802.     username=$(SelectUser "to remove.")
  803.     if [ ! $username = 1 ]; then
  804.         whiptail --title $"Sei sicuro?" --yesno $"Sei sicuro di voler eliminare $username e tutti i suoi file?" 8 78
  805.         if [ $? -eq 0 ]; then
  806.             userdel -rf $username
  807.             whiptail --title $"Operazione terminata con uccesso" --msgbox $"Utente rimosso con successo" 8 78
  808.         fi
  809.     fi
  810.     whiptail --title $"Un altro utente" --yesno $"Vorresti cancellare un altro utente?" 8 78
  811.     if [ $? -eq 0 ]; then
  812.         RemoveUser
  813.     fi
  814. }
  815.  
  816.  
  817. ChangeUserPassword(){
  818.     #Change a users password
  819.     username=$(SelectUser $"cambiare la password di.")
  820.     if [ ! $username = 1 ]; then
  821.         password=$(whiptail --inputbox $"Inserisci la nuova password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
  822.             if ! [ "$password" = "" ]; then
  823.                 echo -e "$password\n$password" | passwd $username
  824.                 whiptail --title $"Operazione terminata con uccesso" --msgbox $"Password cambiata con successo" 8 78
  825.             else
  826.                 whiptail --title $"Errore" --msgbox $"Password non valida" 8 78
  827.             fi
  828.     fi
  829.     whiptail --title $"Un altro utente" --yesno $"Volete cambiare la password di un altro utente?" 8 78
  830.         if [ $? -eq 0 ]; then
  831.             ChangeUserPassword
  832.         fi
  833.  
  834.  
  835. }
  836.  
  837.  
  838. RestoreBackup() {  #Currently incomplete
  839.     whiptail --title $"Seleziona il backup" --msgbox $"Si prega di selezionare un file di backup. Normalmente sono la data, l'ora seguita da Raspi-Users-Backup.tar.gz" 8 78
  840.  
  841. }
  842.  
  843. SelectUser(){
  844. #Using some BASH/Whiptail magic, builds a list of users, formats it perfectly and hads it to whiptail
  845. users=$(cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | sort | awk -F':' '{ print $1"\na"}')
  846. user=$(whiptail --title $"Utenti" --menu $"Seleziona un utente $1" 16 78 5 $users --noitem 3>&1 1>&2 2>&3)
  847. if [ $? -eq 0 ]; then
  848.     echo $user
  849. else
  850.     echo 1
  851. fi
  852. }
  853.  
  854. TroubleShooter(){
  855. #PiNet troubleshooter - Needs some more answers built in
  856.     whiptail --title $"Risoluzione dei problemi" --msgbox $"Benvenuti nello strumento di risoluzione dei problemi PiNet. Lo strumento per la risoluzione dei problemi risolve alcuni problemi che potresti riscontrare nella configurazione e offre consigli. ATTENZIONE - Questo strumento per la risoluzione dei problemi è sperimentale, sentiti libero di aprire rapporti sulle problematiche all'indirizzo $Repository/issues se hai ulteriori problemi." 16 78
  857.     whiptail --title $"Avvio" --yesno $"Sei arrivato fino a quando il tuo Raspberry Pi si avvia?" 8 78
  858.     if [ $? -eq 0 ]; then
  859.         whiptail --title $"Schermata di accesso" --yesno $"Sei arrivato fino alla visualizzazione della schermata di accesso?" 8 78
  860.         if [ $? -eq 0 ]; then
  861.             whiptail --title $"Schermata di accesso" --yesno $"Stai avendo problemi di accesso?" 8 78
  862.             if [ $? -eq 0 ]; then
  863.                 whiptail --title $"Accesso" --msgbox $"LDM (schermata di accesso) non gestisce le password errate molto bene. Se inserisci una serie errata di credenziali, si riavvia da solo. Non preoccuparti di questo.
  864.                 Se non sei sicuro della tua password, ricorda che puoi facilmente modificarla nel sottomenu Gestione utenti" 16 78
  865.             else
  866.                 whiptail --title $"USB drivers" --yesno $"La tua tastiera funziona?" 8 78
  867.                 if [ ! $? -eq 0 ]; then
  868.                     whiptail --title $"Kernel disallineato" --msgbox $"9/10 volte, questo significa che i tuoi kernel sono disallineati. Fondamentalmente c'è un kernel sulla scheda SD e mentre si avvia e si connette al server PiNet, carica i moduli aggiuntivi richiesti (per cose come USB) dal server. Se il server ha moduli compilati per un kernel più recente, sono disallineati e non funzionano. Per risolvere questo problema, assicurati di aver eseguito la versione più recente di PiNet, anche l'opzione update-sd e aggiorna la scheda SD per vedere se lo risolve. In caso contrario, un set di file di avvio patchato potrebbe non essere ancora disponibile (devono essere preparati a mano). La cosa migliore che puoi fare è lasciare un'e-mail di supporto e informarli che stai riscontrando problemi di tastiera / mouse. Visita http://pinet.org.uk/articles/support.html" 17 78
  869.                 else
  870.                     whiptail --title $"???" --msgbox $"Non ho riscontrato nessuno dei problemi in quest'area. Si prega di creare un ticket di supporto a $Repository/issues" 8 78
  871.                 fi
  872.             fi
  873.         else
  874.             resetAndCleanup
  875.             whiptail --title $"Riparato?" --yesno $"È riparato ora? Ho appena ripristinato alcuni dei servizi di rete." 8 78
  876.             if [ ! $? -eq 0 ]; then
  877.                 whiptail --title $"Connessione rifiutata" --yesno $"Stai ottenendo connessione rifiutata o errore di connessione scaduta?" 8 78
  878.                 if [ $? -eq 0 ]; then
  879.                     GetInternalIPAddress #Get the current main IP address
  880.                     whiptail --title $"Risoluzione dei problemi" --msgbox $"Questo è un errore comune, si verifica quando l'indirizzo IP del server sulla scheda SD non è corretto. Inserisci la scheda SD in un computer e apri il file cmdline.txt. Trova NBDRoot = (o NFSRoot =) e assicurati che l'indirizzo che lo segue sia $IP  Se non lo è, cambiala così com'è. Se è attualmente 1.1.1.1 il server non è stato in grado di ottenere il tuo indirizzo corrente quando ha creato la scheda SD. Se si tratta di un indirizzo diverso, il tuo server potrebbe essere stato assegnato un nuovo indirizzo IP. Sarebbe una buona idea assegnare un indirizzo IP statico al tuo server. Parla con il tuo tecnico di questo." 16 78
  881.                 else
  882.                     whiptail --title $"Rinuncia" --yesno $"Stai ricevendo un certo numero di errori di 'rinuncia'?" 8 78
  883.                     if [ $? -eq 0 ]; then
  884.                         whiptail --title $"Rinuncia" --msgbox $"Questo di solito significa che il Raspberry Pi non è fisicamente connesso alla rete, controllare che il cavo Ethernet sia collegato correttamente (il wifi non è supportato) e che sia collegato allo switch principale." 16 78
  885.                     else
  886.                         whiptail --title $"???" --msgbox $"Non ho riscontrato nessuno dei problemi presenti in quest'area. Si prega di creare un ticket di supporto a $Repository/issues" 8 78
  887.                     fi
  888.                 fi
  889.             fi
  890.         fi
  891.     else
  892.         whiptail --title $"Scherda SD" --yesno $"Hai problemi con il caricamento dei file sulla scheda SD?" 8 78
  893.         if [ $? -eq 0 ]; then
  894.             whiptail --title $"Partizioni" --yesno $"Hai problemi con la presenza di 2-3 partizioni sulla scheda SD?" 8 78
  895.             if [ $? -eq 0 ]; then
  896.                 whiptail --title $"Formattare le partizioni" --msgbox $"Quando si esegue il lampeggio di Raspbian o di un altro sistema operativo Raspberry Pi su schede SD, viene creata una serie di partizioni. PiNet ha bisogno solo di una singola partizione, la partizione di avvio. Di solito è una piccola partizione (50mb) formattata come fat32. Se si desidera formattare l'intera scheda SD (che, se si riscontrano problemi, si consiglia di farlo), fare riferimento al manuale sulla formattazione delle schede SD. " 16 78
  897.             else
  898.                 whiptail --title $"???" --msgbox $"Non ho riscontrato nessuno dei problemi presenti in quest'area. Si prega di creare un ticket di supporto a $Repository/issues" 8 78
  899.             fi
  900.         else
  901.             whiptail --title $"???" --msgbox $"Non ho riscontrato nessuno dei problemi presenti in quest'area. Si prega di creare un ticket di supporto a $Repository/issues" 8 78
  902.         fi
  903.     fi
  904. }
  905.  
  906.  
  907. DisplayUsers(){
  908. #Displays system users onto the terminal
  909. clear
  910. local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
  911. echo "-------------------"
  912. echo $"Utenti Linux attuali"
  913. echo "-------------------"
  914. cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  915.     do
  916.         echo "$user"
  917.     done
  918. echo "---------------"
  919. echo $"Utenti Linux attuali nel gruppo di insegnanti"
  920. echo "$TEACHER"
  921. echo "---------------"
  922. echo $"Premere invio per continuare"
  923. read
  924.  
  925. }
  926.  
  927. SetupSambaServer(){
  928. #Unused
  929.     apt-get install samba libpam-smbpass -y
  930.  
  931.  
  932. }
  933.  
  934. SetupSambaPi(){
  935. #Unused
  936.     mkdir /opt/ltsp/armhf/media/school-share
  937.     ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf FSTAB 'FSTAB_0="//server/School-Share  /media/school-share  cifs  guest,uid=1000,iocharset=utf8  0  0"'
  938.     echo "file:///media/school-share School-Share" >>/tmp/.gtk-bookmarks
  939.     CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
  940.     rm -rf /tmp/.gtk-bookmarks
  941.  
  942. }
  943.  
  944. AfterUpdate(){
  945. #Code run after a successful update on the BASH side, given that most update code is handled via Python
  946.     ConfigFileRead
  947.     whiptail --title $"Aggiornamento completato" --msgbox $"L'aggiornamento è riuscito. PiNet è ora aggiornato $ReleaseBranch." 8 78
  948.         whiptail --title $"Aggiorna tutto" --yesno $"Dopo un aggiornamento del software si consiglia di eseguire un aggiornamento del sistema. Questo aggiornerà tutti i pacchetti alla loro versione più recente e aggiungerà i nuovi aggiunti nell'aggiornamento, procedere?" 9 78
  949.         exitstatus=$?
  950.         if [ $exitstatus = 0 ]; then
  951.             exec /bin/bash pinet Update-All
  952.             exit
  953.         else
  954.             exec /bin/bash pinet
  955.             exit
  956.         fi
  957. }
  958.  
  959.  
  960. Updater(){
  961. #Main updater, most of it is handed by updatePiNet on the Python side or by AfterUpdate on BASH side
  962.     $p updatePiNet
  963.     exitstatus=$(gp)
  964.     if [ $exitstatus = 0 ] && [ "$1" = "IgnoreAfterUpdate" ]; then
  965.         if [ ! "$2" = "NoRestart" ]; then
  966.             whiptail --title $"Riavvio di PiNet" --msgbox $"Riavvio di PiNet per garantire che stia eseguendo la versione corretta." 8 78
  967.             exec /bin/bash pinet
  968.             exit
  969.         fi
  970.  
  971.     else
  972.         if [ $exitstatus = 0 ]; then
  973.             AfterUpdate
  974.         else
  975.             whiptail --title $"Aggiornamento non riuscito" --msgbox $"L'aggiornamento automatico non è riuscito. Questo di solito significa che non sei connesso a Internet" 8 78
  976.             exec /bin/bash pinet
  977.         fi
  978.     fi
  979.  
  980. }
  981.  
  982. VerifyPythonPackages(){
  983. #Verify needed Python packages are installed. If not installed, install them.
  984.     $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser  )
  985.     $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests  )
  986.     $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces  )
  987. }
  988.  
  989.  
  990. CheckReleases(){
  991. #Checks if there is a new software release. Mainly uses CheckUpdate on Python side. Also runs sendStats.
  992.     $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser  )
  993.     $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests  )
  994.     $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces  )
  995.     $p sendStats
  996.     $p CheckUpdate $version
  997.     exitstatus=$(gp)
  998.     #echo $exitstatus
  999.     if [ $exitstatus = 1 ]; then
  1000.         AfterUpdate
  1001.     fi
  1002.  
  1003. }
  1004.  
  1005. checkInstallLoc(){
  1006. #Checks PiNet is installed in the correct place (/usr/local/bin/pinet)
  1007. InstallLoc="${BASH_SOURCE[0]}"
  1008. if [ ! "$InstallLoc" = "/usr/local/bin/pinet" ]; then
  1009.     mv $InstallLoc /usr/local/bin/pinet
  1010.     exec /bin/bash pinet
  1011. fi
  1012. }
  1013.  
  1014. AddSambaUser(){
  1015. #Unused
  1016.     whiptail --title "Samaba" --msgbox "Samba utilizza un sistema utente separato rispetto a Linux. Può però condividere utenti, ma per aggiungere un nuovo utente a samba è necessario modificare la password. Puoi cambiarlo esattamente come prima e devi farlo solo una volta." 10 78
  1017.     whiptail --title "Samaba" --msgbox "Gli utenti di Samba potranno modificare la cartella di condivisione della scuola disponibile su tutti i Raspberry Pis. Non è consigliabile aggiungere studenti a questo." 8 78
  1018.     username=$(whiptail --inputbox "Inserisci il nome utente da aggiungere a samba" 8 78 $INIT --title "Nome utente" 3>&1 1>&2 2>&3)
  1019.     if [ $? -eq 0 ]; then
  1020.         if ! [ "$username" = "" ]; then
  1021.             egrep "^$username" /etc/passwd >/dev/null
  1022.             if [ $? -eq 0 ]; then
  1023.                 smbpasswd -a "$username"
  1024.                 password=$(whiptail --inputbox "Si prega di inserire nuovamente la password, deve essere corretta!" 8 78 $INIT --title "Password" 3>&1 1>&2 2>&3)
  1025.                 if ! [ "$password" = "" ]; then
  1026.                     echo -e "$password\n$password" | passwd $username
  1027.                     whiptail --title "Operazione completata con successo" --msgbox "Utente aggiunto a Samba" 8 78
  1028.                 else
  1029.                     whiptail --title "Errore" --msgbox "Password non valida" 8 78
  1030.                 fi
  1031.             else
  1032.                 whiptail --title "Errore" --msgbox "Il nome utente non esiste!" 8 78
  1033.             fi
  1034.         else
  1035.             whiptail --title "Errore" --msgbox "Il nome utente non è valido" 8 78
  1036.         fi
  1037.         whiptail --title "Un altro utente?" --yesno "Vorresti aggiungere un altro utente Samba?" 8 78
  1038.         if [ $? -eq 0 ]; then
  1039.             AddSambaUser
  1040.         fi
  1041.     fi
  1042.  
  1043. }
  1044.  
  1045.  
  1046. UpdateAll(){
  1047. #Does a full system update on the server and on the Raspberry Pi OS
  1048.     checkInternet
  1049.     if [ $? -eq 0 ]; then
  1050.         apt-get update
  1051.         apt-get upgrade -y
  1052.         ltsp-chroot --arch armhf apt-get update
  1053.         ltsp-chroot --arch armhf apt-get upgrade -y
  1054.         AddSoftware
  1055.         NBDRun
  1056.         whiptail --title $"Aggiornamento completato" --msgbox $"Aggiornamenti completati" 7 78
  1057.     else
  1058.         whiptail --title $"Erroer" --msgbox $"Nessuna connesione a internet, impossibile aggiornare il software..." 8 78
  1059.     fi
  1060.  
  1061. }
  1062.  
  1063. SetupSharedStandalone() {
  1064.     #Sets up shared folders. To use shared folders, extra line must be added to lts.conf file for Raspberry Pi
  1065.     mkdir /home/shared > /dev/null 2>&1
  1066.     sudo chown :teacher /home/shared
  1067.     sudo chmod 775 /home/shared
  1068.     ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf LOCAL_APPS_EXTRAMOUNTS 'LOCAL_APPS_EXTRAMOUNTS=/home/shared'
  1069.     DuplicateLTSConf
  1070.  
  1071. }
  1072.  
  1073. SetupShared(){
  1074.     #User frontend for SetupSharedStandalone() for when it is not run directly
  1075.     echo $"Impostazione delle cartelle condivise"
  1076.     whiptail --title $"Impostazione delle cartelle condivise" --msgbox $"Poiché è la prima volta che si utilizzano le cartelle condivise, è necessario configurarle. Questo potrebbe richiedere alcuni minuti." 8 78
  1077.     SetupSharedStandalone
  1078.     NBDRun
  1079.  
  1080. }
  1081.  
  1082. CreateSharedFolder(){
  1083.     #Create a new shared folder on the Raspberry Pis
  1084.     mkdir /home/shared/$1
  1085.     if [ ! $? -eq 0 ]; then
  1086.         whiptail --title $"Errore" --msgbox $"La cartella condivisa in /home/shared/$1 non è stata creata. Potrebbe già esistere" 8 78
  1087.         return 1
  1088.     else
  1089.         chown root: /home/shared/$1
  1090.         chmod 0700 /home/shared/$1
  1091.         return 0
  1092.     fi
  1093. }
  1094.  
  1095. RebuildGTKBookmarks(){
  1096. #Shared folders use GTK bookmarks to appear on the left hand side of the file manager, this rebuilds them for each edit (for example, when you create a new shared folder)
  1097. FILES=/home/shared/*
  1098.     for f in $FILES
  1099.         do
  1100.         local FolderName=$(basename "$f")
  1101.         echo "file://$f $FolderName" >> /tmp/.gtk-bookmarks
  1102.     done
  1103.     CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
  1104.     rm -rf /tmp/.gtk-bookmarks
  1105. }
  1106.  
  1107. SelectSharedFolder(){
  1108. #Select a shared folder using some BASH/Whiptail magic
  1109. SFs=$(ls -1 /home/shared | awk -F':' '{ print $1"\na"}')
  1110. SF=$(whiptail --title "Cartelle condivise" --menu "Seleziona una cartella condivisa $1" 16 78 5 $SFs --noitem 3>&1 1>&2 2>&3)
  1111. if [ $? -eq 0 ]; then
  1112.     echo $SF
  1113. else
  1114.     echo 1
  1115. fi
  1116. }
  1117.  
  1118. CreateSharedFoldersDialog(){
  1119.     #Main dialog for creating new shared folders. Checks if they are installed, if so, displays all current shared folders, then asks for name, then adds it as a bindfs mount for the Pis
  1120.     whiptail --title $"Crea una cartella condivisa" --yesno $"Le cartelle condivise sono accessibili su tutti i Raspberry Pi e appaiono a sinistra nel file manager. Vorresti aggiungerne una?" 8 78
  1121.     if [ $? -eq 0 ]; then
  1122.         if [ ! -d /home/shared ]; then
  1123.             SetupShared
  1124.         fi
  1125.         CheckSharedFolderIntegrity
  1126.         clear
  1127.         echo ""
  1128.         echo "----------------------"
  1129.         echo $"Cartelle condivise correnti"
  1130.         echo "----------------------"
  1131.         echo ""
  1132.         ls /home/shared -1
  1133.         echo ""
  1134.         echo $"Premere invio per continuare"
  1135.         read
  1136.         FolderName=$(whiptail --inputbox $"Inserisci il nome della nuova cartella condivisa" 8 78 --title $"Cartella condivisa" 3>&1 1>&2 2>&3)
  1137.         if [ $? -eq 0 ]; then
  1138.             if ! [ "$FolderName" = "" ]; then
  1139.                 CreateSharedFolder "$FolderName"
  1140.                 if [ $? -eq 0 ]; then
  1141.                     whiptail --title $"Permesso di scrittura per alunni" --yesno $"Gli studenti devono avere accesso in lettura / scrittura a questa cartella condivisa o semplicemente accedere in lettura? (Solo lettura predefinita)" --yes-button $"Lettura" --no-button $"Lettura/Scrittura" 8 78
  1142.                     if [ ! $? -eq 0 ]; then
  1143.                         ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=pupil /home/shared/$FolderName /home/shared/$FolderName"
  1144.                     else
  1145.                         ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=teacher /home/shared/$FolderName /home/shared/$FolderName"
  1146.                     fi
  1147.                     RebuildGTKBookmarks
  1148.                     service bindfs-mount restart
  1149.                     whiptail --title $"Completato" --msgbox $"La cartella condivisa in /home/shared/$FolderName è stata create! Per accederci, riavvia il tuo Raspberry Pis." 8 78
  1150.  
  1151.                 fi
  1152.             else
  1153.                 whiptail --title $"Errore" --msgbox $"Il nome della cartella non può essere lasciato vuoto!" 8 78
  1154.             fi
  1155.         fi
  1156.     fi
  1157.  
  1158.  
  1159. }
  1160.  
  1161. RemoveSharedFolder(){
  1162.     #Used to remove shared folders. Involves removing the GTK bookmark, then removing the bindfs mount. Finally the actual folder is deleted
  1163.     whiptail --title $"Attenzione!" --yesno $"Avvertimento! Se si elimina una cartella condivisa, è necessario riavviare tutti i Raspberry Pis attualmente accessi in quanto potrebbero confondersi. Vuoi continuare?" 8 78
  1164.     if [ $? -eq 0 ]; then
  1165.         toDelete=$(SelectSharedFolder "per eliminare.")
  1166.         if [ ! $toDelete = 1 ]; then
  1167.             whiptail --title $"Sei sicuro?" --yesno $"Sei sicuro di voler eliminare definitivamente /home/shared/$toDelete ?" 8 78
  1168.             if [ $? -eq 0 ]; then
  1169.                 RebuildGTKBookmarks
  1170.                 ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount $"/home/shared/$toDelete" ""
  1171.                 if [ $? -eq 0 ]; then
  1172.                     service bindfs-mount restart
  1173.                     rm -rf "/home/shared/$toDelete"
  1174.                     whiptail --title $"Successo" --msgbox $"La cartella in /home/shared/$toDelete è stata correttamente eliminata." 8 78
  1175.                 else
  1176.                     service bindfs-mount restart
  1177.                     whiptail --title $"Errore" --msgbox $"Si è verificato un problema durante la rimozione della montatura /usr/local/bin/bindfs-mount... Per favore riprova." 8 78
  1178.                 fi
  1179.             fi
  1180.         fi
  1181.     fi
  1182. }
  1183.  
  1184. SharedFolderPerm(){
  1185. #Used to change permission level of a shared folder. Perhaps switch from pupil read only to pupil read/write
  1186.  
  1187.     if [ "$1" = "" ]; then
  1188.         FolderName=$(SelectSharedFolder "da modificare")
  1189.     else
  1190.         FolderName=$1
  1191.     fi
  1192.     if [ ! $FolderName = 1 ]; then
  1193.         whiptail --title $"Permesso di scrittura per alunni" --yesno $"Deve $ FolderName essere in lettura/scrittura per gli studenti o solo in lettura?" --yes-button $"Lettura" --no-button $"Lettura/Scrittura" 8 78
  1194.             if [ ! $? -eq 0 ]; then
  1195.                 ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=pupil /home/shared/$FolderName /home/shared/$FolderName"
  1196.                 service bindfs-mount restart
  1197.                 whiptail --title $"Completato" --msgbox $"Modifica delle autorizzazioni completata, gli studenti ora hanno accesso in lettura/scrittura in /home/shared/$FolderName" 8 78
  1198.             else
  1199.                 ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=teacher /home/shared/$FolderName /home/shared/$FolderName"
  1200.                 service bindfs-mount restart
  1201.                 whiptail --title $"Completato" --msgbox $"Modifica delle autorizzazioni completata, ora gli studenti hanno accesso solo in lettura in /home/shared/$FolderName" 8 78
  1202.             fi
  1203.     fi
  1204. }
  1205.  
  1206. DisplaySharedFolders(){
  1207. #List all the shared folders in /home/shared
  1208.     clear
  1209.     echo ""
  1210.     echo "----------------------"
  1211.     echo $"Cartelle condivise correnti"
  1212.     echo "----------------------"
  1213.     echo ""
  1214.     ls /home/shared -1
  1215.     echo ""
  1216.     echo $"Permere invio per continuare"
  1217.     read
  1218. }
  1219.  
  1220.  
  1221. CheckSharedFolderIntegrity(){
  1222.     #Checks the permissions and everything for shared folders lines up with that that is on the Raspberry Pis. If not, it will ask you to clarify what it should be
  1223.     if [ ! -f /etc/init.d/bindfs-mount ]; then
  1224.         service stop bindfs-mount > /dev/null 2>&1
  1225.         addSharedFolderScript
  1226.     fi
  1227.     touch /usr/local/bin/bindfs-mount
  1228.     inFile=$(grep "bindfs" /usr/local/bin/bindfs-mount  | wc -l)
  1229.     inFolder=$(ls -1 /home/shared | wc -l)
  1230.     if [ ! "$inFile" = "$inFolder" ]; then
  1231.         whiptail --title $"Autorizzazioni di cartella condivisa non valide" --msgbox $"Avviso: le autorizzazioni della cartella condivisa non sono valide. Ciò potrebbe essere dovuto al fatto che hai importato cartelle condivise da un sistema precedente. È necessario selezionare nuovamente il livello di autorizzazione corretto per ogni cartella ora." 9 78
  1232.         for i in 1 2 3 4 5 6 7 8 9 10
  1233.         do
  1234.             ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/" ""
  1235.         done
  1236.         sed -i '/^[[:blank:]]*$/d' /usr/local/bin/bindfs-mount
  1237.  
  1238.         for f in $(ls -1 "/home/shared/")
  1239.         do
  1240.             SharedFolderPerm $f
  1241.             chown :root "/home/shared/$f"
  1242.         done
  1243.         SetupShared
  1244.     fi
  1245.  
  1246. }
  1247.  
  1248. addSharedFolderScript() {
  1249. #Adds the bindfs script which auto mounts the correct bind points and removes them when required (using stop)
  1250.  
  1251. rm -rf /etc/init.d/bindfs-mount
  1252.  
  1253. cat <<EOF1 >> /etc/init.d/bindfs-mount
  1254. #!/bin/bash
  1255. #Version=01
  1256. ### BEGIN INIT INFO
  1257. # Provides:             Bindfs-mounts
  1258. # Required-Start:       \$syslog \$remote_fs
  1259. # Required-Stop:        \$syslog \$remote_fs
  1260. # Should-Start:         \$local_fs
  1261. # Should-Stop:          \$local_fs
  1262. # Default-Start:        2 3 4 5
  1263. # Default-Stop:         0 1 6
  1264. # Short-Description:    Bindfs mounts for PiNet
  1265. # Description:          The shared folder Bindfs mounts for PiNet
  1266. ### END INIT INFO
  1267.  
  1268. start() {
  1269. bash /usr/local/bin/bindfs-mount
  1270. }
  1271.  
  1272. stop() {
  1273. for i in \$(ls -1 /home/shared)
  1274. do
  1275.         umount -l /home/shared/\$i > /dev/null 2>&1
  1276. done
  1277. }
  1278.  
  1279.  
  1280. restart() {
  1281.     stop
  1282.     start
  1283. }
  1284.  
  1285. case "\$1" in
  1286.     start)
  1287.         start
  1288.         ;;
  1289.     stop)
  1290.         stop
  1291.         ;;
  1292.     restart)
  1293.         restart
  1294.         ;;
  1295.     *)
  1296.         echo "Usage: {start|stop|restart}"
  1297.         exit 1
  1298.         ;;
  1299. esac
  1300. exit
  1301.  
  1302. EOF1
  1303. chmod 755 /etc/init.d/bindfs-mount
  1304. update-rc.d bindfs-mount defaults
  1305. touch /usr/local/bin/bindfs-mount
  1306. service bindfs-mount restart > /dev/null 2>&1
  1307.  
  1308. }
  1309.  
  1310.  
  1311. CheckOS(){
  1312.     #Check the correct operating system is being used. Ubuntu is recommended and Debian is no longer supported.
  1313.     OS=$(lsb_release -si)
  1314.     if [ ! $OS == "Ubuntu" ]; then
  1315.         if [ $OS == "Debian" ]; then
  1316.             whiptail --title $"ATTENZIONE!!" --msgbox $"Debian non è più ufficialmente supportato da PiNet! Si prega di utilizzare Ubuntu 14.04 o successivo.La versione può variare con Debian e PiNet..." 8 78
  1317.         else
  1318.             whiptail --title $"ATTENZIONE!!" --msgbox $"Non riconosco questo sistema operativo. Si prega di utilizzare Ubuntu 14.04 o successivo.La versione può variare notevolmente con altre distribuzioni e non verrà fornito alcun supporto." 8 78
  1319.         fi
  1320.     fi
  1321. }
  1322.  
  1323. CheckTerminalSize(){
  1324.     #Resizes the terminal to the correct size for the menus
  1325.         eval `resize`
  1326.         if [ "$LINES" -le "28" ]; then
  1327.                 a='\e[8;28;'
  1328.                 b='t'
  1329.                 printf "$a$COLUMNS$b"
  1330.         fi
  1331.         eval `resize`
  1332.         if [ "$COLUMNS" -le "90" ]; then
  1333.                 a='\e[8;'
  1334.                 b=';90t'
  1335.                 printf "$a$LINES$b"
  1336.         fi
  1337.         sleep 0.5 # Time to allow the terminal to resize.
  1338. }
  1339.  
  1340. listStatus(){
  1341.     #Displays a status of the PiNet. Includes a status of all logged in users
  1342.  
  1343. while true; do
  1344. dpkg-query -s epoptes > /dev/null 2>&1
  1345. if [ $? -eq 0 ]; then
  1346.     local EPOPTES="True"
  1347. else
  1348.     local EPOPTES="False"
  1349. fi
  1350. local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
  1351. local RAM=$(top -bn1 | awk '/Mem/ { mem =  $5 / $3 * 100 }; END { print mem }')
  1352. #local CPU=$(bc <<< "scale=0; $(top -bn 1 | awk '{print $9}' | tail -n +8 | awk '{s+=$1} END {print s}') / $(grep -c ^processor /proc/cpuinfo)")
  1353. clear
  1354.  
  1355. GetInternalIPAddress
  1356. echo "           Stato del sistema PiNet"
  1357. echo "---------------------------------------------------"
  1358. echo "Versione corrente                      - $version"
  1359. echo "Indirizzo IP del server                      - $IP"
  1360. echo "---------------------------------------------------"
  1361. echo "È in esecuzione la versione $version da     - $(stat -c %y /usr/local/bin/pinet | cut -d ' ' -f1)"
  1362. echo "Ultima modifica della cartella Piboot             - $(stat -c %y /home/$SUDO_USER/PiBoot | cut -d ' ' -f1)"
  1363. echo "Ultimo aggiornamento a livello di sistema (aggiornamento-tutto)   - $(stat -c %y /var/lib/apt/periodic/update-success-stamp | cut -d ' ' -f1)"
  1364. echo "----------------"
  1365. echo "Uso del disco rigido (potrebbe essere inaccurato)"
  1366. echo "----------------"
  1367. echo "Spazio totale                            - $(df -h | sed -n 2p | awk '{print $2}')"
  1368. echo "Spazio utilizzato                             - $(df -h | sed -n 2p | awk '{print $3}')"
  1369. echo "Spazio libero                             - $(df -h | sed -n 2p | awk '{print $4}')"
  1370. echo "-----"
  1371. echo "Altro"
  1372. echo "-----"
  1373. echo "Utilizzo della CPU                              - $CPU%"
  1374. #echo "RAM usage                              - $(free -tom | grep 'Total:' | awk '{print $4}')MB / $(free -tom | grep 'Total:' | awk '{print $2}')MB"
  1375. echo "Epoptes installato                    - $EPOPTES"
  1376. echo "Insegnanti                       - $TEACHER"
  1377. echo "-----------------------"
  1378. echo "Attuali utenti attivi"
  1379. echo "-----------------------"
  1380. netstat -tnpa | grep ESTABLISHED.*sshd | awk '{ print $5 " - " $8 } '
  1381. echo ""
  1382. echo "Peremere invio per ritornare al menu principale"
  1383. read -t 2
  1384. if [ $? -eq 0 ]; then
  1385.    break
  1386. fi
  1387. done
  1388.  
  1389. }
  1390.  
  1391. CheckDesktopShortcut(){
  1392.     #Checks if the PiNet desktop shortcut exists. If not it adds it
  1393. checkInternet
  1394. if [ $? -eq 0 ]; then
  1395.     AddDesktopShortcutToUser $SUDO_USER
  1396.  
  1397.     if [ ! -f "/usr/share/pixmaps/pinet-icon.png" ] || [ ! -f "/opt/ltsp/armhf/usr/share/pixmaps/pinet-icon.png" ]; then
  1398.         wget $RawRepository/$ReleaseBranch/images/pinet-icon.png -O /tmp/pinet-icon.png
  1399.         cp /tmp/pinet-icon.png /usr/share/pixmaps/pinet-icon.png
  1400.         cp /tmp/pinet-icon.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-icon.png
  1401.         UpdateConfig NBDBuildNeeded true
  1402.     fi
  1403.  
  1404. fi
  1405. }
  1406.  
  1407. AddDesktopShortcutToUser() {
  1408. #Adds desltop shortcut for PiNet if needed
  1409.  
  1410. if [ ! -f "/home/$1/Desktop/pinet.desktop" ]; then
  1411.     cat <<EOF1 >> /home/$1/Desktop/pinet.desktop
  1412. [Desktop Entry]
  1413. Version=3.0
  1414. Name=PiNet
  1415. Comment=PiNet Control Panel
  1416. Exec=sudo bash pinet
  1417. Icon=/usr/share/pixmaps/pinet-icon.png
  1418. Terminal=true
  1419. Type=Application
  1420. Categories=Utility;Application;
  1421. EOF1
  1422.     chmod +x "/home/$1/Desktop/pinet.desktop"
  1423.     chown "$1" "/home/$1/Desktop/pinet.desktop"
  1424. fi
  1425.  
  1426. if [ ! -f "/opt/ltsp/armhf/usr/local/bin/pinet" ]; then
  1427.     echo "ltsp-remoteapps gnome-terminal -x sh -c 'sudo bash pinet'" > /opt/ltsp/armhf/usr/local/bin/pinet
  1428.     UpdateConfig NBDBuildNeeded true
  1429. fi
  1430.  
  1431. }
  1432.  
  1433.  
  1434. teacherSudoCheck() {
  1435. #Checks if teachers have auto sudo (as in, no password asked each time). If not, it enables it (but requires a log out and in again to apply)
  1436. if [ ! -f "/etc/sudoers.d/01staff" ]; then
  1437.     rm -f /etc/sudoers.d/01staff
  1438.     touch /etc/sudoers.d/01staff
  1439.     chmod 440 /etc/sudoers.d/01staff
  1440.     echo '%teacher ALL=NOPASSWD: ALL' >> /etc/sudoers.d/01staff
  1441. fi
  1442. }
  1443.  
  1444.  
  1445. resetAndCleanup(){
  1446. #Resets the NBD server. Can sometimes help fix weird issues.
  1447. service nfs-kernel-server restart
  1448. sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure nbd-server
  1449. sudo service nbd-server restart
  1450.  
  1451. }
  1452.  
  1453. AddPasswordReset(){
  1454. #Adds the password reset utility to the desktop of new users
  1455.     wget $RawRepository/$ReleaseBranch/Scripts/changePassword.sh -O /tmp/changePassword.sh
  1456.     wget $RawRepository/$ReleaseBranch/images/pinet-change-password.png -O /tmp/pinet-change-password.png
  1457.     cp /tmp/pinet-change-password.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-change-password.png
  1458.     cp /tmp/changePassword.sh /usr/local/bin/changePassword.sh
  1459.     cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  1460.     do
  1461.         AddPasswordResetDesktop $user
  1462.     done
  1463.  
  1464.     if [ ! -f "/etc/skel/Desktop/pinet-password.desktop" ]; then
  1465. cat <<EOF1 >> /etc/skel/Desktop/pinet-password.desktop
  1466. [Desktop Entry]
  1467. Version=1.1
  1468. Name=Change Password
  1469. Comment=Change password
  1470. Exec=ltsp-remoteapps bash changePassword.sh
  1471. Icon=/usr/share/pixmaps/pinet-change-password.png
  1472. Terminal=false
  1473. Type=Application
  1474. Categories=Utility;Application;
  1475.  
  1476. EOF1
  1477. fi
  1478.  
  1479. }
  1480.  
  1481. AddPasswordResetDesktop(){
  1482. #Adds the password reset utility to the desktop of existing users with help of AddPasswordReset
  1483. if [ ! -f "/home/$1/Desktop/pinet-password.desktop" ]; then
  1484. cat <<EOF1 >> /home/$1/Desktop/pinet-password.desktop
  1485. [Desktop Entry]
  1486. Version=1.1
  1487. Name=Change Password
  1488. Comment=Change password
  1489. Exec=ltsp-remoteapps bash changePassword.sh
  1490. Icon=/usr/share/pixmaps/pinet-change-password.png
  1491. Terminal=false
  1492. Type=Application
  1493. Categories=Utility;Application;
  1494.  
  1495. EOF1
  1496. chown "$1" "/home/$1/Desktop/pinet-password.desktop"
  1497. fi
  1498.  
  1499. }
  1500.  
  1501. AddScreenshot(){
  1502. #Adds the screenshot utility to the desktop of new users
  1503.     wget $RawRepository/$ReleaseBranch/Scripts/pinet-screenshot.sh -O /tmp/pinet-screenshot.sh
  1504.     wget $RawRepository/$ReleaseBranch/images/pinet-screenshot.png -O /tmp/pinet-screenshot.png
  1505.     cp /tmp/pinet-screenshot.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-screenshot.png
  1506.     cp /tmp/pinet-screenshot.sh /opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh
  1507.     chmod +x /opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh
  1508.     cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  1509.     do
  1510.         AddScreenshotDesktop $user
  1511.     done
  1512.  
  1513.     if [ ! -f "/etc/skel/Desktop/pinet-screenshot.desktop" ]; then
  1514. cat <<EOF1 >> /etc/skel/Desktop/pinet-screenshot.desktop
  1515. [Desktop Entry]
  1516. Version=1.0
  1517. Name=Take Screenshot
  1518. Comment=Take Screenshot
  1519. Exec=bash pinet-screenshot.sh
  1520. Icon=/usr/share/pixmaps/pinet-screenshot.png
  1521. Terminal=false
  1522. Type=Application
  1523. Categories=Utility;Application;
  1524.  
  1525. EOF1
  1526. fi
  1527.  
  1528. }
  1529.  
  1530. AddScreenshotDesktop(){
  1531. #Adds the screenshot utility to the desktop of existing users with help of AddScreenshot
  1532. if [ ! -f "/home/$1/Desktop/pinet-screenshot.desktop" ]; then
  1533. cat <<EOF1 >> /home/$1/Desktop/pinet-screenshot.desktop
  1534. [Desktop Entry]
  1535. Version=1.0
  1536. Name=Take Screenshot
  1537. Comment=Take Screenshot
  1538. Exec=bash pinet-screenshot.sh
  1539. Icon=/usr/share/pixmaps/pinet-screenshot.png
  1540. Terminal=false
  1541. Type=Application
  1542. Categories=Utility;Application;
  1543.  
  1544. EOF1
  1545. chown "$1" "/home/$1/Desktop/pinet-screenshot.desktop"
  1546. fi
  1547.  
  1548.  
  1549. }
  1550.  
  1551. CreateMoveBackup() {
  1552. #Create a full backup of all users and groups data for moving to a clean system
  1553. whiptail --title $"Attenzione" --yesno $"Questo processo è progettato solo per spostare i file utente su un'installazione Ubuntu completamente nuova in cui PiNet non è installato. Assicurati di verificare che tutti i dati utente siano stati importati correttamente sul nuovo server PiNet. Visita http://PiNet.org.uk/manage-users/migration.html per le istruzioni complete. Sei sicuro di voler procedere?" 11 78
  1554. if [ $? -eq 0 ]; then
  1555.     mkdir /root/move/
  1556.     export UGIDLIMIT=1000
  1557.     awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
  1558.     awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
  1559.     awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
  1560.     cp /etc/gshadow /root/move/gshadow.mig
  1561.     rm /home/$SUDO_USER/toMove.tar.gz # Remove previous toMove.tar.gz file in case is already one there.
  1562.     tar -zcvpf /root/move/home.tar.gz /home
  1563.     tar -zcvpf /home/$SUDO_USER/toMove.tar.gz /root/move
  1564.     chown $SUDO_USER /home/$SUDO_USER/toMove.tar.gz
  1565.     rm -rf /root/move/
  1566.     whiptail --title $"Completato" --msgbox $"Il processo è ora completo. Un file zippato chiamato toMove.tar.gz è stato salvato in /home/$SUDO_USER/toMove.tar.gz. Si prega di copiare questo in /home/youruser/toMove.tar.gz nel nuovo server (via pendrive per esempio) quindi eseguire PiNet e selezionare Sì quando viene chiesto di importare gli utenti." 11 78
  1567. fi
  1568. }
  1569.  
  1570. CheckRestoreMoveBackup(){
  1571. #Checks if LTSP is already installed as importing user data with a server already running PiNet can cause issues..
  1572. if [ -f /home/$SUDO_USER/toMove.tar.gz ]; then
  1573.     if [ -d /opt/ltsp ]; then
  1574.         whiptail --title $"ATTENZIONE!!" --yesno $"PiNet potrebbe essere già installato! Si consiglia vivamente di non importare utenti da un'installazione di PiNet precedente. Sei stato avvertito! Vorresti importarli comunque?" 10 78
  1575.         if [ $? -eq 0 ]; then
  1576.             RestoreMoveBackup
  1577.         fi
  1578.     else
  1579.         RestoreMoveBackup
  1580.     fi
  1581.  
  1582. else
  1583.  
  1584.     whiptail --title $"Errore" --msgbox $"Il file zippato dei dati utente non può essere trovato in /home/$SUDO_USER/toMove.tar.gz." 8 78
  1585. fi
  1586. }
  1587.  
  1588. RestoreMoveBackup() {
  1589. #Restore full backup of all users and group data
  1590. whiptail --title $"Attenzione" --yesno $"L'importazione dovrebbe essere eseguita solo su un'installazione Ubuntu completamente nuova. PiNet o Raspi-LTSP non devono essere già installati. Assicurati di controllare manualmente che tutti i file siano stati copiati correttamente. Vuoi procedere?" 10 78
  1591. if [ $? -eq 0 ]; then
  1592.     if [ -f /home/$SUDO_USER/toMove.tar.gz ]; then
  1593.         $p importMigration "/home/$SUDO_USER/toMove.tar.gz"
  1594.         UpdateConfig "ImportedUsers" "true"
  1595.         return 0
  1596.     else
  1597.         whiptail --title $"Importazione fallita" --yesno $"L'importazione degli utenti è fallita, /home/$SUDO_USER/toMove.tar.gz non è stato trovato? Sei sicuro di averlo copiato in quella posizione? Riprovare?" 9 78
  1598.         if [ $? -eq 0 ]; then
  1599.             RestoreMoveBackup
  1600.         else
  1601.             exit
  1602.         fi
  1603.     fi
  1604. else
  1605.     exit
  1606. fi
  1607.  
  1608. }
  1609.  
  1610. InstallScratchGPIO(){
  1611. #Installs ScratchGPIO 5 by manually pushing an install script to each user
  1612.     whiptail --title $"Nota" --msgbox $"ScratchGPIO non può essere installato direttamente, ogni utente deve installarlo. Un collegamento sul desktop è stato aggiunto a ogni account utente chiamato \"Install ScratchGPIO\". Chiedi a ogni studente di eseguirlo la prima volta che desidera utilizzare il software." 10 78
  1613.     rm -rf /tmp/isgh7.sh
  1614.     rm -rf /opt/ltsp/armhf/usr/local/bin/isgh5.sh
  1615.     rm -rf /opt/ltsp/armhf/usr/local/bin/scratchSudo.sh
  1616.     rm -rf /opt/ltsp/armhf/usr/local/bin/isgh7.sh
  1617.     wget http://bit.ly/1wxrqdp -O /tmp/isgh7.sh
  1618.     cp /tmp/isgh7.sh  /opt/ltsp/armhf/usr/local/bin/isgh7.sh
  1619.     echo "bash /usr/local/bin/isgh7.sh \$SUDO_USER" > /opt/ltsp/armhf/usr/local/bin/scratchSudo.sh
  1620.     cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
  1621.     do
  1622.     if [ ! -f "/home/$user/Desktop/Install-scratchGPIO.desktop" ]; then
  1623. cat <<EOF1 > /home/$user/Desktop/Install-scratchGPIO.desktop
  1624. [Desktop Entry]
  1625. Version=1.0
  1626. Name=Install ScratchGPIO
  1627. Comment=Install ScratchGPIO
  1628. Exec=sudo bash /usr/local/bin/scratchSudo.sh
  1629. Icon=scratch
  1630. Terminal=true
  1631. Type=Application
  1632. Categories=Utility;Application;
  1633.  
  1634. EOF1
  1635. chown "$user" "/home/$user/Desktop/Install-scratchGPIO.desktop"
  1636. fi
  1637.     done
  1638.  
  1639. if [ ! -f " /etc/skel/Desktop/Install-scratchGPIO.desktop" ]; then
  1640. cat <<EOF1 >  /etc/skel/Desktop/Install-scratchGPIO.desktop
  1641. [Desktop Entry]
  1642. Version=1.0
  1643. Name=Install ScratchGPIO
  1644. Comment=Install ScratchGPIO
  1645. Exec=sudo bash /usr/local/bin/scratchSudo.sh
  1646. Icon=scratch
  1647. Terminal=true
  1648. Type=Application
  1649. Categories=Utility;Application;
  1650. EOF1
  1651. fi
  1652.  
  1653.  
  1654.  
  1655. }
  1656.  
  1657. FirstTimeImportUsers(){
  1658. #Asks user if they want to import users on the first startup of PiNet
  1659. if [ ! -f /home/$SUDO_USER/Desktop/lxterminal.desktop ]; then
  1660.     whiptail --title $"Importazione degli utenti"  --defaultno --yesno $"Vorresti importare dati utente da un precedente server PiNet (o Raspi-LTSP)? Questo può essere fatto solo ora durante l'installazione. In caso di dubbio, selezionare no." 8 78
  1661.     if [ $? -eq 0 ]; then
  1662.         RestoreMoveBackup
  1663.     fi
  1664. fi
  1665. }
  1666.  
  1667. DisableI2C_SPI(){
  1668. #Disables both I2C and SPI to allow the pins to be used as general purpose IO
  1669.     if [ ! -f /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf ]; then
  1670.         echo "blacklist spi-bcm2708
  1671. blacklist i2c-bcm2708 " > /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf
  1672.     UpdateConfig NBDBuildNeeded true
  1673.     fi
  1674. }
  1675.  
  1676. DisableSPI(){
  1677. #Disables SPI (and enables I2C) to allow the SPI pins to be used as general purpose IO
  1678.     echo "blacklist spi-bcm2708" > /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf
  1679.     UpdateConfig NBDBuildNeeded true
  1680. }
  1681.  
  1682. InstallBlueJ(){
  1683. #Install BlueJ java IDE. Part of AddSoftware
  1684.     rm -rf /tmp/bluej-314a.deb
  1685.     rm -rf /opt/ltsp/armhf/tmp/bluej-314a.deb
  1686.     wget http://bluej.org/download/files/bluej-314a.deb -O /tmp/bluej-314a.deb
  1687.     cp /tmp/bluej-314a.deb /opt/ltsp/armhf/tmp/bluej-314a.deb
  1688.     ltsp-chroot --arch armhf dpkg -i /tmp/bluej-314a.deb
  1689. }
  1690. #
  1691. #
  1692. #
  1693. #
  1694. #
  1695. #
  1696. #
  1697. # IO SO ARRIVATO QUI, VAVA, 1000 RIGHE ME SO FATTO! 19:16 20/04/2019
  1698. #
  1699. #
  1700. #
  1701. #
  1702. #
  1703. #
  1704. #
  1705.  
  1706. checkPythonFunctionsInstalled(){
  1707. #Checks the vital Python functions file is installed on the system. If not, it goes and downloads it from the web
  1708.     if [ ! -f $PythonFunctions ]; then
  1709.         wget $RawRepository/$ReleaseBranch/Scripts/pinet_functions_python.py -O $PythonFunctions
  1710.         if [ ! $? -eq 0 ]; then
  1711.             whiptail --title $"Errore!" --msgbox $"Scusa, c'è stato un errore critico con PiNet. Una libreria fondamentake non è stata acquisita. PiNet non può funzionare senza questa libreria. Il perchè del problema può essere che non sei connesso a internet. Per favore, scarica manualmente il file da http://bit.ly/pinet-fn e copialo in $PythonFunctions . Se il problema persiste, contatta il supporto a: http://PiNet.org.uk/support.html" 16 78
  1712.             rm -rf $PythonFunctions
  1713.             exit
  1714.         fi
  1715.     fi
  1716.  
  1717. }
  1718.  
  1719. checkKernelFileUpdateWeb(){
  1720. #Checks the web to see if the SD cards need updated with new kernel files
  1721.     $p checkKernelFileUpdateWeb
  1722.     KernelV=$(gp)
  1723.     if [ $KernelV = "1" ]; then
  1724.         current=$(head -n 1 /home/$SUDO_USER/PiBoot/version.txt)
  1725.         newVersion=$(head -n 1 /tmp/kernelVersion.txt)
  1726.         whiptail --title $"Kernel file update" --yesno $"Un aggiornamento importante è disponibile per i file del kernel Raspberry Pi (file sulle schede SD). Se si aggiorna, PiNet tenterà di caricare questi nuovi file sulle schede SD all'avvio. Questo aggiornamento è altamente raccomandato. Attualmente stai usando la versione $current e la versione più aggiornata è $newVersion. Ti piacerebbe procedere con un aggiornamento automatico dei file di avvio e del tuo server?" 12 78
  1727.         if [ $? -eq 0 ]; then
  1728.             whiptail --title $"Auto riavvio" --msgbox $"Il tuo Raspberry Pis tenterà di aggiornare automaticamente le loro schede SD (afferrando la versione dal server) al prossimo riavvio. Lo faranno in background e si riavvieranno al termine dell'aggiornamento ** senza preavviso **." 9 78
  1729.             installKernelUpdater ""
  1730.             UpdateSD
  1731.             UpdateAll
  1732.         fi
  1733.     fi
  1734.  
  1735.  
  1736. }
  1737.  
  1738. checkKernelUpdater(){
  1739. #Runs the installKernelUpdater
  1740.     installKernelUpdater $1
  1741.  
  1742. }
  1743.  
  1744. installKernelUpdater(){
  1745.     #Downloads new kernel files if required
  1746.     local compress=$1
  1747.     $p checkKernelUpdater
  1748.     exitstatus=$(gp)
  1749.     if [ "$exitstatus" = "1" ]; then
  1750.         if [ "$compress" = "NBD" ]; then
  1751.             echo "----------------------------------------------------------------------------------------------"
  1752.             echo $"È stato rilevato un aggiornamento per il programma di aggiornamento del kernel, che verrà applicato automaticamente"
  1753.             echo "----------------------------------------------------------------------------------------------"
  1754.             NBDRun
  1755.         fi
  1756.     fi
  1757.  
  1758. }
  1759.  
  1760. CheckRaspberryPiUIMods(){
  1761.  
  1762.     if [ ! -f "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/desktop-items-0.conf" ]; then
  1763.         InstallRaspberryPiUIMods
  1764.         UpdateConfig NBDBuildNeeded true
  1765.         return
  1766.     fi
  1767.  
  1768.  
  1769.     $p checkIfFileContainsString "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/pcmanfm.conf" "raspberrypi-artwork"
  1770.     exitstatus=$(gp)
  1771.     if [ "$exitstatus" = "1" ]; then
  1772.         InstallRaspberryPiUIMods
  1773.         UpdateConfig NBDBuildNeeded true
  1774.     else
  1775.         $p checkIfFileContainsString "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/desktop-items-0.conf" "raspberrypi-artwork"
  1776.         exitstatus=$(gp)
  1777.         if [ "$exitstatus" = "1" ]; then
  1778.             InstallRaspberryPiUIMods
  1779.             UpdateConfig NBDBuildNeeded true
  1780.         fi
  1781.     fi
  1782.  
  1783. }
  1784.  
  1785. FixUIConfigFile(){
  1786.     if [ $1 == "System" ]; then
  1787.         $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 wallpaper_mode= wallpaper_mode=stretch
  1788.         $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 wallpaper= wallpaper=/etc/alternatives/desktop-background
  1789.         $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 side_pane_mode= side_pane_mode=1
  1790.         $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 desktop_shadow= desktop_shadow=#000000
  1791.         $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 desktop_fg= desktop_fg=#ffffff
  1792.     else
  1793.         $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 wallpaper_mode= wallpaper_mode=stretch
  1794.         $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 wallpaper= wallpaper=/etc/alternatives/desktop-background
  1795.         $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 side_pane_mode= side_pane_mode=1
  1796.         $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 desktop_shadow= desktop_shadow=#000000
  1797.         $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 desktop_fg= desktop_fg=#ffffff
  1798.     fi
  1799. }
  1800.  
  1801. CheckRaspberryPiUIModsAllUsers(){
  1802.     cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user  #Gets all users
  1803.     do
  1804.         if [ -f "/home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf" ]; then
  1805.             FixUIConfigFile "User" "pcmanfm.conf" $user
  1806.             FixUIConfigFile "User" "desktop-items-0.conf" $user
  1807.  
  1808.             #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf wallpaper_mode= wallpaper_mode=stretch
  1809.             #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf wallpaper= wallpaper=/etc/alternatives/desktop-background
  1810.             #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf side_pane_mode= side_pane_mode=1
  1811.         fi
  1812.     done
  1813.     $p resetThemeCacheForAllUsers
  1814. }
  1815.  
  1816. InstallRaspberryPiUIMods(){
  1817. #Fixes the mistakes made in the wallpaper setting of RaspberryPi-UI-Mods
  1818.         #ltsp-chroot apt-get update
  1819.         #ltsp-chroot apt-get -o Dpkg::Options::="--force-confnew" install -y raspberrypi-ui-mods
  1820.         FixUIConfigFile "System" "pcmanfm.conf"
  1821.         FixUIConfigFile "System" "desktop-items-0.conf"
  1822.         CheckRaspberryPiUIModsAllUsers
  1823. }
  1824.  
  1825. ChooseReleaseChannelOld(){
  1826.     whiptail --title $"Release channels" --yesno --yes-button $"Stable" --no-button $"Development" $"Would you like to use the stable or development (dev) software update channels? Stable is recommended. Do not use the development (dev) channels in a production environment (for example a school) as stability is not guaranteed. " 10 78
  1827.     if [ $? -eq 0 ]; then
  1828.         UpdateConfig ReleaseChannel "Stable"
  1829.     else
  1830.         UpdateConfig ReleaseChannel "Dev"
  1831.     fi
  1832.     SetupRepositories
  1833.     if [ $1 = "Restart" ]; then
  1834.         exec /bin/bash pinet
  1835.         exit
  1836.     fi
  1837. }
  1838.  
  1839. ChooseReleaseChannel(){
  1840.     # Select a release channel (branch) for PiNet to use for software updates etc.
  1841.     $p "selectReleaseChannel"
  1842.     exitstatus=$(gp)
  1843.     SetupRepositories
  1844.     if [ $1 = "Restart" ]; then
  1845.         if [ "$exitstatus" = "1" ]; then
  1846.             # Invalidate previous package version caches to force them to be redownloaded
  1847.             rm "/opt/PiNet/pinet-package-versions.txt"
  1848.             rm "/opt/PiNet/PiBootBackup/apt_version.txt"
  1849.  
  1850.             # If the release channel has changed, restart PiNet software to check for updates etc
  1851.             Updater
  1852.         else
  1853.             Menu
  1854.         fi
  1855.     else
  1856.         Updater "IgnoreAfterUpdate" "$1"
  1857.     fi
  1858.  
  1859. }
  1860. GroupCheck(){
  1861.     #Checks if all users permissions are correct in groups. Front end for fixGroups
  1862.     whiptail --title $"Groupcheck" --msgbox $"Il controllo di gruppo passa attraverso ogni account utente controllando che gli vengano assegnati i gruppi corretti. Reimposta anche la configurazione dell'interfaccia utente. Può richiedere un pò di minuti se hai una grande quantità di utenti." 9 78
  1863.     fixGroups
  1864.     CheckRaspberryPiUIModsAllUsers
  1865.     whiptail --title $"Complete" --msgbox $"Tutti i gruppi di utenti sono stati controllati e, se necessario, corretti." 8 78
  1866. }
  1867.  
  1868. CheckForRaspiLTSP(){
  1869.     #Checks if Raspi-LTSP is installed and warns the user if it is.
  1870.     if [ -f /etc/raspi-ltsp ]; then
  1871.         whiptail --title $"Raspi-LTSP trovato!" --msgbox $"È stata trovata una precedente installazione Raspi-LTSP! PiNet e Raspi-LTSP non possono essere installati contemporaneamente! Si prega di reinstallare Ubuntu quindi eseguire PiNet." 9 78
  1872.         echo $"file di configurazione di Raspi-LTSP trovato in: /etc/raspi-ltsp"
  1873.         exit
  1874.     else
  1875.         if [ -d /opt/raspiLTSP ]; then
  1876.             whiptail --title $"Raspi-LTSP trovato!" --msgbox $"È stata trovata una precedente installazione Raspi-LTSP! PiNet e Raspi-LTSP non possono essere installati contemporaneamente! Si prega di reinstallare Ubuntu quindi eseguire PiNet." 9 78
  1877.             echo $"cartella di configurazione di Raspi-LTSP  in: /opt/raspiLTSP"
  1878.             exit
  1879.         fi
  1880.     fi
  1881. }
  1882.  
  1883.  
  1884. ImportUsersFromCSV(){
  1885.     whiptail --title $"Importa da CSV" --yesno $"PiNet supporta l'importazione di utenti da un file CSV. Molti sistemi di gestione degli utenti possono esportare un file CSV con nomi utente e password (o solo nomi utente). Il formato richiesto è 1a colonna è username e 2nd coloum è password. Se la colonna della password è vuota, verrà utilizzata una password predefinita selezionata. Vuoi continuare?" 11 78
  1886.     if [ $? -eq 0 ]; then
  1887.         whiptail --title $"Seleziona CSV" --msgbox $"Perfavore, ora seleziona il tuo file CSV." 9 78
  1888.         cd /home/$SUDO_USER
  1889.         local fileLoc=$(SingleFileSelect)
  1890.         if [ ! fileLoc = "L'utente cancellato :(" ]; then
  1891.             password=$(whiptail --inputbox $"Inserisci una password predefinita da utilizzare se non riesco a trovarne una." 8 78 --title $"Password" 3>&1 1>&2 2>&3)
  1892.             if [ password = "" ]; then
  1893.                 whiptail --title $"Errore" --msgbox $"La casella password predefinita non può essere lasciata vuota!" 9 78
  1894.             else
  1895.                 $p importFromCSV $fileLoc $password
  1896.             fi
  1897.         fi
  1898.     fi
  1899. }
  1900.  
  1901. DeleteUsersFromCSV(){
  1902.     whiptail --title $"Cancella da CSV" --yesno $"PiNet supporta l'eliminazione batch degli utenti da un file CSV. Il formato richiesto è 1a colonna è nome utente. Tutte le altre colonne vengono ignorate. Vuoi continuare?" 11 78
  1903.     if [ $? -eq 0 ]; then
  1904.         whiptail --title $"Seleziona CSV" --msgbox $"Seleziona ora il tuo file CSV." 9 78
  1905.         cd /home/$SUDO_USER
  1906.         fileLoc=$(SingleFileSelect)
  1907.         if [ ! fileLoc = "L'utente cancellato :(" ]; then
  1908.             $p usersCSVDelete $fileLoc False
  1909.         fi
  1910.     fi
  1911. }
  1912.  
  1913. CheckInstallSuccess(){
  1914.     if [ -d "/opt/ltsp/armhf/debootstrap" ]; then
  1915.         whiptail --title $"Errore di installazione" --msgbox $"È stato rilevato un problema con l'installazione PiNet! Il sistema operativo Raspbian è mancante o non è riuscito a installare correttamente. Ciò è più comunemente causato dai filtri Internet scolastici che bloccano gli archivi software o dalla mancata connessione Internet durante l'installazione. In questa fase si consiglia vivamente di eseguire una reinstallazione completa (compresa Ubuntu), se possibile, di una connessione Internet diversa. Se fallisce, contatta l'assistenza http://pinet.org.uk/articles/support.html" 14 78
  1916.         echo $"Potresti voler controllare i log di PiNet per aiutare a diagnosticare il problema. Possono essere trovati su /var/log/pinet.log."
  1917.         exit
  1918.  
  1919.     else
  1920.         $p verifyChrootIntegrity
  1921.     fi
  1922. }
  1923.  
  1924. CreatePartitionTable() {
  1925.   #Directly borrowed from Spindle - https://github.com/asb/spindle/blob/master/wheezy-stage0
  1926.   sudo parted $1 <<EOF
  1927.   unit b
  1928.   mklabel msdos
  1929.   mkpart primary fat32 $(expr 4 \* 1024 \* 1024) $(expr 60 \* 1024 \* 1024 - 1)
  1930.   print
  1931.   quit
  1932. EOF
  1933. }
  1934. CreateSDCardImageFile(){
  1935.     fileName="/tmp/pinet.img"
  1936.     dd if=/dev/zero of=$fileName bs=512 count=208845
  1937.     create_partition_table $fileName
  1938.     sudo mkdosfs -n PINET -S 512 -s 16 -v $fileName
  1939.     mkdir /mnt/sdimage
  1940.     mount $fileName /mnt/sdimage
  1941.     cp -r /home/$SUDO_USER/PiBoot/* /mnt/sdimage/
  1942.     umount /mnt/sdimage
  1943.     rm -r /mnt/sdimage
  1944.     mv $fileName /home/$SUDO_USER/pinetSDImage.img
  1945. }
  1946.  
  1947. CheckPipSymbolicLinkBug(){
  1948.     #Checks and fixes the pip3-2 symbolic link bug added in PiNet 1.1.1 and fixed in PiNet 1.1.4
  1949.     #if [ ! -h "/opt/ltsp/armhf/usr/bin/pip3" ] || [ ! -f "/opt/ltsp/armhf/usr/bin/pip3" ]; then
  1950.     #   ltsp-chroot apt-get purge -y python3-pip
  1951.     #   ltsp-chroot apt-get install -y python3-pip
  1952.     #   ltsp-chroot --arch armhf ln -sf /usr/bin/pip-3.2 /usr/bin/pip3
  1953.     #   UpdateConfig NBDBuildNeeded true
  1954.     #fi
  1955.     echo ""
  1956. }
  1957.  
  1958. CheckDebianVersion(){
  1959.     $p checkDebianVersion
  1960.     exitstatus=$(gp)
  1961.     if [ "$exitstatus" = "1" ]; then
  1962.         RebuildOS
  1963.     fi
  1964.  
  1965. }
  1966.  
  1967. CheckBackupScriptVersion(){
  1968.     if [ -f "/usr/local/bin/pinet-backup.sh" ]; then
  1969.         thirdLineCheck="if [ ! \$backupLoc = \"\" ]; then"
  1970.         currentThirdLine=$(sed '3q;d' /usr/local/bin/pinet-backup.sh)
  1971.         if [ "$thirdLineCheck" == "$currentThirdLine" ]; then
  1972.             createBackupScript
  1973.         fi
  1974.     fi
  1975.  
  1976. }
  1977.  
  1978. DuplicateLTSConf(){
  1979.     #Duplicate the lts.conf from /opt/ltsp/armhf/etc/lts.conf to /var/lib/tftpboot/ltsp/armhf/lts.conf
  1980.     cp /opt/ltsp/armhf/etc/lts.conf /var/lib/tftpboot/ltsp/armhf/lts.conf
  1981.  
  1982. }
  1983.  
  1984. WheezyJessieUpgradePartTwo(){
  1985.     ChooseReleaseChannel "NoRestart"
  1986.     exec /bin/bash pinet "Wheezy-upgrade-part-three"
  1987.     exit
  1988. }
  1989.  
  1990. WheezyJessieUpgradePartThree(){
  1991.     # Delete old pinet-functions-python.py file (has been replaced by pinet_functions_pinet.py and start OS rebuild.
  1992.     rm /usr/local/bin/pinet-functions-python.py
  1993.     RebuildOS
  1994.     $p resetThemeCacheForAllUsers
  1995.     #UpdateAll
  1996. }
  1997.  
  1998. GetInternalIPAddress(){
  1999.     # Gets the current internal IP address and sets the $IP variable to it.
  2000.     $p getInternalIPAddress
  2001.     IP=$(gp)
  2002. }
  2003.  
  2004. #***************************************************************************************************
  2005. backupDeleteTime(){
  2006.   MENUEPT=$(whiptail --menu $"How long would you like to store backups? Note this only runs when a backup runs." --nocancel 20 85 10 \
  2007.     "10 giorni" $"I backup verranno conservati per 10 giorni, quindi cancellati" \
  2008.     "30 giorni" $"I backup verranno conservati per 30 giorni, quindi cancellati " \
  2009.     "90 giorni" $"I backup saranno conservati per 90 giorni e poi cancellati" \
  2010.     "Per Sempre" $"Cancellero i miei backups manualmente" \
  2011.     3>&1 1>&2 2>&3)
  2012.  
  2013. case "$MENUEPT" in
  2014.     Ten-Days)
  2015.     DELETETIME=10
  2016.     ;;
  2017.     Thirty-Days)
  2018.     DELETETIME=30
  2019.     ;;
  2020.     Ninety-Days)
  2021.     DELETETIME=90
  2022.     ;;
  2023.     Forever)
  2024.     DELETETIME=9999
  2025.     ;;
  2026.     *)
  2027.     removeAnacronLines
  2028.     rm -rf /usr/local/bin/pinet-backup.sh
  2029.     Menu
  2030.     ;;
  2031.  
  2032. esac
  2033. }
  2034.  
  2035.  
  2036. #***************************************************************************************************
  2037. backupFrequency(){
  2038.   MENUEPT=$(whiptail --menu $"How often should PiNet create a backup?" --nocancel 20 85 10 \
  2039.     "Every-day" $"Will create a new backup every day" \
  2040.     "Twice-weekly" $"Will create a backup on Tuesday and Thursday" \
  2041.     "Once-a-week" $"Will create a backup every Friday" \
  2042.     3>&1 1>&2 2>&3)
  2043.  
  2044. case "$MENUEPT" in
  2045.     Every-day)
  2046.     removeAnacronLines
  2047.     echo "1       15      PiNet.backup1      /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
  2048.  
  2049.     ;;
  2050.     Twice-weekly)
  2051.     removeAnacronLines
  2052.     echo "3       15      PiNet.backup1      /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
  2053.     ;;
  2054.     Once-a-week)
  2055.     removeAnacronLines
  2056.     echo "1       15      PiNet.backup1      /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
  2057.     ;;
  2058.     *)
  2059.     removeAnacronLines
  2060.     rm -rf /usr/local/bin/pinet-backup.sh
  2061.     Menu
  2062.     ;;
  2063.  
  2064. esac
  2065. }
  2066.  
  2067.  
  2068.  
  2069. #***************************************************************************************************
  2070. OtherMenu() {
  2071. #
  2072.  #
  2073.  #
  2074.  #
  2075.  #
  2076.  #
  2077.  #      BRUH, 24/4/2019
  2078.  #
  2079.  #
  2080.  #
  2081.  #
  2082.  
  2083.   MENUEPT=$(whiptail --title $"Other Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 85 10 \
  2084.     "Refresh-System" $"Refreshes network services. Useful if having boot issues" \
  2085.     "Custom-config" $"Customise the config.txt file on the SD cards." \
  2086.     "NBD-recompress" $"Force an NBD compress if changes are made outside PiNet" \
  2087.     "NBD-compress-disable" $"Disable auto NBD recompression after every change" \
  2088.     "NBD-compress-enable" $"Enable auto NBD recompression after every change (default)" \
  2089.     "Export-users" $"Export all user data for migrating to new PiNet server" \
  2090.     "Change-release-channel" $"Change your current update channel to dev or stable" \
  2091.     "Edit-Information" $"Edit information attached to the PiNet server" \
  2092.     "Full-Install" $"Full install of PiNet server" \
  2093.     3>&1 1>&2 2>&3)
  2094.  
  2095. #<<COMMENT1
  2096. #if [$MENUOPT -eq 0]; then
  2097. case "$MENUEPT" in
  2098.     Collect-work)
  2099.     CollectWork
  2100.     Menu
  2101.     ;;
  2102.     NBD-compress-disable)
  2103.     UpdateConfig NBDuse false
  2104.     ConfigFileRead
  2105.     Menu
  2106.     ;;
  2107.     NBD-compress-enable)
  2108.     UpdateConfig NBDuse true
  2109.     ConfigFileRead
  2110.     Menu
  2111.     ;;
  2112.     Custom-config)
  2113.     $p "customConfig"
  2114.     ConfigFileRead
  2115.     if [ "$NBDBuildNeeded" = "true" ]; then
  2116.         NBDRun
  2117.     fi
  2118.     Menu
  2119.     ;;
  2120.     NBD-recompress)
  2121.     local CurrentNBD=$NBDuse
  2122.     UpdateConfig NBDuse true
  2123.     NBDRun
  2124.     UpdateConfig NBDuse $CurrentNBD
  2125.     ConfigFileRead
  2126.     Menu
  2127.     ;;
  2128.     Refresh-System)
  2129.     resetAndCleanup
  2130.     Menu
  2131.     ;;
  2132.     Export-users)
  2133.     CreateMoveBackup
  2134.     Menu
  2135.     ;;
  2136.     Edit-Information)
  2137.     $p "askExtraStatsInfo"
  2138.     Menu
  2139.     ;;
  2140.     Change-release-channel)
  2141.     ChooseReleaseChannel "Restart"
  2142.     ;;
  2143.     Full-Install)
  2144.     if [ -d /opt/ltsp/armhf ]; then
  2145.         whiptail --title $"Error" --yesno $"An LTSP install has been detected.. Not recommended to continue. Should PiNet continue?" 8 78
  2146.     exitstatus=$?
  2147.     if [ $exitstatus = 0 ]; then
  2148.             echo ""
  2149.     else
  2150.         Menu
  2151.     fi
  2152. fi
  2153.     FullInstall
  2154. Menu
  2155.     ;;
  2156.     *)
  2157.     Menu
  2158.     ;;
  2159.  
  2160. esac
  2161.  
  2162. } #***************************************************************************************************
  2163.  
  2164. SharedFolderMenu() {
  2165.  
  2166.   MENUEPT=$(whiptail --title $"Shared folders" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 85 10 \
  2167.     "Create-Shared-Folder" $"Create a new shared folder" \
  2168.     "Remove-Shared-Folder" $"Remove a shared folder" \
  2169.     "Change-Permissions" $"Changes shared folder permissions" \
  2170.     "Display-Shared-Folders" $"Display a list of all shared folders" \
  2171.     "Add-Teacher" $"Add a new account to the teacher group" \
  2172.     3>&1 1>&2 2>&3)
  2173.  
  2174. case "$MENUEPT" in
  2175.     Create-Shared-Folder)
  2176.     CreateSharedFoldersDialog
  2177.     Menu
  2178.     ;;
  2179.     Remove-Shared-Folder)
  2180.     RemoveSharedFolder
  2181.     Menu
  2182.     ;;
  2183.     Change-Permissions)
  2184.     SharedFolderPerm
  2185.     Menu
  2186.     ;;
  2187.     Display-Shared-Folders)
  2188.     DisplaySharedFolders
  2189.     ;;
  2190.     Add-Teacher)
  2191.     AddTeacher
  2192.     Menu
  2193.     ;;
  2194.     *)
  2195.     Menu
  2196.     ;;
  2197.  
  2198. esac
  2199.  
  2200. } #***************************************************************************************************
  2201.  
  2202. EpoptesMenu() {
  2203.  
  2204.   MENUEPT=$(whiptail --title $"Epoptes Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"Epoptes classroom management software is a free, open source and easy to use computer lab management and monitoring tool. What would you like to do?" 20 80 10 \
  2205.     "Install-Epoptes" $"Install Epoptes onto the server and Raspberry Pis" \
  2206.     "Epoptes-launch" $"Launches Epoptes, it must be installed first though" \
  2207.     "Add-Teacher" $"Add a new account to the teacher group" \
  2208.     "Remove-epoptes" $"Uninstall Epoptes from the server and Raspberry Pis" \
  2209.     3>&1 1>&2 2>&3)
  2210.  
  2211. case "$MENUEPT" in
  2212.     Install-Epoptes)
  2213.     checkInternet
  2214.     if [ $? -eq 0 ]; then
  2215.         whiptail --title $"Epoptes install" --yesno $"I am now going to install Epoptes classroom management software on the server and Raspberry Pis. Would you like to continue?" 8 78
  2216.         if [ $? -eq 0 ];then
  2217.  
  2218.             EpoptesInstaller
  2219.             NBDRun
  2220.         fi
  2221.     else
  2222.         whiptail --title $"Error" --msgbox $"No internet connection, unable to proceed..." 8 78
  2223.     fi
  2224.     Menu
  2225.     ;;
  2226.     Epoptes-launch)
  2227.     EpoptesRun
  2228.     Menu
  2229.         ;;
  2230.     Add-Teacher)
  2231.     AddTeacher
  2232.     Menu
  2233.     ;;
  2234.     Remove-epoptes)
  2235.     ltsp-chroot --arch armhf apt-get remove -y epoptes-client
  2236.     ltsp-chroot --arch armhf apt-get -y autoremove
  2237.     NBDRun
  2238.     whiptail --title $"Epoptes" --msgbox $"Epoptes has been removed from the pi image" 16 78
  2239.     Menu
  2240.     ;;
  2241.     *)
  2242.     Menu
  2243.     ;;
  2244.  
  2245. esac
  2246. }
  2247.  
  2248. #***************************************************************************************************
  2249. ##### WIP ##########################
  2250. BackupMenu() {
  2251.  
  2252.   MENUEPT=$(whiptail --title $"Backup Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 80 10 \
  2253.     "Configure-backup" $"Configure and enable backups. Also use to make changes" \
  2254.     "Disable-backup" $"Disables backup daemon, old backups will not be deleted" \
  2255.     "Display-Logs" $"Displays logs for the backup daemon, check these regularly!" \
  2256.     3>&1 1>&2 2>&3)
  2257.  
  2258. #<<COMMENT1
  2259. #if [$MENUOPT -eq 0]; then
  2260. case "$MENUEPT" in
  2261.     Configure-backup)
  2262.     whiptail --title $"Select Location" --msgbox $"Select the location where you wish to save the backups. An external hard drive is highly recommended! Even a large (16gb+) pendrive should be sufficient. In Linux external drives are attached in /media so you will start there. Do not save backups on the same hard drive as the /home folder!" 12 78
  2263.     cd /media
  2264.     fileSelect
  2265.     exit=$?
  2266.     if [ "$exit" = "1" ]; then
  2267.         Menu
  2268.     else
  2269.         $p setConfigParameter backupLoc "$location/"
  2270.         backupFrequency
  2271.         backupDeleteTime
  2272.         createBackupScript
  2273.         currentDate=`date +"%d-%m-%y"`
  2274.         currentTime=`date +"%H:%M"`
  2275.         logger -s "$currentDate $currentTime - Backup configured. Folder chosen is $location" 2>> /var/log/PiNet-backup.log
  2276.         whiptail --title $"Backup setup" --msgbox $"The backup is now configured, the logs can be viewed at any time by checking /var/log/PiNet-backup.log" 12 78
  2277.     fi
  2278.     Menu
  2279.     ;;
  2280.     Disable-backup)
  2281.     rm -rf /usr/local/bin/pinet-backup.sh
  2282.     removeAnacronLines
  2283.     currentDate=`date +"%d-%m-%y"`
  2284.     currentTime=`date +"%H:%M"`
  2285.     logger -s "$currentDate $currentTime - Backup disabled from PiNet" 2>> /var/log/PiNet-backup.log
  2286.     whiptail --title $"Backup disabled" --msgbox $"The backup daemon has now been disabled, no more backups will be performed till it is enabled again with Configure-backup. All old backups have been kept." 12 78
  2287.     Menu
  2288.     ;;
  2289.     Display-Logs)
  2290.     clear
  2291.     echo "-------------------"
  2292.     echo $"PiNet log file"
  2293.     echo "-------------------"
  2294.     echo " "
  2295.     echo "$(cat /var/log/PiNet-backup.log)"
  2296.     echo " "
  2297.     echo $"Hit enter to continue"
  2298.     read
  2299.     Menu
  2300.     ;;
  2301.     *)
  2302.     Menu
  2303.     ;;
  2304.  
  2305. esac
  2306.  
  2307. }
  2308.  
  2309. ##### WIP ##########################
  2310.  
  2311. #***************************************************************************************************
  2312. UserGroups() {
  2313.  
  2314.   MENUEPT=$(whiptail --title $"Manage-users Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 80 11 \
  2315.     "Add-user" $"Add a new Linux user" \
  2316.     "Remove-user" $"Remove a Linux user" \
  2317.     "Change-password" $"Change password of a user" \
  2318.     "Display-users" $"List all the users on the system" \
  2319.     "Add-teacher" $"Add user to the staff permission group" \
  2320.     "Import-Users" $"Import usernames and passwords from a CSV file" \
  2321.     "Delete-Batch" $"Batch delete users from a CSV file" \
  2322.     "Change-Sudo" $"Change student sudo permissions. Used for GPIO access" \
  2323.     "Group-check" $"Checks all users are in the correct system groups" \
  2324.     "Export-users" $"Export all user data for migrating to new PiNet server" \
  2325.     3>&1 1>&2 2>&3)
  2326.  
  2327. case "$MENUEPT" in
  2328.     Add-user)
  2329.     AddUsers
  2330.     Menu
  2331.     ;;
  2332.     Remove-user)
  2333.     RemoveUser
  2334.     Menu
  2335.     ;;
  2336.     Change-password)
  2337.     ChangeUserPassword
  2338.     Menu
  2339.     ;;
  2340.     Display-users)
  2341.     DisplayUsers
  2342.     ;;
  2343.     Group-check)
  2344.     GroupCheck
  2345.     Menu
  2346.     ;;
  2347.     Add-teacher)
  2348.     AddTeacher
  2349.     Menu
  2350.     ;;
  2351.     Import-Users)
  2352.     ImportUsersFromCSV
  2353.     ;;
  2354.     Delete-Batch)
  2355.     DeleteUsersFromCSV
  2356.     ;;
  2357.     Graphics-fix)
  2358.     fixGroups
  2359.     Menu
  2360.     ;;
  2361.     Change-Sudo)
  2362.     SudoMenu
  2363.     if [ "$NBDBuildNeeded" = "true" ]; then
  2364.         NBDRun
  2365.     fi
  2366.     Menu
  2367.     ;;
  2368.  
  2369.     Remove-Samab-user)
  2370.     user=$(whiptail --inputbox "Enter the username of the user you wish to remove from Samba" 8 78 $INIT --title "Samba" 3>&1 1>&2 2>&3)
  2371.     pdbedit -u "$user" -xl
  2372.     whiptail --title "Samba" --msgbox 'User has been removed from samba. ' 12 78
  2373.     Menu
  2374.     ;;
  2375.     Export-users)
  2376.     CreateMoveBackup
  2377.     Menu
  2378.     ;;
  2379.     *)
  2380.     Menu
  2381.     ;;
  2382.  
  2383. esac
  2384. } #***************************************************************************************************
  2385.  
  2386.  
  2387. FullInstall(){
  2388.   checkInternetDetailed
  2389.   if [ $? -eq 0 ]; then
  2390.         ConfigFileRead
  2391.         if [ "$ImportedUsers" = "" ]; then
  2392.             FirstTimeImportUsers
  2393.         fi
  2394.         if [ "$ReleaseChannel" = "" ]; then
  2395.             ChooseReleaseChannel 1
  2396.         fi
  2397.         $p initialInstallSoftwareList
  2398.         whiptail --title $"Full Install" --msgbox $"A full install will take around 1-2 hours depending on your Internet speed. There will be a number of options to select at the end so do not close this terminal until the install has completed!" 10 78
  2399.         installLTSP   #Installs LTSP and other packages required to build an Raspberry Pi OS
  2400.         buildClient   #Creates config file to build Raspbian with LTSP and builds it
  2401.         OneTimeFixes   #Runs some one off config changes, these are not repeated at any time later
  2402.         #PiConfigFixes   #Adds configuration changes to LXDE and installs Raspi artwork
  2403.         configFixes   #Main configuration changes that are run on the the LTSP chroot (/opt/ltsp/armhf). These must be run every time the image is generated
  2404.         FixRepo   #Adds additional repositories to the Raspbian build
  2405.         AddSoftware   #Adds all the custom software on top of a normal Armhf Debian Wheezy build
  2406.         RaspiTheme   #Installs the PiNet theme which can be seen at login
  2407.         FixDesktopIcons   #Adds desktop icons
  2408.         InstallRaspberryPiUIMods
  2409.         EnableNBDswap   #Enables NBD swap for if the Pi runs out of RAM, it can use server as RAM using NBD
  2410.         UpdateConfig NBD false
  2411.         UpdateConfig NBDuse false
  2412.         $p installSoftwareFromFile
  2413.         DisableSPI
  2414.         SudoMenu   #Asks the user if they wish to enable Sudo for the pupils
  2415.         UpdateSD "NoRecompress"   #Runs the IP address selector and builds the SD card image
  2416.         addSoundcardDefault
  2417.         SetupSharedStandalone
  2418.         installKernelUpdater ""
  2419.         $p checkKernelFileUpdateWeb
  2420.         fixGroups "NoRecompress"   #Adds all current users to the correct groups.
  2421.         DuplicateLTSConf
  2422.         usermod -a -G teacher $SUDO_USER
  2423.         LegacyFixes "NoRecompress"
  2424.         AddSoftware
  2425.         EnableNBD #Enables NBD compression
  2426.         resetAndCleanup
  2427.         $p triggerInstall
  2428.         CheckInstallSuccess
  2429.  
  2430.         whiptail --title "Main installation complete" --msgbox "PiNet main installation is now complete. There may be a few other minor updates that will be applied now. You will need to flash an SD card with the PiNet boot files, instructions can be found at http://pinet.org.uk/articles/installation/sd-card-copy.html. Then plug the Raspberry Pi into the network and boot it up." 11 78
  2431.     else
  2432.         whiptail --title "Error" --msgbox "The installation has been cancelled due to a problem accessing key domains used in the installation." 8 78
  2433.         echo "The installation has been cancelled due to a problem accessing key domains used in the installation."
  2434.         exit 1
  2435.     fi
  2436. }
  2437.  
  2438. RebuildOS(){
  2439. checkInternet
  2440. if [ $? -eq 0 ]; then
  2441.             rm -rf /opt/ltsp/armhf
  2442.             rm -rf /var/lib/tftpboot/ltsp/armhf
  2443.             $p initialInstallSoftwareList
  2444.             buildClient
  2445.             configFixes
  2446.             FixRepo
  2447.             AddSoftware
  2448.             RaspiTheme
  2449.             FixDesktopIcons   #Adds desktop icons
  2450.             InstallRaspberryPiUIMods
  2451.             EnableNBDswap
  2452.             #whiptail --title $"Extra software" --msgbox $"Select any additional software you want to use or use Install-Custom-software to install a specific package from the Raspbian apt repository if you know its name. To quit the menu, use the cancel option. This menu can be later accessed from Install-Program from the main menu." 12 78
  2453.             $p installSoftwareFromFile
  2454.             DisableSPI
  2455.             SudoMenu   #Asks the user if they wish to enable Sudo for the pupils
  2456.             UpdateSD "NoRecompress"
  2457.             addSoundcardDefault
  2458.             SetupSharedStandalone
  2459.             installKernelUpdater ""
  2460.             $p checkKernelFileUpdateWeb
  2461.             fixGroups "NoRecompress"
  2462.             DuplicateLTSConf
  2463.             LegacyFixes "NoRecompress"
  2464.             AddSoftware
  2465.             EnableNBD
  2466.             resetAndCleanup
  2467.             CheckInstallSuccess
  2468.             whiptail --title $"Rebuild complete" --msgbox $"PiNet rebuild is now complete. You will need to flash an SD card with the PiNet boot files, instructions can be found at http://pinet.org.uk/articles/installation/sd-card-copy.html. Then plug the Raspberry Pi into the network and boot it up." 10 78
  2469.         else
  2470.             whiptail --title $"Error" --msgbox $"No internet connection, unable to proceed..." 8 78
  2471.         fi
  2472.  
  2473. }
  2474.  
  2475.  
  2476. Menu() {
  2477. GetInternalIPAddress
  2478.   MENUOPT=$(whiptail --title $"PiNet $version Main Menu - $IP" --cancel-button $"Quit" --ok-button $"Select" --menu $"What would you like to do?" 22 80 14 \
  2479.     "System-Status" $"Display status of key parts of your PiNet server" \
  2480.     "Install-Program" $"Install a new program on the Raspberry Pi's" \
  2481.     "Manage-Users" $"Add new users, change passwords and delete users" \
  2482.     "Update-All" $"Run an automatic update on server and Raspbian" \
  2483.     "Backup-Menu" $"User files backup submenu" \
  2484.     "Shared-Folders" $"Manage and create shared folders" \
  2485.     "Collect-work" $"Collects students work in a single folder" \
  2486.     "Update-SD" $"Update the SD card image. This includes IP address changes" \
  2487.     "Rebuild-OS" $"Rebuilds the LTSP Raspberry Pi image from scratch again" \
  2488.     "Epoptes-Menu" $"Epoptes classroom management submenu" \
  2489.     "Troubleshooter" $"Having issues? Try running the troubleshooter" \
  2490.     "Other" $"Other options and utilities for management" \
  2491.     "Update-PiNet" $"Forces PiNet to update itself" \
  2492.     3>&1 1>&2 2>&3)
  2493.  
  2494. case "$MENUOPT" in
  2495.     System-Status)
  2496.     listStatus
  2497.     Menu
  2498.     ;;
  2499. Update-SD)
  2500.     UpdateSD
  2501.     if [ $? -eq 0 ]; then
  2502.         whiptail --title $"SD image updated" --msgbox $"SD card image updated. A folder of boot files in /home/$SUDO_USER/PiBoot has been created. An experimental disk image ready to flash onto the SD card has also been created at /home/$SUDO_USER/pinetSDImage.img. You can use either option. See http://pinet.org.uk/articles/installation/sd-card-copy.html for help." 11 78
  2503.     fi
  2504.     Menu
  2505.     ;;
  2506. Install-Program)
  2507.     $p installSoftwareList
  2508.     Menu
  2509.     ;;
  2510. Shared-Folders)
  2511.     SharedFolderMenu
  2512.     Menu
  2513.     ;;
  2514. Rebuild-OS)
  2515.     whiptail --title $"WARNING!!" --yesno $"Warning, you are about to delete the entire Raspbian OS from the server and rebuild it. Students files are not affected but any custom programs added will need to be re-added. This will take 1-2 hours. Are you sure?" 9 78
  2516.  
  2517.     exitstatus=$?
  2518.     if [ $exitstatus = 0 ]; then
  2519.         RebuildOS
  2520.     fi
  2521.     Menu
  2522.     ;;
  2523. Backup-Menu)
  2524.     whiptail --title "WARNING" --msgbox 'WARNING - The backup system in PiNet is currently in alpha, you are responsible to check backups are correctly being made and checking the log file frequently. To check the log file, select Display-Logs in the Backup submenu!' 12 78
  2525.     BackupMenu
  2526.     ;;
  2527. Manage-Users)
  2528.     UserGroups
  2529.     Menu
  2530.     ;;
  2531. Install-Epoptes)
  2532.     EpoptesInstaller
  2533.     Menu
  2534.     ;;
  2535. Update-All)
  2536.     UpdateAll
  2537.     Menu
  2538.     ;;
  2539. Epoptes-Menu)
  2540.     EpoptesMenu
  2541.     ;;
  2542. Collect-work)
  2543.     CollectWork
  2544.     Menu
  2545.     ;;
  2546. Other)
  2547.     OtherMenu
  2548.  
  2549.     ;;
  2550. Troubleshooter)
  2551.     TroubleShooter
  2552.     Menu
  2553.     ;;
  2554. Update-PiNet)
  2555.     Updater
  2556.     ;;
  2557.     *)
  2558.     exit
  2559.     ;;
  2560.     esac
  2561.  
  2562.  
  2563. }
  2564.  
  2565.  
  2566.  
  2567. #************************************* Startup stuff **************************************************************
  2568.  
  2569. if [ "$(id -u)" != "0" ]; then  #Check if script is being run as root
  2570.    echo $"This script must be run as root" 1>&2
  2571.    exit 1
  2572. fi
  2573.  
  2574. if [ ! "$BASH_VERSION" ] ; then   #Checks that PiNet is being run using bash and not ash (aka sh)
  2575.     whiptail --title $"Shell error" --msgbox $"Please do not run PiNet with sudo sh $0. Please run it with bash using     sudo bash $0" 8 78
  2576.     echo $"Please do not run PiNet with sh $0. Please run it with bash using     sudo bash $0" 1>&2
  2577.     exit 1
  2578. fi
  2579. CheckOS   #Checks if running Ubuntu, if not complains a little
  2580. if [ "$SUDO_USER" = "" ]; then
  2581.     SUDO_USER=$(whiptail --inputbox $"No user in the SUDO_USER variable was detected. This occurs when you didn't launch the application with sudo. Please enter your normal Linux username." 9 78 --title $"Unsupported operating system" 3>&1 1>&2 2>&3)  #Sometimes can't detect username to run program as.
  2582. fi
  2583.  
  2584. checkInstallLoc   #Checks PiNet is installed in /usr/local/bin. If not offer to move it
  2585.  
  2586. echo $"Starting PiNet - Please wait"
  2587. checkPythonFunctionsInstalled  #Checks the supporting Python functions are installed correctly
  2588. CheckForRaspiLTSP
  2589. VerifyPythonPackages
  2590.  
  2591. CheckTerminalSize  #Changes the terminal to the minimum size if is too small
  2592.  
  2593. case "$1" in  #Checks if PiNet needs to run an update all, usually run after an update when the software is launched by itself
  2594. Update-All)
  2595.     UpdateSD
  2596.     UpdateAll
  2597.     ;;
  2598. SD-card-update)
  2599.     UpdateSD
  2600.     ;;
  2601. Wheezy-upgrade-part-two)
  2602.     WheezyJessieUpgradePartTwo
  2603.     ;;
  2604. Wheezy-upgrade-part-three)
  2605.     WheezyJessieUpgradePartThree
  2606.     ;;
  2607. esac
  2608.  
  2609. if [ ! -d /opt/ltsp/armhf ]; then   # Check if PiNet is installed. If not, offer to install
  2610.         whiptail --title $"Welcome" --yesno $"Welcome to PiNet. No previous PiNet installation is detected, would you like to run the full PiNet installer? " 8 78
  2611.         exitstatus=$?
  2612.         if [ $exitstatus = 0 ]; then
  2613.             UpdateConfig FirstUser $SUDO_USER
  2614.             FullInstall
  2615.         else
  2616.             Menu
  2617.         fi
  2618. fi
  2619. ConfigFileRead  #Reads the main configuration file (/etc/pinet) and loads all values in as environmental variables
  2620.  
  2621. if [ "$ReleaseChannel" = "" ]; then   #Makes sure a release channel is selected, if not asks for one
  2622.     ChooseReleaseChannel "Restart"
  2623. fi
  2624.  
  2625. SetupRepositories #Sets up the correct branch variables as selected in ChooseReleaseChannel()
  2626.  
  2627. checkInternet #Checks if PiNet server has a web connection. If so, checks for updates on PiNet, PiNet kernels and PiNet kernel updater
  2628. if [ $? -eq 0 ]; then
  2629.     if [ ! "$DisableUpdateChecking" = "true" ]; then
  2630.             CheckReleases
  2631.             checkKernelFileUpdateWeb
  2632.             checkKernelUpdater "NBD"
  2633.     fi
  2634. fi
  2635. fixGroups #Verify all groups are set up correctly with correct users
  2636. LegacyFixes #Makes sure all configuration data is correctly configured
  2637. CheckInstallSuccess
  2638. Menu #Runs main menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement