From 938e428eaf5117c3a541697e8c327358b05ecca9 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 10 Feb 2024 11:07:51 +0100 Subject: [PATCH] also delete directory in /usr/src --- roles/batman/files/cleanup.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/roles/batman/files/cleanup.py b/roles/batman/files/cleanup.py index cfa5f57..7992820 100644 --- a/roles/batman/files/cleanup.py +++ b/roles/batman/files/cleanup.py @@ -3,6 +3,14 @@ import subprocess import sys import re +import shutil + +def delete_directory(directory): + try: + shutil.rmtree(directory) + print("Directory deleted successfully!") + except OSError as error: + print("Error deleting directory:", error) # Retrieve the desired version from command line input desired_version = sys.argv[1] @@ -33,6 +41,8 @@ if module_version != desired_version: subprocess.call(["dkms", "remove", module_name, "-v", module_version]) print(f"Uninstalled batman_adv version {module_version}") + batman_folder = f"/usr/src/{module_name}-{module_version}" + delete_directory(batman_folder) except subprocess.CalledProcessError: print(f"Error: Module '{module_name}' might not exist or is unavailable for removal.")