@@ -7,13 +7,12 @@ KERNEL_VERSION="$2"
7
7
BOOT_DIR_ABS=" ${3%/* } /0-rescue"
8
8
KERNEL_IMAGE=" $4 "
9
9
10
-
11
- dropindirs_sort ()
12
- {
13
- suffix=$1 ; shift
10
+ dropindirs_sort () {
11
+ suffix=$1
12
+ shift
14
13
args=(" $@ " )
15
14
files=$(
16
- while (( $# > 0 )) ; do
15
+ while (( $# > 0 )) ; do
17
16
for i in " ${1} " /* " ${suffix} " ; do
18
17
[[ -f $i ]] && echo " ${i##*/ } "
19
18
done
@@ -31,19 +30,29 @@ dropindirs_sort()
31
30
done
32
31
}
33
32
34
- [[ -f /etc/os-release ]] && . /etc/os-release
33
+ if [[ -f /etc/os-release ]]; then
34
+ . /etc/os-release
35
+ elif [[ -f /usr/lib/os-release ]]; then
36
+ . /usr/lib/os-release
37
+ fi
38
+
39
+ [[ -n $PRETTY_NAME ]] || PRETTY_NAME=" Linux $KERNEL_VERSION "
35
40
36
41
if [[ ${KERNEL_INSTALL_MACHINE_ID+x} ]]; then
37
42
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
38
- elif [[ -f /etc/machine-id ]] ; then
43
+ elif [[ -f /etc/machine-id ]]; then
39
44
read -r MACHINE_ID < /etc/machine-id
40
45
fi
41
46
42
47
if ! [[ $MACHINE_ID ]]; then
43
48
exit 0
44
49
fi
45
50
46
- if [[ -f /etc/kernel/cmdline ]]; then
51
+ if [ -n " $KERNEL_INSTALL_CONF_ROOT " ]; then
52
+ if [ -f " $KERNEL_INSTALL_CONF_ROOT /cmdline" ]; then
53
+ read -r -d ' ' -a BOOT_OPTIONS < " $KERNEL_INSTALL_CONF_ROOT /cmdline"
54
+ fi
55
+ elif [[ -f /etc/kernel/cmdline ]]; then
47
56
read -r -d ' ' -a BOOT_OPTIONS < /etc/kernel/cmdline
48
57
elif [[ -f /usr/lib/kernel/cmdline ]]; then
49
58
read -r -d ' ' -a BOOT_OPTIONS < /usr/lib/kernel/cmdline
52
61
53
62
read -r -d ' ' -a line < /proc/cmdline
54
63
for i in " ${line[@]} " ; do
55
- [[ " ${i# initrd=* } " != " $i " ]] && continue
64
+ [[ ${i# initrd=* } != " $i " ]] && continue
56
65
BOOT_OPTIONS+=(" $i " )
57
66
done
58
67
fi
59
68
60
- if [[ -d " ${BOOT_DIR_ABS%/* } " ]]; then
69
+ if [[ -d ${BOOT_DIR_ABS%/* } ]]; then
61
70
BOOT_DIR=" /${MACHINE_ID} /0-rescue"
62
- BOOT_ROOT=${BOOT_DIR_ABS% $BOOT_DIR }
71
+ BOOT_ROOT=${BOOT_DIR_ABS% " $BOOT_DIR " }
63
72
LOADER_ENTRY=" $BOOT_ROOT /loader/entries/${MACHINE_ID} -0-rescue.conf"
64
73
KERNEL=" linux"
65
74
INITRD=" initrd"
75
84
76
85
case " $COMMAND " in
77
86
add)
78
- [[ -f " $LOADER_ENTRY " ]] && [[ -f " $BOOT_DIR_ABS /$KERNEL " ]] \
79
- && [[ -f " $BOOT_DIR_ABS /$INITRD " ]] && exit 0
87
+ if [[ -f $LOADER_ENTRY ]] && [[ -f " $BOOT_DIR_ABS /$KERNEL " ]] \
88
+ && [[ -f " $BOOT_DIR_ABS /$INITRD " ]]; then
89
+ [[ $KERNEL_INSTALL_VERBOSE == 1 ]] \
90
+ && echo " Skipping, there is already a rescue image generated with the same input parameters"
91
+ exit 0
92
+ fi
80
93
81
94
# source our config dir
82
95
for f in $( dropindirs_sort " .conf" " /etc/dracut.conf.d" " /usr/lib/dracut/dracut.conf.d" ) ; do
@@ -87,22 +100,30 @@ case "$COMMAND" in
87
100
done
88
101
89
102
# shellcheck disable=SC2154
90
- [[ $dracut_rescue_image != " yes" ]] && exit 0
103
+ if [[ $dracut_rescue_image != " yes" ]]; then
104
+ [[ $KERNEL_INSTALL_VERBOSE == 1 ]] \
105
+ && echo " Skipping, 'dracut_rescue_image' not set to 'yes' in any dracut configuration file"
106
+ exit 0
107
+ fi
91
108
92
- [[ -d " $BOOT_DIR_ABS " ]] || mkdir -p " $BOOT_DIR_ABS "
109
+ [[ -d $BOOT_DIR_ABS ]] || mkdir -p " $BOOT_DIR_ABS "
93
110
94
111
if ! cp --reflink=auto " $KERNEL_IMAGE " " $BOOT_DIR_ABS /$KERNEL " ; then
95
112
echo " Can't copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS /$KERNEL '!" >&2
96
113
fi
97
114
98
115
if [[ ! -f " $BOOT_DIR_ABS /$INITRD " ]]; then
116
+ # shellcheck disable=SC2046
99
117
dracut -f --no-hostonly --no-uefi \
100
- $( [[ -n " $KERNEL_IMAGE " ]] && echo --kernel-image " ${KERNEL_IMAGE} " ) \
101
- -a " rescue" " $BOOT_DIR_ABS /$INITRD " " $KERNEL_VERSION "
102
- (( ret+= $? ))
118
+ -a " rescue" \
119
+ $( [[ $KERNEL_INSTALL_VERBOSE == 1 ]] && echo --verbose) \
120
+ --kver " $KERNEL_VERSION " \
121
+ " $BOOT_DIR_ABS /$INITRD "
122
+ (( ret += $? ))
103
123
fi
104
124
105
- if [[ " ${BOOT_DIR_ABS} " != " /boot" ]]; then
125
+ [[ $KERNEL_INSTALL_VERBOSE == 1 ]] && echo " Creating $LOADER_ENTRY "
126
+ if [[ ${BOOT_DIR_ABS} != " /boot" ]]; then
106
127
{
107
128
echo " title $PRETTY_NAME - Rescue Image"
108
129
echo " version $KERNEL_VERSION "
@@ -120,16 +141,13 @@ case "$COMMAND" in
120
141
sed -i " s/${KERNEL_VERSION} /0-rescue-${MACHINE_ID} /" " $LOADER_ENTRY "
121
142
fi
122
143
123
- (( ret+= $? ))
144
+ (( ret += $? ))
124
145
;;
125
146
126
147
remove)
127
148
exit 0
128
149
;;
129
150
130
- * )
131
- usage
132
- ret=1;;
133
151
esac
134
152
135
153
exit $ret
0 commit comments