aboutsummaryrefslogtreecommitdiff
path: root/nix/per-host/git/git-shell-commands/create
blob: 459f4288fc4e31a58f30eefa618f9a4097307388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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