Blame 0014-add-51-dracut-rescue-postinst.sh.patch

Harald Hoyer 52ce14
From 2fa6fd3aaa3015ad80b2b16f68c9b6de6724f202 Mon Sep 17 00:00:00 2001
Harald Hoyer 52ce14
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 52ce14
Date: Mon, 11 Mar 2013 15:59:13 +0100
Harald Hoyer 52ce14
Subject: [PATCH] add 51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
Harald Hoyer 52ce14
also fixup 51-dracut-rescue.install to read in dracut conf
Harald Hoyer 52ce14
---
Harald Hoyer 52ce14
 51-dracut-rescue-postinst.sh      | 58 +++++++++++++++++++++++++++++++++++++++
Harald Hoyer 52ce14
 51-dracut-rescue.install          | 58 ++++++++++++++++++++++++++++-----------
Harald Hoyer 52ce14
 dracut.conf.d/fedora.conf.example |  1 +
Harald Hoyer 52ce14
 dracut.spec                       | 18 ++++++++----
Harald Hoyer 52ce14
 4 files changed, 114 insertions(+), 21 deletions(-)
Harald Hoyer 52ce14
 create mode 100755 51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
Harald Hoyer 52ce14
diff --git a/51-dracut-rescue-postinst.sh b/51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
new file mode 100755
Harald Hoyer 52ce14
index 0000000..5c0fe2c
Harald Hoyer 52ce14
--- /dev/null
Harald Hoyer 52ce14
+++ b/51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
@@ -0,0 +1,58 @@
Harald Hoyer 52ce14
+#!/bin/bash
Harald Hoyer 52ce14
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 52ce14
+# ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+export LANG=C
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+KERNEL_VERSION="$1"
Harald Hoyer 52ce14
+KERNEL_IMAGE="$2"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+[[ -f /etc/os-release ]] && . /etc/os-release
Harald Hoyer 52ce14
+[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+INITRDFILE="/boot/initramfs-${MACHINE_ID}-rescue.img"
Harald Hoyer 52ce14
+[[ -f $INITRDFILE ]] && exit 0
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+dropindirs_sort()
Harald Hoyer 52ce14
+{
Harald Hoyer 52ce14
+    suffix=$1; shift
Harald Hoyer 52ce14
+    args=("$@")
Harald Hoyer 52ce14
+    files=$(
Harald Hoyer 52ce14
+        while (( $# > 0 )); do
Harald Hoyer 52ce14
+            for i in ${1}/*${suffix}; do
Harald Hoyer 52ce14
+                [[ -f $i ]] && echo ${i##*/}
Harald Hoyer 52ce14
+            done
Harald Hoyer 52ce14
+            shift
Harald Hoyer 52ce14
+        done | sort -Vu
Harald Hoyer 52ce14
+    )
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+    for f in $files; do
Harald Hoyer 52ce14
+        for d in "${args[@]}"; do
Harald Hoyer 52ce14
+            if [[ -f "$d/$f" ]]; then
Harald Hoyer 52ce14
+                echo "$d/$f"
Harald Hoyer 52ce14
+                continue 2
Harald Hoyer 52ce14
+            fi
Harald Hoyer 52ce14
+        done
Harald Hoyer 52ce14
+    done
Harald Hoyer 52ce14
+}
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+# source our config dir
Harald Hoyer 52ce14
+for f in $(dropindirs_sort ".conf" "/etc/dracut.conf.d" "/usr/lib/dracut/dracut.conf.d"); do
Harald Hoyer 52ce14
+    [[ -e $f ]] && . "$f"
Harald Hoyer 52ce14
+done
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+[[ $dracut_rescue_image != "yes" ]] && exit 0
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+dracut --no-hostonly  -a "rescue" "$INITRDFILE" "$KERNEL_VERSION"
Harald Hoyer 52ce14
+((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+cp "$KERNEL_IMAGE" "${KERNEL_IMAGE%/*}/vmlinuz-${MACHINE_ID}-rescue"
Harald Hoyer 52ce14
+((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+KERNEL_IMAGE="${KERNEL_IMAGE%/*}/vmlinuz-${MACHINE_ID}-rescue"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+new-kernel-image --install "$KERNEL_VERSION" --kernel-image "$KERNEL_IMAGE" --initrdfile "$INITRDFILE" --banner "$PRETTY_NAME Rescue"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+((ret+=$?))
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+exit $ret
Harald Hoyer 52ce14
diff --git a/51-dracut-rescue.install b/51-dracut-rescue.install
Harald Hoyer 52ce14
index e5781d3..94f064c 100755
Harald Hoyer 52ce14
--- a/51-dracut-rescue.install
Harald Hoyer 52ce14
+++ b/51-dracut-rescue.install
Harald Hoyer 52ce14
@@ -1,4 +1,4 @@
Harald Hoyer 52ce14
-#!/bin/sh
Harald Hoyer 52ce14
+#!/bin/bash
Harald Hoyer 52ce14
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer 52ce14
 # ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
@@ -6,8 +6,29 @@ export LANG=C
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 COMMAND="$1"
Harald Hoyer 52ce14
 KERNEL_VERSION="$2"
Harald Hoyer 52ce14
-BOOT_DIR_ABS="$3"
Harald Hoyer 52ce14
-BOOT_DIR="${3#/boot}"
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+dropindirs_sort()
Harald Hoyer 52ce14
+{
Harald Hoyer 52ce14
+    suffix=$1; shift
Harald Hoyer 52ce14
+    args=("$@")
Harald Hoyer 52ce14
+    files=$(
Harald Hoyer 52ce14
+        while (( $# > 0 )); do
Harald Hoyer 52ce14
+            for i in ${1}/*${suffix}; do
Harald Hoyer 52ce14
+                [[ -f $i ]] && echo ${i##*/}
Harald Hoyer 52ce14
+            done
Harald Hoyer 52ce14
+            shift
Harald Hoyer 52ce14
+        done | sort -Vu
Harald Hoyer 52ce14
+    )
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+    for f in $files; do
Harald Hoyer 52ce14
+        for d in "${args[@]}"; do
Harald Hoyer 52ce14
+            if [[ -f "$d/$f" ]]; then
Harald Hoyer 52ce14
+                echo "$d/$f"
Harald Hoyer 52ce14
+                continue 2
Harald Hoyer 52ce14
+            fi
Harald Hoyer 52ce14
+        done
Harald Hoyer 52ce14
+    done
Harald Hoyer 52ce14
+}
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 [[ -f /etc/os-release ]] && . /etc/os-release
Harald Hoyer 52ce14
 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
Harald Hoyer 52ce14
@@ -21,17 +42,30 @@ if ! [[ $BOOT_OPTIONS ]]; then
Harald Hoyer 52ce14
     exit 1
Harald Hoyer 52ce14
 fi
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
-LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-00-${KERNEL_VERSION}-rescue.conf"
Harald Hoyer 52ce14
+LOADER_ENTRY="/boot/loader/entries/${MACHINE_ID}-0-rescue.conf"
Harald Hoyer 52ce14
+BOOT_DIR="/${MACHINE_ID}/0-rescue"
Harald Hoyer 52ce14
+BOOT_DIR_ABS="/boot${BOOT_DIR}"
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 ret=0
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 case "$COMMAND" in
Harald Hoyer 52ce14
     add)
Harald Hoyer 52ce14
-        for i in "/boot/loader/entries/${MACHINE_ID}-00-"*"-rescue.conf"; do
Harald Hoyer 52ce14
+        for i in "/boot/loader/entries/${MACHINE_ID}-0-rescue.conf"; do
Harald Hoyer 52ce14
             [[ -f $i ]] && exit 0
Harald Hoyer 52ce14
         done
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
-	dracut --no-hostonly  -a "rescue" "$3"/initrd-rescue "$2"
Harald Hoyer 52ce14
+        # source our config dir
Harald Hoyer 52ce14
+        for f in $(dropindirs_sort ".conf" "/etc/dracut.conf.d" "/usr/lib/dracut/dracut.conf.d"); do
Harald Hoyer 52ce14
+            [[ -e $f ]] && . "$f"
Harald Hoyer 52ce14
+        done
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        [[ $dracut_rescue_image != "yes" ]] && exit 0
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        if ! cp --preserve "$KERNEL_IMAGE" "$BOOT_DIR_ABS"/linux; then
Harald Hoyer 52ce14
+            echo "Can't copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'!" >&2
Harald Hoyer 52ce14
+        fi
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+        dracut --no-hostonly  -a "rescue" "$BOOT_DIR_ABS"/initrd "$2"
Harald Hoyer 52ce14
         ((ret+=$?))
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
         {
Harald Hoyer 52ce14
@@ -40,21 +74,13 @@ case "$COMMAND" in
Harald Hoyer 52ce14
             echo "machine-id $MACHINE_ID"
Harald Hoyer 52ce14
             echo "options    ${BOOT_OPTIONS[@]} rd.auto=1"
Harald Hoyer 52ce14
             echo "linux      $BOOT_DIR/linux"
Harald Hoyer 52ce14
-            echo "initrd     $BOOT_DIR/initrd-rescue"
Harald Hoyer 52ce14
+            echo "initrd     $BOOT_DIR/initrd"
Harald Hoyer 52ce14
         } > $LOADER_ENTRY
Harald Hoyer 52ce14
         ((ret+=$?))
Harald Hoyer 52ce14
-
Harald Hoyer 52ce14
-        if (( $ret == 0 )); then
Harald Hoyer 52ce14
-            command -v yumdb &>/dev/null && \
Harald Hoyer 52ce14
-                yumdb set installonly keep kernel-$KERNEL_VERSION >/dev/null
Harald Hoyer 52ce14
-        fi
Harald Hoyer 52ce14
-
Harald Hoyer 52ce14
         ;;
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
     remove)
Harald Hoyer 52ce14
-        [[ -f $LOADER_ENTRY ]] || exit 0
Harald Hoyer 52ce14
-
Harald Hoyer 52ce14
-        rm -f "$LOADER_ENTRY" "$3"/initrd-rescue
Harald Hoyer 52ce14
+        exit 0
Harald Hoyer 52ce14
         ;;
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
     *)
Harald Hoyer 52ce14
diff --git a/dracut.conf.d/fedora.conf.example b/dracut.conf.d/fedora.conf.example
Harald Hoyer 52ce14
index 8448fc3..ba7857c 100644
Harald Hoyer 52ce14
--- a/dracut.conf.d/fedora.conf.example
Harald Hoyer 52ce14
+++ b/dracut.conf.d/fedora.conf.example
Harald Hoyer 52ce14
@@ -13,3 +13,4 @@ systemdsystemunitdir=/usr/lib/systemd/system
Harald Hoyer 52ce14
 udevdir=/usr/lib/udev
Harald Hoyer 52ce14
 add_dracutmodules+=" systemd "
Harald Hoyer 52ce14
 hostonly="yes"
Harald Hoyer 52ce14
+dracut_rescue_image="yes"
Harald Hoyer 52ce14
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer 52ce14
index 14ce0d0..940d364 100644
Harald Hoyer 52ce14
--- a/dracut.spec
Harald Hoyer 52ce14
+++ b/dracut.spec
Harald Hoyer 52ce14
@@ -84,6 +84,7 @@ Requires: file
Harald Hoyer 52ce14
 Requires: kpartx
Harald Hoyer 52ce14
 Requires: udev > 166
Harald Hoyer 52ce14
 Requires: kbd kbd-misc
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
 %if 0%{?fedora} || 0%{?rhel} > 6
Harald Hoyer 52ce14
 Requires: util-linux >= 2.21
Harald Hoyer 52ce14
 Conflicts: systemd < 198
Harald Hoyer 52ce14
@@ -234,8 +235,14 @@ rm $RPM_BUILD_ROOT%{_bindir}/mkinitrd
Harald Hoyer 52ce14
 rm $RPM_BUILD_ROOT%{_bindir}/lsinitrd
Harald Hoyer 52ce14
 %endif
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
-mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
Harald Hoyer 52ce14
-install -m 0644 dracut.logrotate $RPM_BUILD_ROOT/etc/logrotate.d/dracut_log
Harald Hoyer 52ce14
+# FIXME: remove after F19
Harald Hoyer 52ce14
+%if 0%{?fedora} || 0%{?rhel} > 6
Harald Hoyer 52ce14
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/kernel/postinst.d
Harald Hoyer 52ce14
+install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kernel/postinst.d/51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
+%endif
Harald Hoyer 52ce14
+
Harald Hoyer 52ce14
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
Harald Hoyer 52ce14
+install -m 0644 dracut.logrotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/dracut_log
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 # create compat symlink
Harald Hoyer 52ce14
 mkdir -p $RPM_BUILD_ROOT/sbin
Harald Hoyer 52ce14
@@ -262,11 +269,11 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer 52ce14
 %{dracutlibdir}/dracut-logger.sh
Harald Hoyer 52ce14
 %{dracutlibdir}/dracut-initramfs-restore
Harald Hoyer 52ce14
 %{dracutlibdir}/dracut-install
Harald Hoyer 52ce14
-%config(noreplace) /etc/dracut.conf
Harald Hoyer 52ce14
+%config(noreplace) %{_sysconfdir}/dracut.conf
Harald Hoyer 52ce14
 %if 0%{?fedora} || 0%{?suse_version} || 0%{?rhel}
Harald Hoyer 52ce14
 %{dracutlibdir}/dracut.conf.d/01-dist.conf
Harald Hoyer 52ce14
 %endif
Harald Hoyer 52ce14
-%dir /etc/dracut.conf.d
Harald Hoyer 52ce14
+%dir %{_sysconfdir}/dracut.conf.d
Harald Hoyer 52ce14
 %dir %{dracutlibdir}/dracut.conf.d
Harald Hoyer 52ce14
 %{_mandir}/man8/dracut.8*
Harald Hoyer 52ce14
 %{_mandir}/man8/*service.8*
Harald Hoyer 52ce14
@@ -329,7 +336,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer 52ce14
 %{dracutlibdir}/modules.d/99fs-lib
Harald Hoyer 52ce14
 %{dracutlibdir}/modules.d/99img-lib
Harald Hoyer 52ce14
 %{dracutlibdir}/modules.d/99shutdown
Harald Hoyer 52ce14
-%config(noreplace) /etc/logrotate.d/dracut_log
Harald Hoyer 52ce14
+%config(noreplace) %{_sysconfdir}/logrotate.d/dracut_log
Harald Hoyer 52ce14
 %attr(0644,root,root) %ghost %config(missingok,noreplace) %{_localstatedir}/log/dracut.log
Harald Hoyer 52ce14
 %dir %{_sharedstatedir}/initramfs
Harald Hoyer 52ce14
 %if %{defined _unitdir}
Harald Hoyer 52ce14
@@ -339,6 +346,7 @@ rm -rf $RPM_BUILD_ROOT
Harald Hoyer 52ce14
 %if 0%{?fedora} || 0%{?rhel} > 6
Harald Hoyer 52ce14
 %{_prefix}/lib/kernel/install.d/50-dracut.install
Harald Hoyer 52ce14
 %{_prefix}/lib/kernel/install.d/51-dracut-rescue.install
Harald Hoyer 52ce14
+%{_sysconfdir}/kernel/postinst.d/51-dracut-rescue-postinst.sh
Harald Hoyer 52ce14
 %endif
Harald Hoyer 52ce14
 
Harald Hoyer 52ce14
 %files network