]> git.mar77i.info Git - admin/commitdiff
add gitweb_configs updater
authormar77i <mar77i@protonmail.ch>
Sun, 26 Nov 2023 22:00:11 +0000 (23:00 +0100)
committermar77i <mar77i@protonmail.ch>
Sun, 26 Nov 2023 22:40:16 +0000 (23:40 +0100)
gitweb_configs.py [new file with mode: 0755]
post-receive.sh
remote_run.py
update_system.sh [changed mode: 0644->0755]

diff --git a/gitweb_configs.py b/gitweb_configs.py
new file mode 100755 (executable)
index 0000000..21b9fa1
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+from pathlib import Path
+from subprocess import CalledProcessError, check_output, run
+
+GITWEB_CONFIGS = {
+    "admin": {
+        "owner": "mar77i <mar77i@protonmail.ch>",
+        "description": "admin scripts",
+    },
+    "mar77i.info": {
+        "owner": "mar77i <mar77i@protonmail.ch>",
+        "description": "mar77i.info website",
+    },
+}
+
+
+def main():
+    base_dir = Path.home() / "git"
+    mismatched = set(GITWEB_CONFIGS) ^ {p.name for p in base_dir.iterdir() if p.is_dir()}
+    if mismatched:
+        print(
+            f"Warning: gitweb_configs mismatch: {', '.join(mismatched)}",
+            file=sys.stderr,
+        )
+    for repository, configs in GITWEB_CONFIGS.items():
+        p = base_dir / repository
+        if not p.exists():
+            continue
+        os.chdir(p)
+        description = p / "description"
+        if description.exists():
+            description.unlink()
+        assert set(configs) == {"owner", "description"}
+        for key, value in configs.items():
+            try:
+                output = check_output(
+                    ["git", "config", "--get", f"gitweb.{key}"], universal_newlines=True
+                )
+            except CalledProcessError:
+                output = None
+            if output != f"{value}\n":
+                run(["git", "config", f"gitweb.{key}", value])
+
+
+if __name__ == "__main__":
+    main()
index 9ed695f602ef9c7e6b158c2b71ad31147a2d9e2e..062d0724a4b8166b875004bb32af2e58fab9e1a7 100755 (executable)
@@ -41,10 +41,14 @@ fi
 
 update_gitweb_theme() {
     local theme_css_dest="${HOME}/gitweb/gitweb-theme.css"
-    print_and_run bash -c "git show master:gitweb-theme.css > ${theme_css_dest}"
+    print_and_run bash -c "git show master:gitweb-theme.css > \"${theme_css_dest}\""
 }
 
-tasks=(update_gitweb_theme)
+update_gitweb_configs() {
+  print_and_run bash -c 'python <(git show master:gitweb_configs.py)'
+}
+
+tasks=(update_gitweb_theme update_gitweb_configs)
 
 for task in "${tasks[@]}"; do
     "${task}"
index 8065fa41dbacbf54aa57b669941c4eda92334351..b253c9aaee5ea476de0570a2cef2a5659ffb0ff6 100755 (executable)
@@ -7,7 +7,7 @@ from argparse import ArgumentError
 from itertools import chain
 from pathlib import Path
 from socketserver import BaseRequestHandler, TCPServer
-from subprocess import DEVNULL, PIPE, Popen, run
+from subprocess import DEVNULL, PIPE, Popen, check_output, run
 
 PORT = "7777"
 REMOTE_HOST = "localhost"
@@ -18,6 +18,10 @@ AUTH_SOCK_PATTERN = re.compile(
 )
 
 
+class ReusableTCPServer(TCPServer):
+    allow_reuse_address = True
+
+
 def check_ssh_auth_sock(**kwargs):
     completed = run(
         ["ssh-add", "-l"],
@@ -48,11 +52,10 @@ def get_ssh_auth_sock():
         ):
             return q_str
     print("starting new ssh-agent")
-    return run(
+    return check_output(
         ["bash", "-c", '. <(ssh-agent); echo "${SSH_AUTH_SOCK}"'],
-        stdout=PIPE,
         universal_newlines=True,
-    ).stdout
+    )
 
 
 def create_tcp_server(server_address, data):
@@ -63,9 +66,6 @@ def create_tcp_server(server_address, data):
         def handle(self):
             self.request.sendall(data)
 
-    class ReusableTCPServer(TCPServer):
-        allow_reuse_address = True
-
     return ReusableTCPServer(server_address, RequestHandler)
 
 
old mode 100644 (file)
new mode 100755 (executable)