#!/usr/bin/env bash
# vim:et:ts=2:sts=2:sw=2

# Get absolute repository root (especially when symlinked)
ROOT="$(realpath "$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")")"

# Load accompanying bash library
source "$ROOT/lib/lib.bash"

if [ -n "$HELP" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  say "
  USAGE:
    $(g "${BASH_SOURCE##*/}")

  DESCRIPTION:
    $(g "${BASH_SOURCE##*/}") uninstalls lots of games and drivers
    from the actively booted TechLit system to make a smaller image
"
  exit 1
fi

# Exit now if run as root user
assert-is-user

say "This script will need root access via $(c sudo)"
sudo echo thank you

say "Uninstalling bigger and less-used programs"
run yay --noconfirm -Rs blender linux-firmware-marvell supertuxkart scratch3 scratchjr-desktop-git

say "Reinstalling supertuxkart back (without addons)"
run yay --noconfirm -S supertuxkart

say "Handing off to $(c tl-sys-personalize)..."
run sudo "$ROOT/bin/tl-sys-personalize" "/var/btrfs"

# Unmount system and quiet exit hook
# shellcheck disable=SC2218
cleanup
cleanup() { :; }

say "Rebooting..."
sudo reboot
