blob: 07c7aa40edb21eec08ce708923a8e8fdbebf1eac (
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
50
51
52
53
54
55
56
57
58
59
|
#! /usr/bin/env sh
set -euo pipefail
if ! id -nG | grep -qwF "gitadm"; then
echo $'\e[31myou are not an admin\e[0m'
exit 13
fi
if [ $# -lt 1 ]; then
echo $'\e[31mrepository name is required\e[0m'
exit 1
fi
read_with_default() {
local var="$1"
local title="$2"
local default="$3"
read -p $'\e[36m'"$title"$'\e[0m \e[1m['"$default"$']\e[0m: ' $var
eval vval="\$$var"
eval $var="\"${vval:-$default}\""
}
name="$1"
path="$(echo "$1" | sed 's/ /-/' | tr '[:upper:]' '[:lower:]').git"
if [ -e "$path" ]; then
echo $'\e[31m'"repository at \"$path\" already exists"$'\e[0m'
exit 1
fi
read_with_default defbranch "default branch" "main"
read_with_default dispname "display name" "$name"
read_with_default owner "owner" "$(id -un)"
read_with_default shared "shared with 'gitdev' group" "yes"
echo $'\e[36mdescription\e[0m (terminate with C-d): '
description=""
while read -r descline; do
description="$description$descline\n"
done
echo "creating repo at: $path..."
sharerepo="false"
case "$(echo "$shared" | tr '[:upper:]' '[:lower:]')" in
y|yes|ye|true|t) sharerepo="group" ;;
esac
git init --bare --shared="$sharerepo" --initial-branch="$defbranch" "$path"
echo "generating web config..."
cat <<EOF > "$path/cgitrc"
name=$dispname
owner=$owner
desc=${description%\\n}
EOF
echo "browse new repo at: https://git.datagubbe.dev/$path"
|