#!/bin/sh

server="ENTER-YOUR-SSH-SERVER-INFO"
pubrepodir="ENTER-YOUR-GIT-DIRECTORY"
bindir="ENTER-STAGIT-BIN-DIRECTORY"
branch="ENTER-DEFAULT-BRANCH-NAME"

hook="$bindir/post-receive-stagit"
[ -f "$hook" ] || { echo "Missing $hook" >&2; exit 1; }
cd "$pubrepodir" || { echo "Cannot cd to $pubrepodir" >&2; exit 1; }

printf "Enter repository name (without .git): "
read -r reponame
reponame="${reponame%.git}"

case "$reponame" in
	""|*[!A-Za-z0-9._-]*|.*)
		echo "Use only letters, digits, . _ - (not starting with a dot)." >&2
		exit 1 ;;
esac

repo="$pubrepodir/$reponame.git"
[ -e "$repo" ] && { echo "$reponame.git already exists." >&2; exit 1; }

printf "Enter short description: "
read -r shrtdesc

git init --bare -b "$branch" "$repo" || exit 1
echo "$shrtdesc" > "$repo/description"
cp "$hook" "$repo/hooks/post-receive"
chmod +x "$repo/hooks/post-receive"

echo
echo "Created $reponame.git. Stagit git hook installed; the website updates on first push."
echo "From your PC:  git remote add origin ssh://$server$repo"
echo "               git push -u origin $branch"
