]>
Commit | Line | Data |
---|---|---|
2fa6fd3a HH |
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 | |
478aa7da HH |
11 | |
12 | if [[ ! -f /etc/machine-id ]] || [[ ! -s /etc/machine-id ]]; then | |
13 | systemd-machine-id-setup | |
14 | fi | |
15 | ||
2fa6fd3a HH |
16 | [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id |
17 | ||
619c1bb3 HH |
18 | [[ $MACHINE_ID ]] || exit 1 |
19 | [[ -f $KERNEL_IMAGE ]] || exit 1 | |
20 | ||
967db700 HH |
21 | INITRDFILE="/boot/initramfs-0-rescue-${MACHINE_ID}.img" |
22 | NEW_KERNEL_IMAGE="${KERNEL_IMAGE%/*}/vmlinuz-0-rescue-${MACHINE_ID}" | |
23 | ||
24 | [[ -f $INITRDFILE ]] && [[ -f $NEW_KERNEL_IMAGE ]] && exit 0 | |
2fa6fd3a HH |
25 | |
26 | dropindirs_sort() | |
27 | { | |
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 | |
37 | ) | |
38 | ||
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 | |
44 | fi | |
45 | done | |
46 | done | |
47 | } | |
48 | ||
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 | |
53 | ||
54 | [[ $dracut_rescue_image != "yes" ]] && exit 0 | |
55 | ||
967db700 HH |
56 | if [[ ! -f $INITRDFILE ]]; then |
57 | dracut --no-hostonly -a "rescue" "$INITRDFILE" "$KERNEL_VERSION" | |
58 | ((ret+=$?)) | |
59 | fi | |
2fa6fd3a | 60 | |
967db700 HH |
61 | if [[ ! -f $NEW_KERNEL_IMAGE ]]; then |
62 | cp "$KERNEL_IMAGE" "$NEW_KERNEL_IMAGE" | |
63 | ((ret+=$?)) | |
64 | fi | |
2fa6fd3a | 65 | |
967db700 | 66 | new-kernel-pkg --install "$KERNEL_VERSION" --kernel-image "$NEW_KERNEL_IMAGE" --initrdfile "$INITRDFILE" --banner "$NAME $VERSION_ID Rescue $MACHINE_ID" |
2fa6fd3a HH |
67 | |
68 | ((ret+=$?)) | |
69 | ||
70 | exit $ret |