diff --git a/SCAutolib/cli_commands.py b/SCAutolib/cli_commands.py index 2a5417b..2c66a40 100644 --- a/SCAutolib/cli_commands.py +++ b/SCAutolib/cli_commands.py @@ -153,13 +153,18 @@ def setup_user(ctx, name, card_dir, card_type, passwd, pin, user_type): exit(ReturnCode.FAILURE.value) exit(ReturnCode.SUCCESS.value) + @click.command() @click.pass_context def cleanup(ctx): - """Configure entire system for smart cards based on the config file.""" + """ + Cleanup all the configurations and system changes done by the prepare + command. + """ ctx.obj["CONTROLLER"].cleanup() exit(ReturnCode.SUCCESS.value) + cli.add_command(setup_ca) cli.add_command(prepare) cli.add_command(setup_user) diff --git a/SCAutolib/controller.py b/SCAutolib/controller.py index f9d2c10..ec47bbc 100644 --- a/SCAutolib/controller.py +++ b/SCAutolib/controller.py @@ -426,9 +426,9 @@ def cleanup(self): opensc_cache_dir = Path(os.path.expanduser('~') + "/.cache/opensc/") if opensc_cache_dir.exists(): - for file in opensc_cache_dir.iterdir(): - file.unlink() - logger.debug("Removed opesc cache") + for cache_file in opensc_cache_dir.iterdir(): + cache_file.unlink() + logger.debug("Removed opensc file cache") self.sssd_conf.restore() pcscd_service = File("/usr/lib/systemd/system/pcscd.service") @@ -436,7 +436,6 @@ def cleanup(self): opensc_module = File("/usr/share/p11-kit/modules/opensc.module") opensc_module.restore() - @staticmethod def _validate_configuration(conf: dict, params: {} = None) -> dict: """ diff --git a/SCAutolib/models/CA.py b/SCAutolib/models/CA.py index 951e4de..1bd4a0a 100644 --- a/SCAutolib/models/CA.py +++ b/SCAutolib/models/CA.py @@ -17,7 +17,7 @@ from socket import gethostname from SCAutolib import TEMPLATES_DIR, logger, run, LIB_DIR, LIB_DUMP_CAS, \ - LIB_BACKUP + LIB_BACKUP from SCAutolib.exceptions import SCAutolibException from SCAutolib.models.file import OpensslCnf from SCAutolib.enums import CAType diff --git a/SCAutolib/models/card.py b/SCAutolib/models/card.py index 443078e..e07a5c4 100644 --- a/SCAutolib/models/card.py +++ b/SCAutolib/models/card.py @@ -326,6 +326,7 @@ def delete(self): logger.info(f"Virtual card dir of {self.name} removed") self._service_location.unlink() + run("systemctl daemon-reload", sleep=3) logger.debug(f"Service {self._service_name} was removed") if self.dump_file.exists(): diff --git a/SCAutolib/models/file.py b/SCAutolib/models/file.py index aef5299..b7e54c9 100644 --- a/SCAutolib/models/file.py +++ b/SCAutolib/models/file.py @@ -240,11 +240,13 @@ def restore(self, name: str = None): f"{name if name else self._conf_file.name}.backup") if original_path.exists(): - with (self._conf_file.open("w") as config, - original_path.open() as backup): + with self._conf_file.open("w") as config, \ + original_path.open() as backup: config.write(backup.read()) original_path.unlink() - logger.debug(f"File {self._conf_file} is restored to {original_path}") + logger.debug( + f"File {self._conf_file} is restored to {original_path}" + ) class SSSDConf(File): @@ -429,8 +431,8 @@ def restore(self): """ if self._backup_original and self._backup_original.exists(): - with (self._backup_original.open() as original, - self._conf_file.open("w") as config): + with self._backup_original.open() as original, \ + self._conf_file.open("w") as config: config.write(original.read()) self._backup_original.unlink() else: