dracut.spec: add new modules
[dracut.git] / 51-dracut-rescue-postinst.sh
blob23158552f55f7215cded5a6359790a9c2a03d389
1 #!/bin/bash
3 export LANG=C
5 KERNEL_VERSION="$1"
6 KERNEL_IMAGE="$2"
8 [[ -f /etc/os-release ]] && . /etc/os-release
10 if [[ ! -f /etc/machine-id ]] || [[ ! -s /etc/machine-id ]]; then
11 systemd-machine-id-setup
14 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
16 [[ $MACHINE_ID ]] || exit 1
17 [[ -f $KERNEL_IMAGE ]] || exit 1
19 INITRDFILE="/boot/initramfs-0-rescue-${MACHINE_ID}.img"
20 NEW_KERNEL_IMAGE="${KERNEL_IMAGE%/*}/vmlinuz-0-rescue-${MACHINE_ID}"
22 [[ -f $INITRDFILE ]] && [[ -f $NEW_KERNEL_IMAGE ]] && exit 0
24 dropindirs_sort()
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
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
43 done
44 done
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
52 [[ $dracut_rescue_image != "yes" ]] && exit 0
54 if [[ ! -f $INITRDFILE ]]; then
55 dracut --no-hostonly -a "rescue" "$INITRDFILE" "$KERNEL_VERSION"
56 ((ret+=$?))
59 if [[ ! -f $NEW_KERNEL_IMAGE ]]; then
60 cp "$KERNEL_IMAGE" "$NEW_KERNEL_IMAGE"
61 ((ret+=$?))
64 new-kernel-pkg --install "$KERNEL_VERSION" --kernel-image "$NEW_KERNEL_IMAGE" --initrdfile "$INITRDFILE" --banner "$NAME $VERSION_ID Rescue $MACHINE_ID"
66 ((ret+=$?))
68 exit $ret