#!/bin/bash
#set -e
###############################################################################
# Author    :   Erik Dubois
# Website   :   https://www.erikdubois.be
# Website   :   https://www.arcolinux.info
# Website   :   https://www.arcolinux.com
# Website   :   https://www.arcolinuxd.com
# Website   :   https://www.arcolinuxb.com
# Website   :   https://www.arcolinuxiso.com
# Website   :   https://www.arcolinuxforum.com
###############################################################################
#
#   DO NOT JUST RUN THIS. EXAMINE AND JUDGE. RUN AT YOUR OWN RISK.
#
###############################################################################

_clean_packages() {
    local _packages_to_remove=(
    gparted
    grsync
    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
    linux-cachyos-zfs
)
    local xx
    # @ does one by one to avoid errors in the entire process
    # * can be used to treat all packages in one command
    for xx in "${_packages_to_remove[@]}"; do pacman -Rsc "$xx" --noconfirm; done
}

_try_v3() {
    local pacman_conf="/etc/pacman.conf"
    local pacman_conf_cachyos="/etc/pacman-more.conf"
    local pacman_conf_path_backup="/etc/pacman.conf.bak"

    if /lib/ld-linux-x86-64.so.2 --help | grep "x86-64-v3 (supported, searched)" > /dev/null; then
        echo "x86-64-v3 is supported"

        sed -i 's/Architecture = auto/#Architecture = auto/' $pacman_conf_cachyos
        sed -i 's/#<disabled_v3>//g' $pacman_conf_cachyos

        echo "backup old config"
        mv $pacman_conf $pacman_conf_path_backup

        echo "CachyOS -v3 Repo changed"
        mv $pacman_conf_cachyos $pacman_conf

    else
        echo "x86-64-v3 is not supported"
    fi

}

_clean_packages
_try_v3
