2015-09-26 01:56:16 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
COMMAND="$1"
|
|
|
|
KVER="$2"
|
|
|
|
|
|
|
|
ESP_MOUNTPOINT=/boot/efi
|
2016-07-21 11:42:33 +00:00
|
|
|
|
|
|
|
EFI_DIR=$(efibootmgr -v 2>/dev/null | awk '
|
|
|
|
/^BootCurrent:/ { current=$2; }
|
2018-06-27 21:23:10 +00:00
|
|
|
/^Boot....\* .*xen\.efi/ {
|
2016-07-21 11:42:33 +00:00
|
|
|
if ("Boot" current "*" == $1) {
|
|
|
|
sub(".*File\\(", "");
|
2016-11-11 21:22:23 +00:00
|
|
|
sub("\\\\xen.efi\\).*", "");
|
2016-07-21 11:42:33 +00:00
|
|
|
gsub("\\\\", "/");
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
}')
|
|
|
|
|
|
|
|
if [ -z "$EFI_DIR" ]; then
|
|
|
|
EFI_DIR="$ESP_MOUNTPOINT/EFI/qubes"
|
|
|
|
else
|
|
|
|
EFI_DIR="$ESP_MOUNTPOINT$EFI_DIR"
|
|
|
|
fi
|
2015-09-26 01:56:16 +00:00
|
|
|
|
2019-06-27 12:28:15 +00:00
|
|
|
if [ ! -r "$EFI_DIR/xen.cfg" ]; then
|
2015-09-26 01:56:16 +00:00
|
|
|
# non-EFI system
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$COMMAND" in
|
|
|
|
add)
|
2016-06-03 18:51:18 +00:00
|
|
|
if ! fgrep -q "[${KVER}]" $EFI_DIR/xen.cfg; then
|
|
|
|
# take the default section and use it as a template for the new entry
|
|
|
|
awk -F = --assign "kver=${KVER}" '
|
|
|
|
/^\[/ {
|
|
|
|
# section header - previous section (if any) ended
|
2015-09-26 01:56:16 +00:00
|
|
|
|
2016-06-03 18:51:18 +00:00
|
|
|
# if default section already processed, that is all
|
|
|
|
if (in_default) exit;
|
|
|
|
in_global=0;
|
|
|
|
in_default=0;
|
|
|
|
}
|
|
|
|
/\[global\]/ {
|
|
|
|
in_global=1;
|
2015-09-26 01:56:16 +00:00
|
|
|
}
|
2016-06-03 18:51:18 +00:00
|
|
|
/^\[/ {
|
|
|
|
if ("[" default_name "]" == $0) {
|
|
|
|
in_default=1;
|
|
|
|
print "[" kver "]";
|
|
|
|
next;
|
|
|
|
}
|
2015-09-26 01:56:16 +00:00
|
|
|
}
|
2016-06-03 18:51:18 +00:00
|
|
|
/^default=/ {
|
|
|
|
if (in_global)
|
|
|
|
default_name=$2;
|
2015-09-26 01:56:16 +00:00
|
|
|
}
|
2016-06-03 18:51:18 +00:00
|
|
|
/^kernel=/ {
|
|
|
|
if (in_default) {
|
|
|
|
sub("=[^ ]*", "=vmlinuz-" kver);
|
|
|
|
}
|
2015-09-26 01:56:16 +00:00
|
|
|
}
|
2016-06-03 18:51:18 +00:00
|
|
|
/^ramdisk=/ {
|
|
|
|
if (in_default) {
|
|
|
|
sub("=[^ ]*", "=initramfs-" kver ".img");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if (in_default) {
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
}' $EFI_DIR/xen.cfg >> $EFI_DIR/xen.cfg
|
|
|
|
|
|
|
|
# then change the default
|
|
|
|
sed -e "s/default=.*/default=$KVER/" -i $EFI_DIR/xen.cfg
|
|
|
|
fi
|
2015-09-26 01:56:16 +00:00
|
|
|
|
2015-12-05 14:18:08 +00:00
|
|
|
cp "/boot/vmlinuz-$KVER" "$EFI_DIR/"
|
2018-02-27 22:19:50 +00:00
|
|
|
if [ -e "/boot/initramfs-${KVER}.img" ]; then
|
|
|
|
cp -f "/boot/initramfs-${KVER}.img" "$EFI_DIR/"
|
|
|
|
else
|
|
|
|
dracut -f "$EFI_DIR/initramfs-${KVER}.img" "$KVER"
|
|
|
|
fi
|
2015-09-26 01:56:16 +00:00
|
|
|
;;
|
|
|
|
remove)
|
|
|
|
# don't care about changing default= line - yum should prevent removing
|
|
|
|
# currently running kernel
|
2016-05-15 09:19:18 +00:00
|
|
|
if [ -r $EFI_DIR/xen.cfg ]; then
|
|
|
|
awk -F = --assign "kver=${KVER}" '
|
|
|
|
/^\[/ {
|
|
|
|
# section header - previous section (if any) ended
|
2015-09-26 01:56:16 +00:00
|
|
|
|
2016-05-15 09:19:18 +00:00
|
|
|
in_current=0;
|
|
|
|
}
|
|
|
|
/^\[/ {
|
|
|
|
if ($0 == "[" kver "]")
|
|
|
|
in_current=1;
|
2015-09-26 01:56:16 +00:00
|
|
|
}
|
2016-05-15 09:19:18 +00:00
|
|
|
{
|
|
|
|
if (!in_current) {
|
|
|
|
print;
|
|
|
|
}
|
|
|
|
}' $EFI_DIR/xen.cfg > $EFI_DIR/xen.cfg.new
|
|
|
|
mv $EFI_DIR/xen.cfg.new $EFI_DIR/xen.cfg
|
|
|
|
fi
|
2015-09-26 01:56:16 +00:00
|
|
|
rm -f "$EFI_DIR/initramfs-${KVER}.img"
|
2018-05-22 17:51:47 +00:00
|
|
|
rm -f "$EFI_DIR/vmlinuz-${KVER}"
|
2015-09-26 01:56:16 +00:00
|
|
|
;;
|
|
|
|
esac
|