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