summaryrefslogtreecommitdiff
path: root/playbooks.d
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2022-09-26 11:55:05 +0200
committerPatrick Spek <p.spek@tyil.nl>2022-09-26 11:56:06 +0200
commit806e43fb607e8b0c8743e5a7e226a2edb607ebc1 (patch)
tree729740288367719d89e1df2cc9c8eced780b6484 /playbooks.d
parentd967d0c51bda1e246d1cfbc98f638cb89ebc282b (diff)
Add playbook for gitolite
Diffstat (limited to 'playbooks.d')
-rw-r--r--playbooks.d/git-gitolite/description.txt1
-rw-r--r--playbooks.d/git-gitolite/etc/defaults2
-rw-r--r--playbooks.d/git-gitolite/playbook.bash53
3 files changed, 56 insertions, 0 deletions
diff --git a/playbooks.d/git-gitolite/description.txt b/playbooks.d/git-gitolite/description.txt
new file mode 100644
index 0000000..592b2aa
--- /dev/null
+++ b/playbooks.d/git-gitolite/description.txt
@@ -0,0 +1 @@
+Simple git server with gitolite
diff --git a/playbooks.d/git-gitolite/etc/defaults b/playbooks.d/git-gitolite/etc/defaults
new file mode 100644
index 0000000..9af718a
--- /dev/null
+++ b/playbooks.d/git-gitolite/etc/defaults
@@ -0,0 +1,2 @@
+pkg.gitolite=gitolite
+git.repodir=/var/lib/gitolite
diff --git a/playbooks.d/git-gitolite/playbook.bash b/playbooks.d/git-gitolite/playbook.bash
new file mode 100644
index 0000000..046295a
--- /dev/null
+++ b/playbooks.d/git-gitolite/playbook.bash
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+playbook_add() {
+ case "${BASHTARD_PLATFORM[distro]}" in
+ gentoo)
+ mkdir -pv "/etc/portage/package.use"
+ printf "acct-user/git gitolite" > /etc/portage/package.use/bashtard-gitolite
+ ;;
+ *)
+ notice "$BASHTARD_PLAYBOOK" "Creating user 'git'"
+ useradd \
+ --home-dir "$(config "git.repodir")" \
+ --create-home \
+ --shell "$(config "fs.bindir")/git-shell" \
+ git
+ ;;
+ esac
+
+ notice "$BASHTARD_PLAYBOOK" "Installing packages"
+ pkg install \
+ "$(config "pkg.gitolite")"
+
+ playbook_sync
+}
+
+playbook_sync() {
+ notice "$BASHTARD_PLAYBOOK" "Ensuring all desired repositories exist"
+ while read -r repo
+ do
+ local name="$(config "git.repos.$repo.name" "$repo")"
+ local path="$(config "git.repodir")/$(config "git.repos.$repo.path" "$repo")"
+
+ info "$BASHTARD_PLAYBOOK" "Ensuring $name exists ($repo)"
+
+ if [[ ! -d "$path" ]]
+ then
+ notice "$BASHTARD_PLAYBOOK" "Creating bare repository at $path"
+ mkdir -pv -- "$path"
+ git -C "$path" --bare init
+ fi
+
+ printf "$(config "git.repos.$repo.description", "Nondescript")\n" > "$path/description"
+ done < <(config_subkeys "git.repos")
+}
+
+playbook_del() {
+ notice "$BASHTARD_PLAYBOOK" "Removing packages"
+ pkg uninstall \
+ "$(config "pkg.gitolite")"
+
+ notice "$BASHTARD_PLAYBOOK" "Cleaning up srv directory"
+ rm -frv --one-file-system -- "$(config "git.repodir")"
+}