2016-11-03 23:26:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-27 20:16:15 +00:00
|
|
|
if [[ ! -f /etc/default/grub ]]; then
|
2016-11-04 13:12:11 +00:00
|
|
|
exit 0
|
2016-11-03 23:26:21 +00:00
|
|
|
fi
|
|
|
|
|
2018-02-27 20:16:15 +00:00
|
|
|
. /etc/default/grub
|
|
|
|
|
|
|
|
[[ -f /etc/os-release ]] && . /etc/os-release
|
|
|
|
|
2016-11-03 23:26:21 +00:00
|
|
|
COMMAND="$1"
|
|
|
|
KERNEL_VERSION="$2"
|
|
|
|
BOOT_DIR_ABS="$3"
|
|
|
|
KERNEL_IMAGE="$4"
|
|
|
|
|
|
|
|
KERNEL_DIR="${KERNEL_IMAGE%/*}"
|
2018-02-27 20:16:15 +00:00
|
|
|
|
|
|
|
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
|
|
|
|
|
|
|
|
# Remove it, since for grub2 the images are always installed in /boot
|
|
|
|
rm -rf "${BOOT_DIR_ABS%/*}"
|
|
|
|
|
|
|
|
BLS_DIR="/boot/loader/entries"
|
|
|
|
if [ -d /sys/firmware/efi ]; then
|
|
|
|
BLS_DIR="/boot/efi/EFI/${ID}/loader/entries"
|
|
|
|
fi
|
|
|
|
|
2016-11-03 23:26:21 +00:00
|
|
|
[[ "$KERNEL_VERSION" == *\+* ]] && flavor=-"${KERNEL_VERSION##*+}"
|
|
|
|
case "$COMMAND" in
|
|
|
|
add)
|
|
|
|
if [[ "${KERNEL_DIR}" != "/boot" ]]; then
|
|
|
|
for i in \
|
|
|
|
"$KERNEL_IMAGE" \
|
|
|
|
"$KERNEL_DIR"/System.map \
|
|
|
|
"$KERNEL_DIR"/config \
|
|
|
|
"$KERNEL_DIR"/zImage.stub \
|
|
|
|
"$KERNEL_DIR"/dtb \
|
|
|
|
; do
|
|
|
|
[[ -e "$i" ]] || continue
|
|
|
|
cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac"
|
|
|
|
if [[ -e "$i" ]]; then
|
|
|
|
cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
fi
|
|
|
|
fi
|
2018-02-27 20:16:15 +00:00
|
|
|
|
|
|
|
if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
|
|
|
|
[[ -d "$BLS_DIR" ]] || mkdir -p "$BLS_DIR"
|
|
|
|
cp -aT "${KERNEL_DIR}/bls.conf" "${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf" || exit $?
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-11-03 23:26:21 +00:00
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --install "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --mkinitrd --dracut --depmod --update "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --rpmposttrans "$KERNEL_VERSION" || exit $?
|
2018-02-27 20:16:15 +00:00
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
2016-11-03 23:26:21 +00:00
|
|
|
;;
|
|
|
|
remove)
|
2018-02-27 20:16:15 +00:00
|
|
|
|
|
|
|
if [ "x${GRUB_ENABLE_BLSCFG}" = "xtrue" ]; then
|
|
|
|
rm -f "${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
|
|
|
|
|
|
|
|
for i in vmlinuz System.map config zImage.stub dtb; do
|
|
|
|
rm -rf "/boot/${i}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
rm -f "/boot/.vmlinuz-${KERNEL_VERSION}.hmac"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-11-03 23:26:21 +00:00
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor+-$flavor}" --rminitrd --rmmoddep --remove "$KERNEL_VERSION" || exit $?
|
2018-02-27 20:16:15 +00:00
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
2016-11-03 23:26:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|