#!/bin/bash
echo "Installing Pi Dashboard software"
echo ""
if [[ $EUID -ne 0 ]]; then 
   echo "FAILED!"
   echo ""
   echo "-----------------------------"
   echo "This script must be run as root!"
   echo "Eg. sudo bash install.sh"
   echo "-----------------------------"
   echo ""
   exit 1
fi
echo "Updating system and installing packages..."
apt-get remove --purge wolfram-engine scratch nuscratch sonic-pi idle3 smartsim java-common minecraft-pi python-minecraftpi python3-minecraftpi libreoffice python3-thonny geany claws-mail bluej greenfoot | debconfg-apt-progress
apt-get autoremove | debconfg-apt-progress
apt-get update > /dev/null | debconfg-apt-progress
apt-get --assume-yes dist-upgrade > /dev/null | debconfg-apt-progress
apt-get --assume-yes install chromium-browser unclutter lxde nginx php-fpm php-curl > /dev/null | debconfg-apt-progress
echo "Creating directories..."
mkdir /home/pi/.config > /dev/null
mkdir /home/pi/.config/lxsession > /dev/null
mkdir /home/pi/.config/lxsession/LXDE > /dev/null
chown -R pi:pi /home/pi/.config > /dev/null
echo "Copying system configuration files..."
cp lxde-autostart /home/pi/.config/lxsession/LXDE/autostart > /dev/null
cp boot-config.txt /boot/config.txt > /dev/null
cp lightdm.conf /etc/lightdm/lightdm.conf > /dev/null
cp nginx-default /etc/nginx/sites-available/default > /dev/null
echo "Copying application files..."
rm /var/www/html/index.nginx-debian.html > /dev/null
cp -R html/* /var/www/html/ > /dev/null
echo "Done!"
echo ""
echo "-----------------------------"
echo "Please reboot the pi"
echo "Eg. sudo reboot now"
echo "-----------------------------"
echo ""
exit 0