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 $"A required system update has been found. The Raspbian operating system will now be recompressed to apply this update."
- NBDRun
- fi
- return
- }
- EnableNBDswap(){
- #Enables NBD swap system. Allows the Raspberry Pis to use NBD partition as swap
- rm /etc/nbd-server/conf.d/swap.conf
- cat <<EOF > /etc/nbd-server/conf.d/swap.conf
- [swap]
- exportname = /tmp/nbd-swap/%s
- prerun = nbdswapd %s
- postrun = rm -f %s
- EOF
- service nbd-server restart
- }
- FixRepo() {
- #Adds the repositories used by Raspbian. The public keys are included
- # Adds PiNet repo
- echo "Adding PiNet repository key."
- echo deb http://apt.pinet.org.uk 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 $"Network technology" --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 $"WARNING" --yesno $"The current submitted folder will be deleted, are you sure?" 8 78
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- rm -rf /home/"$USERHAND"/submitted
- mkdir /home/"$USERHAND"/submitted
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- if [ "$USERHAND" != "" ]; then
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- if groups "$user" | grep -q -E ' pupil(\s|$)'; then
- if [ -d "/home/$user/handin" ]; then
- echo $"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=$?
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- # CANCELLAMI SONO ARRIVATO QUII! 20/4/2019
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- rm -f /opt/ltsp/armhf/etc/sudoers.d/01pupil
- touch /opt/ltsp/armhf/etc/sudoers.d/01pupil
- chmod 440 /opt/ltsp/armhf/etc/sudoers.d/01pupil
- if [ $exitstatus = 0 ]; then
- echo '%pupil ALL=NOPASSWD: ALL' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- fi
- echo '%pupil ALL = NOPASSWD: /sbin/shutdown' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/reboot' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/poweroff' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- echo '%pupil ALL = NOPASSWD: /sbin/halt' >> /opt/ltsp/armhf/etc/sudoers.d/01pupil
- UpdateConfig NBDBuildNeeded true
- }
- fileSelect(){
- #Selects a folder using some BASH/Whiptail trickery
- results=$(whiptail --title $"Current location $(pwd)" --menu $"Select a folder. To select this folder, select ./ and to go up a folder, select ../ " 20 80 10 `for x in $(ls -pa | grep "/"); do echo $x "-"; done` 2>&1 >/dev/tty)
- exitstatus=$?
- if [ "$exitstatus" = "1" ]; then
- echo "The user canceled :( "
- return "1"
- else
- if [ "$results" = "./" ]; then
- location=$(pwd)
- echo $"chosen location is $location"
- else
- cd "$results"
- fileSelect
- fi
- fi
- }
- SingleFileSelect(){
- #Selects a folder using some BASH/Whiptail trickery
- results=$(whiptail --title $"Current location $(pwd)" --menu $"Select a folder. To select this folder, select ./ and to go up a folder, select ../ " 20 80 10 `echo "../ -"; for x in $(ls -p); do echo $x "-"; done` 2>&1 >/dev/tty)
- exitstatus=$?
- if [ "$exitstatus" = "1" ]; then
- echo "The user canceled :("
- return "1"
- else
- if [ -f "$results" ]; then
- location=$(pwd)/$results
- echo "$location"
- else
- cd "$results"
- SingleFileSelect
- fi
- fi
- }
- removeAnacronLines() {
- #Removes anacrontab lines which can cause issues. Used for backup scheduling
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- sed --in-place '/PiNet.backup/d' /etc/anacrontab
- }
- createBackupScript(){
- #Adds the backup script to the system to auto backup user data
- rm -rf /usr/local/bin/pinet-backup.sh
- echo '#!/bin/sh
- version=2
- #PiNet backup utility script
- ConfigFileLoc=/etc/pinet
- ConfigFileRead(){
- if egrep -q -v "^#|^[^ ]*=[^;]*" "$ConfigFileLoc"; then
- # filter the original to a new file
- egrep "^#|^[^ ]*=[^;&]*" "$ConfigFileLoc" > "$configfile_secured"
- ConfigFileLoc="$configfile_secured"
- source "$ConfigFileLoc"
- else
- source "$ConfigFileLoc"
- fi
- #echo config read
- }
- ConfigFileRead
- currentDate=`date +"%d-%m-%y"`
- currentTime=`date +"%H_%M"`
- if [ ! $backupLoc = "" ]; then
- LOCATION=$backupLoc
- if [ -d "$LOCATION" ]; then
- find "$LOCATION" -name "*PiNet-Users-Backup.tar.gz" -ctime +"$DELETETIME" | xargs rm -rf
- tar -zcvf "$LOCATION$currentDate--$currentTime--PiNet-Users-Backup.tar.gz" /home
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- logger -s "$currentDate $currentTime - Backup of users files was successful" 2>> /var/log/PiNet-backup.log
- else
- logger -s "$currentDate $currentTime - Backup failed with tar errorcode $exitstatus" 2>> /var/log/PiNet-backup.log
- fi
- else
- logger -s "$currentDate $currentTime - Backup folder unavailable!" 2>> /var/log/PiNet-backup.log
- fi
- else
- logger -s "$currentDate $currentTime - No backup location specified!" 2>> /var/log/PiNet-backup.log
- fi' >> /usr/local/bin/pinet-backup.sh
- chmod +x /usr/local/bin/pinet-backup.sh
- }
- AddUsers(){
- #Add users to the system. Manually adds the user hash instead of using adduser
- username=$(whiptail --inputbox $"Enter new username" 8 78 $INIT --title $"Username" 3>&1 1>&2 2>&3)
- exitstatus=$?
- if [ "$exitstatus" = "0" ]; then
- password=$(whiptail --inputbox $"Enter new password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
- exitstatus=$?
- if [ "$exitstatus" = "0" ]; then
- egrep "^$username" /etc/passwd >/dev/null
- if [ $? -eq 0 ]; then
- whiptail --title "Error" --msgbox $"Username already exists!" 8 78
- else
- pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
- useradd -m -s /bin/bash -p $pass $username
- [ $? -eq 0 ] && echo $"$username has been added to system!" || echo $"Failed to add a user!"
- fixGroupsSingle $username
- whiptail --title $"Permission level" --yesno $"Is $username a pupil or a teacher? Teachers have a lot more permissions including write access to all shared folders, Epoptes teacher access and the ability to run PiNet control software." --yes-button $"Pupil" --no-button $"Teacher" 8 78 ############
- if [ ! $? -eq 0 ]; then
- AddUserToTeacher $username
- whiptail --title $"Success" --msgbox $"A new teacher user has been added to the system successfully with the name - $username" 8 78
- else
- whiptail --title $"Success" --msgbox $"A new student user has been added to the system successfully with the name - $username" 8 78
- fi
- fi
- whiptail --title $"Another user" --yesno $"Would you like to add another user?" 8 78
- if [ $? -eq 0 ]; then
- AddUsers
- fi
- fi
- fi
- }
- RemoveUser(){
- #Removes user from list
- username=$(SelectUser "to remove.")
- if [ ! $username = 1 ]; then
- whiptail --title $"Are you sure?" --yesno $"Are you sure you want to delete $username and all $username's user files?" 8 78
- if [ $? -eq 0 ]; then
- userdel -rf $username
- whiptail --title $"Successful" --msgbox $"User successfully removed" 8 78
- fi
- fi
- whiptail --title $"Another user" --yesno $"Would you like to delete another user?" 8 78
- if [ $? -eq 0 ]; then
- RemoveUser
- fi
- }
- ChangeUserPassword(){
- #Change a users password
- username=$(SelectUser $"to change the password of.")
- if [ ! $username = 1 ]; then
- password=$(whiptail --inputbox $"Enter the new password" 8 78 $INIT --title $"Password" 3>&1 1>&2 2>&3)
- if ! [ "$password" = "" ]; then
- echo -e "$password\n$password" | passwd $username
- whiptail --title $"Successful" --msgbox $"Password successfully changed" 8 78
- else
- whiptail --title $"Error" --msgbox $"Password not valid" 8 78
- fi
- fi
- whiptail --title $"Another user" --yesno $"Would you like to change another users password?" 8 78
- if [ $? -eq 0 ]; then
- ChangeUserPassword
- fi
- }
- RestoreBackup() { #Currently incomplete
- whiptail --title $"Select backup" --msgbox $"Please select a backup file. They are normally the date, time followed by Raspi-Users-Backup.tar.gz" 8 78
- }
- SelectUser(){
- #Using some BASH/Whiptail magic, builds a list of users, formats it perfectly and hads it to whiptail
- users=$(cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | sort | awk -F':' '{ print $1"\na"}')
- user=$(whiptail --title $"Users" --menu $"Select a user $1" 16 78 5 $users --noitem 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- echo $user
- else
- echo 1
- fi
- }
- TroubleShooter(){
- #PiNet troubleshooter - Needs some more answers built in
- whiptail --title $"Troubleshooter" --msgbox $"Welcome to PiNet troubleshooter. The troubleshooter goes over a few possible issues you may be having with your setup and offers advice. WARNING - This troubleshooter is experimental, feel free to open issue reports at $Repository/issues if you have any additional issues." 16 78
- whiptail --title $"Boot" --yesno $"Have you got as far as your Raspberry Pi starting up?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Login screen" --yesno $"Have you got as far as the login screen displaying?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Login screen" --yesno $"Are you having login issues?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Login" --msgbox $"LDM (login screen) does not handle incorrect passwords very well. If you enter an incorrect set of credentials, it just restarts itself. Don't worry about this.
- If you are unsure about your password, remember you can easily change it in the Manage-users submenu" 16 78
- else
- whiptail --title $"USB drivers" --yesno $"Is your keyboard working?" 8 78
- if [ ! $? -eq 0 ]; then
- whiptail --title $"Kernel misaligned" --msgbox $"9/10 times, this means your kernels are misaligned. Basically there is a kernel on the SD card and as it boots and connects to the PiNet server, it loads the required additional modules (for stuff like USB) from the server. If the server has modules compiled for a more recent kernel, they are misaligned and don't work. To fix this, make sure you are running the most recent version of PiNet, also hit the update-sd option and reflash your SD card to see if that fixes it. If not, a patched set of boot files may not be available yet (they have to be prepared by hand). Best thing you can do is drop support an email and let them know that you are having keyboard/mouse issues. Visit http://pinet.org.uk/articles/support.html" 17 78
- else
- whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
- fi
- fi
- else
- resetAndCleanup
- whiptail --title $"Fixed?" --yesno $"Is it fixed now? I just reset some of the networking services." 8 78
- if [ ! $? -eq 0 ]; then
- whiptail --title $"Connection refused" --yesno $"Are you getting connection refused or connection timed out error?" 8 78
- if [ $? -eq 0 ]; then
- GetInternalIPAddress #Get the current main IP address
- whiptail --title $"Troubleshooter" --msgbox $"This is a common error, it occurs when the IP address of the server on the SD card is incorrect. Insert the SD card into a computer and open the cmdline.txt file. Find NBDRoot= (or NFSRoot=) and make sure the address that follows it is $IP If it isn't, change it so it is. If it is currently 1.1.1.1 the server was unable to get your current address when it created the SD card. If it is a different address, your server may have been assigned a new IP address. It would be a good idea to assign a static IP address to your server. Talk to your technician about this." 16 78
- else
- whiptail --title $"Giving up" --yesno $"Are you getting a number of 'giving up' errors?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Giving up" --msgbox $"This usually means the Raspberry Pi isn't physically connected to the network, check the ethernet cable is correctly plugged in (wifi is not supported) and is connected to your main switch." 16 78
- else
- whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
- fi
- fi
- fi
- fi
- else
- whiptail --title $"SD card" --yesno $"Are you having issues with loading the files onto the SD card?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Partitions" --yesno $"Are you having issues with there being 2-3 partitions on the SD card?" 8 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Formating partitions" --msgbox $"When flashing Raspbian or another Raspberry Pi operating system onto SD cards, a number of partitions are created. PiNet only needs a single partition, the boot partition. This is usually a small (~50mb) partition which is formatted as fat32. If you wish to format the entire SD card (which if you are having issues, you may want to), please refer to the userguide section on formatting SD cards. " 16 78
- else
- whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
- fi
- else
- whiptail --title $"???" --msgbox $"I am not aware of any other issues in this area. Please create a support ticket at $Repository/issues" 8 78
- fi
- fi
- }
- DisplayUsers(){
- #Displays system users onto the terminal
- clear
- local TEACHER=$(cat /etc/group | grep --regex "^teacher:.*" | awk -F: '{print $4}')
- echo "-------------------"
- echo $"Current Linux users"
- echo "-------------------"
- cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1 | while IFS= read -r user
- do
- echo "$user"
- done
- echo "---------------"
- echo $"Current Linux users in the teacher group"
- echo "$TEACHER"
- echo "---------------"
- echo $"Press enter to continue"
- read
- }
- SetupSambaServer(){
- #Unused
- apt-get install samba libpam-smbpass -y
- }
- SetupSambaPi(){
- #Unused
- mkdir /opt/ltsp/armhf/media/school-share
- ReplaceTextLine /opt/ltsp/armhf/etc/lts.conf FSTAB 'FSTAB_0="//server/School-Share /media/school-share cifs guest,uid=1000,iocharset=utf8 0 0"'
- echo "file:///media/school-share School-Share" >>/tmp/.gtk-bookmarks
- CopyToUsers /tmp/.gtk-bookmarks .gtk-bookmarks True False
- rm -rf /tmp/.gtk-bookmarks
- }
- AfterUpdate(){
- #Code run after a successful update on the BASH side, given that most update code is handled via Python
- ConfigFileRead
- whiptail --title $"Update complete" --msgbox $"The update succeeded. PiNet is now up to date on $ReleaseBranch." 8 78
- whiptail --title $"Update-all" --yesno $"After a software update it is recommended you do a system update. This will update all packages to their most recent version and add any new ones added in the update, do you want to?" 9 78
- exitstatus=$?
- if [ $exitstatus = 0 ]; then
- exec /bin/bash pinet Update-All
- exit
- else
- exec /bin/bash pinet
- exit
- fi
- }
- Updater(){
- #Main updater, most of it is handed by updatePiNet on the Python side or by AfterUpdate on BASH side
- $p updatePiNet
- exitstatus=$(gp)
- if [ $exitstatus = 0 ] && [ "$1" = "IgnoreAfterUpdate" ]; then
- if [ ! "$2" = "NoRestart" ]; then
- whiptail --title $"Restarting PiNet" --msgbox $"Restarting PiNet to guarantee is running the correct branch version." 8 78
- exec /bin/bash pinet
- exit
- fi
- else
- if [ $exitstatus = 0 ]; then
- AfterUpdate
- else
- whiptail --title $"Update failed" --msgbox $"The auto update failed. This usually means you aren't connected to the internet" 8 78
- exec /bin/bash pinet
- fi
- fi
- }
- VerifyPythonPackages(){
- #Verify needed Python packages are installed. If not installed, install them.
- $PythonStart -c 'import feedparser' 2>/dev/null || (sudo apt-get install -y python3-feedparser )
- $PythonStart -c 'import requests' 2>/dev/null || (sudo apt-get install -y python3-requests )
- $PythonStart -c 'import netifaces' 2>/dev/null || (sudo apt-get install -y python3-netifaces )
- }
- 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 uses a seperate user system than Linux. It can though share users, but to add a new user to samba you must change your password. You can change it to the exact same thing as it was before and you only need to do this once." 10 78
- whiptail --title "Samaba" --msgbox "Samba users will be able to edit the school-share folder available on all Raspberry Pis. It is not recommended to add students to this." 8 78
- username=$(whiptail --inputbox "Enter the username to add to samaba" 8 78 $INIT --title "Username" 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 "Please enter your password again, it must be correct!" 8 78 $INIT --title "Password" 3>&1 1>&2 2>&3)
- if ! [ "$password" = "" ]; then
- echo -e "$password\n$password" | passwd $username
- whiptail --title "Successful" --msgbox "User added to Samba" 8 78
- else
- whiptail --title "Error" --msgbox "Password not valid" 8 78
- fi
- else
- whiptail --title "Error" --msgbox "Username does not exist!" 8 78
- fi
- else
- whiptail --title "Error" --msgbox "Username isn't valid" 8 78
- fi
- whiptail --title "Another user" --yesno "Would you like to add another Samaba user" 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 $"Update complete" --msgbox $"Updates are complete" 7 78
- else
- whiptail --title $"Error" --msgbox $"No internet connection, unable to update 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 $"Setting up shared folders"
- whiptail --title $"Setting up shared folders" --msgbox $"As this is the first time you are using shared folders, they must be configured. This may take a few minutes." 8 78
- SetupSharedStandalone
- NBDRun
- }
- CreateSharedFolder(){
- #Create a new shared folder on the Raspberry Pis
- mkdir /home/shared/$1
- if [ ! $? -eq 0 ]; then
- whiptail --title $"Error" --msgbox $"The shared folder at /home/shared/$1 could not be created. It may already exist." 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 "Shared-folders" --menu "Select a shared folder $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 $"Create shared folder" --yesno $"Shared folders are accessible on all the Raspberry Pis and appear on the left in the file manager. Would you like to add one?" 8 78
- if [ $? -eq 0 ]; then
- if [ ! -d /home/shared ]; then
- SetupShared
- fi
- CheckSharedFolderIntegrity
- clear
- echo ""
- echo "----------------------"
- echo $"Current shared folders"
- echo "----------------------"
- echo ""
- ls /home/shared -1
- echo ""
- echo $"Hit enter to continue"
- read
- FolderName=$(whiptail --inputbox $"Enter the name of the new shared folder" 8 78 --title $"Shared folder" 3>&1 1>&2 2>&3)
- if [ $? -eq 0 ]; then
- if ! [ "$FolderName" = "" ]; then
- CreateSharedFolder "$FolderName"
- if [ $? -eq 0 ]; then
- whiptail --title $"Pupil write access" --yesno $"Should pupils have read/write access to this shared folder or just read access? (Default read only)" --yes-button $"Read" --no-button $"Read/Write" 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 $"Complete" --msgbox $"The shared folder at /home/shared/$FolderName has been created! To access it reboot your Raspberry Pis." 8 78
- fi
- else
- whiptail --title $"Error" --msgbox $"Folder name can not be blank!" 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 $"Warning!" --yesno $"Warning! If you delete a shared folder, you must reboot all Raspberry Pis currently on as they may get confused. Would you like to continue?" 8 78
- if [ $? -eq 0 ]; then
- toDelete=$(SelectSharedFolder "to remove.")
- if [ ! $toDelete = 1 ]; then
- whiptail --title $"Are you sure?" --yesno $"Are you sure you want to permanently delete /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 $"Success" --msgbox $"The folder /home/shared/$toDelete has been successfully deleted." 8 78
- else
- service bindfs-mount restart
- whiptail --title $"Error" --msgbox $"There was an issue removing the mount from /usr/local/bin/bindfs-mount... Please try again." 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 "to edit.")
- else
- FolderName=$1
- fi
- if [ ! $FolderName = 1 ]; then
- whiptail --title $"Pupil write access" --yesno $"Should $FolderName be Read/Write access for students or read only?" --yes-button $"Read" --no-button $"Read/Write" 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 $"Complete" --msgbox $"Permissions change complete, students now have read/write access 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 $"Complete" --msgbox $"Permissions change complete, students now have read only access in /home/shared/$FolderName" 8 78
- fi
- fi
- }
- DisplaySharedFolders(){
- #List all the shared folders in /home/shared
- clear
- echo ""
- echo "----------------------"
- echo $"Current shared folders"
- echo "----------------------"
- echo ""
- ls /home/shared -1
- echo ""
- echo $"Hit enter to continue"
- 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 $"Invalid shared folder permissions" --msgbox $"Warning - Your shared folder permissions are invalid. This may be because you imported shared folders from a previous system. You must reselect the correct permission level for each folder now." 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 $"WARNING!!" --msgbox $"Debian is no longer officially supported by PiNet! Please use Ubuntu 14.04 or later. Mileage may vary with Debian and PiNet..." 8 78
- else
- whiptail --title $"WARNING!!" --msgbox $"I don't recognise this operating system. Please use Ubuntu 14.04 or later. Mileage will vary greatly with other distributions and no support will be provided." 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 " PiNet System Status"
- echo "---------------------------------------------------"
- echo "Current version - $version"
- echo "Server IP address - $IP"
- echo "---------------------------------------------------"
- echo "Been running version $version since - $(stat -c %y /usr/local/bin/pinet | cut -d ' ' -f1)"
- echo "Piboot folder last updated - $(stat -c %y /home/$SUDO_USER/PiBoot | cut -d ' ' -f1)"
- echo "Last system-wide update (update-all) - $(stat -c %y /var/lib/apt/periodic/update-success-stamp | cut -d ' ' -f1)"
- echo "----------------"
- echo "Hard Drive Usage (may be inaccurate)"
- echo "----------------"
- echo "Total space - $(df -h | sed -n 2p | awk '{print $2}')"
- echo "Used space - $(df -h | sed -n 2p | awk '{print $3}')"
- echo "Free space - $(df -h | sed -n 2p | awk '{print $4}')"
- echo "-----"
- echo "Other"
- echo "-----"
- echo "CPU usage - $CPU%"
- #echo "RAM usage - $(free -tom | grep 'Total:' | awk '{print $4}')MB / $(free -tom | grep 'Total:' | awk '{print $2}')MB"
- echo "Epoptes installed - $EPOPTES"
- echo "Teacher members - $TEACHER"
- echo "-----------------------"
- echo "Current active users"
- echo "-----------------------"
- netstat -tnpa | grep ESTABLISHED.*sshd | awk '{ print $5 " - " $8 } '
- echo ""
- echo "Hit enter to return to the main menu"
- 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 $"Warning" --yesno $"This process is only designed to move user files to a completely fresh Ubuntu install in which PiNet is not installed. Please make sure to verify all user data is imported correctly on the new PiNet server. Visit http://PiNet.org.uk/manage-users/migration.html for full instructions. Are you sure you want to proceed?" 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 $"Complete" --msgbox $"The process is now complete. A zipped file called toMove.tar.gz has been saved in /home/$SUDO_USER/toMove.tar.gz. Please copy this to /home/youruser/toMove.tar.gz on the new server (via a pendrive for example) then run PiNet and select yes when asked about importing users." 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 $"WARNING!!" --yesno $"PiNet may already be installed! It is highly recommended against importing users with a previous PiNet install. You have been warned! Would you like to import them anyway?" 10 78
- if [ $? -eq 0 ]; then
- RestoreMoveBackup
- fi
- else
- RestoreMoveBackup
- fi
- else
- whiptail --title $"Error" --msgbox $"The zipped file of user data can't be found at /home/$SUDO_USER/toMove.tar.gz." 8 78
- fi
- }
- RestoreMoveBackup() {
- #Restore full backup of all users and group data
- whiptail --title $"Warning" --yesno $"Importing should only be performed on a completely fresh Ubuntu install. PiNet or Raspi-LTSP must not already be installed. Make sure to manually check all files have copied correctly. Do you want to proceed?" 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 $"Import failed" --yesno $"The user import has failed, /home/$SUDO_USER/toMove.tar.gz wasn't found? Are you sure you copied it to that location? Would you like to try again?" 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 $"Note" --msgbox $"ScratchGPIO can't be directly installed, each user must install it. A desktop shortcut has been added to each user account called \"Install ScratchGPIO\". Get each student to run this the first time they want to use the 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 $"Importing users" --defaultno --yesno $"Would you like to import user data from a previous PiNet (or Raspi-LTSP) server? This can only be done now on installation. If in doubt, select 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
- }
- 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 $"Error!" --msgbox $"I am sorry, there has been a critical error with pinet. A required library file could not be acquired. PiNet is unable to function without this library. This may be because you are not connected to the internet or there may be another problem. Please manually download the file from http://bit.ly/pinet-fn and copy it to $PythonFunctions. If the issue persists, please contact support at 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 $"An important update is available for the Raspberry Pi kernel files (files on the SD cards). If you upgrade, PiNet will attempt to load these new files onto your SD cards on boot up. This update is highly recommended. You currently are using version $current and the most up to date version is $newVersion. Would you like to proceed with an automatic update of the boot files and your server?" 12 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Auto reboot" --msgbox $"Your Raspberry Pis will attempt to auto update their SD cards (by grabbing the version from the server) on next reboot. They will do this in the background and reboot when the update is complete **without warning**." 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 $"An update for the kernel update program has been detected, this will be applied automatically"
- 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 $"Group-check goes through each user account checking it is assigned the correct groups. It also resets UI configuration. It can take a number of minutes if you have a large amount of users." 9 78
- fixGroups
- CheckRaspberryPiUIModsAllUsers
- whiptail --title $"Complete" --msgbox $"All user groups have been checked and if need be, corrected." 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 found!" --msgbox $"A previous Raspi-LTSP installation has been found! PiNet and Raspi-LTSP can not be installed at the same time! Please reinstall Ubuntu then run PiNet." 9 78
- echo $"Raspi-LTSP configuration file found at /etc/raspi-ltsp"
- exit
- else
- if [ -d /opt/raspiLTSP ]; then
- whiptail --title $"Raspi-LTSP found!" --msgbox $"A previous Raspi-LTSP installation has been found! PiNet and Raspi-LTSP can not be installed at the same time! Please reinstall Ubuntu then run PiNet." 9 78
- echo $"Raspi-LTSP configuration folder found at /opt/raspiLTSP"
- exit
- fi
- fi
- }
- ImportUsersFromCSV(){
- whiptail --title $"Import from CSV" --yesno $"PiNet supports importing users from a CSV file. Many user management systems can export a CSV file with usernames and passwords (or just usernames). The required format is 1st column is username and 2nd coloum is password. If the password column is left blank, a default password you select will be used. Would you like to continue?" 11 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Select CSV" --msgbox $"Please now select your CSV file." 9 78
- cd /home/$SUDO_USER
- local fileLoc=$(SingleFileSelect)
- if [ ! fileLoc = "The user canceled :(" ]; then
- password=$(whiptail --inputbox $"Enter a default password to use if am unable to find one." 8 78 --title $"Password" 3>&1 1>&2 2>&3)
- if [ password = "" ]; then
- whiptail --title $"Error" --msgbox $"Default password box can't be left blank!" 9 78
- else
- $p importFromCSV $fileLoc $password
- fi
- fi
- fi
- }
- DeleteUsersFromCSV(){
- whiptail --title $"Delete from CSV" --yesno $"PiNet supports batch deleting users from a CSV file. The required format is 1st column is username. All other colums are ignored. Would you like to continue?" 11 78
- if [ $? -eq 0 ]; then
- whiptail --title $"Select CSV" --msgbox $"Please now select your CSV file." 9 78
- cd /home/$SUDO_USER
- fileLoc=$(SingleFileSelect)
- if [ ! fileLoc = "The user canceled :(" ]; then
- $p usersCSVDelete $fileLoc False
- fi
- fi
- }
- CheckInstallSuccess(){
- if [ -d "/opt/ltsp/armhf/debootstrap" ]; then
- whiptail --title $"Installation error" --msgbox $"An issue with your PiNet installation has been detected! The Raspbian operating system is missing or failed to install correctly. This most commonly is caused by school internet filters blocking software repositories or the internet connection failing in the middle of installation. At this stage it is highly recommended attempting a full (including Ubuntu) reinstall with if possible, a different internet connection. If that fails, contact support http://pinet.org.uk/articles/support.html" 14 78
- echo $"You may wish to check the PiNet logs to help diagnose the issue. They can be found at /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 \
- "Ten-Days" $"Backups will be kept for 10 days then deleted" \
- "Thirty-Days" $"Backups will be kept for 30 days then deleted" \
- "Ninety-Days" $"Backups will be kept for 90 days then deleted" \
- "Forever" $"I will delete my backups manually" \
- 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() {
- 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