1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/sh
#
# Copyright (C) 2013, 2016, 2017 Etersoft
# Copyright (C) 2013, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-check_updated_repo
load_helper epm-sh-warmup
EFI=$(a="" bootctl -p 2>/dev/null)
sdboot_loader_id=$(a="" bootctl status 2>/dev/null | grep -oP '(?<=id: ).*')
if [ -f "$EFI/loader/entries/$sdboot_loader_id" ]; then
entry_file="$EFI/loader/entries/$sdboot_loader_id"
options="options"
bootloader="systemd"
elif [ -f "/etc/sysconfig/grub2" ]; then
entry_file="/etc/sysconfig/grub2"
options="GRUB_CMDLINE_LINUX_DEFAULT="
bootloader="grub"
elif [ -f "/etc/default/grub" ]; then
entry_file="/etc/default/grub"
options="GRUB_CMDLINE_LINUX_DEFAULT="
bootloader="grub"
elif [ -f "$EFI/refind_linux.conf" ]; then
entry_file="$EFI/refind_linux.conf"
options="Boot with standard options"
bootloader="refind"
fi
epm_kernel_update()
{
case $1 in
'--list-kernel-options' )
assure_root
kernel_options_list
return ;;
'--add-kernel-options')
assure_root
shift
kernel_options_add "$@"
return ;;
'--remove-kernel-options')
assure_root
shift
kernel_options_remove "$@"
return ;;
'--used-kflavour' )
used_kflavour
info 'You used $USED_KFLAVOUR kernel kflavour'
return ;;
'--check-run-kernel' )
assure_root
check_run_kernel
return ;;
esac
warmup_bases
update_repo_if_needed
info "Updating system kernel to the latest version..."
case $BASEDISTRNAME in
"alt")
load_helper epm-query_package
if ! __epm_query_package kernel-image >/dev/null ; then
info "No installed kernel packages, skipping update"
return
fi
assure_exists update-kernel update-kernel 0.9.9
sudocmd update-kernel $dryrun $(subst_option non_interactive -y) $force $interactive $reinstall $verbose "$@" || return
#docmd epm remove-old-kernels "$@" || fatal
return ;;
esac
case $PMTYPE in
dnf-rpm|dnf5-rpm)
docmd epm install kernel
;;
apt-*)
message "Skipping: kernel package will update during dist-upgrade"
;;
*)
fatal 'Have no suitable command for $PMTYPE'
;;
esac
}
kernel_options_list () {
if [ "$bootloader" = "refind" ] ; then
grep "^\"$options\"" "$entry_file" | sed 's/^\"'"$options"'" //' | sed 's/\s*$//' | tr ' ' '\n'
else
grep "^$options" "$entry_file" | sed 's/^"'$options'" //' | sed 's/\s*$//' | tr ' ' '\n'
fi
}
kernel_options_add () {
for search_string in "$@"; do
if grep -qF "$search_string" "$entry_file"; then
echo "The string '$search_string' is already present in $entry_file"
else
echo "The string '$search_string' is not present in $entry_file"
echo "Updating $entry_file"
if [ $bootloader = "systemd" ]; then
sed -i "/^$options/ s~\$~ $search_string~" "$entry_file"
else
sed -i "s|\(^$options[\"']\)\(.*\)\([\"']\)|\1\2 $search_string\3|" "$entry_file"
fi
echo "Added '$search_string' to the kernel boot parameters in $entry_file"
fi
done
}
kernel_options_remove() {
for remove_string in "$@"; do
if grep -qF "$remove_string" "$entry_file"; then
sed -i "s~ $remove_string~~" "$entry_file"
echo "Removed '$remove_string' from the kernel parameters in $entry_file"
else
echo "The string '$remove_string' is not present in $entry_file"
fi
done
}
used_kflavour () {
if [ $(uname -r | grep "def") ] ; then
USED_KFLAVOUR=$(uname -r | awk -F'-' '{print $2 "-" $3}')
else
USED_KFLAVOUR=$(uname -r | awk -F'-' '{print $2}')
fi
}
check_run_kernel() {
used_kflavour
if ls /boot | grep -E "^vmlinuz-[0-9]+\.[0-9]+(\.[0-9]+)?-${USED_KFLAVOUR}-alt[0-9]*" | sort -Vr | head -n 1 | grep -q "$(uname -r)"; then
echo "The newest installed ${USED_KFLAVOUR} kernel is running."
return 0
else
echo "The system has a newer ${USED_KFLAVOUR} kernel."
return 1
fi
}