#!/usr/bin/env bash

# Update changes
function _5_2_2_2_changes() {
    echo ":: Update 5.2.2-2: A new command line option was added: add page_alloc.shuffle=1"
}

function _5_2_9_6_changes() {
    echo ":: Update 5.2.9-6: Microcode is no longer builtin. See https://wiki.archlinux.org/index.php/Microcode"
}


# Clear Linux patchset fork CTA
function print_fork_cta() {
    echo ":: IMPORTANT NOTICE"
    echo ""
    echo "   Intel has announced that they are shutting the Clear Linux distribution,"
    echo "   which includes the Linux kernel patches that this package relies on."
    echo ""
    echo "   This means that we (JeremyStarTM and yarost12) won't be able to update the"
    echo "   linux-clear package anymore."
    echo ""
    echo "   To avoid this, we have decided to fork the Clear Linux kernel patchset and"
    echo "   want to continue updating it for newer kernel versions. Unfortunately, we"
    echo "   both will not be able to maintain that patchset alone and require help from"
    echo "   others. If you have experience with kernel development and want to help out,"
    echo "   please contribute! If we don't manage to get enough developers on board, we"
    echo "   might need to kill the package, which we definitely want to avoid."
    echo ""
    echo "   You can find the fork here:"
    echo "   https://git.staropensource.de/StarOpenSource/Linux-Tachyon"
    echo ""
    echo "   Thank you for using this package!"
}


# Standard methods
function post_upgrade() {
    local version upgrades=(
        "5.2.2-2"
        "5.2.9-6"
    )
    
    for version in "${upgrades[@]}"; do
        if [[ "$(vercmp "${version}" "$2")" -eq "1" ]]; then
            "_${version//[.-]/_}_changes"
        fi
    done
    
    # Print the fork CTA
    print_fork_cta
}

function post_install() {
    echo ":: Clear Linux bundles a custom command line which must be applied manually on other distributions."
    echo "   This is their default command line:"
    echo "   quiet console=tty0 console=ttyS0,115200n8 cryptomgr.notests initcall_debug"
    echo "   intel_iommu=igfx_off kvm-intel.nested=1 no_timer_check noreplace-smp"
    echo "   page_alloc.shuffle=1 rcupdate.rcu_expedited=1"
    echo "   rootfstype=ext4,btrfs,xfs,f2fs tsc=reliable rw"
    
    # Print the fork CTA
    print_fork_cta
}
