#!/bin/bash
foxy=$(systemctl show -p ActiveState foxypool.service | sed 's/ActiveState=//g')
if [ $foxy = "active" ]
then
echo "FoxyPool is enabled and running"
echo "Disable FoxyPool (needed for update cuda)"
sudo systemctl stop foxypool.service
sudo systemctl disable foxypool.service
touch .foxy
fi

if [ ! -f /home/wareck/.cuda_install ]
then
if [ ! -f cuda_12.8.1_570.124.06_linux.run ]
then
#wget -c https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run
#wget -c https://developer.download.nvidia.com/compute/cuda/12.6.0/local_installers/cuda_12.6.0_560.28.03_linux.run
wget -c https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_570.124.06_linux.run
fi
#chmod +x cuda_12.4.1_550.54.15_linux.run
#chmod +x cuda_12.6.0_560.28.03_linux.run
chmod +x cuda_12.8.1_570.124.06_linux.run
sudo service lightdm stop
touch /home/wareck/.cuda_install
sudo init 3
fi
echo "Updating ..."
sudo rm /tmp/.X1-lock
#sudo ./cuda_12.4.1_550.54.15_linux.run --silent --driver
#sudo ./cuda_12.6.0_560.28.03_linux.run --silent --driver
sudo ./cuda_12.8.1_570.124.06_linux.run --silent --driver
sudo rm /home/wareck/.cuda_install

if [ -f .foxy ]
then
echo "Re-enable FoxyPool:"
sudo systemctl start foxypool.service
sudo systemctl enable foxypool.service
rm .foxy
fi
echo "Done."