#!/bin/bash

if [ "$(id -u)" != "0" ]; then
  echo "This script must be run as root" 1>&2
  exit 1
fi
clear;
echo "Neptune Upgrade Script";
echo "-----------------------------";
echo "This will upgrade Neptune 5.x to Neptune 6."; 
echo -e "\033[1mPlease make sure to have a working internet connection, enough free space and a plugged in power cord on your laptop\033[0m"; 
echo ""; 
echo "Press any key to continue or CTRL+C to abort" ; 
read FOO
echo "Upgrade process starts...";

export DEBIAN_FRONTEND=noninteractive

# Create Backup in case anything goes wrong
find /etc/apt/sources.list.d/ -exec cp {}{,.bak} \;
cp /etc/apt/sources.list{,.bak}

sed -i -e "s/stretch/buster/" /etc/apt/sources.list.d/*.list /etc/apt/sources.list

apt update
apt -y -f -o Dpkg::Options::="--force-confnew" install neptune-sourceslist
apt update
apt -y install plasma-desktop plasma-workspace -o Dpkg::Options::="--force-overwrite"

apt update
# Downgrade X-Server packages to the buster version which are identical but with lower verison number
apt -y install xserver-xorg-video-intel=2:2.99.917+git20180925-2 xserver-xorg-video-nouveau=1:1.0.15-3 xserver-xorg-video-ati=1:18.1.0-1 xserver-xorg-video-radeon=1:18.1.0-1
apt update
# Downgrade sddm
apt -y install sddm=0.18.0-1

apt update
# Run the full upgrade hopefully without any issue
apt -y -f -o Dpkg::Options::="--force-overwrite" -o Dpkg::Options::="--force-confnew" full-upgrade


echo " ";
echo "Upgrade finished. Please reboot.";






#----PROBLEMS----
#dpkg: error processing archive /tmp/apt-dpkg-install-um2lwV/116-libkf5screen-bin_4%3a5.14.5-1_amd64.deb (--unpack):
# trying to overwrite '/usr/lib/x86_64-linux-gnu/libexec/kf5/kscreen_backend_launcher', which is also in package libkf5screen7 4:5.12.0-0neon+neptune1
#
#dpkg: error processing archive /tmp/apt-dpkg-install-um2lwV/100-breeze_4%3a5.14.5-1_amd64.deb (--unpack):
# trying to overwrite '/usr/share/metainfo/org.kde.breezedark.desktop.appdata.xml', which is also in package plasma-look-and-feel-org-kde-breezedark-desktop 4:5.12.4-0neon+neptune1
