teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame 20-grubby.install

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