2018-03-22 22:28:38 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-07-02 14:00:49 +00:00
|
|
|
if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-03-22 22:28:38 +00:00
|
|
|
[[ -f /etc/sysconfig/kernel ]] && . /etc/sysconfig/kernel
|
|
|
|
|
|
|
|
COMMAND="$1"
|
|
|
|
KERNEL_VERSION="$2"
|
|
|
|
BOOT_DIR_ABS="$3"
|
|
|
|
KERNEL_IMAGE="$4"
|
|
|
|
|
|
|
|
KERNEL_DIR="${KERNEL_IMAGE%/*}"
|
|
|
|
|
|
|
|
MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
|
|
|
|
|
|
|
|
BLS_DIR="/boot/loader/entries"
|
2019-12-02 12:36:43 +00:00
|
|
|
ZIPLCFG="/etc/zipl.conf"
|
2018-03-22 22:28:38 +00:00
|
|
|
CMDLINE_LINUX_DEBUG=" systemd.log_level=debug systemd.log_target=kmsg"
|
|
|
|
LINUX_DEBUG_VERSION_POSTFIX="_with_debugging"
|
|
|
|
LINUX_DEBUG_TITLE_POSTFIX=" with debugging"
|
|
|
|
|
|
|
|
mkbls() {
|
|
|
|
local kernelver=$1 && shift
|
|
|
|
local datetime=$1 && shift
|
|
|
|
local kernelopts=$1 && shift
|
|
|
|
|
|
|
|
local debugname=""
|
|
|
|
local flavor=""
|
|
|
|
|
|
|
|
if [[ "$kernelver" == *\+* ]] ; then
|
|
|
|
local flavor=-"${kernelver##*+}"
|
|
|
|
if [[ "${flavor}" == "-debug" ]]; then
|
|
|
|
local debugname=" with debugging"
|
|
|
|
local debugid="-debug"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
title ${NAME} (${kernelver}) ${VERSION}${debugname}
|
|
|
|
version ${kernelver}${debugid}
|
|
|
|
linux /boot/vmlinuz-${kernelver}
|
|
|
|
initrd /boot/initramfs-${kernelver}.img
|
|
|
|
options ${kernelopts}
|
|
|
|
id ${ID}-${datetime}-${kernelver}${debugid}
|
|
|
|
grub_users \$grub_users
|
|
|
|
grub_arg --unrestricted
|
|
|
|
grub_class kernel${flavor}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ "$KERNEL_VERSION" == *\+* ]] && flavor=-"${KERNEL_VERSION##*+}"
|
|
|
|
case "$COMMAND" in
|
|
|
|
add)
|
|
|
|
if [[ "${KERNEL_DIR}" != "/boot" ]]; then
|
|
|
|
for i in \
|
|
|
|
"$KERNEL_IMAGE" \
|
|
|
|
"$KERNEL_DIR"/System.map \
|
|
|
|
"$KERNEL_DIR"/config \
|
|
|
|
"$KERNEL_DIR"/zImage.stub
|
|
|
|
do
|
|
|
|
[[ -e "$i" ]] || continue
|
|
|
|
cp -aT "$i" "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon -R "/boot/${i##*/}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
i="$KERNEL_DIR/.${KERNEL_IMAGE##*/}.hmac"
|
|
|
|
if [[ -e "$i" ]]; then
|
|
|
|
cp -a "$i" "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
command -v restorecon &>/dev/null && \
|
|
|
|
restorecon "/boot/.${KERNEL_IMAGE##*/}-${KERNEL_VERSION}.hmac"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-11-29 16:57:18 +00:00
|
|
|
if [[ ! -f /sbin/new-kernel-pkg || -d "${BLS_DIR}" ]]; then
|
2018-03-22 22:28:38 +00:00
|
|
|
declare -a BOOT_OPTIONS
|
2023-01-17 16:33:21 +00:00
|
|
|
if [[ ! -f /etc/kernel/cmdline ]]; then
|
|
|
|
last=''
|
|
|
|
for entry in "${BLS_DIR}"/*.conf; do
|
|
|
|
last="$entry"
|
|
|
|
done
|
|
|
|
if [[ ! -z "$last" ]]; then
|
|
|
|
args="$(awk '/options/{$1="";$0=$0;$1=$1;print}' $last)"
|
|
|
|
echo "$args" > /etc/kernel/cmdline
|
|
|
|
fi
|
|
|
|
fi
|
2018-03-22 22:28:38 +00:00
|
|
|
if [[ -f /etc/kernel/cmdline ]]; then
|
|
|
|
read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [[ ${BOOT_OPTIONS[*]} ]]; then
|
2023-01-17 16:33:21 +00:00
|
|
|
echo "Could not determine the kernel command line parameters." >&2
|
|
|
|
echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
|
|
|
|
exit 1
|
2018-03-22 22:28:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
[[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR"
|
|
|
|
BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
|
|
|
|
if [[ -f "${KERNEL_DIR}/bls.conf" ]]; then
|
|
|
|
cp -aT "${KERNEL_DIR}/bls.conf" "${BLS_TARGET}" || exit $?
|
|
|
|
sed -i -e "s,^linux.*,linux /boot/vmlinuz-${KERNEL_VERSION},g" "${BLS_TARGET}"
|
|
|
|
sed -i -e "s,^initrd.*,initrd /boot/initramfs-${KERNEL_VERSION}.img,g" "${BLS_TARGET}"
|
2018-10-01 15:51:30 +00:00
|
|
|
sed -i -e "s#^options.*#options ${BOOT_OPTIONS[*]}#g" "${BLS_TARGET}"
|
2018-03-22 22:28:38 +00:00
|
|
|
else
|
|
|
|
mkbls "${KERNEL_VERSION}" \
|
|
|
|
"$(date -u +%Y%m%d%H%M%S -d "$(stat -c '%y' "${KERNEL_DIR}")")" \
|
|
|
|
"${BOOT_OPTIONS[*]}" >"${BLS_TARGET}"
|
|
|
|
fi
|
|
|
|
|
2019-12-02 12:36:43 +00:00
|
|
|
if [[ "$KERNEL_VERSION" == *\+* ]] && [ "x$DEFAULTDEBUG" != "xyes" ]; then
|
|
|
|
UPDATEDEFAULT="no"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "x$UPDATEDEFAULT" = "xyes" ]]; then
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_TARGET}" | sed -e 's/^title[ \t]*//')"
|
|
|
|
NEWDEFAULT="${TITLE}"
|
|
|
|
fi
|
|
|
|
|
2018-03-22 22:28:38 +00:00
|
|
|
if [ "x${MAKEDEBUG}" = "xyes" ]; then
|
2018-10-15 17:57:18 +00:00
|
|
|
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
|
2018-03-22 22:28:38 +00:00
|
|
|
cp -aT "${BLS_TARGET}" "${BLS_DEBUG}"
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
|
|
|
|
VERSION="$(grep '^version[ \t]' "${BLS_DEBUG}" | sed -e 's/^version[ \t]*//')"
|
2018-10-15 17:57:18 +00:00
|
|
|
BLSID="$(grep '^id[ \t]' "${BLS_DEBUG}" | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
|
2018-03-22 22:28:38 +00:00
|
|
|
sed -i -e "s/^title.*/title ${TITLE}${LINUX_DEBUG_TITLE_POSTFIX}/" "${BLS_DEBUG}"
|
|
|
|
sed -i -e "s/^version.*/version ${VERSION}${LINUX_DEBUG_VERSION_POSTFIX}/" "${BLS_DEBUG}"
|
|
|
|
sed -i -e "s/^id.*/${BLSID}/" "${BLS_DEBUG}"
|
2018-10-01 15:51:30 +00:00
|
|
|
sed -i -e "s#^options.*#options ${BOOT_OPTIONS[*]}${CMDLINE_LINUX_DEBUG}#" "${BLS_DEBUG}"
|
2019-12-02 12:36:43 +00:00
|
|
|
if [ -n "$NEWDEFAULT" -a "x$DEFAULTDEBUG" = "xyes" ]; then
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
|
|
|
|
NEWDEFAULT="${TITLE}"
|
|
|
|
fi
|
2018-03-22 22:28:38 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-03 15:26:20 +00:00
|
|
|
if [ -n "$NEWDEFAULT" ] && [ -f "${ZIPLCFG}" ]; then
|
|
|
|
if grep -q "^default=" "${ZIPLCFG}"; then
|
|
|
|
sed -i -e "s,^default=.*,default=${NEWDEFAULT}," "${ZIPLCFG}"
|
|
|
|
else
|
|
|
|
echo "default=${NEWDEFAULT}" >> "${ZIPLCFG}"
|
|
|
|
fi
|
2019-12-02 12:36:43 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-22 22:28:38 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --install "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --mkinitrd --dracut --depmod --update "$KERNEL_VERSION" || exit $?
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor}" --rpmposttrans "$KERNEL_VERSION" || exit $?
|
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
|
|
|
;;
|
|
|
|
remove)
|
2019-11-29 16:57:18 +00:00
|
|
|
if [[ ! -f /sbin/new-kernel-pkg || -d "${BLS_DIR}" ]]; then
|
2018-03-22 22:28:38 +00:00
|
|
|
ARCH="$(uname -m)"
|
|
|
|
BLS_TARGET="${BLS_DIR}/${MACHINE_ID}-${KERNEL_VERSION}.conf"
|
2019-12-02 12:36:43 +00:00
|
|
|
BLS_DEBUG="$(echo ${BLS_TARGET} | sed -e "s/${KERNEL_VERSION}/${KERNEL_VERSION}~debug/")"
|
|
|
|
|
2020-07-03 15:26:20 +00:00
|
|
|
if [ -f "${BLS_TARGET}" ] && [ -f "${ZIPLCFG}" ]; then
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_TARGET}" | sed -e 's/^title[ \t]*//')"
|
|
|
|
sed -i -e "/^default=${TITLE}/d" "${ZIPLCFG}"
|
|
|
|
fi
|
2019-12-02 12:36:43 +00:00
|
|
|
|
|
|
|
if [[ -f "${BLS_DEBUG}" ]]; then
|
|
|
|
TITLE="$(grep '^title[ \t]' "${BLS_DEBUG}" | sed -e 's/^title[ \t]*//')"
|
|
|
|
sed -i -e "/^default=${TITLE}/d" "${ZIPLCFG}"
|
|
|
|
fi
|
|
|
|
|
2018-03-22 22:28:38 +00:00
|
|
|
rm -f "${BLS_TARGET}" "${BLS_DEBUG}"
|
|
|
|
|
|
|
|
for i in vmlinuz System.map config zImage.stub dtb; do
|
|
|
|
rm -rf "/boot/${i}-${KERNEL_VERSION}"
|
|
|
|
done
|
|
|
|
# hmac is .vmlinuz-<version>.hmac so needs a special treatment
|
|
|
|
rm -f "/boot/.vmlinuz-${KERNEL_VERSION}.hmac"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
/sbin/new-kernel-pkg --package "kernel${flavor+-$flavor}" --rminitrd --rmmoddep --remove "$KERNEL_VERSION" || exit $?
|
|
|
|
# If grubby is used there's no need to run other installation plugins
|
|
|
|
exit 77
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|