diff options
| author | Albert Cervin <albert@acervin.com> | 2023-03-19 17:18:01 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-03-19 17:18:01 +0100 |
| commit | c6f2fd36e0a8188e1f6b2a15b292e3d0a5610ac4 (patch) | |
| tree | d1c21cf0d9a2529154b33438bd91821268be5eb4 /jails/gubbhub/gubbshell/create-repo | |
| download | datagubbe-setup-main.tar.gz datagubbe-setup-main.tar.xz datagubbe-setup-main.zip | |
Diffstat (limited to 'jails/gubbhub/gubbshell/create-repo')
| -rw-r--r-- | jails/gubbhub/gubbshell/create-repo | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/jails/gubbhub/gubbshell/create-repo b/jails/gubbhub/gubbshell/create-repo new file mode 100644 index 0000000..07c7aa4 --- /dev/null +++ b/jails/gubbhub/gubbshell/create-repo @@ -0,0 +1,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" + |
