-
Notifications
You must be signed in to change notification settings - Fork 0
/
newrepo
executable file
·43 lines (34 loc) · 1.29 KB
/
newrepo
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
#!/bin/sh
# This utility runs on the server, where it creates a new repo. Usage:
# newrepo NAME
#
# This file is part of newrepo-findrepo, tools for small Git servers.
#
# Written in 2018, 2019 by Eliah Kagan <degeneracypressure@gmail.com>.
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
readonly conf='/etc/newrepo-findrepo.conf'
readonly bad_command=1 bad_config=2
bail() {
status="$1" message="$2"
printf '%s\n' "$message" >&2
exit "$status"
}
get_host() {
conf_path="$1"
sed -nE 's/^host=([^[:space:]]+)$/\1/p' -- "$conf_path" | tail -n 1
}
{ host="$(get_host "$conf")" && [ -n "$host" ]; } ||
bail "$bad_config" "Can't get host name configuration from $conf."
name="$1"
[ -n "$name" ] || bail "$bad_command" 'What do you want to call the new repo?'
dir="$name.git"
url="ssh://$host/repos/$dir"
cd /repos && mkdir -- "$dir" && cd -- "$dir" && git init --bare &&
printf '\nThe URL of the newly created repository is:\n\n\t%s\n\n' "$url"