#!/bin/bash
#set -e

_clean_files() {
local _files_to_remove=(
  /usr/local/bin/choose-mirror
  /usr/local/bin/prepare-live-desktop.sh
  /usr/local/bin/removeun-online
  /usr/local/share/livecd-sound
)

  local xx
  for xx in "${_files_to_remove[@]}"; do rm -rf "$xx" || true; done
}

_clean_packages() {
local _packages_to_remove=(
  gparted
  grsync
  cachyos-calamares-grub
  cachyos-calamares-systemd
  cachyos-calamares-refind
  cachyos-calamares
  cachyos-calamares-config
  edk2-shell
  boost-libs
  doxygen
  expect
  gpart
  tcpdump
  arch-install-scripts
  squashfs-tools
  extra-cmake-modules
  cmake
  elinks
  yaml-cpp
  syslinux
  clonezilla
  memtest86+
  mkinitcpio-archiso
)

  local _check_nvidia_card="$(chwd --is_nvidia_card | grep -q 'NVIDIA card found!'; echo $?)"
  if [[ "${_check_nvidia_card}" -ne 0 ]]; then
    echo "No NVIDIA card detected. Removing nvidia drivers"
    _packages_to_remove+=(linux-cachyos-lts-nvidia-open nvidia-utils egl-wayland)
  fi

  local xx
  # @ does one by one to avoid errors in the entire process
  # taken from Erik Dubois script
  for xx in "${_packages_to_remove[@]}"; do pacman -Rsnc "$xx" --noconfirm; done
}

_clean_packages
_clean_files

# vim:set ft=bash sw=2 sts=2 et:
