浏览代码

Add a python script

jherve 1 月之前
父节点
当前提交
ce0e5b91f6
共有 1 个文件被更改,包括 43 次插入0 次删除
  1. 43 0
      start.py

+ 43 - 0
start.py

@@ -0,0 +1,43 @@
+import os
+import subprocess
+from pathlib import Path
+
+def to_volume_string(vol: str):
+    return f"-v {vol}:/mnt/source{vol}:ro"
+
+def main():
+    hostname = "host"
+    container_name = "borgmatic"
+    ssh_auth_sock = os.getenv("SSH_AUTH_SOCK")
+    config_path = Path.cwd() / "data" / "borgmatic.d"
+    ssh_config_path = Path.home() / ".ssh"
+    volumes = [
+        f"{config_path}:/etc/borgmatic.d/",
+        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"]
+
+    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()