aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_git
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-07 21:06:35 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-11 18:36:50 -0700
commitf60e2a723c744628823cad6344a8d3d0dd4c32e4 (patch)
tree02201b37edbe05070aac9c5f2c2335dbe25c22bc /roles/obsd_git
parentRetab file (diff)
downloadsite-configs-f60e2a723c744628823cad6344a8d3d0dd4c32e4.zip
Update configs
Diffstat (limited to 'roles/obsd_git')
-rw-r--r--roles/obsd_git/defaults/main.yml2
-rw-r--r--roles/obsd_git/files/git-shell-commands/create27
-rw-r--r--roles/obsd_git/handlers/main.yml2
-rw-r--r--roles/obsd_git/tasks/main.yml3
-rw-r--r--roles/obsd_git/templates/git-shell-commands/create71
-rw-r--r--roles/obsd_git/templates/git-shell-commands/no-interactive-login10
6 files changed, 84 insertions, 31 deletions
diff --git a/roles/obsd_git/defaults/main.yml b/roles/obsd_git/defaults/main.yml
index 19018f2..d0ca79a 100644
--- a/roles/obsd_git/defaults/main.yml
+++ b/roles/obsd_git/defaults/main.yml
@@ -1,4 +1,4 @@
git_user: git
-git_home: /var/www/pub/git
+git_home: /var/www/git
git_packages:
- git
diff --git a/roles/obsd_git/files/git-shell-commands/create b/roles/obsd_git/files/git-shell-commands/create
deleted file mode 100644
index db38900..0000000
--- a/roles/obsd_git/files/git-shell-commands/create
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-set -e
-
-main() {
- repo="$1"
- desc="$2"
- if [ -z "$repo" ]; then
- echo "Usage: provide a repository name" >&2
- exit 1
- fi
-
- repo_name=$(basename "$repo" .git)
- repo_path="/var/www/pub/git/$repo_name.git"
-
- if [ ! -d "$repo_path" ]; then
- echo "Creating bare repository: $repo_name.git"
- git init --bare --initial-branch=main "$repo_path"
- chown -R git:git "$repo_path"
-
- if [ -n "$desc" ]; then
- # cgit will lookup the git repository description via the git config.
- git -C "$repo_path" config gitweb.description "$desc"
- fi
- fi
-}
-
-main "$@"
diff --git a/roles/obsd_git/handlers/main.yml b/roles/obsd_git/handlers/main.yml
deleted file mode 100644
index 3af955f..0000000
--- a/roles/obsd_git/handlers/main.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-- name: restart httpd
- ansible.builtin.command: rcctl restart httpd
diff --git a/roles/obsd_git/tasks/main.yml b/roles/obsd_git/tasks/main.yml
index a5d9e69..aeb3bb7 100644
--- a/roles/obsd_git/tasks/main.yml
+++ b/roles/obsd_git/tasks/main.yml
@@ -7,6 +7,7 @@
ansible.builtin.user:
name: "{{ git_user }}"
home: "{{ git_home }}"
+ create_home: false
shell: /usr/local/bin/git-shell
system: true
@@ -51,7 +52,7 @@
mode: "0755"
- name: Deploy git-shell create-repo helper script
- ansible.builtin.copy:
+ ansible.builtin.template:
src: git-shell-commands/create
dest: "{{ git_home }}/git-shell-commands/create"
owner: "{{ git_user }}"
diff --git a/roles/obsd_git/templates/git-shell-commands/create b/roles/obsd_git/templates/git-shell-commands/create
new file mode 100644
index 0000000..9ac25a5
--- /dev/null
+++ b/roles/obsd_git/templates/git-shell-commands/create
@@ -0,0 +1,71 @@
+#!/bin/sh
+set -e
+
+REPO=""
+DESC=""
+PROJ=""
+VISIBILITY="public"
+
+main() {
+ parse_args "$@"
+
+ repo_name=$(basename "$REPO" .git)
+ if [ -n "$PROJ" ]; then
+ proj_dir="{{ git_home }}/$VISIBILITY/$PROJ"
+ if [ ! -d "$proj_dir" ]; then
+ mkdir "$proj_dir"
+ fi
+ repo_path="$proj_dir/$repo_name.git"
+ else
+ repo_path="{{ git_home }}/$VISIBILITY/$repo_name.git"
+ fi
+
+ if [ ! -d "$repo_path" ]; then
+ echo "Creating bare repository: $repo_name.git"
+ git init --bare --initial-branch=main "$repo_path"
+ chown -R git:git "$repo_path"
+ if [ -n "$DESC" ]; then
+ echo "$DESC" >>"$repo_path/description"
+ fi
+ fi
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --visibility)
+ VISIBILITY="$2"
+ case "$VISIBILITY" in public | private) ;; *) usage ;; esac
+ shift 2
+ ;;
+ --description)
+ DESC="$2"
+ shift 2
+ ;;
+ --project)
+ PROJ="$2"
+ shift 2
+ ;;
+ -*)
+ echo "Unknown option: $1" >&2
+ exit 1
+ ;;
+ *)
+ if [ -n "$REPO" ]; then
+ echo "Unexpected argument: $1" >&2
+ usage
+ fi
+ REPO="$1"
+ shift
+ ;;
+ esac
+ done
+ [ -n "$REPO" ] || usage
+}
+
+usage() {
+ echo "Usage: $0 [--visibility public|private] [--description DESC] [--project PROJ] <repo>" >&2
+ exit 1
+}
+
+main "$@"
diff --git a/roles/obsd_git/templates/git-shell-commands/no-interactive-login b/roles/obsd_git/templates/git-shell-commands/no-interactive-login
new file mode 100644
index 0000000..7c774ca
--- /dev/null
+++ b/roles/obsd_git/templates/git-shell-commands/no-interactive-login
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+main() {
+ printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
+ printf '%s\n' "provide interactive shell access."
+ exit 128
+}
+
+main "$@"