From: Michael Tremer Date: Fri, 21 Jun 2019 15:12:05 +0000 (+0200) Subject: Implement install action X-Git-Tag: 20190621~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ee4984c6f5c7234eb8970ff9b33da9695bac2ba;p=people%2Farne_f%2Fkernel-updater.git Implement install action Signed-off-by: Michael Tremer --- 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