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