From 3d718692117ee4e716e3460cf4a19f8493aea6ab Mon Sep 17 00:00:00 2001 From: nbenedek Date: Mon, 3 Apr 2023 22:25:19 +0200 Subject: [PATCH] bepasty: Completely uninstall app During the uninstall process: * Remove bepasty data directory * Remove freedombox config file * Remove bepasty user (and group) Test: * Manually test if data is indeed removed * Run functional tests Signed-off-by: nbenedek [sunil: Update docstrings, make uninstall fail-safe] [sunil: Remove bapasty group as well] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/bepasty/__init__.py | 5 +++++ plinth/modules/bepasty/privileged.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/plinth/modules/bepasty/__init__.py b/plinth/modules/bepasty/__init__.py index d02b8139b..8b2b9a423 100644 --- a/plinth/modules/bepasty/__init__.py +++ b/plinth/modules/bepasty/__init__.py @@ -99,3 +99,8 @@ class BepastyApp(app_module.App): # Upgrade to a better default only if user hasn't changed the # value. privileged.set_default(['read']) + + def uninstall(self): + """De-configure and uninstall the app.""" + super().uninstall() + privileged.uninstall() diff --git a/plinth/modules/bepasty/privileged.py b/plinth/modules/bepasty/privileged.py index 4c28ec803..d0e37bcb8 100644 --- a/plinth/modules/bepasty/privileged.py +++ b/plinth/modules/bepasty/privileged.py @@ -168,3 +168,12 @@ def _generate_password(): """Generate a random password.""" alphabet = string.ascii_letters + string.digits return ''.join(secrets.choice(alphabet) for _ in range(PASSWORD_LENGTH)) + + +@privileged +def uninstall(): + """Remove bepasty user, group and data.""" + shutil.rmtree(DATA_DIR, ignore_errors=True) + CONF_FILE.unlink(missing_ok=True) + subprocess.run(['deluser', 'bepasty'], check=False) + subprocess.run(['delgroup', 'bepasty'], check=False)