bundles/apt: add a bit of code to remove old, unused kernel images
This commit is contained in:
parent
8a0c8f32ae
commit
7ca24d27d3
2 changed files with 21 additions and 0 deletions
|
@ -48,6 +48,26 @@ fi
|
|||
DEBIAN_FRONTEND=noninteractive apt-get -y -q autoclean
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -y -q autoremove
|
||||
|
||||
% if clean_old_kernels:
|
||||
existing=$(dpkg --get-selections | grep -E '^linux-(image|headers)-[0-9]' || true)
|
||||
|
||||
if [[ -z "$existing" ]]
|
||||
then
|
||||
echo "ERROR: No installed kernels found! Aborting!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current=$(uname -r | sed -r 's/-[a-zA-Z]+$//')
|
||||
latest=$(echo "$existing" | sort --version-sort -t- -k 3,4 | tail -n 1 | sed -r 's/[^0-9]+([0-9]\.[^-]+-[0-9]+).*/\1/')
|
||||
todelete=$(echo "$existing" | grep -v -E "($current|$latest)" | awk '{ print $1 }' || true)
|
||||
|
||||
if [[ -n "$todelete" ]]
|
||||
then
|
||||
DEBIAN_FRONTEND=noninteractive apt-get -qy purge $todelete
|
||||
fi
|
||||
% endif
|
||||
|
||||
|
||||
if [[ -f /var/run/reboot-required ]]
|
||||
then
|
||||
% if 'mail' in data:
|
||||
|
|
|
@ -31,6 +31,7 @@ files = {
|
|||
'content_type': 'mako',
|
||||
'mode': '0700',
|
||||
'context': {
|
||||
'clean_old_kernels': node.metadata.get('apt/clean_old_kernels', True),
|
||||
'data': node.metadata.get('apt/unattended-upgrades', {}),
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue