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 <contact@nbenedek.me>
[sunil: Update docstrings, make uninstall fail-safe]
[sunil: Remove bapasty group as well]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
nbenedek 2023-04-03 22:25:19 +02:00 committed by Sunil Mohan Adapa
parent a6e728fc0f
commit 3d71869211
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 14 additions and 0 deletions

View File

@ -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()

View File

@ -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)