]> git.ipfire.org Git - thirdparty/dracut.git/blame - 51-dracut-rescue.install
add /lib/kernel/install.d/51-dracut-rescue.install
[thirdparty/dracut.git] / 51-dracut-rescue.install
CommitLineData
d837ac39
HH
1#!/bin/sh
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
4
5export LANG=C
6
7COMMAND="$1"
8KERNEL_VERSION="$2"
9BOOT_DIR_ABS="$3"
10BOOT_DIR="${3#/boot}"
11
12[[ -f /etc/os-release ]] && . /etc/os-release
13[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
14if [[ -f /etc/kernel/cmdline ]]; then
15 readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
16fi
17if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
18 readarray -t BOOT_OPTIONS < /proc/cmdline
19fi
20if ! [[ $BOOT_OPTIONS ]]; then
21 exit 1
22fi
23
24LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-00-${KERNEL_VERSION}-rescue.conf"
25
26ret=0
27
28case "$COMMAND" in
29 add)
30 for i in "/boot/loader/entries/${MACHINE_ID}-00-"*"-rescue.conf"; do
31 [[ -f $i ]] && exit 0
32 done
33
34 dracut --no-hostonly -a "rescue" "$3"/initrd-rescue "$2"
35 ((ret+=$?))
36
37 {
38 echo "title $PRETTY_NAME - Rescue Image"
39 echo "version $KERNEL_VERSION"
40 echo "machine-id $MACHINE_ID"
41 echo "options ${BOOT_OPTIONS[@]} rd.auto=1"
42 echo "linux $BOOT_DIR/linux"
43 echo "initrd $BOOT_DIR/initrd-rescue"
44 } > $LOADER_ENTRY
45 ((ret+=$?))
46
47 if (( $ret == 0 )); then
48 command -v yumdb &>/dev/null && \
49 yumdb set installonly keep kernel-$KERNEL_VERSION >/dev/null
50 fi
51
52 ;;
53
54 remove)
55 [[ -f $LOADER_ENTRY ]] || exit 0
56
57 rm -f "$LOADER_ENTRY" "$3"/initrd-rescue
58
59 if command -v yumdb &>/dev/null; then
60 if [[ $(yumdb get installonly kernel-$KERNEL_VERSION 2>/dev/null) == *installonly\ \=\ keep* ]]; then
61 yumdb del installonly kernel-$KERNEL_VERSION >/dev/null
62 fi
63 fi
64 ;;
65
66 *)
67 usage
68 ret=1;;
69esac
70
71((ret+=$?))
72
73exit $ret