Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a pending kernel update requires a reboot to be applied #65

Merged
merged 8 commits into from
Dec 1, 2023
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Features:
- Offers to print the latest Arch Linux news before applying updates (through [curl](https://archlinux.org/packages/core/x86_64/curl/ "curl package") and [htmlq](https://archlinux.org/packages/extra/x86_64/htmlq/ "htmlq package")).
- Automatic check and listing of orphan packages and offering you to remove them.
- Helps you processing pacnew/pacsave files (through [pacdiff](https://archlinux.org/packages/extra/x86_64/pacman-contrib/ "pacman-contrib package"), optionally requires [vim](https://archlinux.org/packages/extra/x86_64/vim/ "vim package") as the default [merge program](https://wiki.archlinux.org/title/Pacman/Pacnew_and_Pacsave#pacdiff "pacdiff merge program")).
- Automatic check for pending kernel updates requiring a reboot to be applied and offers to do so if there's one.
- Support for both [sudo](https://archlinux.org/packages/core/x86_64/sudo/ "sudo package") and [doas](https://archlinux.org/packages/extra/x86_64/opendoas/ "opendoas package").
- Optional support for AUR packages update (through [yay](https://aur.archlinux.org/packages/yay "yay AUR package") or [paru](https://aur.archlinux.org/packages/paru "paru AUR package")).
- Optional support for Flatpak packages update (through [flatpak](https://archlinux.org/packages/extra/x86_64/flatpak "Flatpak package")).
Expand Down Expand Up @@ -121,6 +122,10 @@ Additionally `arch-update` will search for pacnew/pacsave files and offers to pr

![process_pacnew](https://github.com/Antiz96/arch-update/assets/53110319/6f3430f7-fc28-48fa-b107-230f3f32ac5b)

Finally, `arch-update` will check if there's a pending kernel update requiring a reboot to be applied and offers you to do so (if there is):

![kernel_reboot](https://github.com/Antiz96/arch-update/assets/53110319/1eec68c0-e619-44ab-9dd9-74a341f7a5b7)

## Documentation

```text
Expand All @@ -141,6 +146,7 @@ Exit Codes:
3 Error when changing icon
4 User didn't gave the confirmation to proceed
5 Error when updating the packages
6 Error when calling the reboot command to apply a pending kernel update
```

For more information, see the arch-update(1) man page
Expand Down
12 changes: 9 additions & 3 deletions doc/man/arch-update.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "ARCH-UPDATE" "1" "November 2023" "Arch-Update v1" "Arch-Update Manual"
.TH "ARCH-UPDATE" "1" "December 2023" "Arch-Update v1" "Arch-Update Manual"

.SH NAME
arch-update \- An update notifier/applier for Arch Linux that assists you with important pre/post update tasks.
Expand All @@ -20,7 +20,7 @@ An update notifier/applier for Arch Linux that assists you with important pre/po
.br
.RB "Before performing the update, it offers to print the latest Arch Linux news to the user. Arch news that have been published within the last 15 days are tagged as '[NEW]'."
.br
.RB "It also checks for orphan packages, unused Flatpak packages and pacnew/pacsave files and, if there are, offers to process them."
.RB "It also checks for orphan packages, unused Flatpak packages, pacnew/pacsave files and pending kernel update requiring a reboot to be applied and, if there are, offers to process them."
.br
.RB "The " "update " "function is launched when you click on the (.desktop) icon."
.PP
Expand Down Expand Up @@ -70,6 +70,10 @@ User didn't gave the confirmation to proceed
.B 5
Error when updating the packages

.TP
.B 6
Error when calling the reboot command to apply a pending kernel update

.SH USAGE
.TP
.B The (.desktop) icon
Expand Down Expand Up @@ -130,7 +134,9 @@ sudo sed -i "s/packages=$(checkupdates)/packages=$(checkupdates | awk '{print $1
.BR echo (1),
.BR sudo (8),
.BR doas (1),
.BR find (1),
.BR sed (1),
.BR file (1),
.BR grep (1),
.BR curl (1),
.BR pacman (8),
.BR pacdiff (8),
Expand Down
31 changes: 30 additions & 1 deletion src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ list_packages() {
echo -e "No update available\n"
orphan_packages
pacnew_files
kernel_reboot
exit 0
else
icon_updates_available
Expand Down Expand Up @@ -206,6 +207,8 @@ update() {

orphan_packages
pacnew_files
kernel_reboot

}

# Definition of the orphan_packages function: Print orphan packages and offer to remove them if there are (used in the "list_packages" and "update" functions)
Expand Down Expand Up @@ -289,7 +292,33 @@ pacnew_files() {
else
echo -e "No pacnew file found\n"
fi

}

# Definition of the kernel_reboot function: Verify if there's a kernel update waiting for a reboot to be applied
kernel_reboot() {
kernel_compare=$(file /boot/vmlinuz* | sed 's/^.*version\ //' | awk '{print $1}' | grep "$(uname -r)")

if [ -z "${kernel_compare}" ]; then
echo -e "--Reboot required--\nThere's a pending kernel update on your system requiring a reboot to be applied"
read -rp $'Would you like to reboot now? [y/N] ' answer

case "${answer}" in
[Yy])
echo -e "\nRebooting in 5 seconds...\nPress ctrl+c to abort"
sleep 5
if ! reboot; then
echo -e >&2 "\nAn error has occurred\nThe reboot has been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
exit 6
fi
;;
*)
echo -e "\nThe reboot hasn't been performed\nPlease, consider rebooting to finalize the pending kernel update\n"
;;
esac
else
echo -e "No pending kernel update found\n"
fi

read -n 1 -r -s -p $'Press \"enter\" to quit\n'
}

Expand Down