From 7ee4984c6f5c7234eb8970ff9b33da9695bac2ba Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 21 Jun 2019 17:12:05 +0200 Subject: [PATCH] Implement install action Signed-off-by: Michael Tremer --- src/kernel-updater.in | 69 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/kernel-updater.in b/src/kernel-updater.in index 3b7d02d..1e4f7b8 100644 --- a/src/kernel-updater.in +++ b/src/kernel-updater.in @@ -22,11 +22,78 @@ PACKAGE_NAME="@PACKAGE_NAME@" PACKAGE_VERSION="@PACKAGE_VERSION@" +GRUB_CFG="/boot/grub/grub.cfg" +MODULES_PATH="/lib/modules" + +update_bootloader() { + # GRUB + if [ -e "${GRUB_CFG}" ]; then + grub-mkconfig -o "${GRUB_CFG}" || return $? + fi + + return 0 +} + +# This function installs a new kernel +do_install() { + local version="${1}" + + # Check if we actually have a kernel with this version + if ! check_version "${version}"; then + echo "Kernel ${version} does not exist" >&2 + return 2 + fi + + # Update module dependencies + echo "Updating module dependencies..." + if ! depmod -A "${version}"; then + echo "Could not update module dependencies. Exiting." >&2 + return 1 + fi + + # Generate initramfs + echo "Generating initramfs..." + if ! dracut --quiet --force --early-microcode --xz \ + "/boot/initramfs-${version}.img" "${version}"; then + echo "Could not generate the initramfs" >&2 + return 1 + fi + + # Update bootloader + echo "Updating bootloader configuration..." + if ! update_bootloader; then + echo "Could not update the bootloader configuration" >&2 + return 1 + fi + + # All done + return 0 +} + +check_version() { + local version="${1}" + + if [ -d "${MODULES_PATH}/${version}" ]; then + return 0 + else + return 1 + fi +} + main() { local action="${1}" - shift + local version="${2}" + shift 2 + + if [ -z "${version}" ]; then + version="$(uname -r)" + fi case "${action}" in + install) + do_install "${version}" || return $? + ;; + version) echo "${PACKAGE_NAME}: Version ${PACKAGE_VERSION}" return 0 -- 2.47.3