repos/kloeckner.com.ar

Backup of part of my webpage
Commits Files Refs README LICENSE
commit 74519008470a82de3701f63bf64bf0c2598be5c1
parent 67df955fa3d9d6e31d63f3a026882702541b7a3d
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Tue,  1 Sep 2026 12:53:09 -0300

Update git update scripts

Diffstat:
Agit/generate-git-frontend | 35+++++++++++++++++++++++++++++++++++
Agit/generate-git-main-index | 30++++++++++++++++++++++++++++++
Agit/sync-repos | 35+++++++++++++++++++++++++++++++++++
Agit/update-git-repo | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 161 insertions(+), 0 deletions(-)
diff --git a/git/generate-git-frontend b/git/generate-git-frontend
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+[ -z "$1" ] && echo "file path not provided" && exit 1
+
+git_folder="$1"
+
+bare_repos_list=$(find "$git_folder" -mindepth 1 -maxdepth 2 -name '*.git' \
+    -type d -printf '%P\n' | sort)
+
+[ -z "$bare_repos_list" ] \
+    && echo "folder does not contain bare repositories" \
+    && exit 1
+
+# generate git repositories index (main page)
+stagit-index $bare_repos_list > index.html
+
+repos_name_list=$(find "$git_folder" \
+    -mindepth 1 -maxdepth 1 -type d -printf '%f\n')
+
+for repo in $repos_name_list;\
+do
+    echo "$git_folder/$repo".git;
+    (
+        cd "$git_folder/$repo" || exit
+        stagit "$git_folder/$repo".git -c "$git_folder"/.cache
+        ln -sf files.html index.html
+        ln -sf ../style.css style.css
+        ln -sf ../logo.png logo.png
+        ln -sf ../favicon.png favicon.png
+    )
+    # link repos to git home (makes url prettier)
+    # for repo in $(find repos -name *.git); do ln -sf $repo /home/git; done
+    # ln -sf "$git_folder/$repo".git /home/git
+done
+
diff --git a/git/generate-git-main-index b/git/generate-git-main-index
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+[ -z "$1" ] && echo "ERROR: file path not provided" && exit 1
+
+git_folder="$1"
+
+# generate index
+# stagit-index $(find "$git_folder" -mindepth 1 -maxdepth 2 -name '*.git' \
+#     -type d -printf '%P\n' | sort) > "$git_folder"/index.html
+
+stagit-index $(find "$git_folder" -mindepth 1 -maxdepth 2 -name '*.git' \
+    -type d -printf '%P\n' | sort) > "$git_folder"/index.html
+
+# append git files to .gitignore
+# ignore symlinks
+# find . -type l | sed -e s'/^\.\///g' >> .gitignore
+
+# for repo in $(find "$git_folder" -mindepth 1 -maxdepth 1 -type d -printf '%f\n');\
+# do
+#     (cd "$git_folder"/"$repo"; stagit "$git_folder"/"$repo".git \
+#         -c "$git_folder"/.cache;
+#     ln -sf files.html index.html;
+#     ln -sf ../style.css style.css
+#     ln -sf ../logo.png logo.png
+#     ln -sf ../favicon.png favicon.png
+#     )
+# done
+
+# link repos to git home (makes url prettier)
+# for repo in $(find repos -name *.git); do ln -sf $repo /home/git; done
diff --git a/git/sync-repos b/git/sync-repos
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+set -xu
+
+BIN_DIR="/root/git"
+GIT_DIR="/var/www/git"
+GIT_SSH_COMMAND=''
+
+mkdir -p "$GIT_DIR"
+
+gh repo list --limit 1000 --json nameWithOwner,isPrivate,isFork \
+    --jq '.[] | select(.isPrivate == false and .isFork == false) |
+    .nameWithOwner' |
+while read -r repo; do
+    name=$(basename "$repo")
+    repo_dir="$GIT_DIR/$name"
+    bare_repo_path="$repo_dir/$name.git"
+
+    if [ -d "$repo_dir" ]; then
+        git -C "$bare_repo_path" remote update --prune
+    gh repo view $repo --json description --jq '.description' > \
+        $bare_repo_path/description
+    else
+        mkdir -p "$repo_dir"
+        git clone --mirror "https://github.com/$repo.git" "$bare_repo_path"
+        gh repo view $repo --json description --jq '.description' > \
+            $bare_repo_path/description
+
+        ln -sf "$bare_repo_path" /home/git
+    fi
+
+    (cd "$GIT_DIR"; "$BIN_DIR"/update-git-repo "$repo_dir")
+done
+
+(cd "$GIT_DIR"; "$BIN_DIR"/generate-git-main-index .)
diff --git a/git/update-git-repo b/git/update-git-repo
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+[ -z "$1" ] && echo "ERROR: repo name not provided" && exit 1
+
+repo_folder="$1"
+name="$(basename $repo_folder)"
+repo_bare_path="$repo_folder/$name.git"
+
+echo "updating '$repo_folder' git frontend"
+echo "cache file: '$repo_folder/.cache'"
+
+(
+    cd "$repo_folder"; 
+    stagit "$repo_bare_path" -c .cache;
+    ln -sf files.html index.html;
+    ln -sf ../style.css style.css;
+    ln -sf ../logo.png logo.png;
+    ln -sf ../favicon.png favicon.png;
+)
+
+# echo "updateing \`git.kloeckner.com.ar\` main index"
+
+# generate index
+# stagit-index $(find "$git_folder" -mindepth 1 -maxdepth 2 -name '*.git' \
+#    -type d -printf '%P\n' | sort) > "$git_folder"/index.html
+
+# stagit-index $(find "$git_folder" -mindepth 1 -maxdepth 2 -name '*.git' \
+#    -type d -printf '%P\n' | sort) > index.html
+
+# append git files to .gitignore
+# ignore symlinks
+# find . -type l | sed -e s'/^\.\///g' >> .gitignore
+
+# for repo in $(find "$git_folder" -mindepth 1 -maxdepth 1 -type d -printf '%f\n');\
+# do
+#      (cd "$repo"; stagit "$repo".git \
+#          -c .cache;
+#      ln -sf files.html index.html;
+#      ln -sf ../style.css style.css
+#      ln -sf ../logo.png logo.png
+#      ln -sf ../favicon.png favicon.png
+#      )
+# done
+
+# detect git push -f
+# force=0
+# while read -r old new ref; do
+#     test "${old}" = "0000000000000000000000000000000000000000" && continue
+#     test "${new}" = "0000000000000000000000000000000000000000" && continue
+# 
+#     hasrevs=$(git rev-list "${old}" "^${new}" | sed 1q)
+#     if test -n "${hasrevs}"; then
+#         force=1
+#         break
+#     fi
+# done
+# 
+# echo "forced pushed detected"
+
+# link repos to git home (makes url prettier)
+# for repo in $(find repos -name *.git); do ln -sf $repo /home/git; done