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