import os import subprocess import socket from pathlib import Path 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"] 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", "--security-opt=label=disable" ] + volume_args + [image_name] print(args) subprocess.run(args) if __name__ == "__main__": main()