#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export LANG=C COMMAND="$1" KERNEL_VERSION="$2" BOOT_DIR_ABS="$3" BOOT_DIR="${3#/boot}" [[ -f /etc/os-release ]] && . /etc/os-release [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id if [[ -f /etc/kernel/cmdline ]]; then readarray -t BOOT_OPTIONS < /etc/kernel/cmdline fi if ! [[ "${BOOT_OPTIONS[@]}" ]]; then readarray -t BOOT_OPTIONS < /proc/cmdline fi if ! [[ $BOOT_OPTIONS ]]; then exit 1 fi LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-00-${KERNEL_VERSION}-rescue.conf" ret=0 case "$COMMAND" in add) for i in "/boot/loader/entries/${MACHINE_ID}-00-"*"-rescue.conf"; do [[ -f $i ]] && exit 0 done dracut --no-hostonly -a "rescue" "$3"/initrd-rescue "$2" ((ret+=$?)) { echo "title $PRETTY_NAME - Rescue Image" echo "version $KERNEL_VERSION" echo "machine-id $MACHINE_ID" echo "options ${BOOT_OPTIONS[@]} rd.auto=1" echo "linux $BOOT_DIR/linux" echo "initrd $BOOT_DIR/initrd-rescue" } > $LOADER_ENTRY ((ret+=$?)) if (( $ret == 0 )); then command -v yumdb &>/dev/null && \ yumdb set installonly keep kernel-$KERNEL_VERSION >/dev/null fi ;; remove) [[ -f $LOADER_ENTRY ]] || exit 0 rm -f "$LOADER_ENTRY" "$3"/initrd-rescue if command -v yumdb &>/dev/null; then if [[ $(yumdb get installonly kernel-$KERNEL_VERSION 2>/dev/null) == *installonly\ \=\ keep* ]]; then yumdb del installonly kernel-$KERNEL_VERSION >/dev/null fi fi ;; *) usage ret=1;; esac ((ret+=$?)) exit $ret