dcavalca / rpms / systemd

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