All checks were successful
continuous-integration/drone/push Build is passing
35 lines
1.8 KiB
Bash
Executable file
35 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
. /etc/os-release
|
|
if [ -d /sys/firmware/efi -a -e /boot/efi/EFI/centos/grub.cfg ]; then
|
|
CONFDIR=/boot/efi/EFI/centos
|
|
elif [ -d /sys/firmware/efi -a -e /boot/efi/EFI/rocky/grub.cfg ]; then
|
|
CONFDIR=/boot/efi/EFI/rocky
|
|
elif [ -d /sys/firmware/efi -a -e /boot/efi/EFI/almalinux/grub.cfg ]; then
|
|
CONFDIR=/boot/efi/EFI/almalinux
|
|
elif [ -d /sys/firmware/efi -a -e /boot/efi/EFI/redhat/grub.cfg ]; then
|
|
CONFDIR=/boot/efi/EFI/redhat
|
|
else
|
|
CONFDIR=/boot/grub2
|
|
fi
|
|
#grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2 | grep -Ev '(with debugging$|-rescue-)' | grep ^"$NAME" | sort -n | tail -n 1
|
|
# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2 | grep -Ev '(with debugging$|-rescue-)' | head -n1
|
|
# grub2-set-default "CentOS Linux (4.7.2-1.el7.elrepo.x86_64) 7 (Core)"
|
|
# Contrôle : grub2-editenv list
|
|
KERNLIST="$(ls -1 /boot/vmlinuz-* | grep -v rescue | sed 's|/boot/vmlinuz-\([.0-9]*\)-.*|\1|')"
|
|
LASTMAJKERNEL="$(echo $KERNLIST | sed 's/ /\n/g' | cut -d. -f1 | sort -n -u | while read i; do
|
|
echo $KERNLIST | sed 's/ /\n/g' | grep ^$i | cut -d. -f1-2 | sort -n -u -k2 -t.
|
|
done | while read j; do
|
|
echo $KERNLIST | sed 's/ /\n/g' | grep ^$j | sort -n -u -k3 -t.
|
|
done | tail -n 1)"
|
|
|
|
KERNLIST="$(ls -1 /boot/vmlinuz-* | grep -v rescue | sed 's|/boot/vmlinuz-'${LASTMAJKERNEL}'-\([.0-9]*\).*|\1|')"
|
|
LASTKERNEL="${LASTMAJKERNEL}-$(echo $KERNLIST | sed -e 's/ /\n/g' -e 's/.$//' | cut -d. -f1 | sort -n -u | while read i; do
|
|
echo $KERNLIST | sed 's/ /\n/g' | grep ^$i | cut -d. -f1-2 | sort -n -u -k2 -t.
|
|
done | while read j; do
|
|
echo $KERNLIST | sed 's/ /\n/g' | grep ^$j | sort -n -u -k3 -t.
|
|
done | tail -n 1)"
|
|
|
|
grub2-set-default "$(grep "^menuentry" "${CONFDIR}"/grub.cfg | cut -d \' -f2 | grep -Ev '(with debugging$|-rescue-)' | grep ^"$NAME" | grep $LASTKERNEL | sort -n | tail -n 1)"
|
|
|
|
grub2-mkconfig -o "${CONFDIR}"/grub.cfg
|