Unverified Commit c1599805 authored by Massimiliano Adamo's avatar Massimiliano Adamo
Browse files

minor changes

parent 327ab0a4
......@@ -3,7 +3,6 @@
# the deb is tracked with git lfs:
# git lfs track "deb/**"
#
# I'll wait for better days to implement tags
PROG_NAME="ubuntu-kernel-cleanup"
EMAIL="Massimiliano Adamo<massimiliano.adamo@geant.org"
DESCRIPTION="Clean up unused kernel packages"
......@@ -18,9 +17,6 @@ LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
PROG_VERSION=${LATEST_TAG:1}
git checkout $LATEST_TAG
# ensure the we don't have extraneous files around
rm -fr *.deb
fpm -f -t deb -n ${PROG_NAME} -v $PROG_VERSION --maintainer "$EMAIL" --vendor "$EMAIL" \
-a all --description "$DESCRIPTION" --config-files etc/${PROG_NAME}.ini \
-p deb/${PROG_NAME}_${PROG_VERSION}_all.deb \
......
......@@ -15,7 +15,7 @@ Options:
"""
import re
import os
import subprocess
import subprocess as sp
import configparser
from distutils.version import LooseVersion
import platform
......@@ -39,10 +39,10 @@ def get_packages_list(pkg_match):
Or if we need the version only:
dpkg-query -f '${Status} ${Version}\n' -W linux-image-[1-9]* | awk '/ok installed/{print $NF}'
"""
installed = subprocess.Popen(
installed = sp.Popen(
"dpkg --list %s[1-9]* | awk \'/^ii /&&/%s/{print $2}\'" % (
pkg_match, pkg_match),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
stdout=sp.PIPE, stderr=sp.PIPE, shell=True
)
installed_out, _ = installed.communicate()
installed_list = installed_out.decode('utf-8').split('\n')
......@@ -148,22 +148,29 @@ if __name__ == '__main__':
sanitized_kernel_list = kern_list
del kern_list[-1]
# delete running kernel package from list
purged_list = [
item for item in sanitized_kernel_list if running_kernel not in item]
# uninstall packages from list
for kernel_pkg in KERNEL_PREFIXES:
for kernel_version in purged_list:
remove_pkg(kernel_version, kernel_pkg, EXECUTION)
try:
sanitized_kernel_list
except NameError:
pass
else:
# delete running kernel package from list
purged_list = [
item for item in sanitized_kernel_list if running_kernel not in item]
# uninstall packages from list
for kernel_pkg in KERNEL_PREFIXES:
for kernel_version in purged_list:
remove_pkg(kernel_version, kernel_pkg, EXECUTION)
CACHE.close() # it returns always true... keeps closing :)
# purge empty packages
purge = subprocess.Popen(
"dpkg-query -f \'${Package} ${Status}\\n\' -W linux-* | awk \'/deinstall ok/{print $1}\' | xargs apt-get purge -y", # pylint: disable=C0301
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
)
if EXECUTION == 'real':
CMD = "dpkg-query -f \'${Package} ${Status}\\n\' -W linux-* | awk \'/deinstall ok/{print $1}\' | xargs apt-get purge -y" # pylint: disable=C0301
else:
CMD = "dpkg-query -f \'${Package} ${Status}\\n\' -W linux-* | awk \'/deinstall ok/{print $1}\' | xargs apt-get purge --assume-no" # pylint: disable=C0301
purge = sp.Popen(CMD, stdout=sp.PIPE, stderr=sp.PIPE, shell=True)
purge_out, _ = purge.communicate()
print("trying to purge empty kernel packages:\n{}".format(
purge_out.decode('utf-8')))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment