#!/bin/sh
#----------------------------------------------------------------------------
# /var/install/deinstall/linux-source-5.15.107 - deinstall script
#
# Creation   :  2021-01-06 dv
# Last update:  2021-03-15 21:02:54 dv
#
# Copyright (c) 2019-2023 the eisfair team, team(at)eisfar(dot)org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------

. /var/install/include/eislib

kernel_version="5.15.107"

# clean up source directory if present
if [ -d "/usr/src/linux-${kernel_version}-eisfair" ]
then
    rm -rf "/usr/src/linux-${kernel_version}-eisfair"

    if [ -L /usr/src/linux ]
    then
        link_path="$(basename $(readlink /usr/src/linux))"

        if [ "${link_path}" = "linux-${kernel_version}-eisfair" ]
        then
            rm -f /usr/src/linux

            next_source_package="$(ls -d /usr/src/linux-*-eisfair* 2> /dev/null |
                sort -rV | head -1)"
            if [ -n "${next_source_package}" ]
            then
                ln -sr "${next_source_package}" /usr/src/linux
            fi
        fi
    fi
fi