]> git.ipfire.org Git - people/arne_f/kernel-updater.git/commitdiff
Implement install action
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jun 2019 15:12:05 +0000 (17:12 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jun 2019 15:12:05 +0000 (17:12 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/kernel-updater.in

index 3b7d02db5c80a84cba82b998d144585dc922b4df..1e4f7b8986610fd435bbeba2fa11cdefca9a7d78 100644 (file)
 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