]> git.ipfire.org Git - thirdparty/dracut.git/blob - 51-dracut-rescue-postinst.sh
add 51-dracut-rescue-postinst.sh
[thirdparty/dracut.git] / 51-dracut-rescue-postinst.sh
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
4
5 export LANG=C
6
7 KERNEL_VERSION="$1"
8 KERNEL_IMAGE="$2"
9
10 [[ -f /etc/os-release ]] && . /etc/os-release
11 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
12
13 INITRDFILE="/boot/initramfs-${MACHINE_ID}-rescue.img"
14 [[ -f $INITRDFILE ]] && exit 0
15
16 dropindirs_sort()
17 {
18 suffix=$1; shift
19 args=("$@")
20 files=$(
21 while (( $# > 0 )); do
22 for i in ${1}/*${suffix}; do
23 [[ -f $i ]] && echo ${i##*/}
24 done
25 shift
26 done | sort -Vu
27 )
28
29 for f in $files; do
30 for d in "${args[@]}"; do
31 if [[ -f "$d/$f" ]]; then
32 echo "$d/$f"
33 continue 2
34 fi
35 done
36 done
37 }
38
39 # source our config dir
40 for f in $(dropindirs_sort ".conf" "/etc/dracut.conf.d" "/usr/lib/dracut/dracut.conf.d"); do
41 [[ -e $f ]] && . "$f"
42 done
43
44 [[ $dracut_rescue_image != "yes" ]] && exit 0
45
46 dracut --no-hostonly -a "rescue" "$INITRDFILE" "$KERNEL_VERSION"
47 ((ret+=$?))
48
49 cp "$KERNEL_IMAGE" "${KERNEL_IMAGE%/*}/vmlinuz-${MACHINE_ID}-rescue"
50 ((ret+=$?))
51
52 KERNEL_IMAGE="${KERNEL_IMAGE%/*}/vmlinuz-${MACHINE_ID}-rescue"
53
54 new-kernel-image --install "$KERNEL_VERSION" --kernel-image "$KERNEL_IMAGE" --initrdfile "$INITRDFILE" --banner "$PRETTY_NAME Rescue"
55
56 ((ret+=$?))
57
58 exit $ret