summaryrefslogtreecommitdiff
path: root/create-repo.sh
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-04-24 23:36:52 +0200
committerJesper Jensen <jesper@jnsn.dev>2026-06-04 19:39:17 +0200
commitac89b3c715fd3eddca7898e069ee04498c1a1ba2 (patch)
treeeb0294e645dd494ebe2b222292e6f8463d936277 /create-repo.sh
INITIAL COMMIT
Diffstat (limited to 'create-repo.sh')
-rw-r--r--create-repo.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/create-repo.sh b/create-repo.sh
new file mode 100644
index 0000000..5bc213a
--- /dev/null
+++ b/create-repo.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+set -eu
+
+GIT_REPO_ROOT="${GIT_REPO_ROOT:-/var/lib/git}"
+GIT_USER="${GIT_USER:-git}"
+GIT_GROUP="${GIT_GROUP:-git}"
+
+usage() {
+ echo "usage: create-repo <name> [description]" >&2
+ echo "example: create-repo myrepo 'My application repository'" >&2
+ exit 64
+}
+
+[ "$#" -ge 1 ] || usage
+
+name="$1"
+description="${2:-Unnamed repository}"
+
+case "${name}" in
+ */* | .* | *" "* | *".."* )
+ echo "invalid repository name: ${name}" >&2
+ exit 64
+ ;;
+esac
+
+case "${name}" in
+ *.git) repo_name="${name}" ;;
+ *) repo_name="${name}.git" ;;
+esac
+
+repo_path="${GIT_REPO_ROOT}/${repo_name}"
+
+if [ -e "${repo_path}" ]; then
+ echo "repository already exists: ${repo_path}" >&2
+ exit 1
+fi
+
+install -d -o "${GIT_USER}" -g "${GIT_GROUP}" "${repo_path}"
+git init --bare "${repo_path}" >/dev/null
+printf '%s\n' "${description}" > "${repo_path}/description"
+chown -R "${GIT_USER}:${GIT_GROUP}" "${repo_path}"
+
+echo "created ${repo_path}"