#!/bin/bash
set -e

if [[ ! "$1" =~ ^[a-zA-Z0-9._-]+$ ]] || [[ "$1" =~ \.git$ ]]; then
	echo "invalid repo name"
	exit 1
fi

repo_path=$(realpath "/home/git/repo/$1")

if [[ $repo_path != /home/git/repo/* ]]; then
	echo "you are forbidden!"
	exit 1
fi

if [[ -d $repo_path ]]; then
	echo "repo <$1> already exists"
	exit 1
fi

git init --bare $repo_path
echo "$GIT_USER" > $repo_path/c
touch $repo_path/p
echo
echo "you are the creator, $GIT_USER"
