#!/bin/bash
set -e

if [ ! -n "$1" ]; then
	find /home/git/repo -maxdepth 1 -mindepth 1 -type d -exec basename {} \;
	exit 0
fi

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!"
	# not actually
	exit 1
fi

if [[ ! -d $repo_path ]]; then
	echo "repo not exists"
	exit 1
fi

echo "repo: $1"
echo
echo -n "CREATOR: "
cat ${repo_path}/c
echo "PUSHLIST: "
cat ${repo_path}/p
echo
