diskimage-builder/elements/redhat-common/finalise.d/01-clean-old-kernels
Yolanda Robla Mota c1bac651cb Allow to skip kernel cleanup
For some use cases, it can be useful to keep all the kernels
and not just keep the latest one. Add a parameter that allows
it, and continue cleaning up kernels by default.

Change-Id: Ia6e6c1fa18e3724c1eb89226151d81e9e748b793
2016-08-12 12:49:19 +02:00

27 lines
572 B
Bash
Executable File

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
if [ $DIB_DISABLE_KERNEL_CLEANUP -ne 0 ]; then
echo "Skipping kernel cleanup as configured"
exit 0
fi
YUM=${YUM:-yum}
if [[ ${YUM} == "dnf" ]]; then
# cribbed from
# http://dnf.readthedocs.org/en/latest/cli_vs_yum.html
_old_kernels="$(dnf repoquery --installonly --latest-limit -1 -q)"
if [[ -n "${_old_kernels}" ]]; then
dnf remove -y ${_old_kernels}
fi
else
install-packages yum-utils
package-cleanup --oldkernels -y --count=1
fi