#!/bin/bash # Post-remove script for linux-xanmod-bin # Get kernel version from boot files (since modules may already be removed) kernel_version=$(ls /boot/vmlinuz-*-xanmod1 2>/dev/null | head -n 1 | sed 's|/boot/vmlinuz-||') if [ -z "$kernel_version" ]; then echo "Kernel version could not be determined, cleanup may be incomplete" exit 0 fi echo "Cleaning up after removal of kernel $kernel_version..." kernel_path="/boot/vmlinuz-$kernel_version" # Remove from bootloader first echo "Removing kernel from bootloader..." if command -v grubby >/dev/null 2>&1; then # For RHEL/Fedora/RedOS with grubby if grubby --info="$kernel_path" >/dev/null 2>&1; then echo "Removing kernel entry using grubby..." grubby --remove-kernel="$kernel_path" echo "Kernel removed from bootloader" fi fi # Remove initramfs if it exists initramfs_img="/boot/initramfs-$kernel_version.img" if [ -f "$initramfs_img" ]; then echo "Removing initramfs: $initramfs_img" rm -f "$initramfs_img" fi # Remove kernel image from /boot if it still exists if [ -f "$kernel_path" ]; then echo "Removing kernel image: $kernel_path" rm -f "$kernel_path" fi # Remove System.map if it exists if [ -f "/boot/System.map-$kernel_version" ]; then echo "Removing System.map: /boot/System.map-$kernel_version" rm -f "/boot/System.map-$kernel_version" fi # Update GRUB configuration (for non-BLS systems) if command -v update-grub >/dev/null 2>&1; then echo "Updating GRUB configuration..." update-grub elif command -v grub2-mkconfig >/dev/null 2>&1 && ! command -v grubby >/dev/null 2>&1; then echo "Updating GRUB2 configuration..." grub2-mkconfig -o /boot/grub2/grub.cfg elif command -v grub-mkconfig >/dev/null 2>&1 && ! command -v grubby >/dev/null 2>&1; then echo "Updating GRUB configuration..." grub-mkconfig -o /boot/grub/grub.cfg fi echo "Kernel $kernel_version has been removed." echo "Please ensure you have another kernel installed before rebooting."