#! /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 < "$path/cgitrc" name=$dispname owner=$owner desc=${description%\\n} EOF echo "browse new repo at: https://git.datagubbe.dev/$path"