diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-14 11:31:00 -0800 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-14 11:31:00 -0800 |
| commit | 8e16d8d0907780a0e85f4de7e9b7f4c03a1b5f12 (patch) | |
| tree | df04e16bc8391c0395809bcc9581168e71000f3e | |
| parent | Add plain README file as recognized readme for cgit (diff) | |
| download | site-configs-main.zip | |
| -rw-r--r-- | roles/obsd_cgit/defaults/main.yml | 2 | ||||
| -rw-r--r-- | roles/obsd_cgit/files/post-receive.d/cgit | 19 | ||||
| -rw-r--r-- | roles/obsd_cgit/tasks/main.yml | 8 | ||||
| -rw-r--r-- | roles/obsd_git/tasks/main.yml | 8 | ||||
| -rw-r--r-- | roles/obsd_git/templates/hooks/post-receive | 37 | ||||
| -rw-r--r-- | site.yml | 2 |
6 files changed, 61 insertions, 15 deletions
diff --git a/roles/obsd_cgit/defaults/main.yml b/roles/obsd_cgit/defaults/main.yml index 77e4d4f..66e857f 100644 --- a/roles/obsd_cgit/defaults/main.yml +++ b/roles/obsd_cgit/defaults/main.yml @@ -1,5 +1,7 @@ obsd_cgit_domain: "{{ cgit_domain }}" obsd_cgit_chroot: "/var/www" +obsd_cgit_git_user: git +obsd_cgit_hooks_dir: /var/www/git/hooks # Absolute path from /var/www chroot that httpd runs in obsd_cgit_cache_dir: /cache/cgit obsd_cgit_repos_dir: /git/public diff --git a/roles/obsd_cgit/files/post-receive.d/cgit b/roles/obsd_cgit/files/post-receive.d/cgit new file mode 100644 index 0000000..34bfda4 --- /dev/null +++ b/roles/obsd_cgit/files/post-receive.d/cgit @@ -0,0 +1,19 @@ +#!/bin/sh +set -o errexit +set -o nounset + +# $ man cgitrc +# ... +# agefile +# Specifies a path, relative to each repository path, which can be used +# to specify the date and time of the youngest commit in the +# repository. The first line in the file is used as input to the +# "parse_date" function in libgit. Recommended timestamp-format is +# "yyyy-mm-dd hh:mm:ss". You may want to generate this file from a +# post-receive hook. Default value: "info/web/last-modified". +agefile="$(git rev-parse --git-dir)"/info/web/last-modified +mkdir -p "$(dirname "$agefile")" && + git for-each-ref \ + --sort=-authordate --count=1 \ + --format='%(authordate:iso8601)' \ + >"$agefile" diff --git a/roles/obsd_cgit/tasks/main.yml b/roles/obsd_cgit/tasks/main.yml index e0b7ea4..7833cc3 100644 --- a/roles/obsd_cgit/tasks/main.yml +++ b/roles/obsd_cgit/tasks/main.yml @@ -77,6 +77,14 @@ - name: Compile markdown renderer into chroot ansible.builtin.include_tasks: markdown.yml +- name: Deploy cgit post-receive hook + ansible.builtin.copy: + src: post-receive.d/cgit + dest: "{{ obsd_cgit_hooks_dir }}/post-receive.d/cgit" + owner: "{{ obsd_cgit_git_user }}" + group: "{{ obsd_cgit_git_user }}" + mode: "0755" + - name: Enable slowcgi ansible.builtin.service: name: slowcgi diff --git a/roles/obsd_git/tasks/main.yml b/roles/obsd_git/tasks/main.yml index bf6abc8..93ea3c2 100644 --- a/roles/obsd_git/tasks/main.yml +++ b/roles/obsd_git/tasks/main.yml @@ -84,6 +84,14 @@ group: "{{ obsd_git_user }}" mode: "0755" +- name: Create post-receive.d hooks directory + ansible.builtin.file: + path: "{{ obsd_git_hooks_dir }}/post-receive.d" + state: directory + owner: "{{ obsd_git_user }}" + group: "{{ obsd_git_user }}" + mode: "0755" + - name: Deploy post-receive hook ansible.builtin.template: src: hooks/post-receive diff --git a/roles/obsd_git/templates/hooks/post-receive b/roles/obsd_git/templates/hooks/post-receive index 34bfda4..18034d5 100644 --- a/roles/obsd_git/templates/hooks/post-receive +++ b/roles/obsd_git/templates/hooks/post-receive @@ -1,19 +1,26 @@ #!/bin/sh +# +# Run the post-receive scripts in post-receive.d/ +# +# 1. After `git push` to a repository, when git finishes updating the refs in +# the bare repo, it would run this `post-receive` hook. +# 2. When run, the bare repo is the working directory and Git will write one +# line per updated ref to stdin e.g. <old-sha> <new-sha> refs/heads/main +# 3. *This script* then runs every executable that exists in post-receive.d +# sequentially. set -o errexit set -o nounset -# $ man cgitrc -# ... -# agefile -# Specifies a path, relative to each repository path, which can be used -# to specify the date and time of the youngest commit in the -# repository. The first line in the file is used as input to the -# "parse_date" function in libgit. Recommended timestamp-format is -# "yyyy-mm-dd hh:mm:ss". You may want to generate this file from a -# post-receive hook. Default value: "info/web/last-modified". -agefile="$(git rev-parse --git-dir)"/info/web/last-modified -mkdir -p "$(dirname "$agefile")" && - git for-each-ref \ - --sort=-authordate --count=1 \ - --format='%(authordate:iso8601)' \ - >"$agefile" +main() { + input=$(cat) + for hook in "$(dirname "$0")"/post-receive.d/*; do + is_executable "$hook" || continue + printf '%s\n' "$input" | "$hook" + done +} + +is_executable() { + [ -x "$1" ] +} + +main @@ -29,6 +29,8 @@ - role: obsd_cgit vars: obsd_cgit_domain: git.eugenetriguba.com + obsd_cgit_git_user: git + obsd_cgit_hooks_dir: /var/www/git/hooks - role: restic_backups vars: restic_backups_b2_key_id: "{{ vault_b2_key_id }}" |