echo "This script will install everything for your simple DIY Linux tablet."
echo "Warning! I only tested this with Debian 12."

USER=$(whoami)

if [ $USER = "root" ]
then
  echo ""
  echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  echo " !!! Please don't run this script as root! !!!"
  echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  exit 1
fi


echo "The device will auto login with the $USER user."
echo "If prompted, please enter your root password to proceed."

su - root

# Installing DE and a browser
apt install plasma-mobile chromium

# Removing some unnecessary packages
apt remove kdeconnect system-config-printer partitionmanager kwalletmanager zutty
apt autoremove

# Set up autologin
echo "NAutoVTs=1" >> /etc/systemd/logind.conf
mkdir /etc/systemd/system/getty@tty1.service.d
echo "[Service]" >> /etc/systemd/system/getty@tty1.service.d/override.conf
echo "ExecStart=" >> /etc/systemd/system/getty@tty1.service.d/override.conf
echo "ExecStart=-/sbin/agetty --autologin $USER --noclear %I 38400 linux" >> /etc/systemd/system/getty@tty1.service.d/override.conf

# Disabling GRUB timeout to get faster boot times
echo "TIMEOUT=0" >> /etc/default/grub
update-grub

# This enables the on-screen keyboard without touchscreen
KWIN_IM_SHOW_ALWAYS=1

# Get back to the user
exit

# Autostart plasma-mobile after login
echo startplasmamobile >> .xprofile