4295f9
#!/bin/bash
4295f9
4295f9
if [[ ! -x /sbin/new-kernel-pkg ]]; then
4295f9
    exit 0
4295f9
fi
4295f9
4295f9
COMMAND="$1"
4295f9
KERNEL_VERSION="$2"
4295f9
BOOT_DIR_ABS="$3"
4295f9
KERNEL_IMAGE="$4"
4295f9
4295f9
KERNEL_DIR="${KERNEL_IMAGE%/*}"
4295f9
[[ "$KERNEL_VERSION" == *\+* ]] && flavor=-"${KERNEL_VERSION##*+}"
4295f9
case "$COMMAND" in
4295f9
    add)
4295f9
        if [[ "${KERNEL_DIR}" != "/boot" ]]; then
4295f9
            for i in \
4295f9
                "$KERNEL_IMAGE" \
4295f9
                    "$KERNEL_DIR"/System.map \
4295f9
                    "$KERNEL_DIR"/config \
4295f9
                    "$KERNEL_DIR"/zImage.stub \
4295f9
                    "$KERNEL_DIR"/dtb \
4295f9
                ; do
4295f9
                [[ -e "$i" ]] || continue
4295f9
                cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}"
4295f9
                command -v restorecon &>/dev/null && \
4295f9
                    restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}"
4295f9
            done
4295f9
            # hmac is .vmlinuz-<version>.hmac so needs a special treatment
4295f9
            i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac"
4295f9
            if [[ -e "$i" ]]; then
4295f9
                cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
4295f9
                command -v restorecon &>/dev/null && \
4295f9
                    restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
4295f9
            fi
4295f9
        fi
4295f9
        /sbin/new-kernel-pkg --package "kernel${flavor}" --install "$KERNEL_VERSION" || exit $?
4295f9
        /sbin/new-kernel-pkg --package "kernel${flavor}" --mkinitrd --dracut --depmod --update "$KERNEL_VERSION" || exit $?
4295f9
        /sbin/new-kernel-pkg --package "kernel${flavor}" --rpmposttrans "$KERNEL_VERSION" || exit $?
4295f9
        ;;
4295f9
    remove)
4295f9
        /sbin/new-kernel-pkg --package "kernel${flavor+-$flavor}" --rminitrd --rmmoddep --remove "$KERNEL_VERSION" || exit $?
4295f9
        ;;
4295f9
    *)
4295f9
        ;;
4295f9
esac
4295f9
4295f9
# skip other installation plugins, if we can't find a boot loader spec conforming setup
4295f9
if ! [[ -d /boot/loader/entries || -L /boot/loader/entries ]]; then
4295f9
    exit 77
4295f9
fi