#!/bin/bash
set -e
Version=6.3
Cuda=NO
ZFS=NO
Drivers=AMD
Webmin="webmin-1.998"

if (( $EUID != 0 )); then
   echo -e "\n$(tput setaf 5)This must be run as root. Try 'sudo bash $0'.$(tput setaf 7)\n"
   exit 1
fi
clear

function kernel_check_ {
if [ $Driver="AMD" ]
then
	unamestr=$(uname -r)
	if ! [[ "$unamestr" == '5.4.0-54-generic' ]];
	then
	echo "Linux Kernel version $unamestr:"
	echo "L'installation des Drivers AMD necessite le kernel 5.4.0-54-generic."
	echo ""
	echo "Pour l'installer:"
	echo "sudo apt install linux-image-5.4.0-54-generic linux-headers-5.4.0-54-generic linux-modules-extra-5.4.0-54-generic"
	echo "puis rebootez, maintenez ESC pour activer le menu grub"
	echo "booter sur le kernel 5.4.0-54-generic"
	echo -e "et enfin supprimez les autres kernels et relancez l'installation.\n"
	exit
	fi
fi
}

function print_centered {
     [[ $# == 0 ]] && return 1

     declare -i TERM_COLS="$(tput cols)"
     declare -i str_len="${#1}"
     [[ $str_len -ge $TERM_COLS ]] && {
          echo "$1";
          return 0;
     }

     declare -i filler_len="$(( (TERM_COLS - str_len) / 2 ))"
     [[ $# -ge 2 ]] && ch="${2:0:1}" || ch=" "
     filler=""
     for (( i = 0; i < filler_len; i++ )); do
          filler="${filler}${ch}"
     done

     printf "%s%s%s" "$filler" "$1" "$filler"
     [[ $(( (TERM_COLS - str_len) % 2 )) -ne 0 ]] && printf "%s" "${ch}"
     printf "\n"

     return 0
}

function intro_ {
print_centered "$(tput setaf 5)"
print_centered " ██████╗██╗   ██╗██████╗ ███████╗"
print_centered "██╔════╝██║   ██║██╔══██╗██╔════╝"
print_centered "██║     ██║   ██║██████╔╝█████╗  "
print_centered "██║     ██║   ██║██╔══██╗██╔══╝  "
print_centered "╚██████╗╚██████╔╝██████╔╝███████╗"
print_centered " ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝"
echo -n "$(tput setaf 7)"
print_centered "Cube Server installation script v$Version"
sleep 2
}

function update_ {
if [ -f /home/wareck/.pass2 ]  && [ ! -f /home/wareck/.pass3 ] && [ ! -f /home/wareck/.pass4 ]
then
echo -e "$(tput setaf 10)\nUpdate and install packages:$(tput sgr0)"
sudo apt-get update
echo -e ""
sudo apt-get install lxde lxde-icon-theme -y
echo -e ""
sudo apt-get install samba cifs-utils mdadm git build-essential libtool pkg-config automake autoconf ethtool net-tools openvpn filezilla \
tasksel lzma-dev lzma cmake libuv1-dev libssl-dev msr-tools tightvncserver lm-sensors openssh-server -y
echo -e ""
sudo apt-get install htop pixz pbzip2 pigz btrfs-progs gparted gnome-remote-desktop libcanberra-gtk-module \
ctorrent libcurl4-openssl-dev bison byacc screen libudev-dev libjansson-dev libncurses5-dev libmicrohttpd-dev curl -y
echo -e ""
sudo apt-get install libglib2.0-dev libgtk2.0-dev libsensors4-dev htop vlc locate -y
echo -e ""
if [ $ZFS = "YES" ]
then
sudo apt-get install zfsutils-linux -y
fi
if [ $Cuda = "YES" ]
then
echo -e "$(tput setaf 10)\nInstall Cuda packages:$(tput sgr0)"
sudo apt-get install nvidia-cuda-toolkit -y
echo -e "Done."
fi
fi
}

function decompte_ {
echo -e "$(tput setaf 10)\nReboot in 10 seconds (CRTL+C to abord):$(tput sgr0)"
for i in {10..0}
do
echo -e -n "$i "
sleep 1
done
echo ""
sudo reboot
}

function nvidia_driver_ {
if ! [ -f /home/wareck/.pass1 ]
then
	if [ $Drivers = "NVIDIA" ]
	then
		if ! [ -f /etc/modprobe.d/blacklist-nvidia-nouveau.conf ]
		then
			sudo apt-get install build-essential libglvnd-dev -y
			sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
			sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
			sudo update-initramfs -u
			touch /home/wareck/.pass1
			decompte_
		fi
	fi
	if [ $Drivers = "AMD" ]
	then
	touch ~/.pass1
	fi
fi

if ! [ -f /home/wareck/.pass2 ]
then
sleep 2
case $Drivers in
NVIDIA)
		echo -e "$(tput setaf 10)\nInstall NVIDIA GT710 Drivers 470.$Drivers :$(tput sgr0)"
                cd /home/wareck/
                echo -e "Download MegaDownload:"
                git clone https://github.com/wareck/megadown.git
                sudo cp /home/wareck/megadown/megadown /usr/local/bin/megadown
                sudo rm -r /home/wareck/megadown
                cd /home/wareck
                echo -e ""
                echo -e "Install drivers:"
                sudo apt-get install nvidia-driver-470 -y
                touch /home/wareck/.pass2
                decompte_
;;
AMD)
		echo -e "$(tput setaf 10)\nInstall AMD Drivers :$(tput sgr0)"
                cd /home/wareck
                echo -e ""
                echo -e "Install drivers:"
		wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/amdgpu-install_22.20.50200-1_all.deb -O /home/wareck/Build_Cube/pack/amdgpu-install_22.20.50200-1_all.deb
		wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/linux-firmware.tar.xz
		tar xvfJ linux-firmware.tar.xz
		sudo cp /home/wareck/linux-firmware/amdgpu/* /lib/firmware/amdgpu/
		sudo rm -r -f /home/wareck/linux-firmware /home/wareck/linux-firmware.tar.xz
		sudo apt-get install /home/wareck/Build_Cube/pack/amdgpu-install_22.20.50200-1_all.deb -y
		sudo apt-get update
		sudo amdgpu-install --opencl=legacy --accept-eula -y
		sudo apt-get install ocl-icd-opencl-dev -y
		sudo usermod -a -G video $LOGNAME
		touch /home/wareck/.pass2
;;
*)
echo -e "$(tput setaf 9)Error driver number ! $(tput sgr0)\n"
exit 0
;;
esac
fi
}

function download_packs_ {
if [ ! -f /home/wareck/.pass3 ]
then
echo -e "$(tput setaf 10)\nDownload complement packs:$(tput sgr0)"
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/cgminer.conf -O /home/wareck/Build_Cube/pack/cgminer.conf
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/chia-miner.tar.xz -O /home/wareck/Build_Cube/pack/chia-miner.tar.xz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/gerbera.tar.xz -O /home/wareck/Build_Cube/pack/gerbera.tar.xz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/start_cgminer.tar.xz -O /home/wareck/Build_Cube/pack/start_cgminer.tar.xz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/$Webmin.tar.xz -O /home/wareck/Build_Cube/pack/$Webmin.tar.xz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/xmrig.tar.xz -O /home/wareck/Build_Cube/pack/xmrig.tar.xz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/zfsmanager-0.0.4.wbm.gz -O /home/wareck/Build_Cube/pack/zfsmanager-0.0.4.wbm.gz
wget -c -q --show-progress http://folivier.homelinux.org/cube/pack/gpu-miners.tar.xz -O /home/wareck/Build_Cube/pack/gpu-miners.tar.xz
if [ $Drivers = "AMD" ]
then
cp /home/wareck/Build_Cube/pack/gpu-miners.tar.xz /home/wareck
fi
cp /home/wareck/Build_Cube/pack/pack1.tar.xz /home/wareck
cp /home/wareck/Build_Cube/pack/pack2.tar.xz /home/wareck
cp /home/wareck/Build_Cube/pack/xmrig.tar.xz /home/wareck
cp /home/wareck/Build_Cube/pack/start_cgminer.tar.xz /home/wareck
echo "Done."
if  [ ! -d /home/wareck/$Webmin ]
then
cp /home/wareck/Build_Cube/pack/$Webmin.tar.xz /home/wareck/
cd /home/wareck/
echo -e "$(tput setaf 10)\nWebmin uncompress:$(tput sgr0)"
tar xfJ $Webmin.tar.xz --checkpoint=.100
rm $Webmin.tar.xz
echo -n -e "\n"
echo -e "Done"
fi

echo -e "$(tput setaf 10)\nDownloading miners:$(tput sgr0)"
cd /home/wareck
if ! [ -d miners ]; then mkdir miners;fi

cd /home/wareck/miners
if ! [ -d xmrig ]
then
git clone https://github.com/xmrig/xmrig.git
echo -e ""
fi
if ! [ -d xmr-stak ]
then
git clone https://github.com/fireice-uk/xmr-stak.git
echo -e ""
fi
if ! [ -d xmr-stak-rx ]
then
git clone https://github.com/fireice-uk/xmr-stak.git -b xmr-stak-rx xmr-stak-rx
echo -e ""
fi
if ! [ -d cgminer-gekko ]
then
git clone https://github.com/wareck/cgminer-gekko.git
fi
fi
}

function build_miners_ {
if [ ! -f /home/wareck/.pass3 ]
then
if [ $Drivers = "AMD" ]
then
cd /home/wareck
tar xvfJ gpu-miners.tar.xz
fi
cd /home/wareck/miners
echo -e "$(tput setaf 10)\nBuild Cgminer-gekko:$(tput sgr0)"
cd cgminer-gekko
sudo usermod -a -G dialout,plugdev wareck
sudo cp 01-cgminer.rules /etc/udev/rules.d/
CFLAGS="-O2 -march=native" ./autogen.sh
./configure --enable-gekko
make -j4
tar xvfJ /home/wareck/start_cgminer.tar.xz
rm /home/wareck/start_cgminer.tar.xz
cd ..
cat <<'EOF'>> /tmp/cgminer
#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          cgminer
# Required-Start:    networking
# Default-Start:     3 4 5
# Default-Stop:      0 6
### END INIT INFO
cd /home/wareck/miners/cgminer-gekko/
su wareck -c "screen -dmS cgminer /home/wareck/miners/cgminer-gekko/cgminer"
exit 0
EOF
chmod +x /tmp/cgminer
sudo cp /tmp/cgminer /etc/init.d/cgminer
sudo update-rc.d cgminer defaults
echo "Done."

echo -e "$(tput setaf 10)\nUncompress xmr files:$(tput sgr0)"
tar xfJ /home/wareck/xmrig.tar.xz --checkpoint=.100
echo "Done."
echo -n -e "\n"
echo -e "$(tput setaf 10)\nBuild xmrig:$(tput sgr0)"
cd xmrig
git config --global --add safe.directory /home/wareck/miners/xmrig
git pull
sed -i "s/kDefaultDonateLevel = 5;/kDefaultDonateLevel = 0;/g" src/donate.h
sed -i "s/kMinimumDonateLevel = 1;/kMinimumDonateLevel = 0;/g" src/donate.h
wget -c https://download.open-mpi.org/release/hwloc/v2.7/hwloc-2.7.1.tar.bz2
tar xfj hwloc-2.7.1.tar.bz2 --checkpoint=.100
cd hwloc-2.7.1
./configure
make -j4
sudo make install
cd ..
sudo ldconfig
cd build
cmake ..
make -j4
cd ..
cd ..
echo "Done."
echo -e "$(tput setaf 10)\nBuild xmrig-upx:$(tput sgr0)"
cd xmrig-upx
git config --global --add safe.directory /home/wareck/miners/xmrig-upx
git pull
sed -i "s/kDefaultDonateLevel = 5;/kDefaultDonateLevel = 0;/g" src/donate.h
sed -i "s/kMinimumDonateLevel = 1;/kMinimumDonateLevel = 0;/g" src/donate.h
cd build
cmake .. -DWITH_HTTPD=OFF
make -j4
cd ..
cd ..
echo "Done."
echo -e "$(tput setaf 10)\nBuild xmr-stak-rx:$(tput sgr0)"
cd xmr-stak-rx
git config --global --add safe.directory /home/wareck/miners/xmr-stak-rx
git pull
cd build
cmake ..
make -j4
cd ..
cd ..
echo "Done."
echo -e "$(tput setaf 10)\nBuild xmr-stak:$(tput sgr0)"
cd xmr-stak
if ! [ -d build ];then mkdir build ;fi
git config --global --add safe.directory /home/wareck/miners/xmr-stak
git pull
cd build
if [ $Drivers = "AMD" ]
then
cmake .. -DCUDA_ENABLE=OFF
else
cmake .. -DOpenCL_ENABLE=OFF -DCUDA_ENABLE=OFF
fi
make -j4
cd ..
cd ..
echo "Done."

if [ $Cuda = "YES" ]
then
echo -e "$(tput setaf 10)\nBuild xmrig-cuda:$(tput sgr0)"
sudo apt-get install git build-essential cmake libuv1-dev nvidia-cuda-dev nvidia-cuda-toolkit libmicrohttpd-dev gcc-8 g++-8
git clone https://github.com/xmrig/xmrig-nvidia.git
cd xmrig-nvidia
mkdir build
cd build
cmake .. -DCMAKE_C_COMPILER=$(which gcc-8) -DCMAKE_CXX_COMPILER=$(which g++-8)
make -j4
fi

echo "Done"
touch /home/wareck/.pass3
fi
}

function configure_ {
if [ ! -f /home/wareck/.pass4 ]
then
echo -e "$(tput setaf 10)\nlxPanel sensors:$(tput sgr0)"
cd /home/wareck
if ! [ -d sensors-lxpanel-plugin ]
then
git clone https://github.com/danamlund/sensors-lxpanel-plugin.git
fi
cd /home/wareck
cd sensors-lxpanel-plugin
make
sudo make install
sudo rm -r /home/wareck/sensors-lxpanel-plugin
echo "Done."

echo -e "$(tput setaf 10)\nConfig files:$(tput sgr0)"
cd /home/wareck/
su wareck -c 'gsettings set org.gnome.desktop.background picture-uri /home/wareck/Images/mr-robot-wallpapers.jpg'
su wareck -c 'gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 32'
#su wareck -c 'gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts false'
sleep 0.5
sudo rm -r -f /etc/update-motd.d/*
tar xfJ pack1.tar.xz --checkpoint=.10
echo -n -e "\n"
sudo cp /home/wareck/pack2.tar.xz /
cd /
sudo tar xfJ pack2.tar.xz --checkpoint=.10
echo -n -e "\n"
cd /home/wareck

#clear
dynmotd

sudo sed -i -e "s/# set constantshow/set constantshow/g" /etc/nanorc

if ! grep "wareck" /etc/sudoers >/dev/null
then
sudo sh -c "echo \"wareck ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
fi

echo -e "$(tput setaf 10)\nBuild folder and mount drives:$(tput sgr0)"
if ! [ -r /media/Backup ];then sudo mkdir /media/Backup && cd / & sudo ln -s /media/Backup /Backup ;fi
if ! [ -r /media/Store ];then sudo mkdir /media/Store && cd / & sudo ln -s /media/Store /Store;fi
if ! [ -r /media/Partage ];then sudo mkdir /media/Partage && cd / & sudo ln -s /media/Partage /Partage;fi
if ! [ -r /media/Nas ];then sudo mkdir /media/Nas && cd / & sudo ln -s /media/Nas /Nas;fi
if ! [ -r /media/Chia ];then sudo mkdir /media/Chia && cd / & sudo ln -s /media/Chia /Chia;fi
if ! [ -r /media/Nvme ];then sudo mkdir /media/Nvme && cd / & sudo ln -s /media/Nvme /Nvme ;fi
if ! grep "UUID=UUID=1df72b63-fca0-45c6-992c-3e2532d5591a /media/Store ext4" /etc/fstab >/dev/null
then
cp /etc/fstab /tmp/fstab
cat <<"EOF">> /tmp/fstab
#ext4
UUID=9c449ef0-1008-422c-9105-87342e9c9072 /media/Backup ext4
UUID=1df72b63-fca0-45c6-992c-3e2532d5591a /media/Store ext4
UUID=9a837a47-aa05-4ca5-a2e1-2838e53bb9b7 /media/Partage ext4
#btrfs
UUID=d1bef3f1-a806-4498-9294-c266e84fd1ef /media/Nvme btrfs ssd,nodatacow,noatime
#external drive
#UUID=5C8687930F62EE79 /media/Chia ntfs auto,nofail,noatime,rw,user    0   0
UUID=66be44f6-f8e9-473c-9b71-db849f870099 /media/Chia ext4 auto,nofail,noatime,rw,user    0   0
EOF
sudo cp /tmp/fstab /etc/fstab
fi
echo "Done."

echo -e "$(tput setaf 10)\nSensors drivers:$(tput sgr0)"
if ! grep "nct6775" /etc/modules >/dev/null
then
cp /etc/modules /tmp/modules
cat <<"EOF">> /tmp/modules

# Chip drivers
nct6775
EOF
sudo cp /tmp/modules /etc/modules
fi
echo "Done."

echo -e "$(tput setaf 10)\nVnc init:$(tput sgr0)"
sudo update-rc.d vncserver defaults
echo "Done."

echo -e "$(tput setaf 10)\nOpening ports:$(tput sgr0)"
sudo ufw allow 8333 >/dev/null
sudo ufw allow 22 >/dev/null
sudo ufw allow 5900 >/dev/null
sudo ufw allow 10000 >/dev/null
sudo ufw allow 139 >/dev/null
sudo ufw allow 5901 >/dev/null
sudo ufw allow 5902 >/dev/null
sudo ufw allow 445 >/dev/null
echo "Done."

echo -e "$(tput setaf 10)\nBashrc mod:$(tput sgr0)"
if ! grep "#mod for tightvncserver" /home/wareck/.bashrc
then
echo "#mod for tightvncserver" >>/home/wareck/.bashrc
echo "cd ~" >>/home/wareck/.bashrc
fi
echo "Done."

echo -e "$(tput setaf 10)\nDisable IPv6:$(tput sgr0)"
if ! grep "ipv6.disable=1" /etc/default/grub >/dev/null
then
sed -i -e "s/quiet splash/quiet splash ipv6.disable=1/g" /etc/default/grub
sed -i -e "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"ipv6.disable=1/g" /etc/default/grub
sudo update-grub2
fi
sudo chown -R wareck:wareck /home/wareck/miners/xmr*
sudo chown -R wareck:wareck /home/wareck/miners/cgminer*
sudo apt-get remove light-locker* -y
if [ ! -d /home/wareck/.config/lxpanel/LXDE/panels ]
then
mkdir /home/wareck/.config/lxpanel
mkdir /home/wareck/.config/lxpanel/LXDE
mkdir /home/wareck/.config/lxpanel/LXDE/panels
fi
sudo cp /home/wareck/Build_Cube/pack/panel /home/wareck/.config/lxpanel/LXDE/panels/panel
sudo chmod 777 /home/wareck/.config/lxpanel/LXDE/panels/panel
if [ ! -d  /home/wareck/.config/lxterminal ]
then
mkdir /home/wareck/.config/lxterminal
fi
sudo cp /home/wareck/Build_Cube/pack/lxterminal.conf /home/wareck/.config/lxterminal/
sudo chmod 777 /home/wareck/.config/lxterminal/lxterminal.conf

echo "Done."
touch /home/wareck/.pass4
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 32
sleep 0.5
gsettings set org.gnome.desktop.background picture-uri /home/wareck/Images/mr-robot-wallpapers.jpg
sleep 0.5
#su wareck -c 'gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts false'
#sleep 0.5
decompte_
fi
}

function printer_ {
if [ ! -f /home/wareck/.pass3 ]
then
if [ ! -d /usr/local/share/foomatic/ ]
then
if [ ! -d /tmp/foomatic-db/ ]
then
cd /tmp/
echo -e "$(tput setaf 10)\nPrinter Drivers$(tput sgr0)"
git clone https://github.com/OpenPrinting/foomatic-db.git
fi
cd /tmp/foomatic-db
if [ ! -d /usr/local/share/foomatic/ ]
then
./make_configure
./configure
sudo make install
echo "Done."
fi
fi
fi
}

function mounting_drives_ {
if [ ! -f /home/wareck/.pass4 ]
then
echo -e "$(tput setaf 10)\nMounting Drives$(tput sgr0)"
if [ $ZFS = "YES" ]
then
if findmnt /media/Backup/ >/dev/null 2>&1
then
sudo zpool export Backup
else
sudo zpool import Backup
fi
fi
if ! findmnt /media/Partage >/dev/null ; then sudo mount /media/Partage ;fi
if ! findmnt /media/Store >/dev/null ; then sudo mount /media/Store ;fi
sudo chmod 777 /media/Store
sudo chmod 777 /media/Partage
sudo chmod 777 /media/nvme
sudo chmod 777 /media/Nas
echo "Done."
fi
}

function cleaning_ {
if [ -f /home/wareck/.pass4 ]
then
echo -e "$(tput setaf 10)\nCleaning install files:$(tput sgr0)"
if [ -f /pack2.tar.xz ]; then sudo rm /pack2.tar.xz ;fi
if [ -f /home/wareck/pack1.tar.xz ]; then rm /home/wareck/pack1.tar.xz ;fi
if [ -f /home/wareck/pack2.tar.xz ]; then rm /home/wareck/pack2.tar.xz ;fi
if [ -f /home/wareck/xmrig.tar.xz ]; then rm /home/wareck/xmrig.tar.xz ;fi
if [ -f /home/wareck/gpu-miners.tar.xz ]; then rm /home/wareck/gpu-miners.tar.xz;fi
if [ -r /home/wareck/Music ]; then sudo rm -r -f /home/wareck/Music ;fi
if [ -r /home/wareck/Public ]; then sudo rm -r -f /home/wareck/Public ;fi
if [ -r /home/wareck/Templates ]; then sudo rm -r -f /home/wareck/Templates ;fi
if [ -r /home/wareck/Vidéos ]; then sudo rm -r -f /home/wareck/Vidéos ;fi
if [ -f /home/wareck/NVIDIA-Linux-x86_64-470.74.run ]; then rm /home/wareck/NVIDIA-Linux-x86_64-470.74.run ;fi
if [ -f /home/wareck/NVIDIA-Linux-x86_64-470.82.00.run ]; then rm /home/wareck/NVIDIA-Linux-x86_64-470.82.00.run ;fi
if [ -f /home/wareck/.pass1 ]; then rm /home/wareck/.pass1 ;fi
if [ -f /home/wareck/.pass2 ]; then rm /home/wareck/.pass2 ;fi
if [ -f /home/wareck/.pass3 ]; then rm /home/wareck/.pass3 ;fi
if [ -f /home/wareck/.pass4 ]; then rm /home/wareck/.pass4 ;fi
if [ -f /home/wareck/.config/autostart/install_os.desktop ];then sudo rm /home/wareck/.config/autostart/install_os.desktop;fi
cd /home/wareck/Build_Cube/pack
./clean.sh
echo -e "Done. \n"
echo `date` "install/update" >/home/wareck/.buildcube
fi
sudo apt-get autoremove -y
sleep 1
}

function autoroot_ {
if [ ! -d /home/wareck/.config/autostart ]
then
echo -e "$(tput setaf 10)\nInit install & autostart:$(tput sgr0)"
mkdir /home/wareck/.config/autostart
echo -e "Done."
fi

if [ ! -f /home/wareck/.config/autostart/install_os.desktop ]
then
cat <<'EOF'>> /home/wareck/.config/autostart/install_os.desktop
[Desktop Entry]
# VERSION=3.36.2
Name=Terminal
Comment=Use the command line
Keywords=shell;prompt;command;commandline;cmd;
TryExec=gnome-terminal
Exec=gnome-terminal -- bash -c "sudo /home/wareck/Build_Cube/build_cube.sh; exec bash"
Icon=org.gnome.Terminal
Type=Application
Categories=GNOME;GTK;System;TerminalEmulator;
StartupNotify=true
X-GNOME-SingleWindow=false
OnlyShowIn=GNOME;Unity;
Actions=new-window;preferences;
X-Ubuntu-Gettext-Domain=gnome-terminal

[Desktop Action new-window]
Name=New Window
Exec=gnome-terminal --window

[Desktop Action preferences]
Name=Preferences
Exec=gnome-terminal --preferences
EOF
chmod +x /home/wareck/.config/autostart/install_os.desktop
fi
if ! grep "wareck" /etc/sudoers >/dev/null
then
sudo sh -c "echo \"wareck ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
fi
}

intro_
kernel_check_
autoroot_
nvidia_driver_
update_
download_packs_
printer_
build_miners_
configure_
mounting_drives_
cleaning_
clear
dynmotd

echo -e "$(tput setaf 10)\nEnd of script:$(tput sgr0) \n"
echo -e "$(tput setaf 7)Need to install webmin manually (reboot required)$(tput sgr0)"
echo -e "$(tput setaf 7)Need to start tightvncserver manually $(tput sgr0)"
echo -e "$(tput setaf 7)after install webmin, reboot is required for raid drive$(tput sgr0)"
echo -e ""
