diff options
Diffstat (limited to 'nix/per-host/git/git-shell-commands/create')
| -rwxr-xr-x | nix/per-host/git/git-shell-commands/create | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nix/per-host/git/git-shell-commands/create b/nix/per-host/git/git-shell-commands/create new file mode 100755 index 0000000..459f428 --- /dev/null +++ b/nix/per-host/git/git-shell-commands/create @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# git-shell-commands(5) subcommand: create a new bare repo. +# Prompts for each configurable setting: name (if not given as an +# argument), description, owner and visibility. Pipe </dev/null to accept +# the defaults (empty description, owner kdam0, private). +# Run: ssh git@git.kumardamani.net create [name] + +name="${1:-}" + +if [ -z "$name" ]; then + printf 'repo name: ' + read -r name +fi +case "$name" in + ""|*[!a-zA-Z0-9._-]*|*..*) + echo "error: invalid name '$name' (allowed: a-z 0-9 . _ -)" >&2 + exit 1 + ;; +esac +repo="/srv/git/$name.git" +if [ -e "$repo" ]; then + echo "error: repo '$name' already exists" >&2 + exit 1 +fi + +printf 'description (optional): ' +read -r desc + +printf 'owner [kdam0]: ' +read -r owner +owner="${owner:-kdam0}" + +printf 'publish now? [y/N]: ' +read -r pub + +git init --bare --quiet "$repo" +git -C "$repo" config gitweb.owner "$owner" +[ -n "$desc" ] && printf '%s\n' "$desc" > "$repo/description" + +case "$pub" in + y|Y|yes) + touch "$repo/git-daemon-export-ok" + echo "created public repo '$name': https://git.kumardamani.net/$name" + ;; + *) + echo "created private repo '$name'" + echo "publish it with: ssh git@git.kumardamani.net publish $name" + ;; +esac |
