]> git.ipfire.org Git - people/arne_f/kernel-updater.git/commitdiff
Implement uninstall action 20190621
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jun 2019 15:18:38 +0000 (17:18 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jun 2019 15:18:38 +0000 (17:18 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/kernel-updater.in

index 1e4f7b8986610fd435bbeba2fa11cdefca9a7d78..9ce96b7a777b527798cafe2314b023cf3ee25c44 100644 (file)
@@ -25,6 +25,8 @@ PACKAGE_VERSION="@PACKAGE_VERSION@"
 GRUB_CFG="/boot/grub/grub.cfg"
 MODULES_PATH="/lib/modules"
 
+RUNNING_VERSION="$(uname -r)"
+
 update_bootloader() {
        # GRUB
        if [ -e "${GRUB_CFG}" ]; then
@@ -70,6 +72,24 @@ do_install() {
        return 0
 }
 
+do_uninstall() {
+       local version="${1}"
+
+       # Check if we are removing the running kernel
+       if [ "${version}" = "${RUNNING_VERSION}" ]; then
+               echo "You cannot remove the currently running kernel ${RUNNING_VERSION}" >&2
+               return 1
+       fi
+
+       # Remove initramfs
+       rm -f "/boot/initramfs-${version}.img"
+
+       # Update the bootloader configuration
+       update_bootloader || return $?
+
+       return 0
+}
+
 check_version() {
        local version="${1}"
 
@@ -86,7 +106,7 @@ main() {
        shift 2
 
        if [ -z "${version}" ]; then
-               version="$(uname -r)"
+               version="${RUNNING_VERSION}"
        fi
 
        case "${action}" in
@@ -94,6 +114,10 @@ main() {
                        do_install "${version}" || return $?
                        ;;
 
+               uninstall)
+                       do_uninstall "${version}" || return $?
+                       ;;
+
                version)
                        echo "${PACKAGE_NAME}: Version ${PACKAGE_VERSION}"
                        return 0