void-minecraft-usb/kernel.d/post-install/99-void-usb

60 lines
2.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
#
# Kernel post-install hook for Void-USB
# This script generates the symlinks for default /boot/{vmlinuz,initramfs}.
# It also re-generates the GRUB config.
#
# Arguments: $1 package name, $2 kernel version
PKGNAME="$1"
VERSION="$2"
echo "Updating default kernel and initramfs symlinks..."
#####################
# Delete old symlinks
#####################
OLD_LINUX=/boot/vmlinu?
if [ ! -f "$OLD_LINUX" ]; then
# in cases where its a .gz or .xz or whatever
OLD_LINUX=$(find /boot -type l -name "vmlinu*" 2>/dev/null | sort | head -n1)
fi
[ -f "$OLD_LINUX" ] && rm "$OLD_LINUX"
OLD_INITRAMFS=/boot/initramfs.img
if [ ! -f "$OLD_INITRAMFS" ]; then
# hope to find anything named initramfs or initrd
OLD_INITRAMFS=$(find /boot -type l -name "init*" 2>/dev/null | sort | head -n1)
fi
[ -f "$OLD_INITRAMFS" ] && rm "$OLD_INITRAMFS"
#####################
# Create new symlinks
#####################
NEW_LINUX_FILE="$(find /boot -name "*$VERSION*" 2>/dev/null | sed 's|^/boot/||' | grep -e '^vmlinu' -e '^linux' -e '^linuz' -e '^kernel')"
NEW_LINUX_SYMLINK="vmlinuz"
if grep -e '^vmlinux' -e '^linux' -e '^kernel' >/dev/null 2>&1 <<< "$NEW_LINUX_FILE"; then
NEW_LINUX_SYMLINK="vmlinux"
fi
if grep -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" >/dev/null 2>&1 <<< "$NEW_LINUX_FILE"; then
NEW_LINUX_SYMLINK="$NEW_LINUX_SYMLINK$(grep -o -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" 2>/dev/null <<< "$NEW_LINUX_FILE")"
fi
ln -s "$NEW_LINUX_FILE" "/boot/$NEW_LINUX_SYMLINK"
NEW_INITRAMFS_FILE="$(find /boot -name "init*$VERSION*" 2>/dev/null | sed 's|^/boot/||')"
NEW_INITRAMFS_SYMLINK="initramfs"
if grep '^initrd' >/dev/null 2>&1 <<< "$NEW_INITRAMFS_FILE"; then
NEW_INITRAMFS_SYMLINK="initrd"
fi
if grep -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" >/dev/null 2>&1 <<< "$NEW_INITRAMFS_FILE"; then
NEW_INITRAMFS_SYMLINK="$NEW_INITRAMFS_SYMLINK$(grep -o -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" 2>/dev/null <<< "$NEW_INITRAMFS_FILE")"
fi
ln -s "$NEW_INITRAMFS_FILE" "/boot/$NEW_INITRAMFS_SYMLINK"
echo "Default kernel and initramfs are now: $NEW_LINUX_FILE, $NEW_INITRAMFS_FILE"
####################
# Update GRUB config
####################
/opt/void-usb/grub-config