Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Part of PiNet https://github.com/PiNet/PiNet
- #
- # See LICENSE file for copyright and license details
- version=1.2.10
- #PiNet (Previously RaspberryPi-LTSP)
- #Written by Andrew Mulholland, based off the fantastic work by vagrantc and alksig from the LTSP community
- #Initial guide available at http://cascadia.debian.net/trenza/Documentation/raspberrypi-ltsp-howto/
- #Spindle was used to figure out needed changes to generate Raspbian image https://github.com/asb/spindle
- #
- #PiNet is a utility for setting up and configuring a Linux Terminal Server Project (LTSP) network for Raspberry Pi's
- #Constants
- #------------------------
- ConfigFileLoc=/etc/pinet
- Timeout=1
- PythonFunctions="/usr/local/bin/pinet_functions_python.py"
- PythonStart="python3"
- p="$PythonStart $PythonFunctions"
- RepositoryBase="https://github.com/PiNet/"
- RepositoryName="PiNet"
- BootRepositoryName="PiNet-Boot"
- RawRepositoryBase="https://raw.github.com/PiNet/"
- Repository="$RepositoryBase$RepositoryName"
- BootRepository="$RepositoryBase$BootRepositoryName"
- RawRepository="$RawRepositoryBase$RepositoryName"
- ReleaseBranch="jessie-stable" #Overwriten later on in SetupRepositories()
- ltspBase="/opt/ltsp/"
- cpuArch="armhf"
- #------------------------
- SetupRepositories(){
- ReleaseChannel=$(echo "$ReleaseChannel" | tr '[:upper:]' '[:lower:]')
- case "$ReleaseChannel" in
- stable)
- ReleaseBranch="stable"
- ;;
- beta)
- ReleaseBranch="beta"
- ;;
- dev)
- ReleaseBranch="beta"
- ;;
- alpha)
- ReleaseBranch="alpha"
- ;;
- "custom:*")
- ReleaseBranch=${ReleaseChannel:7:channelLength}
- ;;
- *)
- ReleaseBranch="stable"
- ;;
- esac
- }
- LegacyFixes() {
- #Runs a number of legacy code checks, making sure everything is configured correctly.
- if [ -d "/home/shared" ]; then
- CheckSharedFolderIntegrity
- fi
- CheckDesktopShortcut
- teacherSudoCheck
- CheckRaspberryPiUIMods
- ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf "NFS_HOME=/home" ""
- if [ -f "/etc/default/epoptes" ]; then
- ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP=staff" "SOCKET_GROUP=teacher"
- fi
- if [ ! -f "/opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh" ]; then
- AddScreenshot
- UpdateConfig NBDBuildNeeded true
- fi
- if [ ! -f "/usr/local/bin/changePassword.sh" ]; then
- AddPasswordReset
- UpdateConfig NBDBuildNeeded true
- fi
- CheckPipSymbolicLinkBug
- local passwdVersion=$(cat /home/$SUDO_USER/Desktop/pinet-password.desktop | sed -n '2p')
- ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
- exitcode=$?
- sed -i '/^[[:blank:]]*$/d' /opt/ltsp/armhf/etc/lts.conf
- if [ "$exitcode" = "1" ]; then
- UpdateConfig NBDBuildNeeded true
- fi
- CheckDebianVersion
- CheckBackupScriptVersion
- if [ -f "/usr/local/bin/pinet-functions-python.py" ]; then
- mv "/usr/local/bin/pinet-functions-python.py" "/usr/local/bin/pinet_functions_python.py"
- fi
- # Make sure that all the required Python libraries are installed
- $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
- $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
- $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
- if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
- echo $"A required system update has been found. The Raspbian operating system will now be recompressed to apply this update"
- NBDRun
- else
- UpdateConfig NBDBuildNeeded false
- fi
- $p "checkStatsNotification"
- }
- ConfigFileRead(){
- #Reads the config file and loads in data as variables
- #Taken from - http://wiki.bash-hackers.org/howto/conffile
- configfile_secured="/tmp/pinet-config"
- if egrep -q -v '^#|^[^ ]*=[^;]*' "$ConfigFileLoc"; then
- # filter the original to a new file
- egrep '^#|^[^ ]*=[^;&]*' "$ConfigFileLoc" > "$configfile_secured"
- ConfigFileLoc="$configfile_secured"
- source "$ConfigFileLoc"
- else
- source "$ConfigFileLoc"
- fi
- }
- ReplaceTextLine(){
- # ReplaceTextLine /textfile bob brian
- egrep -i "^$2" $1 >> /dev/null
- if [ $? = 0 ]; then
- sed -i "s/$2.*/$3/g" $1
- else
- echo "$3" >> $1
- fi
- }
- ReplaceAnyTextOnLine(){
- # ReplaceTextLine /textfile bob brian
- #REMEMBER!! The & symbol can't be in any of the strings as SED is using it for separating. Can change it if need be
- egrep -i "$2" $1 >> /dev/null
- if [ $? -eq 0 ]; then
- sed -i "s&.*$2.*&$3&g" $1
- return 0
- else
- echo "$3" >> $1
- return 1
- fi
- }
- UpdateConfig(){
- #Updates the PiNet config file with provided values
- #Example - UpdateConfig bob false
- local configName=$1
- local configValue=$2
- egrep -i "^$configName" $ConfigFileLoc >> /dev/null
- if [ $? = 0 ]; then
- sed -i "s/$configName.*/$configName=$configValue/g" $ConfigFileLoc
- else
- echo "$configName=$configValue" >> $ConfigFileLoc
- fi
- ConfigFileRead
- }
- gp(){
- #Part of the Python functions code. As Python functions uses a text file to communicate back and forth, this reads it and echos to console.
- if [ -f /tmp/ltsptmp ]; then
- echo $(head -n 1 /tmp/ltsptmp)
- fi
- }
- installLTSP() {
- #Installs main packages required by LTSP
- apt-get update && apt-get upgrade -y
- apt-get install -y ltsp-server qemu-user-static binfmt-support ldm-server sed git gnome-control-center nfs-kernel-server xml2 openssh-server inotify-tools bindfs
- exitstatus=$?
- if ! [ $exitstatus = 0 ]; then
- 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
- exit 1
- fi
- }
- buildClient() {
- #Creates the custom config file needed to build Raspbian and grabs keychain. Then starts the build
- wget http://archive.raspbian.org/raspbian.public.key -O - | gpg --import
- gpg --export 90FDDD2E >> /etc/ltsp/raspbian.public.key.gpg
- rm /etc/ltsp/ltsp-raspbian.conf
- cat <<EOF > /etc/ltsp/ltsp-raspbian.conf
- DEBOOTSTRAP_KEYRING=/etc/ltsp/raspbian.public.key.gpg
- DIST=jessie
- # For alternate raspbian mirrors, see: http://www.raspbian.org/RaspbianMirrors
- MIRROR=http://mirrordirector.raspbian.org/raspbian
- SECURITY_MIRROR=none
- UPDATES_MIRROR=none
- LOCALE="$LANG UTF-8"
- KERNEL_PACKAGES=linux-image-3.10-3-rpi
- EOF
- VENDOR=Debian ltsp-build-client --arch armhf --config /etc/ltsp/ltsp-raspbian.conf
- }
- OneTimeFixes(){
- #A number of one off fixes needed to be run
- echo "/opt/ltsp *(ro,no_root_squash,async,no_subtree_check)" >> /etc/exports #sets up OS exporting for NFS
- echo "/home *(rw,sync,no_subtree_check)" >> /etc/exports #Sets up home folder exporting for NFS
- mkdir /etc/skel/handin
- echo '#!/bin/sh' >> /etc/network/if-up.d/tftpd-hpa #Script to make sure tftpd-hpa autostarts
- echo "service tftpd-hpa restart" >> /etc/network/if-up.d/tftpd-hpa
- chmod 755 /etc/network/if-up.d/tftpd-hpa
- service tftpd-hpa restart
- groupadd -g 628 pupil
- groupadd -g 629 teacher
- }
- configFixes() {
- #Configuration file changes required after the client is built. These are not once off as they reside inside the Raspberry Pi OS
- sed -i -e 's,/bin/plymouth quit --retain-splash.*,/bin/plymouth quit --retain-splash || true,g' /opt/ltsp/armhf/etc/init.d/ltsp-client-core
- echo 'LTSP_FATCLIENT=true' >> /opt/ltsp/armhf/etc/lts.conf
- ReplaceAnyTextOnLine /opt/ltsp/armhf/etc/lts.conf REMOTE_APPS REMOTE_APPS=True
- DuplicateLTSConf
- ltsp-chroot --arch armhf groupadd -g 628 pupil
- ltsp-chroot --arch armhf groupadd -g 629 teacher
- AddUdevRules
- printf 'snd-bcm2835\n' >> /opt/ltsp/armhf/etc/modules
- addSoundcardDefault
- }
- addSoundcardDefault(){
- #Adds the soundcard settings for Raspbian
- grep -q mmap_emul "/opt/ltsp/armhf/etc/asound.conf" > /dev/null 2>&1
- checkSound=$?
- if [ ! $checkSound = 1 ]; then
- cat <<\EOF1 > /opt/ltsp/armhf/etc/asound.conf
- pcm.!default {
- type hw;
- card 0;
- }
- ctl.!default {
- type hw
- card 0
- }
- EOF1
- return 1
- else
- return 0
- fi
- }
- checkInternet(){
- #Checks if the internet is connected. Mainly passes off to CheckInternet Python programme in Python functions
- if [ ! "$CheckInternetConnection" = "false" ]; then
- $p CheckInternet $Timeout
- result=$(gp)
- return $result
- else
- return 0
- fi
- }
- checkInternetDetailed(){
- #Does a more detailed internet connection check than checkInternet, uses internetFullStatusCheck()
- if [ ! "$CheckInternetConnection" = "false" ]; then
- $p internetFullStatusCheck
- status=$(gp)
- return $status
- else
- return 0
- fi
- }
- UpdateSD() {
- #Function for updating the SD card images
- $p updateSD
- ConfigFileRead # Grab updated $NBDBuildNeeded
- if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ]; then
- echo $"È stato trovato un aggiornamento di sistema richiesto. Il sistema operativo Raspbian verrà ora ricompresso per applicare questo aggiornamento."
- NBDRun
- fi
- return
- }
- EnableNBDswap(){
- #Enables NBD swap system. Allows the Raspberry Pis to use NBD partition as swap
- rm /etc/nbd-server/conf.d/swap.conf
- cat <<EOF > /etc/nbd-server/conf.d/swap.conf
- [swap]
- exportname = /tmp/nbd-swap/%s
- prerun = nbdswapd %s
- postrun = rm -f %s
- EOF
- service nbd-server restart
- }
- FixRepo() {
- #Adds the repositories used by Raspbian. The public keys are included
- # Adds PiNet repo
- echo "Aggiunta della chiave del repository PiNet."
- echo deb http://apt.pinet.org.uk jessie main > /opt/ltsp/armhf/etc/apt/sources.list.d/pinet.list
- wget http://apt.pinet.org.uk/pinet.public.key -O /opt/ltsp/armhf/tmp/pinet.public.key
- sudo ltsp-chroot --arch armhf apt-key add /tmp/pinet.public.key
- rm -rf /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
- echo "Sto aggiungendo la chiave del repository della PiNet Foundation."
- echo "deb http://archive.raspberrypi.org/debian/ jessie main ui staging" > /opt/ltsp/armhf/etc/apt/sources.list.d/raspi.list
- ltsp-chroot --arch armhf apt-key add - <<EOF1
- -----BEGIN PGP PUBLIC KEY BLOCK-----
- Version: GnuPG v1.4.12 (GNU/Linux)
- mQENBE/d7o8BCACrwqQacGJfn3tnMzGui6mv2lLxYbsOuy/+U4rqMmGEuo3h9m92
- 30E2EtypsoWczkBretzLUCFv+VUOxaA6sV9+puTqYGhhQZFuKUWcG7orf7QbZRuu
- TxsEUepW5lg7MExmAu1JJzqM0kMQX8fVyWVDkjchZ/is4q3BPOUCJbUJOsE+kK/6
- 8kW6nWdhwSAjfDh06bA5wvoXNjYoDdnSZyVdcYCPEJXEg5jfF/+nmiFKMZBraHwn
- eQsepr7rBXxNcEvDlSOPal11fg90KXpy7Umre1UcAZYJdQeWcHu7X5uoJx/MG5J8
- ic6CwYmDaShIFa92f8qmFcna05+lppk76fsnABEBAAG0IFJhc3BiZXJyeSBQaSBB
- cmNoaXZlIFNpZ25pbmcgS2V5iQE4BBMBAgAiBQJP3e6PAhsDBgsJCAcDAgYVCAIJ
- CgsEFgIDAQIeAQIXgAAKCRCCsSmSf6MwPk6vB/9pePB3IukU9WC9Bammh3mpQTvL
- OifbkzHkmAYxzjfK6D2I8pT0xMxy949+ThzJ7uL60p6T/32ED9DR3LHIMXZvKtuc
- mQnSiNDX03E2p7lIP/htoxW2hDP2n8cdlNdt0M9IjaWBppsbO7IrDppG2B1aRLni
- uD7v8bHRL2mKTtIDLX42Enl8aLAkJYgNWpZyPkDyOqamjijarIWjGEPCkaURF7g4
- d44HvYhpbLMOrz1m6N5Bzoa5+nq3lmifeiWKxioFXU+Hy5bhtAM6ljVb59hbD2ra
- X4+3LXC9oox2flmQnyqwoyfZqVgSQa0B41qEQo8t1bz6Q1Ti7fbMLThmbRHiuQEN
- BE/d7o8BCADNlVtBZU63fm79SjHh5AEKFs0C3kwa0mOhp9oas/haDggmhiXdzeD3
- 49JWz9ZTx+vlTq0s+I+nIR1a+q+GL+hxYt4HhxoA6vlDMegVfvZKzqTX9Nr2VqQa
- S4Kz3W5ULv81tw3WowK6i0L7pqDmvDqgm73mMbbxfHD0SyTt8+fk7qX6Ag2pZ4a9
- ZdJGxvASkh0McGpbYJhk1WYD+eh4fqH3IaeJi6xtNoRdc5YXuzILnp+KaJyPE5CR
- qUY5JibOD3qR7zDjP0ueP93jLqmoKltCdN5+yYEExtSwz5lXniiYOJp8LWFCgv5h
- m8aYXkcJS1xVV9Ltno23YvX5edw9QY4hABEBAAGJAR8EGAECAAkFAk/d7o8CGwwA
- CgkQgrEpkn+jMD5Figf/dIC1qtDMTbu5IsI5uZPX63xydaExQNYf98cq5H2fWF6O
- yVR7ERzA2w33hI0yZQrqO6pU9SRnHRxCFvGv6y+mXXXMRcmjZG7GiD6tQWeN/3wb
- EbAn5cg6CJ/Lk/BI4iRRfBX07LbYULCohlGkwBOkRo10T+Ld4vCCnBftCh5x2OtZ
- TOWRULxP36y2PLGVNF+q9pho98qx+RIxvpofQM/842ZycjPJvzgVQsW4LT91KYAE
- 4TVf6JjwUM6HZDoiNcX6d7zOhNfQihXTsniZZ6rky287htsWVDNkqOi5T3oTxWUo
- m++/7s3K3L0zWopdhMVcgg6Nt9gcjzqN1c0gy55L/g==
- =mNSj
- -----END PGP PUBLIC KEY BLOCK-----
- EOF1
- ltsp-chroot --arch armhf debconf-set-selections <<SELEOF
- wolfram-engine shared/accepted-wolfram-eula boolean true
- SELEOF
- #Auto accepts wolfram eula
- echo deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi > /opt/ltsp/armhf/etc/apt/sources.list
- ltsp-chroot --arch armhf apt-get update
- #Fetches most recent package lists
- }
- Finished() {
- #Function performing any actions that should happen after the boot image has been created
- whiptail --title $"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
- }
- RaspiTheme(){
- #Grabs a copy of the PiNet desktop/login theme and installs
- rm -rf /tmp/pinet
- git clone --no-single-branch --depth 1 $Repository.git /tmp/pinet #Clones main repository, including boot files
- (cd "/tmp/pinet"; git checkout "$ReleaseBranch")
- cp -r /tmp/pinet/themes/raspi /opt/ltsp/armhf/usr/share/ldm/themes/raspi
- rm /opt/ltsp/armhf/etc/alternatives/ldm-theme
- ln -s /usr/share/ldm/themes/raspi /opt/ltsp/armhf/etc/alternatives/ldm-theme
- rm -rf /tmp/pinet
- cp /opt/ltsp/armhf/usr/share/ldm/themes/raspi/bg.png /opt/ltsp/armhf/usr/share/images/desktop-base/pinet.png
- 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
- }
- NBDRun() {
- #Checks if it should be auto NBD compressing or not, if it should be, it recompresses the image
- ConfigFileRead
- if [ "$NBD" = "true" ]; then #If NBD is enabled on the system overall
- if [ "$NBDuse" = "true" ]; then #If temporarily NBD is disable
- echo "--------------------------------------------------------"
- echo $"Compressione dell'immagine, questo processo potrebbe durare 5 minuti"
- echo "--------------------------------------------------------"
- ltsp-update-image /opt/ltsp/armhf #If NBD is enabled, recompress the image
- UpdateConfig NBDBuildNeeded false
- else
- echo $"L'auto recomprissione del Raspbian OS è disabilitata. Per attivarla, avvia il comando NBD-recompress dall'altro menu"
- fi
- fi
- }
- NBDSetup() {
- #Setup function for NBD, asks user if they wish to use it, if not it defaults to NFS
- 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
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- EnableNBD
- else
- UpdateConfig NBD false
- UpdateConfig NBDuse false
- UpdateConfig NBDBuildNeeded false
- ConfigFileRead
- fi
- }
- EnableNBD() {
- /usr/sbin/ltsp-update-image --config-nbd /opt/ltsp/armhf
- service nbd-server restart
- UpdateConfig NBD true
- UpdateConfig NBDuse true
- UpdateConfig NBDBuildNeeded false
- ConfigFileRead
- }
- AddSoftware(){
- #All the software not included in normal base Debian that has been added to Raspbian normally by Spindle
- #------------------------------------------------------------------------------------------
- #******************************************************************************************
- $p installChrootSoftware
- return 0
- }
- AddUdevRules(){
- ltsp-chroot --arch armhf printf 'ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev"' >> /etc/udev/rules.d/40-scratch.rules
- ltsp-chroot --arch armhf printf "SUBSYSTEM==\"gpio*\", PROGRAM=\"/bin/sh -c 'chown -R root:pupil /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:pupil /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; chown -R root:pupil /sys/devices/platform/soc/*.gpio/gpio && chmod -R 770 /sys/devices/platform/soc/*.gpio/gpio'\"\n" > /etc/udev/rules.d/99-com.rules
- ltsp-chroot --arch armhf printf 'SUBSYSTEM=="input", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
- ltsp-chroot --arch armhf printf 'SUBSYSTEM=="i2c-dev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
- ltsp-chroot --arch armhf printf 'SUBSYSTEM=="spidev", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
- ltsp-chroot --arch armhf printf 'SUBSYSTEM=="bcm2835-gpiomem", GROUP="pupil", MODE="0660"\n' >> /etc/udev/rules.d/99-com.rules
- }
- PiConfigFixes(){
- #Configuration changes to Raspberry Pi files, mostly to do with LXDE instead of Raspbian itself
- ltsp-chroot --arch armhf sed /etc/xdg/lxsession/LXDE/desktop.conf -i -e "s|sNet/ThemeName.*|sNet/ThemeName=Mist|"
- ltsp-chroot --arch armhf sed /etc/xdg/openbox/LXDE/rc.xml -i -e \
- "s|<drawContents>yes</drawContents>|<drawContents>no</drawContents>|"
- ltsp-chroot --arch armhf apt-get install -y raspberrypi-artwork
- 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
- ltsp-chroot --arch armhf PCMANFMCFG=/etc/xdg/pcmanfm/LXDE/pcmanfm.conf
- ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^wallpaper_mode.*/wallpaper_mode=3/'
- ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^desktop_bg.*/desktop_bg=#ffffff/'
- ltsp-chroot --arch armhf sed "$PCMANFMCFG" -i -e 's/^su_cmd.*/su_cmd=gksu %s/'
- }
- EpoptesInstaller() {
- #Installs Epoptes classroom managment software
- apt-get update
- apt-get install -y epoptes
- gpasswd -a root staff
- ltsp-chroot --arch armhf apt-get update
- ltsp-chroot --arch armhf apt-get install -y epoptes-client --no-install-recommends
- ltsp-chroot --arch armhf epoptes-client -c
- ReplaceTextLine "/etc/default/epoptes" "SOCKET_GROUP" "SOCKET_GROUP=teacher"
- }
- EpoptesRun() {
- #Launches Epoptes classroom management software. Makes sure it is being run as the user, not as root.
- su -c "epoptes &" $SUDO_USER > /dev/null 2>&1 &
- }
- fixGroups(){
- # Verify correct groups exist, then make sure all users are in correct groups.
- $p verifyCorrectGroupUsers
- ConfigFileRead
- if [ "$NBDBuildNeeded" = "true" ] && [ ! "$1" = "NoRecompress" ] ; then
- NBDRun
- whiptail --title $"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
- fi
- }
- fixGroupsSingle() {
- #Check a single user is in the correct groups
- $p verifyCorrectGroupSingleUser $1
- }
- AddTeacher() {
- #Adds a new teacher user to the system
- whiptail --title $"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
- username=$(SelectUser $"per aggiungere al gruppo degli insegnanti")
- if [ ! $username = 1 ]; then
- INIT=""
- AddUserToTeacher $username
- whiptail --title $"Successo!" --msgbox "L'utente $username è stato aggiunto al gruppo insegnanti." 8 78
- fi
- }
- AddUserToTeacher() {
- #Adds the user to the teacher group
- usermod -a -G teacher $1
- AddDesktopShortcutToUser $1
- }
- FixDesktopIcons(){
- #Adds all the correct desktop icons for PiNet
- rm -rf /etc/skel/Desktop
- cd /opt/ltsp/armhf/usr/share/applications
- mkdir /etc/skel/Desktop
- sudo cp -a scratch.desktop idle.desktop idle3.desktop lxterminal.desktop debian-reference-common.desktop wolfram-mathematica.desktop epiphany-browser.desktop wolfram-language.desktop sonic-pi.desktop minecraft-pi.desktop /etc/skel/Desktop
- cd /etc/skel
- wget "https://github.com/KenT2/python-games/tarball/master" -O python_games.tar.gz
- tar -xvf python_games.tar.gz
- mv KenT2-python-games* python_games
- chmod +x python_games/launcher.sh
- rm python_games.tar.gz
- cd /etc/skel/Desktop
- cat <<\EOF2 > python-games.desktop
- [Desktop Entry]
- Name=Python Games
- Comment=From http://inventwithpython.com/pygame/
- Exec=sh -c $HOME/python_games/launcher.sh
- Icon=/usr/share/pixmaps/python.xpm
- Terminal=false
- Type=Application
- Categories=Application;Games;
- StartupNotify=true
- EOF2
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- mkdir /home/$user/Desktop
- cd /home/$user/Desktop/
- cp -R /etc/skel/Desktop/* /home/$user/Desktop/
- chown -R "$user" *
- cp -R /etc/skel/python_games /home/$user/python_games
- done
- AddScreenshot
- AddPasswordReset
- }
- CollectWork(){
- #A work collection system. It grabs files from students "handin" folders, copies them to "submitted" folder on the server and changes their owner
- INIT="$SUDO_USER"
- USERHAND=$(whiptail --inputbox $"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)
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- whiptail --title $"AVVERTIMENTO" --yesno $"La cartella attuale scelta verrà eliminata, sei sicuro?" 8 78
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- rm -rf /home/"$USERHAND"/submitted
- mkdir /home/"$USERHAND"/submitted
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- if [ "$USERHAND" != "" ]; then
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- if groups "$user" | grep -q -E ' pupil(\s|$)'; then
- if [ -d "/home/$user/handin" ]; then
- echo $"l'utente $user ha una cartella di handin"
- cp -r "/home/$user/handin/" "/home/$USERHAND/submitted/$user/"
- fi
- else
- echo $"L'utente $user non ha una cartella di handin"
- fi
- done
- chown -R "$USERHAND" /home/"$USERHAND"/submitted
- whiptail --title $"Completato!" --msgbox $"I lavori degli studenti sono stati raccolti e sono accessibili in : /home/$USERHAND/submitted/" 8 78
- else
- whiptail --title $"ERRORE" --msgbox $"l'username non può essere uno spazio vuoto" 8 78
- fi
- else
- whiptail --title $"ERRORE" --msgbox $"L'utente $USERHAND non è stato trovato" 8 78
- fi
- fi
- fi
- }
- CopyToUsers(){ #(Path-to-folder, path-in-home, skel? warning?)
- #Used to copy files out to every user, plus to the skel folder for new users
- if [ $4 == "True" ]; then
- whiptail --title "ATTENZIONE" --yesno "Questo comporta copiare una cartella alla directory home, se esiste la cancello?" 8 78
- local delete=$?
- else
- local delete=0
- fi
- local CurrentFilepath=$1
- local NewFilepath=$2
- local filename=$(basename "$NewFilepath")
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- if [ $delete = 0 ] ; then
- rm -rf "/home/$user/$NewFilepath"
- fi
- mkdir -p "/home/$user/"$(dirname ${NewFilepath})
- cp -r "$CurrentFilepath" "/home/$user/$NewFilepath"
- chown -R "$user" "/home/$user/$NewFilepath"
- done
- if [ $3 == "True" ]; then
- mkdir -p "/etc/skel/"$(dirname ${NewFilepath})
- cp -r "$CurrentFilepath" "/etc/skel/$NewFilepath"
- fi
- }
- SudoMenu(){
- #Used to enable Sudo on pupil accounts
- whiptail --title $"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
- exitstatus=$?
- rm -f /opt/ltsp/armhf/etc/sudoers.d/01pupil
- touch /opt/ltsp/armhf/etc/sudoers.d/01pupil
- chmod 440 /opt/ltsp/armhf/etc/sudoers.d/01pupil
- if [ $exitstatus = 0 ]; then
- echo '%pupil ALL=NOPASSWD: ALL' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- fi
- echo '%pupil ALL = NOPASSWD: /sbin/shutdown' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/reboot' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/poweroff' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/halt' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- UpdateConfig NBDBuildNeeded true
- }
- fileSelect(){
- #Selects a folder using some BASH/Whiptail trickery
- results=$(whiptail --title $"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)
- exitstatus=$?
- if [ "$exitstatus" = "1" ]; then
- echo "L'utente annullato :( "
- return "1"
- else
- if [ "$results" = "./" ]; then
- location=$(pwd)
- echo $"la posizione scelta è: $location"
- else
- cd "$results"
- fileSelect
- fi
- fi
- }
- SingleFileSelect(){
- #Selects a folder using some BASH/Whiptail trickery
- 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)
- exitstatus=$?
- if [ "$exitstatus" = "1" ]; then
- echo "L'utente annullato :("
- return "1"
- else
- if [ -f "$results" ]; then
- location=$(pwd)/$results
- echo "$location"
- else
- cd "$results"
- SingleFileSelect
- fi
- fi
- }
- removeAnacronLines() {
- #Removes anacrontab lines which can cause issues. Used for backup scheduling
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- }
- createBackupScript(){
- #Adds the backup script to the system to auto backup user data
- rm -rf /usr/local/bin/pinet-backup.sh
- echo '#!/bin/sh
- version=2
- #PiNet backup utility script
- ConfigFileLoc=/etc/pinet
- ConfigFileRead(){
- if egrep -q -v "^#|^[^ ]*=[^;]*" "$ConfigFileLoc"; then
- # filter the original to a new file
- egrep "^#|^[^ ]*=[^;&]*" "$ConfigFileLoc" > "$configfile_secured"
- ConfigFileLoc="$configfile_secured"
- source "$ConfigFileLoc"
- else
- source "$ConfigFileLoc"
- fi
- #echo config read
- }
- ConfigFileRead
- currentDate=`date +"%d-%m-%y"`
- currentTime=`date +"%H_%M"`
- if [ ! $backupLoc = "" ]; then
- LOCATION=$backupLoc
- if [ -d "$LOCATION" ]; then
- find "$LOCATION" -name "*PiNet-Users-Backup.tar.gz" -ctime +"$DELETETIME" | xargs rm -rf
- tar -zcvf "$LOCATION$currentDate--$currentTime--PiNet-Users-Backup.tar.gz" /home
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- logger -s "$currentDate $currentTime - Il backup dei file degli utenti ha avuto successo" 2>> /var/log/PiNet-backup.log
- else
- logger -s "$currentDate $currentTime - Backup fallito con codice errore tar $exitstatus" 2>> /var/log/PiNet-backup.log
- fi
- else
- logger -s "$currentDate $currentTime - Cartella di backup non disponibile!" 2>> /var/log/PiNet-backup.log
- fi
- else
- logger -s "$currentDate $currentTime - Nessuna posizione di backup specificata!" 2>> /var/log/PiNet-backup.log
- fi' >> /usr/local/bin/pinet-backup.sh
- chmod +x /usr/local/bin/pinet-backup.sh
- }
- AddUsers(){
- #Add users to the system. Manually adds the user hash instead of using adduser
- username=$(whiptail --inputbox $"Inserisci un nuovo nome utente" 8 78 $INIT --title $"Nome utente" 3>&1 1>&2 2>&3)
- exitstatus=$?
- if [ "$exitstatus" = "0" ]; then
- password=$(whiptail --inputbox $"Inserire una nuova password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
- exitstatus=$?
- if [ "$exitstatus" = "0" ]; then
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- whiptail --title "Errore" --msgbox $"Il nome utente esiste già!" 8 78
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m -s /bin/bash -p $pass $username
- [ $? -eq 0 ] && echo $"$username è stato aggiunto al sistema!" || echo $"Impossibile aggiungere un utente!"
- fixGroupsSingle $username
- 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 ############
- if [ ! $? -eq 0 ]; then
- AddUserToTeacher $username
- whiptail --title $"Successo" --msgbox $"Un nuovo utente insegnante è stato aggiunto al sistema con successo con il nome - $username" 8 78
- else
- whiptail --title $"Successo" --msgbox $"Un nuovo utente studente è stato aggiunto al sistema con successo con il nome - $username" 8 78
- fi
- fi
- whiptail --title $"Un altro utente" --yesno $"Vorresti aggiungere un altro utente?" 8 78
- if [ $? -eq 0 ]; then
- AddUsers
- fi
- fi
- fi
- }
- RemoveUser(){
- #Removes user from list
- username=$(SelectUser "to remove.")
- if [ ! $username = 1 ]; then
- whiptail --title $"Sei sicuro?" --yesno $"Sei sicuro di voler eliminare $username e tutti i suoi file?" 8 78
- if [ $? -eq 0 ]; then
- userdel -rf $username
- whiptail --title $"Operazione terminata con uccesso" --msgbox $"Utente rimosso con successo" 8 78
- fi
- fi
- whiptail --title $"Un altro utente" --yesno $"Vorresti cancellare un altro utente?" 8 78
- if [ $? -eq 0 ]; then
- RemoveUser
- fi
- }
- ChangeUserPassword(){
- #Change a users password
- username=$(SelectUser $"cambiare la password di.")
- if [ ! $username = 1 ]; then
- password=$(whiptail --inputbox $"Inserisci la nuova password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
- if ! [ "$password" = "" ]; then
- echo -e "$password\n$password" | passwd $username
- whiptail --title $"Operazione terminata con uccesso" --msgbox $"Password cambiata con successo" 8 78
- else
- whiptail --title $"Errore" --msgbox $"Password non valida" 8 78
- fi
- fi
- whiptail --title $"Un altro utente" --yesno $"Volete cambiare la password di un altro utente?" 8 78
- if [ $? -eq 0 ]; then
- ChangeUserPassword
- fi
- }
- RestoreBackup() { #Currently incomplete
- 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
- }
- SelectUser(){
- #Using some BASH/Whiptail magic, builds a list of users, formats it perfectly and hads it to whiptail
- users=$(cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | sort | awk -F':' '{ print $1"\na"}')
- user=$(whiptail --title $"Utenti" --menu $"Seleziona un utente $1" 16 78 5 $users --noitem 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- echo $user
- else
- echo 1
- fi
- }
- TroubleShooter(){
- #PiNet troubleshooter - Needs some more answers built in
- whiptail --title $"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
- whiptail --title $"Avvio" --yesno $"Sei arrivato fino a quando il tuo Raspberry Pi si avvia?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Schermata di accesso" --yesno $"Sei arrivato fino alla visualizzazione della schermata di accesso?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Schermata di accesso" --yesno $"Stai avendo problemi di accesso?" 8 78
- if [ $? -eq 0 ]; then
- 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.
- Se non sei sicuro della tua password, ricorda che puoi facilmente modificarla nel sottomenu Gestione utenti" 16 78
- else
- whiptail --title $"USB drivers" --yesno $"La tua tastiera funziona?" 8 78
- if [ ! $? -eq 0 ]; then
- 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
- else
- 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
- fi
- fi
- else
- resetAndCleanup
- whiptail --title $"Riparato?" --yesno $"È riparato ora? Ho appena ripristinato alcuni dei servizi di rete." 8 78
- if [ ! $? -eq 0 ]; then
- whiptail --title $"Connessione rifiutata" --yesno $"Stai ottenendo connessione rifiutata o errore di connessione scaduta?" 8 78
- if [ $? -eq 0 ]; then
- GetInternalIPAddress #Get the current main IP address
- 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
- else
- whiptail --title $"Rinuncia" --yesno $"Stai ricevendo un certo numero di errori di 'rinuncia'?" 8 78
- if [ $? -eq 0 ]; then
- 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
- else
- 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
- fi
- fi
- fi
- fi
- else
- whiptail --title $"Scherda SD" --yesno $"Hai problemi con il caricamento dei file sulla scheda SD?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Partizioni" --yesno $"Hai problemi con la presenza di 2-3 partizioni sulla scheda SD?" 8 78
- if [ $? -eq 0 ]; then
- 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
- else
- 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
- fi
- else
- 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
- fi
- fi
- }
- DisplayUsers(){
- #Displays system users onto the terminal
- clear
- local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
- echo "-------------------"
- echo $"Utenti Linux attuali"
- echo "-------------------"
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- echo "$user"
- done
- echo "---------------"
- echo $"Utenti Linux attuali nel gruppo di insegnanti"
- echo "$TEACHER"
- echo "---------------"
- echo $"Premere invio per continuare"
- read
- }
- SetupSambaServer(){
- #Unused
- apt-get install samba libpam-smbpass -y
- }
- SetupSambaPi(){
- #Unused
- mkdir /opt/ltsp/armhf/media/school-share
- ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf FSTAB 'FSTAB_0="//server/School-Share /media/school-share cifs guest,uid=1000,iocharset=utf8 0 0"'
- echo "file:///media/school-share School-Share" >>/tmp/.gtk-bookmarks
- CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
- rm -rf /tmp/.gtk-bookmarks
- }
- AfterUpdate(){
- #Code run after a successful update on the BASH side, given that most update code is handled via Python
- ConfigFileRead
- whiptail --title $"Aggiornamento completato" --msgbox $"L'aggiornamento è riuscito. PiNet è ora aggiornato $ReleaseBranch." 8 78
- 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
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- exec /bin/bash pinet Update-All
- exit
- else
- exec /bin/bash pinet
- exit
- fi
- }
- Updater(){
- #Main updater, most of it is handed by updatePiNet on the Python side or by AfterUpdate on BASH side
- $p updatePiNet
- exitstatus=$(gp)
- if [ $exitstatus = 0 ] && [ "$1" = "IgnoreAfterUpdate" ]; then
- if [ ! "$2" = "NoRestart" ]; then
- whiptail --title $"Riavvio di PiNet" --msgbox $"Riavvio di PiNet per garantire che stia eseguendo la versione corretta." 8 78
- exec /bin/bash pinet
- exit
- fi
- else
- if [ $exitstatus = 0 ]; then
- AfterUpdate
- else
- whiptail --title $"Aggiornamento non riuscito" --msgbox $"L'aggiornamento automatico non è riuscito. Questo di solito significa che non sei connesso a Internet" 8 78
- exec /bin/bash pinet
- fi
- fi
- }
- VerifyPythonPackages(){
- #Verify needed Python packages are installed. If not installed, install them.
- $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
- $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
- $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
- }
- CheckReleases(){
- #Checks if there is a new software release. Mainly uses CheckUpdate on Python side. Also runs sendStats.
- $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
- $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
- $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
- $p sendStats
- $p CheckUpdate $version
- exitstatus=$(gp)
- #echo $exitstatus
- if [ $exitstatus = 1 ]; then
- AfterUpdate
- fi
- }
- checkInstallLoc(){
- #Checks PiNet is installed in the correct place (/usr/local/bin/pinet)
- InstallLoc="${BASH_SOURCE[0]}"
- if [ ! "$InstallLoc" = "/usr/local/bin/pinet" ]; then
- mv $InstallLoc /usr/local/bin/pinet
- exec /bin/bash pinet
- fi
- }
- AddSambaUser(){
- #Unused
- 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
- 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
- username=$(whiptail --inputbox "Inserisci il nome utente da aggiungere a samba" 8 78 $INIT --title "Nome utente" 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- if ! [ "$username" = "" ]; then
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- smbpasswd -a "$username"
- password=$(whiptail --inputbox "Si prega di inserire nuovamente la password, deve essere corretta!" 8 78 $INIT --title "Password" 3>&1 1>&2 2>&3)
- if ! [ "$password" = "" ]; then
- echo -e "$password\n$password" | passwd $username
- whiptail --title "Operazione completata con successo" --msgbox "Utente aggiunto a Samba" 8 78
- else
- whiptail --title "Errore" --msgbox "Password non valida" 8 78
- fi
- else
- whiptail --title "Errore" --msgbox "Il nome utente non esiste!" 8 78
- fi
- else
- whiptail --title "Errore" --msgbox "Il nome utente non è valido" 8 78
- fi
- whiptail --title "Un altro utente?" --yesno "Vorresti aggiungere un altro utente Samba?" 8 78
- if [ $? -eq 0 ]; then
- AddSambaUser
- fi
- fi
- }
- UpdateAll(){
- #Does a full system update on the server and on the Raspberry Pi OS
- checkInternet
- if [ $? -eq 0 ]; then
- apt-get update
- apt-get upgrade -y
- ltsp-chroot --arch armhf apt-get update
- ltsp-chroot --arch armhf apt-get upgrade -y
- AddSoftware
- NBDRun
- whiptail --title $"Aggiornamento completato" --msgbox $"Aggiornamenti completati" 7 78
- else
- whiptail --title $"Erroer" --msgbox $"Nessuna connesione a internet, impossibile aggiornare il software..." 8 78
- fi
- }
- SetupSharedStandalone() {
- #Sets up shared folders. To use shared folders, extra line must be added to lts.conf file for Raspberry Pi
- mkdir /home/shared > /dev/null 2>&1
- sudo chown :teacher /home/shared
- sudo chmod 775 /home/shared
- ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf LOCAL_APPS_EXTRAMOUNTS 'LOCAL_APPS_EXTRAMOUNTS=/home/shared'
- DuplicateLTSConf
- }
- SetupShared(){
- #User frontend for SetupSharedStandalone() for when it is not run directly
- echo $"Impostazione delle cartelle condivise"
- 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
- SetupSharedStandalone
- NBDRun
- }
- CreateSharedFolder(){
- #Create a new shared folder on the Raspberry Pis
- mkdir /home/shared/$1
- if [ ! $? -eq 0 ]; then
- whiptail --title $"Errore" --msgbox $"La cartella condivisa in /home/shared/$1 non è stata creata. Potrebbe già esistere" 8 78
- return 1
- else
- chown root: /home/shared/$1
- chmod 0700 /home/shared/$1
- return 0
- fi
- }
- RebuildGTKBookmarks(){
- #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)
- FILES=/home/shared/*
- for f in $FILES
- do
- local FolderName=$(basename "$f")
- echo "file://$f $FolderName" >> /tmp/.gtk-bookmarks
- done
- CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
- rm -rf /tmp/.gtk-bookmarks
- }
- SelectSharedFolder(){
- #Select a shared folder using some BASH/Whiptail magic
- SFs=$(ls -1 /home/shared | awk -F':' '{ print $1"\na"}')
- SF=$(whiptail --title "Cartelle condivise" --menu "Seleziona una cartella condivisa $1" 16 78 5 $SFs --noitem 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- echo $SF
- else
- echo 1
- fi
- }
- CreateSharedFoldersDialog(){
- #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
- 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
- if [ $? -eq 0 ]; then
- if [ ! -d /home/shared ]; then
- SetupShared
- fi
- CheckSharedFolderIntegrity
- clear
- echo ""
- echo "----------------------"
- echo $"Cartelle condivise correnti"
- echo "----------------------"
- echo ""
- ls /home/shared -1
- echo ""
- echo $"Premere invio per continuare"
- read
- FolderName=$(whiptail --inputbox $"Inserisci il nome della nuova cartella condivisa" 8 78 --title $"Cartella condivisa" 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- if ! [ "$FolderName" = "" ]; then
- CreateSharedFolder "$FolderName"
- if [ $? -eq 0 ]; then
- 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
- if [ ! $? -eq 0 ]; then
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=pupil /home/shared/$FolderName /home/shared/$FolderName"
- else
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=teacher /home/shared/$FolderName /home/shared/$FolderName"
- fi
- RebuildGTKBookmarks
- service bindfs-mount restart
- whiptail --title $"Completato" --msgbox $"La cartella condivisa in /home/shared/$FolderName è stata create! Per accederci, riavvia il tuo Raspberry Pis." 8 78
- fi
- else
- whiptail --title $"Errore" --msgbox $"Il nome della cartella non può essere lasciato vuoto!" 8 78
- fi
- fi
- fi
- }
- RemoveSharedFolder(){
- #Used to remove shared folders. Involves removing the GTK bookmark, then removing the bindfs mount. Finally the actual folder is deleted
- 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
- if [ $? -eq 0 ]; then
- toDelete=$(SelectSharedFolder "per eliminare.")
- if [ ! $toDelete = 1 ]; then
- whiptail --title $"Sei sicuro?" --yesno $"Sei sicuro di voler eliminare definitivamente /home/shared/$toDelete ?" 8 78
- if [ $? -eq 0 ]; then
- RebuildGTKBookmarks
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount $"/home/shared/$toDelete" ""
- if [ $? -eq 0 ]; then
- service bindfs-mount restart
- rm -rf "/home/shared/$toDelete"
- whiptail --title $"Successo" --msgbox $"La cartella in /home/shared/$toDelete è stata correttamente eliminata." 8 78
- else
- service bindfs-mount restart
- whiptail --title $"Errore" --msgbox $"Si è verificato un problema durante la rimozione della montatura /usr/local/bin/bindfs-mount... Per favore riprova." 8 78
- fi
- fi
- fi
- fi
- }
- SharedFolderPerm(){
- #Used to change permission level of a shared folder. Perhaps switch from pupil read only to pupil read/write
- if [ "$1" = "" ]; then
- FolderName=$(SelectSharedFolder "da modificare")
- else
- FolderName=$1
- fi
- if [ ! $FolderName = 1 ]; then
- 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
- if [ ! $? -eq 0 ]; then
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=pupil /home/shared/$FolderName /home/shared/$FolderName"
- service bindfs-mount restart
- whiptail --title $"Completato" --msgbox $"Modifica delle autorizzazioni completata, gli studenti ora hanno accesso in lettura/scrittura in /home/shared/$FolderName" 8 78
- else
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/$FolderName" "bindfs -o perms=0775,force-group=teacher /home/shared/$FolderName /home/shared/$FolderName"
- service bindfs-mount restart
- whiptail --title $"Completato" --msgbox $"Modifica delle autorizzazioni completata, ora gli studenti hanno accesso solo in lettura in /home/shared/$FolderName" 8 78
- fi
- fi
- }
- DisplaySharedFolders(){
- #List all the shared folders in /home/shared
- clear
- echo ""
- echo "----------------------"
- echo $"Cartelle condivise correnti"
- echo "----------------------"
- echo ""
- ls /home/shared -1
- echo ""
- echo $"Permere invio per continuare"
- read
- }
- CheckSharedFolderIntegrity(){
- #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
- if [ ! -f /etc/init.d/bindfs-mount ]; then
- service stop bindfs-mount > /dev/null 2>&1
- addSharedFolderScript
- fi
- touch /usr/local/bin/bindfs-mount
- inFile=$(grep "bindfs" /usr/local/bin/bindfs-mount | wc -l)
- inFolder=$(ls -1 /home/shared | wc -l)
- if [ ! "$inFile" = "$inFolder" ]; then
- 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
- for i in 1 2 3 4 5 6 7 8 9 10
- do
- ReplaceAnyTextOnLine /usr/local/bin/bindfs-mount "/home/shared/" ""
- done
- sed -i '/^[[:blank:]]*$/d' /usr/local/bin/bindfs-mount
- for f in $(ls -1 "/home/shared/")
- do
- SharedFolderPerm $f
- chown :root "/home/shared/$f"
- done
- SetupShared
- fi
- }
- addSharedFolderScript() {
- #Adds the bindfs script which auto mounts the correct bind points and removes them when required (using stop)
- rm -rf /etc/init.d/bindfs-mount
- cat <<EOF1 >> /etc/init.d/bindfs-mount
- #!/bin/bash
- #Version=01
- ### BEGIN INIT INFO
- # Provides: Bindfs-mounts
- # Required-Start: \$syslog \$remote_fs
- # Required-Stop: \$syslog \$remote_fs
- # Should-Start: \$local_fs
- # Should-Stop: \$local_fs
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Bindfs mounts for PiNet
- # Description: The shared folder Bindfs mounts for PiNet
- ### END INIT INFO
- start() {
- bash /usr/local/bin/bindfs-mount
- }
- stop() {
- for i in \$(ls -1 /home/shared)
- do
- umount -l /home/shared/\$i > /dev/null 2>&1
- done
- }
- restart() {
- stop
- start
- }
- case "\$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- restart
- ;;
- *)
- echo "Usage: {start|stop|restart}"
- exit 1
- ;;
- esac
- exit
- EOF1
- chmod 755 /etc/init.d/bindfs-mount
- update-rc.d bindfs-mount defaults
- touch /usr/local/bin/bindfs-mount
- service bindfs-mount restart > /dev/null 2>&1
- }
- CheckOS(){
- #Check the correct operating system is being used. Ubuntu is recommended and Debian is no longer supported.
- OS=$(lsb_release -si)
- if [ ! $OS == "Ubuntu" ]; then
- if [ $OS == "Debian" ]; then
- 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
- else
- 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
- fi
- fi
- }
- CheckTerminalSize(){
- #Resizes the terminal to the correct size for the menus
- eval `resize`
- if [ "$LINES" -le "28" ]; then
- a='\e[8;28;'
- b='t'
- printf "$a$COLUMNS$b"
- fi
- eval `resize`
- if [ "$COLUMNS" -le "90" ]; then
- a='\e[8;'
- b=';90t'
- printf "$a$LINES$b"
- fi
- sleep 0.5 # Time to allow the terminal to resize.
- }
- listStatus(){
- #Displays a status of the PiNet. Includes a status of all logged in users
- while true; do
- dpkg-query -s epoptes > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- local EPOPTES="True"
- else
- local EPOPTES="False"
- fi
- local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
- local RAM=$(top -bn1 | awk '/Mem/ { mem = $5 / $3 * 100 }; END { print mem }')
- #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)")
- clear
- GetInternalIPAddress
- echo " Stato del sistema PiNet"
- echo "---------------------------------------------------"
- echo "Versione corrente - $version"
- echo "Indirizzo IP del server - $IP"
- echo "---------------------------------------------------"
- echo "È in esecuzione la versione $version da - $(stat -c %y /usr/local/bin/pinet | cut -d ' ' -f1)"
- echo "Ultima modifica della cartella Piboot - $(stat -c %y /home/$SUDO_USER/PiBoot | cut -d ' ' -f1)"
- echo "Ultimo aggiornamento a livello di sistema (aggiornamento-tutto) - $(stat -c %y /var/lib/apt/periodic/update-success-stamp | cut -d ' ' -f1)"
- echo "----------------"
- echo "Uso del disco rigido (potrebbe essere inaccurato)"
- echo "----------------"
- echo "Spazio totale - $(df -h | sed -n 2p | awk '{print $2}')"
- echo "Spazio utilizzato - $(df -h | sed -n 2p | awk '{print $3}')"
- echo "Spazio libero - $(df -h | sed -n 2p | awk '{print $4}')"
- echo "-----"
- echo "Altro"
- echo "-----"
- echo "Utilizzo della CPU - $CPU%"
- #echo "RAM usage - $(free -tom | grep 'Total:' | awk '{print $4}')MB / $(free -tom | grep 'Total:' | awk '{print $2}')MB"
- echo "Epoptes installato - $EPOPTES"
- echo "Insegnanti - $TEACHER"
- echo "-----------------------"
- echo "Attuali utenti attivi"
- echo "-----------------------"
- netstat -tnpa | grep ESTABLISHED.*sshd | awk '{ print $5 " - " $8 } '
- echo ""
- echo "Peremere invio per ritornare al menu principale"
- read -t 2
- if [ $? -eq 0 ]; then
- break
- fi
- done
- }
- CheckDesktopShortcut(){
- #Checks if the PiNet desktop shortcut exists. If not it adds it
- checkInternet
- if [ $? -eq 0 ]; then
- AddDesktopShortcutToUser $SUDO_USER
- if [ ! -f "/usr/share/pixmaps/pinet-icon.png" ] || [ ! -f "/opt/ltsp/armhf/usr/share/pixmaps/pinet-icon.png" ]; then
- wget $RawRepository/$ReleaseBranch/images/pinet-icon.png -O /tmp/pinet-icon.png
- cp /tmp/pinet-icon.png /usr/share/pixmaps/pinet-icon.png
- cp /tmp/pinet-icon.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-icon.png
- UpdateConfig NBDBuildNeeded true
- fi
- fi
- }
- AddDesktopShortcutToUser() {
- #Adds desltop shortcut for PiNet if needed
- if [ ! -f "/home/$1/Desktop/pinet.desktop" ]; then
- cat <<EOF1 >> /home/$1/Desktop/pinet.desktop
- [Desktop Entry]
- Version=3.0
- Name=PiNet
- Comment=PiNet Control Panel
- Exec=sudo bash pinet
- Icon=/usr/share/pixmaps/pinet-icon.png
- Terminal=true
- Type=Application
- Categories=Utility;Application;
- EOF1
- chmod +x "/home/$1/Desktop/pinet.desktop"
- chown "$1" "/home/$1/Desktop/pinet.desktop"
- fi
- if [ ! -f "/opt/ltsp/armhf/usr/local/bin/pinet" ]; then
- echo "ltsp-remoteapps gnome-terminal -x sh -c 'sudo bash pinet'" > /opt/ltsp/armhf/usr/local/bin/pinet
- UpdateConfig NBDBuildNeeded true
- fi
- }
- teacherSudoCheck() {
- #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)
- if [ ! -f "/etc/sudoers.d/01staff" ]; then
- rm -f /etc/sudoers.d/01staff
- touch /etc/sudoers.d/01staff
- chmod 440 /etc/sudoers.d/01staff
- echo '%teacher ALL=NOPASSWD: ALL' >> /etc/sudoers.d/01staff
- fi
- }
- resetAndCleanup(){
- #Resets the NBD server. Can sometimes help fix weird issues.
- service nfs-kernel-server restart
- sudo DEBIAN_FRONTEND=noninteractive dpkg-reconfigure nbd-server
- sudo service nbd-server restart
- }
- AddPasswordReset(){
- #Adds the password reset utility to the desktop of new users
- wget $RawRepository/$ReleaseBranch/Scripts/changePassword.sh -O /tmp/changePassword.sh
- wget $RawRepository/$ReleaseBranch/images/pinet-change-password.png -O /tmp/pinet-change-password.png
- cp /tmp/pinet-change-password.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-change-password.png
- cp /tmp/changePassword.sh /usr/local/bin/changePassword.sh
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- AddPasswordResetDesktop $user
- done
- if [ ! -f "/etc/skel/Desktop/pinet-password.desktop" ]; then
- cat <<EOF1 >> /etc/skel/Desktop/pinet-password.desktop
- [Desktop Entry]
- Version=1.1
- Name=Change Password
- Comment=Change password
- Exec=ltsp-remoteapps bash changePassword.sh
- Icon=/usr/share/pixmaps/pinet-change-password.png
- Terminal=false
- Type=Application
- Categories=Utility;Application;
- EOF1
- fi
- }
- AddPasswordResetDesktop(){
- #Adds the password reset utility to the desktop of existing users with help of AddPasswordReset
- if [ ! -f "/home/$1/Desktop/pinet-password.desktop" ]; then
- cat <<EOF1 >> /home/$1/Desktop/pinet-password.desktop
- [Desktop Entry]
- Version=1.1
- Name=Change Password
- Comment=Change password
- Exec=ltsp-remoteapps bash changePassword.sh
- Icon=/usr/share/pixmaps/pinet-change-password.png
- Terminal=false
- Type=Application
- Categories=Utility;Application;
- EOF1
- chown "$1" "/home/$1/Desktop/pinet-password.desktop"
- fi
- }
- AddScreenshot(){
- #Adds the screenshot utility to the desktop of new users
- wget $RawRepository/$ReleaseBranch/Scripts/pinet-screenshot.sh -O /tmp/pinet-screenshot.sh
- wget $RawRepository/$ReleaseBranch/images/pinet-screenshot.png -O /tmp/pinet-screenshot.png
- cp /tmp/pinet-screenshot.png /opt/ltsp/armhf/usr/share/pixmaps/pinet-screenshot.png
- cp /tmp/pinet-screenshot.sh /opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh
- chmod +x /opt/ltsp/armhf/usr/local/bin/pinet-screenshot.sh
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- AddScreenshotDesktop $user
- done
- if [ ! -f "/etc/skel/Desktop/pinet-screenshot.desktop" ]; then
- cat <<EOF1 >> /etc/skel/Desktop/pinet-screenshot.desktop
- [Desktop Entry]
- Version=1.0
- Name=Take Screenshot
- Comment=Take Screenshot
- Exec=bash pinet-screenshot.sh
- Icon=/usr/share/pixmaps/pinet-screenshot.png
- Terminal=false
- Type=Application
- Categories=Utility;Application;
- EOF1
- fi
- }
- AddScreenshotDesktop(){
- #Adds the screenshot utility to the desktop of existing users with help of AddScreenshot
- if [ ! -f "/home/$1/Desktop/pinet-screenshot.desktop" ]; then
- cat <<EOF1 >> /home/$1/Desktop/pinet-screenshot.desktop
- [Desktop Entry]
- Version=1.0
- Name=Take Screenshot
- Comment=Take Screenshot
- Exec=bash pinet-screenshot.sh
- Icon=/usr/share/pixmaps/pinet-screenshot.png
- Terminal=false
- Type=Application
- Categories=Utility;Application;
- EOF1
- chown "$1" "/home/$1/Desktop/pinet-screenshot.desktop"
- fi
- }
- CreateMoveBackup() {
- #Create a full backup of all users and groups data for moving to a clean system
- 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
- if [ $? -eq 0 ]; then
- mkdir /root/move/
- export UGIDLIMIT=1000
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/move/passwd.mig
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/move/group.mig
- awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/move/shadow.mig
- cp /etc/gshadow /root/move/gshadow.mig
- rm /home/$SUDO_USER/toMove.tar.gz # Remove previous toMove.tar.gz file in case is already one there.
- tar -zcvpf /root/move/home.tar.gz /home
- tar -zcvpf /home/$SUDO_USER/toMove.tar.gz /root/move
- chown $SUDO_USER /home/$SUDO_USER/toMove.tar.gz
- rm -rf /root/move/
- 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
- fi
- }
- CheckRestoreMoveBackup(){
- #Checks if LTSP is already installed as importing user data with a server already running PiNet can cause issues..
- if [ -f /home/$SUDO_USER/toMove.tar.gz ]; then
- if [ -d /opt/ltsp ]; then
- 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
- if [ $? -eq 0 ]; then
- RestoreMoveBackup
- fi
- else
- RestoreMoveBackup
- fi
- else
- whiptail --title $"Errore" --msgbox $"Il file zippato dei dati utente non può essere trovato in /home/$SUDO_USER/toMove.tar.gz." 8 78
- fi
- }
- RestoreMoveBackup() {
- #Restore full backup of all users and group data
- 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
- if [ $? -eq 0 ]; then
- if [ -f /home/$SUDO_USER/toMove.tar.gz ]; then
- $p importMigration "/home/$SUDO_USER/toMove.tar.gz"
- UpdateConfig "ImportedUsers" "true"
- return 0
- else
- 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
- if [ $? -eq 0 ]; then
- RestoreMoveBackup
- else
- exit
- fi
- fi
- else
- exit
- fi
- }
- InstallScratchGPIO(){
- #Installs ScratchGPIO 5 by manually pushing an install script to each user
- 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
- rm -rf /tmp/isgh7.sh
- rm -rf /opt/ltsp/armhf/usr/local/bin/isgh5.sh
- rm -rf /opt/ltsp/armhf/usr/local/bin/scratchSudo.sh
- rm -rf /opt/ltsp/armhf/usr/local/bin/isgh7.sh
- wget http://bit.ly/1wxrqdp -O /tmp/isgh7.sh
- cp /tmp/isgh7.sh /opt/ltsp/armhf/usr/local/bin/isgh7.sh
- echo "bash /usr/local/bin/isgh7.sh \$SUDO_USER" > /opt/ltsp/armhf/usr/local/bin/scratchSudo.sh
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- if [ ! -f "/home/$user/Desktop/Install-scratchGPIO.desktop" ]; then
- cat <<EOF1 > /home/$user/Desktop/Install-scratchGPIO.desktop
- [Desktop Entry]
- Version=1.0
- Name=Install ScratchGPIO
- Comment=Install ScratchGPIO
- Exec=sudo bash /usr/local/bin/scratchSudo.sh
- Icon=scratch
- Terminal=true
- Type=Application
- Categories=Utility;Application;
- EOF1
- chown "$user" "/home/$user/Desktop/Install-scratchGPIO.desktop"
- fi
- done
- if [ ! -f " /etc/skel/Desktop/Install-scratchGPIO.desktop" ]; then
- cat <<EOF1 > /etc/skel/Desktop/Install-scratchGPIO.desktop
- [Desktop Entry]
- Version=1.0
- Name=Install ScratchGPIO
- Comment=Install ScratchGPIO
- Exec=sudo bash /usr/local/bin/scratchSudo.sh
- Icon=scratch
- Terminal=true
- Type=Application
- Categories=Utility;Application;
- EOF1
- fi
- }
- FirstTimeImportUsers(){
- #Asks user if they want to import users on the first startup of PiNet
- if [ ! -f /home/$SUDO_USER/Desktop/lxterminal.desktop ]; then
- 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
- if [ $? -eq 0 ]; then
- RestoreMoveBackup
- fi
- fi
- }
- DisableI2C_SPI(){
- #Disables both I2C and SPI to allow the pins to be used as general purpose IO
- if [ ! -f /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf ]; then
- echo "blacklist spi-bcm2708
- blacklist i2c-bcm2708 " > /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf
- UpdateConfig NBDBuildNeeded true
- fi
- }
- DisableSPI(){
- #Disables SPI (and enables I2C) to allow the SPI pins to be used as general purpose IO
- echo "blacklist spi-bcm2708" > /opt/ltsp/armhf/etc/modprobe.d/raspi-blacklist.conf
- UpdateConfig NBDBuildNeeded true
- }
- InstallBlueJ(){
- #Install BlueJ java IDE. Part of AddSoftware
- rm -rf /tmp/bluej-314a.deb
- rm -rf /opt/ltsp/armhf/tmp/bluej-314a.deb
- wget http://bluej.org/download/files/bluej-314a.deb -O /tmp/bluej-314a.deb
- cp /tmp/bluej-314a.deb /opt/ltsp/armhf/tmp/bluej-314a.deb
- ltsp-chroot --arch armhf dpkg -i /tmp/bluej-314a.deb
- }
- #
- #
- #
- #
- #
- #
- #
- # IO SO ARRIVATO QUI, VAVA, 1000 RIGHE ME SO FATTO! 19:16 20/04/2019
- #
- #
- #
- #
- #
- #
- #
- checkPythonFunctionsInstalled(){
- #Checks the vital Python functions file is installed on the system. If not, it goes and downloads it from the web
- if [ ! -f $PythonFunctions ]; then
- wget $RawRepository/$ReleaseBranch/Scripts/pinet_functions_python.py -O $PythonFunctions
- if [ ! $? -eq 0 ]; then
- 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
- rm -rf $PythonFunctions
- exit
- fi
- fi
- }
- checkKernelFileUpdateWeb(){
- #Checks the web to see if the SD cards need updated with new kernel files
- $p checkKernelFileUpdateWeb
- KernelV=$(gp)
- if [ $KernelV = "1" ]; then
- current=$(head -n 1 /home/$SUDO_USER/PiBoot/version.txt)
- newVersion=$(head -n 1 /tmp/kernelVersion.txt)
- 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
- if [ $? -eq 0 ]; then
- 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
- installKernelUpdater ""
- UpdateSD
- UpdateAll
- fi
- fi
- }
- checkKernelUpdater(){
- #Runs the installKernelUpdater
- installKernelUpdater $1
- }
- installKernelUpdater(){
- #Downloads new kernel files if required
- local compress=$1
- $p checkKernelUpdater
- exitstatus=$(gp)
- if [ "$exitstatus" = "1" ]; then
- if [ "$compress" = "NBD" ]; then
- echo "----------------------------------------------------------------------------------------------"
- echo $"È stato rilevato un aggiornamento per il programma di aggiornamento del kernel, che verrà applicato automaticamente"
- echo "----------------------------------------------------------------------------------------------"
- NBDRun
- fi
- fi
- }
- CheckRaspberryPiUIMods(){
- if [ ! -f "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/desktop-items-0.conf" ]; then
- InstallRaspberryPiUIMods
- UpdateConfig NBDBuildNeeded true
- return
- fi
- $p checkIfFileContainsString "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/pcmanfm.conf" "raspberrypi-artwork"
- exitstatus=$(gp)
- if [ "$exitstatus" = "1" ]; then
- InstallRaspberryPiUIMods
- UpdateConfig NBDBuildNeeded true
- else
- $p checkIfFileContainsString "/opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/desktop-items-0.conf" "raspberrypi-artwork"
- exitstatus=$(gp)
- if [ "$exitstatus" = "1" ]; then
- InstallRaspberryPiUIMods
- UpdateConfig NBDBuildNeeded true
- fi
- fi
- }
- FixUIConfigFile(){
- if [ $1 == "System" ]; then
- $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 wallpaper_mode= wallpaper_mode=stretch
- $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 wallpaper= wallpaper=/etc/alternatives/desktop-background
- $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 side_pane_mode= side_pane_mode=1
- $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 desktop_shadow= desktop_shadow=#000000
- $p replaceLineOrAdd /opt/ltsp/armhf/etc/xdg/pcmanfm/LXDE-pi/$2 desktop_fg= desktop_fg=#ffffff
- else
- $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 wallpaper_mode= wallpaper_mode=stretch
- $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 wallpaper= wallpaper=/etc/alternatives/desktop-background
- $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 side_pane_mode= side_pane_mode=1
- $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 desktop_shadow= desktop_shadow=#000000
- $p replaceLineOrAdd /home/$3/.config/pcmanfm/LXDE-pi/$2 desktop_fg= desktop_fg=#ffffff
- fi
- }
- CheckRaspberryPiUIModsAllUsers(){
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user #Gets all users
- do
- if [ -f "/home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf" ]; then
- FixUIConfigFile "User" "pcmanfm.conf" $user
- FixUIConfigFile "User" "desktop-items-0.conf" $user
- #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf wallpaper_mode= wallpaper_mode=stretch
- #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf wallpaper= wallpaper=/etc/alternatives/desktop-background
- #$p replaceLineOrAdd /home/$user/.config/pcmanfm/LXDE-pi/desktop-items-0.conf side_pane_mode= side_pane_mode=1
- fi
- done
- $p resetThemeCacheForAllUsers
- }
- InstallRaspberryPiUIMods(){
- #Fixes the mistakes made in the wallpaper setting of RaspberryPi-UI-Mods
- #ltsp-chroot apt-get update
- #ltsp-chroot apt-get -o Dpkg::Options::="--force-confnew" install -y raspberrypi-ui-mods
- FixUIConfigFile "System" "pcmanfm.conf"
- FixUIConfigFile "System" "desktop-items-0.conf"
- CheckRaspberryPiUIModsAllUsers
- }
- ChooseReleaseChannelOld(){
- 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
- if [ $? -eq 0 ]; then
- UpdateConfig ReleaseChannel "Stable"
- else
- UpdateConfig ReleaseChannel "Dev"
- fi
- SetupRepositories
- if [ $1 = "Restart" ]; then
- exec /bin/bash pinet
- exit
- fi
- }
- ChooseReleaseChannel(){
- # Select a release channel (branch) for PiNet to use for software updates etc.
- $p "selectReleaseChannel"
- exitstatus=$(gp)
- SetupRepositories
- if [ $1 = "Restart" ]; then
- if [ "$exitstatus" = "1" ]; then
- # Invalidate previous package version caches to force them to be redownloaded
- rm "/opt/PiNet/pinet-package-versions.txt"
- rm "/opt/PiNet/PiBootBackup/apt_version.txt"
- # If the release channel has changed, restart PiNet software to check for updates etc
- Updater
- else
- Menu
- fi
- else
- Updater "IgnoreAfterUpdate" "$1"
- fi
- }
- GroupCheck(){
- #Checks if all users permissions are correct in groups. Front end for fixGroups
- 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
- fixGroups
- CheckRaspberryPiUIModsAllUsers
- whiptail --title $"Complete" --msgbox $"Tutti i gruppi di utenti sono stati controllati e, se necessario, corretti." 8 78
- }
- CheckForRaspiLTSP(){
- #Checks if Raspi-LTSP is installed and warns the user if it is.
- if [ -f /etc/raspi-ltsp ]; then
- 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
- echo $"file di configurazione di Raspi-LTSP trovato in: /etc/raspi-ltsp"
- exit
- else
- if [ -d /opt/raspiLTSP ]; then
- 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
- echo $"cartella di configurazione di Raspi-LTSP in: /opt/raspiLTSP"
- exit
- fi
- fi
- }
- ImportUsersFromCSV(){
- 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
- if [ $? -eq 0 ]; then
- whiptail --title $"Seleziona CSV" --msgbox $"Perfavore, ora seleziona il tuo file CSV." 9 78
- cd /home/$SUDO_USER
- local fileLoc=$(SingleFileSelect)
- if [ ! fileLoc = "L'utente cancellato :(" ]; then
- 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)
- if [ password = "" ]; then
- whiptail --title $"Errore" --msgbox $"La casella password predefinita non può essere lasciata vuota!" 9 78
- else
- $p importFromCSV $fileLoc $password
- fi
- fi
- fi
- }
- DeleteUsersFromCSV(){
- 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
- if [ $? -eq 0 ]; then
- whiptail --title $"Seleziona CSV" --msgbox $"Seleziona ora il tuo file CSV." 9 78
- cd /home/$SUDO_USER
- fileLoc=$(SingleFileSelect)
- if [ ! fileLoc = "L'utente cancellato :(" ]; then
- $p usersCSVDelete $fileLoc False
- fi
- fi
- }
- CheckInstallSuccess(){
- if [ -d "/opt/ltsp/armhf/debootstrap" ]; then
- 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
- echo $"Potresti voler controllare i log di PiNet per aiutare a diagnosticare il problema. Possono essere trovati su /var/log/pinet.log."
- exit
- else
- $p verifyChrootIntegrity
- fi
- }
- CreatePartitionTable() {
- #Directly borrowed from Spindle - https://github.com/asb/spindle/blob/master/wheezy-stage0
- sudo parted $1 <<EOF
- unit b
- mklabel msdos
- mkpart primary fat32 $(expr 4 \* 1024 \* 1024) $(expr 60 \* 1024 \* 1024 - 1)
- print
- quit
- EOF
- }
- CreateSDCardImageFile(){
- fileName="/tmp/pinet.img"
- dd if=/dev/zero of=$fileName bs=512 count=208845
- create_partition_table $fileName
- sudo mkdosfs -n PINET -S 512 -s 16 -v $fileName
- mkdir /mnt/sdimage
- mount $fileName /mnt/sdimage
- cp -r /home/$SUDO_USER/PiBoot/* /mnt/sdimage/
- umount /mnt/sdimage
- rm -r /mnt/sdimage
- mv $fileName /home/$SUDO_USER/pinetSDImage.img
- }
- CheckPipSymbolicLinkBug(){
- #Checks and fixes the pip3-2 symbolic link bug added in PiNet 1.1.1 and fixed in PiNet 1.1.4
- #if [ ! -h "/opt/ltsp/armhf/usr/bin/pip3" ] || [ ! -f "/opt/ltsp/armhf/usr/bin/pip3" ]; then
- # ltsp-chroot apt-get purge -y python3-pip
- # ltsp-chroot apt-get install -y python3-pip
- # ltsp-chroot --arch armhf ln -sf /usr/bin/pip-3.2 /usr/bin/pip3
- # UpdateConfig NBDBuildNeeded true
- #fi
- echo ""
- }
- CheckDebianVersion(){
- $p checkDebianVersion
- exitstatus=$(gp)
- if [ "$exitstatus" = "1" ]; then
- RebuildOS
- fi
- }
- CheckBackupScriptVersion(){
- if [ -f "/usr/local/bin/pinet-backup.sh" ]; then
- thirdLineCheck="if [ ! \$backupLoc = \"\" ]; then"
- currentThirdLine=$(sed '3q;d' /usr/local/bin/pinet-backup.sh)
- if [ "$thirdLineCheck" == "$currentThirdLine" ]; then
- createBackupScript
- fi
- fi
- }
- DuplicateLTSConf(){
- #Duplicate the lts.conf from /opt/ltsp/armhf/etc/lts.conf to /var/lib/tftpboot/ltsp/armhf/lts.conf
- cp /opt/ltsp/armhf/etc/lts.conf /var/lib/tftpboot/ltsp/armhf/lts.conf
- }
- WheezyJessieUpgradePartTwo(){
- ChooseReleaseChannel "NoRestart"
- exec /bin/bash pinet "Wheezy-upgrade-part-three"
- exit
- }
- WheezyJessieUpgradePartThree(){
- # Delete old pinet-functions-python.py file (has been replaced by pinet_functions_pinet.py and start OS rebuild.
- rm /usr/local/bin/pinet-functions-python.py
- RebuildOS
- $p resetThemeCacheForAllUsers
- #UpdateAll
- }
- GetInternalIPAddress(){
- # Gets the current internal IP address and sets the $IP variable to it.
- $p getInternalIPAddress
- IP=$(gp)
- }
- #***************************************************************************************************
- backupDeleteTime(){
- MENUEPT=$(whiptail --menu $"How long would you like to store backups? Note this only runs when a backup runs." --nocancel 20 85 10 \
- "10 giorni" $"I backup verranno conservati per 10 giorni, quindi cancellati" \
- "30 giorni" $"I backup verranno conservati per 30 giorni, quindi cancellati " \
- "90 giorni" $"I backup saranno conservati per 90 giorni e poi cancellati" \
- "Per Sempre" $"Cancellero i miei backups manualmente" \
- 3>&1 1>&2 2>&3)
- case "$MENUEPT" in
- Ten-Days)
- DELETETIME=10
- ;;
- Thirty-Days)
- DELETETIME=30
- ;;
- Ninety-Days)
- DELETETIME=90
- ;;
- Forever)
- DELETETIME=9999
- ;;
- *)
- removeAnacronLines
- rm -rf /usr/local/bin/pinet-backup.sh
- Menu
- ;;
- esac
- }
- #***************************************************************************************************
- backupFrequency(){
- MENUEPT=$(whiptail --menu $"How often should PiNet create a backup?" --nocancel 20 85 10 \
- "Every-day" $"Will create a new backup every day" \
- "Twice-weekly" $"Will create a backup on Tuesday and Thursday" \
- "Once-a-week" $"Will create a backup every Friday" \
- 3>&1 1>&2 2>&3)
- case "$MENUEPT" in
- Every-day)
- removeAnacronLines
- echo "1 15 PiNet.backup1 /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
- ;;
- Twice-weekly)
- removeAnacronLines
- echo "3 15 PiNet.backup1 /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
- ;;
- Once-a-week)
- removeAnacronLines
- echo "1 15 PiNet.backup1 /bin/sh /usr/local/bin/pinet-backup.sh" >> /etc/anacrontab
- ;;
- *)
- removeAnacronLines
- rm -rf /usr/local/bin/pinet-backup.sh
- Menu
- ;;
- esac
- }
- #***************************************************************************************************
- OtherMenu() {
- #
- #
- #
- #
- #
- #
- # BRUH, 24/4/2019
- #
- #
- #
- #
- MENUEPT=$(whiptail --title $"Other Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 85 10 \
- "Refresh-System" $"Refreshes network services. Useful if having boot issues" \
- "Custom-config" $"Customise the config.txt file on the SD cards." \
- "NBD-recompress" $"Force an NBD compress if changes are made outside PiNet" \
- "NBD-compress-disable" $"Disable auto NBD recompression after every change" \
- "NBD-compress-enable" $"Enable auto NBD recompression after every change (default)" \
- "Export-users" $"Export all user data for migrating to new PiNet server" \
- "Change-release-channel" $"Change your current update channel to dev or stable" \
- "Edit-Information" $"Edit information attached to the PiNet server" \
- "Full-Install" $"Full install of PiNet server" \
- 3>&1 1>&2 2>&3)
- #<<COMMENT1
- #if [$MENUOPT -eq 0]; then
- case "$MENUEPT" in
- Collect-work)
- CollectWork
- Menu
- ;;
- NBD-compress-disable)
- UpdateConfig NBDuse false
- ConfigFileRead
- Menu
- ;;
- NBD-compress-enable)
- UpdateConfig NBDuse true
- ConfigFileRead
- Menu
- ;;
- Custom-config)
- $p "customConfig"
- ConfigFileRead
- if [ "$NBDBuildNeeded" = "true" ]; then
- NBDRun
- fi
- Menu
- ;;
- NBD-recompress)
- local CurrentNBD=$NBDuse
- UpdateConfig NBDuse true
- NBDRun
- UpdateConfig NBDuse $CurrentNBD
- ConfigFileRead
- Menu
- ;;
- Refresh-System)
- resetAndCleanup
- Menu
- ;;
- Export-users)
- CreateMoveBackup
- Menu
- ;;
- Edit-Information)
- $p "askExtraStatsInfo"
- Menu
- ;;
- Change-release-channel)
- ChooseReleaseChannel "Restart"
- ;;
- Full-Install)
- if [ -d /opt/ltsp/armhf ]; then
- whiptail --title $"Error" --yesno $"An LTSP install has been detected.. Not recommended to continue. Should PiNet continue?" 8 78
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- echo ""
- else
- Menu
- fi
- fi
- FullInstall
- Menu
- ;;
- *)
- Menu
- ;;
- esac
- } #***************************************************************************************************
- SharedFolderMenu() {
- MENUEPT=$(whiptail --title $"Shared folders" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 85 10 \
- "Create-Shared-Folder" $"Create a new shared folder" \
- "Remove-Shared-Folder" $"Remove a shared folder" \
- "Change-Permissions" $"Changes shared folder permissions" \
- "Display-Shared-Folders" $"Display a list of all shared folders" \
- "Add-Teacher" $"Add a new account to the teacher group" \
- 3>&1 1>&2 2>&3)
- case "$MENUEPT" in
- Create-Shared-Folder)
- CreateSharedFoldersDialog
- Menu
- ;;
- Remove-Shared-Folder)
- RemoveSharedFolder
- Menu
- ;;
- Change-Permissions)
- SharedFolderPerm
- Menu
- ;;
- Display-Shared-Folders)
- DisplaySharedFolders
- ;;
- Add-Teacher)
- AddTeacher
- Menu
- ;;
- *)
- Menu
- ;;
- esac
- } #***************************************************************************************************
- EpoptesMenu() {
- 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 \
- "Install-Epoptes" $"Install Epoptes onto the server and Raspberry Pis" \
- "Epoptes-launch" $"Launches Epoptes, it must be installed first though" \
- "Add-Teacher" $"Add a new account to the teacher group" \
- "Remove-epoptes" $"Uninstall Epoptes from the server and Raspberry Pis" \
- 3>&1 1>&2 2>&3)
- case "$MENUEPT" in
- Install-Epoptes)
- checkInternet
- if [ $? -eq 0 ]; then
- 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
- if [ $? -eq 0 ];then
- EpoptesInstaller
- NBDRun
- fi
- else
- whiptail --title $"Error" --msgbox $"No internet connection, unable to proceed..." 8 78
- fi
- Menu
- ;;
- Epoptes-launch)
- EpoptesRun
- Menu
- ;;
- Add-Teacher)
- AddTeacher
- Menu
- ;;
- Remove-epoptes)
- ltsp-chroot --arch armhf apt-get remove -y epoptes-client
- ltsp-chroot --arch armhf apt-get -y autoremove
- NBDRun
- whiptail --title $"Epoptes" --msgbox $"Epoptes has been removed from the pi image" 16 78
- Menu
- ;;
- *)
- Menu
- ;;
- esac
- }
- #***************************************************************************************************
- ##### WIP ##########################
- BackupMenu() {
- MENUEPT=$(whiptail --title $"Backup Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 80 10 \
- "Configure-backup" $"Configure and enable backups. Also use to make changes" \
- "Disable-backup" $"Disables backup daemon, old backups will not be deleted" \
- "Display-Logs" $"Displays logs for the backup daemon, check these regularly!" \
- 3>&1 1>&2 2>&3)
- #<<COMMENT1
- #if [$MENUOPT -eq 0]; then
- case "$MENUEPT" in
- Configure-backup)
- 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
- cd /media
- fileSelect
- exit=$?
- if [ "$exit" = "1" ]; then
- Menu
- else
- $p setConfigParameter backupLoc "$location/"
- backupFrequency
- backupDeleteTime
- createBackupScript
- currentDate=`date +"%d-%m-%y"`
- currentTime=`date +"%H:%M"`
- logger -s "$currentDate $currentTime - Backup configured. Folder chosen is $location" 2>> /var/log/PiNet-backup.log
- 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
- fi
- Menu
- ;;
- Disable-backup)
- rm -rf /usr/local/bin/pinet-backup.sh
- removeAnacronLines
- currentDate=`date +"%d-%m-%y"`
- currentTime=`date +"%H:%M"`
- logger -s "$currentDate $currentTime - Backup disabled from PiNet" 2>> /var/log/PiNet-backup.log
- 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
- Menu
- ;;
- Display-Logs)
- clear
- echo "-------------------"
- echo $"PiNet log file"
- echo "-------------------"
- echo " "
- echo "$(cat /var/log/PiNet-backup.log)"
- echo " "
- echo $"Hit enter to continue"
- read
- Menu
- ;;
- *)
- Menu
- ;;
- esac
- }
- ##### WIP ##########################
- #***************************************************************************************************
- UserGroups() {
- MENUEPT=$(whiptail --title $"Manage-users Submenu" --cancel-button $"Main Menu" --ok-button $"Select" --menu $"What would you like to do?" 20 80 11 \
- "Add-user" $"Add a new Linux user" \
- "Remove-user" $"Remove a Linux user" \
- "Change-password" $"Change password of a user" \
- "Display-users" $"List all the users on the system" \
- "Add-teacher" $"Add user to the staff permission group" \
- "Import-Users" $"Import usernames and passwords from a CSV file" \
- "Delete-Batch" $"Batch delete users from a CSV file" \
- "Change-Sudo" $"Change student sudo permissions. Used for GPIO access" \
- "Group-check" $"Checks all users are in the correct system groups" \
- "Export-users" $"Export all user data for migrating to new PiNet server" \
- 3>&1 1>&2 2>&3)
- case "$MENUEPT" in
- Add-user)
- AddUsers
- Menu
- ;;
- Remove-user)
- RemoveUser
- Menu
- ;;
- Change-password)
- ChangeUserPassword
- Menu
- ;;
- Display-users)
- DisplayUsers
- ;;
- Group-check)
- GroupCheck
- Menu
- ;;
- Add-teacher)
- AddTeacher
- Menu
- ;;
- Import-Users)
- ImportUsersFromCSV
- ;;
- Delete-Batch)
- DeleteUsersFromCSV
- ;;
- Graphics-fix)
- fixGroups
- Menu
- ;;
- Change-Sudo)
- SudoMenu
- if [ "$NBDBuildNeeded" = "true" ]; then
- NBDRun
- fi
- Menu
- ;;
- Remove-Samab-user)
- 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)
- pdbedit -u "$user" -xl
- whiptail --title "Samba" --msgbox 'User has been removed from samba. ' 12 78
- Menu
- ;;
- Export-users)
- CreateMoveBackup
- Menu
- ;;
- *)
- Menu
- ;;
- esac
- } #***************************************************************************************************
- FullInstall(){
- checkInternetDetailed
- if [ $? -eq 0 ]; then
- ConfigFileRead
- if [ "$ImportedUsers" = "" ]; then
- FirstTimeImportUsers
- fi
- if [ "$ReleaseChannel" = "" ]; then
- ChooseReleaseChannel 1
- fi
- $p initialInstallSoftwareList
- 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
- installLTSP #Installs LTSP and other packages required to build an Raspberry Pi OS
- buildClient #Creates config file to build Raspbian with LTSP and builds it
- OneTimeFixes #Runs some one off config changes, these are not repeated at any time later
- #PiConfigFixes #Adds configuration changes to LXDE and installs Raspi artwork
- 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
- FixRepo #Adds additional repositories to the Raspbian build
- AddSoftware #Adds all the custom software on top of a normal Armhf Debian Wheezy build
- RaspiTheme #Installs the PiNet theme which can be seen at login
- FixDesktopIcons #Adds desktop icons
- InstallRaspberryPiUIMods
- EnableNBDswap #Enables NBD swap for if the Pi runs out of RAM, it can use server as RAM using NBD
- UpdateConfig NBD false
- UpdateConfig NBDuse false
- $p installSoftwareFromFile
- DisableSPI
- SudoMenu #Asks the user if they wish to enable Sudo for the pupils
- UpdateSD "NoRecompress" #Runs the IP address selector and builds the SD card image
- addSoundcardDefault
- SetupSharedStandalone
- installKernelUpdater ""
- $p checkKernelFileUpdateWeb
- fixGroups "NoRecompress" #Adds all current users to the correct groups.
- DuplicateLTSConf
- usermod -a -G teacher $SUDO_USER
- LegacyFixes "NoRecompress"
- AddSoftware
- EnableNBD #Enables NBD compression
- resetAndCleanup
- $p triggerInstall
- CheckInstallSuccess
- 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
- else
- whiptail --title "Error" --msgbox "The installation has been cancelled due to a problem accessing key domains used in the installation." 8 78
- echo "The installation has been cancelled due to a problem accessing key domains used in the installation."
- exit 1
- fi
- }
- RebuildOS(){
- checkInternet
- if [ $? -eq 0 ]; then
- rm -rf /opt/ltsp/armhf
- rm -rf /var/lib/tftpboot/ltsp/armhf
- $p initialInstallSoftwareList
- buildClient
- configFixes
- FixRepo
- AddSoftware
- RaspiTheme
- FixDesktopIcons #Adds desktop icons
- InstallRaspberryPiUIMods
- EnableNBDswap
- #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
- $p installSoftwareFromFile
- DisableSPI
- SudoMenu #Asks the user if they wish to enable Sudo for the pupils
- UpdateSD "NoRecompress"
- addSoundcardDefault
- SetupSharedStandalone
- installKernelUpdater ""
- $p checkKernelFileUpdateWeb
- fixGroups "NoRecompress"
- DuplicateLTSConf
- LegacyFixes "NoRecompress"
- AddSoftware
- EnableNBD
- resetAndCleanup
- CheckInstallSuccess
- 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
- else
- whiptail --title $"Error" --msgbox $"No internet connection, unable to proceed..." 8 78
- fi
- }
- Menu() {
- GetInternalIPAddress
- MENUOPT=$(whiptail --title $"PiNet $version Main Menu - $IP" --cancel-button $"Quit" --ok-button $"Select" --menu $"What would you like to do?" 22 80 14 \
- "System-Status" $"Display status of key parts of your PiNet server" \
- "Install-Program" $"Install a new program on the Raspberry Pi's" \
- "Manage-Users" $"Add new users, change passwords and delete users" \
- "Update-All" $"Run an automatic update on server and Raspbian" \
- "Backup-Menu" $"User files backup submenu" \
- "Shared-Folders" $"Manage and create shared folders" \
- "Collect-work" $"Collects students work in a single folder" \
- "Update-SD" $"Update the SD card image. This includes IP address changes" \
- "Rebuild-OS" $"Rebuilds the LTSP Raspberry Pi image from scratch again" \
- "Epoptes-Menu" $"Epoptes classroom management submenu" \
- "Troubleshooter" $"Having issues? Try running the troubleshooter" \
- "Other" $"Other options and utilities for management" \
- "Update-PiNet" $"Forces PiNet to update itself" \
- 3>&1 1>&2 2>&3)
- case "$MENUOPT" in
- System-Status)
- listStatus
- Menu
- ;;
- Update-SD)
- UpdateSD
- if [ $? -eq 0 ]; then
- 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
- fi
- Menu
- ;;
- Install-Program)
- $p installSoftwareList
- Menu
- ;;
- Shared-Folders)
- SharedFolderMenu
- Menu
- ;;
- Rebuild-OS)
- 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
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- RebuildOS
- fi
- Menu
- ;;
- Backup-Menu)
- 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
- BackupMenu
- ;;
- Manage-Users)
- UserGroups
- Menu
- ;;
- Install-Epoptes)
- EpoptesInstaller
- Menu
- ;;
- Update-All)
- UpdateAll
- Menu
- ;;
- Epoptes-Menu)
- EpoptesMenu
- ;;
- Collect-work)
- CollectWork
- Menu
- ;;
- Other)
- OtherMenu
- ;;
- Troubleshooter)
- TroubleShooter
- Menu
- ;;
- Update-PiNet)
- Updater
- ;;
- *)
- exit
- ;;
- esac
- }
- #************************************* Startup stuff **************************************************************
- if [ "$(id -u)" != "0" ]; then #Check if script is being run as root
- echo $"This script must be run as root" 1>&2
- exit 1
- fi
- if [ ! "$BASH_VERSION" ] ; then #Checks that PiNet is being run using bash and not ash (aka sh)
- 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
- echo $"Please do not run PiNet with sh $0. Please run it with bash using sudo bash $0" 1>&2
- exit 1
- fi
- CheckOS #Checks if running Ubuntu, if not complains a little
- if [ "$SUDO_USER" = "" ]; then
- 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.
- fi
- checkInstallLoc #Checks PiNet is installed in /usr/local/bin. If not offer to move it
- echo $"Starting PiNet - Please wait"
- checkPythonFunctionsInstalled #Checks the supporting Python functions are installed correctly
- CheckForRaspiLTSP
- VerifyPythonPackages
- CheckTerminalSize #Changes the terminal to the minimum size if is too small
- case "$1" in #Checks if PiNet needs to run an update all, usually run after an update when the software is launched by itself
- Update-All)
- UpdateSD
- UpdateAll
- ;;
- SD-card-update)
- UpdateSD
- ;;
- Wheezy-upgrade-part-two)
- WheezyJessieUpgradePartTwo
- ;;
- Wheezy-upgrade-part-three)
- WheezyJessieUpgradePartThree
- ;;
- esac
- if [ ! -d /opt/ltsp/armhf ]; then # Check if PiNet is installed. If not, offer to install
- whiptail --title $"Welcome" --yesno $"Welcome to PiNet. No previous PiNet installation is detected, would you like to run the full PiNet installer? " 8 78
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- UpdateConfig FirstUser $SUDO_USER
- FullInstall
- else
- Menu
- fi
- fi
- ConfigFileRead #Reads the main configuration file (/etc/pinet) and loads all values in as environmental variables
- if [ "$ReleaseChannel" = "" ]; then #Makes sure a release channel is selected, if not asks for one
- ChooseReleaseChannel "Restart"
- fi
- SetupRepositories #Sets up the correct branch variables as selected in ChooseReleaseChannel()
- checkInternet #Checks if PiNet server has a web connection. If so, checks for updates on PiNet, PiNet kernels and PiNet kernel updater
- if [ $? -eq 0 ]; then
- if [ ! "$DisableUpdateChecking" = "true" ]; then
- CheckReleases
- checkKernelFileUpdateWeb
- checkKernelUpdater "NBD"
- fi
- fi
- fixGroups #Verify all groups are set up correctly with correct users
- LegacyFixes #Makes sure all configuration data is correctly configured
- CheckInstallSuccess
- Menu #Runs main menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement