dracut-functions.sh: fix inst*() functions for "-H" handling
[dracut.git] / 51-dracut-rescue-postinst.sh
blobe290f1a17163a4a4ea57ea632329d04b73313c27
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 export LANG=C
7 KERNEL_VERSION="$1"
8 KERNEL_IMAGE="$2"
10 [[ -f /etc/os-release ]] && . /etc/os-release
12 if [[ ! -f /etc/machine-id ]] || [[ ! -s /etc/machine-id ]]; then
13 systemd-machine-id-setup
16 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
18 [[ $MACHINE_ID ]] || exit 1
19 [[ -f $KERNEL_IMAGE ]] || exit 1
21 INITRDFILE="/boot/initramfs-0-rescue-${MACHINE_ID}.img"
22 NEW_KERNEL_IMAGE="${KERNEL_IMAGE%/*}/vmlinuz-0-rescue-${MACHINE_ID}"
24 [[ -f $INITRDFILE ]] && [[ -f $NEW_KERNEL_IMAGE ]] && exit 0
26 dropindirs_sort()
28 suffix=$1; shift
29 args=("$@")
30 files=$(
31 while (( $# > 0 )); do
32 for i in ${1}/*${suffix}; do
33 [[ -f $i ]] && echo ${i##*/}
34 done
35 shift
36 done | sort -Vu
39 for f in $files; do
40 for d in "${args[@]}"; do
41 if [[ -f "$d/$f" ]]; then
42 echo "$d/$f"
43 continue 2
45 done
46 done
49 # source our config dir
50 for f in $(dropindirs_sort ".conf" "/etc/dracut.conf.d" "/usr/lib/dracut/dracut.conf.d"); do
51 [[ -e $f ]] && . "$f"
52 done
54 [[ $dracut_rescue_image != "yes" ]] && exit 0
56 if [[ ! -f $INITRDFILE ]]; then
57 dracut --no-hostonly -a "rescue" "$INITRDFILE" "$KERNEL_VERSION"
58 ((ret+=$?))
61 if [[ ! -f $NEW_KERNEL_IMAGE ]]; then
62 cp "$KERNEL_IMAGE" "$NEW_KERNEL_IMAGE"
63 ((ret+=$?))
66 new-kernel-pkg --install "$KERNEL_VERSION" --kernel-image "$NEW_KERNEL_IMAGE" --initrdfile "$INITRDFILE" --banner "$NAME $VERSION_ID Rescue $MACHINE_ID"
68 ((ret+=$?))
70 exit $ret