From: Shane Date: Sun, 11 Jan 2026 02:23:59 +0000 (+0000) Subject: add scripts for setting gitweb owner/repo description X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=7a4228c39a5298db323e4f337bbb89d11e1dbe89;p=nutratech%2Fvps-root.git add scripts for setting gitweb owner/repo description --- diff --git a/Makefile b/Makefile index 24f3733..743f27a 100644 --- a/Makefile +++ b/Makefile @@ -113,3 +113,26 @@ else @echo "Listing certificates..." sudo certbot certificates endif + +.PHONY: gitweb/set-owner +gitweb/set-owner: ##H @Local Set gitweb.owner for all repos (usage: make gitweb/set-owner OWNER="Shane") +ifndef OWNER + $(error OWNER is undefined. Usage: make gitweb/set-owner OWNER="Shane") +endif +ifdef SUDO_USER + @echo "Setting owner as $(SUDO_USER)..." + su -P $(SUDO_USER) -c "bash scripts/set_gitweb_owner.sh '$(OWNER)'" +else + @echo "Setting owner..." + bash scripts/set_gitweb_owner.sh "$(OWNER)" +endif + +.PHONY: gitweb/update-metadata +gitweb/update-metadata: ##H @Local Bulk update repo metadata from CSV (usage: make gitweb/update-metadata CSV=repo_metadata.csv) + @echo "Updating repository metadata..." +ifdef SUDO_USER + @# Run as SUDO_USER (usually gg) to have permission to write to git repos + su -P $(SUDO_USER) -c "python3 scripts/update_repo_metadata.py $(or $(CSV),repo_metadata.csv)" +else + python3 scripts/update_repo_metadata.py $(or $(CSV),repo_metadata.csv) +endif diff --git a/scripts/deploy.sh b/scripts/deploy.sh index db95697..90873c6 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -31,7 +31,7 @@ if [ "$1" = "diff" ]; then if [ -f "$GITWEB_CONF_SRC" ]; then diff -u --color=always /etc/gitweb.conf "$GITWEB_CONF_SRC" || true fi - + exit 0 fi diff --git a/scripts/repo_metadata.csv b/scripts/repo_metadata.csv new file mode 100644 index 0000000..d16ec9f --- /dev/null +++ b/scripts/repo_metadata.csv @@ -0,0 +1,3 @@ +repo_path,owner,description +projects/git-remote-gcrypt.git,Shane,Progressive fork of `git-remote-gcrypt` +projects/@tg-svelte/kit.git,Shane,SvelteKit fork with legacy browser support (IE11) and static builds diff --git a/scripts/set_gitweb_owner.sh b/scripts/set_gitweb_owner.sh new file mode 100644 index 0000000..acd5707 --- /dev/null +++ b/scripts/set_gitweb_owner.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +OWNER="$1" +PROJECT_ROOT="/srv/git/projects" + +if [ -z "$OWNER" ]; then + echo "Usage: $0 \"Owner Name\"" + exit 1 +fi + +if [ ! -d "$PROJECT_ROOT" ]; then + echo "Error: Directory $PROJECT_ROOT not found." + exit 1 +fi + +echo "Setting 'gitweb.owner' to '$OWNER' for all repos in $PROJECT_ROOT..." + +# Iterate over directories ending in .git +find "$PROJECT_ROOT" -name "*.git" -type d | while read -r repo; do + if [ -f "$repo/config" ]; then + echo "Updating $repo..." + git config --file "$repo/config" gitweb.owner "$OWNER" + else + echo "Skipping $repo (no config file found)" + fi +done + +echo "Done." diff --git a/scripts/update_repo_metadata.py b/scripts/update_repo_metadata.py new file mode 100644 index 0000000..56ecf68 --- /dev/null +++ b/scripts/update_repo_metadata.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +import csv +import os +import subprocess +import sys + +# Default to repo_metadata.csv in the current directory if not provided +CSV_FILE = sys.argv[1] if len(sys.argv) > 1 else "repo_metadata.csv" +GIT_ROOT = "/srv/git" + + +def main(): + if not os.path.exists(CSV_FILE): + print(f"Error: CSV file '{CSV_FILE}' not found.") + sys.exit(1) + + print(f"Reading metadata from {CSV_FILE}...") + + with open(CSV_FILE, mode="r", newline="", encoding="utf-8") as f: + reader = csv.DictReader(f) + + # Normalize column names (strip whitespace) + reader.fieldnames = [name.strip() for name in reader.fieldnames] + + if "repo_path" not in reader.fieldnames: + print("Error: CSV must have a 'repo_path' column.") + sys.exit(1) + + for row in reader: + repo_rel_path = row["repo_path"].strip() + owner = row.get("owner", "").strip() + description = row.get("description", "").strip() + + if not repo_rel_path: + continue + + full_repo_path = os.path.join(GIT_ROOT, repo_rel_path) + + if not os.path.isdir(full_repo_path): + print( + f"Skipping {repo_rel_path}: Not found directly at {full_repo_path}" + ) + # Try prepending projects/ if not present, just in case user omitted it + if not repo_rel_path.startswith("projects/"): + alt_path = os.path.join(GIT_ROOT, "projects", repo_rel_path) + if os.path.isdir(alt_path): + full_repo_path = alt_path + print(f"Found at {full_repo_path}") + else: + continue + else: + continue + + print(f"Updating {repo_rel_path}...") + + # 1. Set Owner (git config gitweb.owner) + if owner: + config_file = os.path.join(full_repo_path, "config") + if os.path.exists(config_file): + try: + subprocess.run( + [ + "git", + "config", + "--file", + config_file, + "gitweb.owner", + owner, + ], + check=True, + ) + print(f" - Owner set to: {owner}") + except subprocess.CalledProcessError as e: + print(f" - Failed to set owner: {e}") + else: + print(f" - Warning: No config file found at {config_file}") + + # 2. Set Description (write to description file) + if description: + desc_file = os.path.join(full_repo_path, "description") + try: + with open(desc_file, "w", encoding="utf-8") as df: + df.write(description + "\n") + print(f" - Description updated.") + except Exception as e: + print(f" - Failed to write description: {e}") + + print("Done.") + + +if __name__ == "__main__": + main()