From 07b45bc892b636dd55472d0a4510c0b064418c01 Mon Sep 17 00:00:00 2001 From: Jan Sydänviita Date: Fri, 21 Aug 2026 16:12:48 +0300 Subject: Update forge --- roles/jails/22_forge/files/footer.html | 5 ++ roles/jails/22_forge/files/git-shell-commands/help | 15 +++-- roles/jails/22_forge/files/git-shell-commands/ls | 13 +++- .../jails/22_forge/files/git-shell-commands/mirror | 75 ++++++++++++++++++++++ .../22_forge/files/git-shell-commands/mirror-from | 44 ------------- .../22_forge/files/git-shell-commands/mirror-to | 44 ------------- roles/jails/22_forge/tasks/main.yml | 26 +++----- .../22_forge/templates/usr_local_etc_cgitrc.j2 | 1 + 8 files changed, 108 insertions(+), 115 deletions(-) create mode 100644 roles/jails/22_forge/files/footer.html create mode 100644 roles/jails/22_forge/files/git-shell-commands/mirror delete mode 100644 roles/jails/22_forge/files/git-shell-commands/mirror-from delete mode 100644 roles/jails/22_forge/files/git-shell-commands/mirror-to diff --git a/roles/jails/22_forge/files/footer.html b/roles/jails/22_forge/files/footer.html new file mode 100644 index 0000000..2774ace --- /dev/null +++ b/roles/jails/22_forge/files/footer.html @@ -0,0 +1,5 @@ + diff --git a/roles/jails/22_forge/files/git-shell-commands/help b/roles/jails/22_forge/files/git-shell-commands/help index acd24a9..0494ae3 100644 --- a/roles/jails/22_forge/files/git-shell-commands/help +++ b/roles/jails/22_forge/files/git-shell-commands/help @@ -2,12 +2,13 @@ cat </dev/null)" + mirror_to="$(git -C "$repo" remote get-url mirror-to 2>/dev/null)" + mirror_from="$(git -C "$repo" remote get-url mirror-from 2>/dev/null)" + + printf "%-30s %s\n" "$name" "$desc" + [ -n "$mirror_to" ] && printf " %-28s -> %s\n" "" "$mirror_to" + [ -n "$mirror_from" ] && printf " %-28s <- %s\n" "" "$mirror_from" +done diff --git a/roles/jails/22_forge/files/git-shell-commands/mirror b/roles/jails/22_forge/files/git-shell-commands/mirror new file mode 100644 index 0000000..30237af --- /dev/null +++ b/roles/jails/22_forge/files/git-shell-commands/mirror @@ -0,0 +1,75 @@ +#!/bin/sh +# mirror [REPO] to [URL] - set up hourly push mirror +# mirror [REPO] from [URL] - set up hourly fetch mirror +# mirror [REPO] delete - remove any mirror + +_usage() { + echo "Usage:" + echo " mirror [REPO] to [URL] set up hourly push mirror" + echo " mirror [REPO] from [URL] set up hourly fetch mirror" + echo " mirror [REPO] delete remove any mirror" + exit "${1:-0}" +} + +[ -z "$1" ] && _usage +[ -z "$2" ] && _usage + +REPO="$1" +CMD="$2" +ARG="$3" +REPO_PATH="$HOME/$REPO.git" + +if [ ! -d "$REPO_PATH" ]; then + echo "Repository $REPO does not exist" + exit 1 +fi + +cd "$REPO_PATH" || exit 1 + +case "$CMD" in +to) + [ -z "$ARG" ] && _usage 1 + if git remote get-url mirror-from >/dev/null 2>&1; then + echo "Error: $REPO already has a mirror-from. Remove it first with: mirror $REPO delete" + exit 1 + fi + if git remote get-url mirror-to >/dev/null 2>&1; then + git remote set-url mirror-to "$ARG" + else + git remote add mirror-to "$ARG" + fi + echo "Configured $REPO to mirror to $ARG" + echo "Runs hourly. Logs: /var/log/git-mirrors.log" + ;; +from) + [ -z "$ARG" ] && _usage 1 + if git remote get-url mirror-to >/dev/null 2>&1; then + echo "Error: $REPO already has a mirror-to. Remove it first with: mirror $REPO delete" + exit 1 + fi + if git remote get-url mirror-from >/dev/null 2>&1; then + git remote set-url mirror-from "$ARG" + else + git remote add mirror-from "$ARG" + fi + echo "Configured $REPO to mirror from $ARG" + echo "Runs hourly. Logs: /var/log/git-mirrors.log" + ;; +delete) + removed=0 + if git remote get-url mirror-to >/dev/null 2>&1; then + git remote remove mirror-to + echo "Removed mirror-to for $REPO" + removed=1 + fi + if git remote get-url mirror-from >/dev/null 2>&1; then + git remote remove mirror-from + echo "Removed mirror-from for $REPO" + removed=1 + fi + [ "$removed" -eq 0 ] && echo "No mirror configured for $REPO" + ;; +*) + _usage 1 + ;; +esac diff --git a/roles/jails/22_forge/files/git-shell-commands/mirror-from b/roles/jails/22_forge/files/git-shell-commands/mirror-from deleted file mode 100644 index 2666cac..0000000 --- a/roles/jails/22_forge/files/git-shell-commands/mirror-from +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -# mirror-from [REPO_NAME] [GIT_URL] -# Configures a repo to pull updates from a remote git URL hourly. -# Pass empty URL to remove the mirror source. -# Example: mirror-from myrepo https://github.com/user/myrepo.git -if [ -z "$1" ]; then - echo "Usage: mirror-from [REPO_NAME] [GIT_URL]" - echo " mirror-from [REPO_NAME] - remove mirror source" - exit 1 -fi -if [ ! -d "$1.git" ]; then - echo "Repository $1 does not exist" - exit 1 -fi - -REPO="$1" -REMOTE="$2" -REPO_PATH="$HOME/$REPO.git" - -cd "$REPO_PATH" || exit 1 - -if [ -z "$REMOTE" ]; then - if git remote get-url mirror-from >/dev/null 2>&1; then - git remote remove mirror-from - echo "Removed mirror source for $REPO" - else - echo "No mirror source configured for $REPO" - fi - exit 0 -fi - -if git remote get-url mirror-to >/dev/null 2>&1; then - echo "Error: $REPO already has a mirror-to configured. Remove it first with: mirror-to $REPO" - exit 1 -fi - -if git remote get-url mirror-from >/dev/null 2>&1; then - git remote set-url mirror-from "$REMOTE" -else - git remote add mirror-from "$REMOTE" -fi - -echo "Configured $REPO to mirror from $REMOTE" -echo "Mirrors run hourly. Logs: /var/log/git-mirrors.log" diff --git a/roles/jails/22_forge/files/git-shell-commands/mirror-to b/roles/jails/22_forge/files/git-shell-commands/mirror-to deleted file mode 100644 index 6a0c20e..0000000 --- a/roles/jails/22_forge/files/git-shell-commands/mirror-to +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -# mirror-to [REPO_NAME] [GIT_URL] -# Configures a repo to be mirrored hourly to a remote git URL. -# Example: mirror-to myrepo git@example.com:user/myrepo.git -if [ -z "$1" ]; then - echo "Usage: mirror-to [REPO_NAME] [GIT_URL]" - echo " mirror-to [REPO_NAME] - remove mirror" - echo "Example: mirror-to myrepo git@example.com:user/myrepo.git" - exit 1 -fi -if [ ! -d "$1.git" ]; then - echo "Repository $1 does not exist" - exit 1 -fi - -REPO="$1" -REMOTE="$2" -REPO_PATH="$HOME/$REPO.git" - -cd "$REPO_PATH" || exit 1 - -if [ -z "$REMOTE" ]; then - if git remote get-url mirror-to >/dev/null 2>&1; then - git remote remove mirror-to - echo "Removed mirror for $REPO" - else - echo "No mirror configured for $REPO" - fi - exit 0 -fi - -if git remote get-url mirror-from >/dev/null 2>&1; then - echo "Error: $REPO already has a mirror-from configured. Remove it first with: mirror-from $REPO" - exit 1 -fi - -if git remote get-url mirror-to >/dev/null 2>&1; then - git remote set-url mirror-to "$REMOTE" -else - git remote add mirror-to "$REMOTE" -fi - -echo "Configured $REPO to mirror to $REMOTE" -echo "Mirrors run hourly. Logs: /var/log/git-mirrors.log" diff --git a/roles/jails/22_forge/tasks/main.yml b/roles/jails/22_forge/tasks/main.yml index e837d72..24fe362 100644 --- a/roles/jails/22_forge/tasks/main.yml +++ b/roles/jails/22_forge/tasks/main.yml @@ -26,23 +26,7 @@ - delete - rename - describe - - mirror-to - - mirror-from - -# --- Remove legacy git user --- - -- name: Remove legacy git user - user: - name: git - state: absent - remove: false - ignore_errors: true - -- name: Remove legacy git group - group: - name: git - state: absent - ignore_errors: true + - mirror # --- Forge users --- @@ -202,6 +186,14 @@ group: wheel mode: "0644" +- name: Deploy cgit footer + copy: + src: "{{ jail_role_dir }}/files/footer.html" + dest: /usr/local/etc/cgit/footer.html + owner: root + group: wheel + mode: "0644" + - name: Deploy custom cgit.css copy: src: "{{ jail_role_dir }}/files/cgit.css" diff --git a/roles/jails/22_forge/templates/usr_local_etc_cgitrc.j2 b/roles/jails/22_forge/templates/usr_local_etc_cgitrc.j2 index 7a0e040..a1e7c9e 100644 --- a/roles/jails/22_forge/templates/usr_local_etc_cgitrc.j2 +++ b/roles/jails/22_forge/templates/usr_local_etc_cgitrc.j2 @@ -2,6 +2,7 @@ css=/cgit.css logo=/cgit.png favicon=/favicon.ico head-include=/usr/local/etc/cgit/head-include.html +footer=/usr/local/etc/cgit/footer.html virtual-root=/ -- cgit v1.3