tor: Completely uninstall app

Tests:
* Manually reinstall the app and check if hidden service is regenerated
* Functional tests passed

Signed-off-by: nbenedek <contact@nbenedek.me>
[sunil: Update docstrings, make uninstall fail-safe]
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-09 14:58:52 +02:00 committed by Sunil Mohan Adapa
parent 6c14b9a304
commit 82101cc9b3
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 17 additions and 0 deletions

View File

@ -187,6 +187,11 @@ class TorApp(app_module.App):
if not old_version:
self.enable()
def uninstall(self):
"""De-configure and uninstall the app."""
super().uninstall()
privileged.uninstall()
def update_hidden_service_domain(status=None):
"""Update HS domain with Name Services module."""

View File

@ -5,6 +5,7 @@ import codecs
import os
import pathlib
import re
import shutil
import socket
import subprocess
import time
@ -507,3 +508,14 @@ def _set_onion_header(hidden_service):
encoding='utf-8')
action_utils.service_reload('apache2')
@privileged
def uninstall():
"""Remove create instances."""
directories = [
'/etc/tor/instances/', '/var/lib/tor-instances/',
'/var/run/tor-instances/'
]
for directory in directories:
shutil.rmtree(directory, ignore_errors=True)