jherve 1 месяц назад
Родитель
Сommit
7fe59bad9e
1 измененных файлов с 5 добавлено и 3 удалено
  1. 5 3
      pc_backup/start.py

+ 5 - 3
pc_backup/start.py

@@ -127,11 +127,13 @@ class Configuration:
     borgmatic_d_path: Path
     borgmatic_d_path: Path
     borgmatic_path: Path
     borgmatic_path: Path
     history_file: Path
     history_file: Path
+    ssh_auth_sock: Path | None
 
 
     @classmethod
     @classmethod
     def read(cls, hostname: str, login: str, config_dir: Path):
     def read(cls, hostname: str, login: str, config_dir: Path):
         secret_sources_file = config_dir / f"secret_sources_{hostname}_{login}"
         secret_sources_file = config_dir / f"secret_sources_{hostname}_{login}"
         data_sources_file = config_dir / f"data_sources_{hostname}_{login}"
         data_sources_file = config_dir / f"data_sources_{hostname}_{login}"
+        ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
 
 
         return cls(
         return cls(
             secret_sources=Secret.read_sources(secret_sources_file),
             secret_sources=Secret.read_sources(secret_sources_file),
@@ -139,6 +141,7 @@ class Configuration:
             borgmatic_d_path=config_dir / "borgmatic.d",
             borgmatic_d_path=config_dir / "borgmatic.d",
             borgmatic_path=config_dir / "borgmatic",
             borgmatic_path=config_dir / "borgmatic",
             history_file=config_dir / ".bash_history",
             history_file=config_dir / ".bash_history",
+            ssh_auth_sock=Path(ssh_auth_sock) if ssh_auth_sock else None
         )
         )
 
 
 
 
@@ -151,7 +154,6 @@ class BorgmaticContainer:
 
 
     def run(self, config: Configuration):
     def run(self, config: Configuration):
         container_name = f"borgmatic_{self.login}"
         container_name = f"borgmatic_{self.login}"
-        ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
 
 
         config.history_file.touch()
         config.history_file.touch()
         volumes = [
         volumes = [
@@ -163,8 +165,8 @@ class BorgmaticContainer:
             "borg_cache:/root/.cache/borg",
             "borg_cache:/root/.cache/borg",
             "borgmatic_state:/root/.local/state/borgmatic",
             "borgmatic_state:/root/.local/state/borgmatic",
         ]
         ]
-        if ssh_auth_sock:
-            volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"]
+        if config.ssh_auth_sock:
+            volumes += [f"{config.ssh_auth_sock}:{config.ssh_auth_sock}:Z"]
 
 
         volumes += [
         volumes += [
             f"{vol}:{self.to_source_path(vol)}:ro" for vol in config.data_sources
             f"{vol}:{self.to_source_path(vol)}:ro" for vol in config.data_sources