Skip to content

Instantly share code, notes, and snippets.

@ChrisTX
Created July 28, 2025 07:48
Show Gist options
  • Select an option

  • Save ChrisTX/62337d4f32a8e999fd0a3c9dc3161550 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisTX/62337d4f32a8e999fd0a3c9dc3161550 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#shellcheck disable=SC2034
COMMAND="${1}"
KERNEL_VERSION="${2}"
BOOT_DIR_ABS="${3}"
KERNEL_IMAGE="${4}"
if [[ ${KERNEL_INSTALL_LAYOUT} != "arch" ]]; then
exit 0
fi
KERNEL_SUFFIX=$(echo "$KERNEL_VERSION" | sed -n "s/^.*[0-9]\(-\?[a-zA-Z]*\)$/\1/p")
KERNEL_PACKAGE_NAME="linux${KERNEL_SUFFIX}"
KERNEL_INSTALL_ROOT="/boot"
if [[ ${COMMAND} == add ]]; then
mkdir -p "${KERNEL_INSTALL_ROOT}" || exit 1
[[ ${KERNEL_INSTALL_VERBOSE} == 1 ]] && echo "Installing kernel image for ${KERNEL_PACKAGE_NAME}..."
install -m 0644 "${KERNEL_IMAGE}" "${KERNEL_INSTALL_ROOT}/vmlinuz-${KERNEL_PACKAGE_NAME}" || exit 1
INITRD="${KERNEL_INSTALL_STAGING_AREA}/initrd"
if [[ -f ${INITRD} ]]; then
[[ ${KERNEL_INSTALL_VERBOSE} == 1 ]] && echo "Installing initramfs image for ${KERNEL_PACKAGE_NAME}..."
install -m 0644 "${INITRD}" "${KERNEL_INSTALL_ROOT}/initramfs-${KERNEL_PACKAGE_NAME}.img" || exit 1
fi
elif [[ ${COMMAND} == remove ]]; then
[[ ${KERNEL_INSTALL_VERBOSE} == 1 ]] && echo "Removing kernel and initramfs image for ${KERNEL_PACKAGE_NAME}..."
rm -f \
"${KERNEL_INSTALL_ROOT}/vmlinuz-${KERNEL_PACKAGE_NAME}" \
"${KERNEL_INSTALL_ROOT}/initramfs-${KERNEL_PACKAGE_NAME}.img" || exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment