import os import subprocess import socket from pathlib import Path is_windows = os.name == "nt" data_sources = [ Path.home() / "Documents" / "cv", Path.home() / "Documents" / "formations" / "5_jours" ] def to_volume_string(vol: str | Path): return f"-v {vol}:/mnt/source{vol}:ro" def main(): hostname = socket.gethostname() container_name = "borgmatic" ssh_auth_sock = os.getenv("SSH_AUTH_SOCK") config_path = Path.cwd() / "data" / "borgmatic.d" credentials_path = Path.cwd() / "data" / "credentials" ssh_config_path = Path.home() / ".ssh" volumes = [ f"{config_path}:/etc/borgmatic.d/", f"{credentials_path}:/credentials/", f"{ssh_config_path}:/root/.ssh", "borg_config:/root/.config/borg", "borg_cache:/root/.cache/borg", "borgmatic_state:/root/.local/state/borgmatic", ] if ssh_auth_sock: volumes += [f"{ssh_auth_sock}:{ssh_auth_sock}:Z"] if is_windows: ssh_key_name = "theenglishway-windows" else: ssh_key_name = "theenglishway.pub" volumes += [ f"{vol}:/mnt/source{vol}:ro" for vol in data_sources ] volume_args = [a for vol in volumes for a in ["-v", vol]] image_name = "ghcr.io/borgmatic-collective/borgmatic" args = [ "podman", "run", "-h", hostname, "--detach", "--name", container_name, "-e SSH_AUTH_SOCK", "-e TZ=Europe/Paris", "-e", f"SSH_KEY_NAME={ssh_key_name}", "--security-opt=label=disable" ] + volume_args + [image_name] print(args) subprocess.run(args) if __name__ == "__main__": main()