From: mar77i Date: Sun, 26 Nov 2023 22:00:11 +0000 (+0100) Subject: add gitweb_configs updater X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=4acf3cd93e95206921d32d466983d0a30a2372f2;p=admin add gitweb_configs updater --- diff --git a/gitweb_configs.py b/gitweb_configs.py new file mode 100755 index 0000000..21b9fa1 --- /dev/null +++ b/gitweb_configs.py @@ -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 ", + "description": "admin scripts", + }, + "mar77i.info": { + "owner": "mar77i ", + "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() diff --git a/post-receive.sh b/post-receive.sh index 9ed695f..062d072 100755 --- a/post-receive.sh +++ b/post-receive.sh @@ -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}" diff --git a/remote_run.py b/remote_run.py index 8065fa4..b253c9a 100755 --- a/remote_run.py +++ b/remote_run.py @@ -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) diff --git a/update_system.sh b/update_system.sh old mode 100644 new mode 100755