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

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

creator=`cat ${repo_path}/c`
if [[ "$creator" != "$GIT_USER" ]]; then
	echo "Permission denied"
	exit 1
fi

mv $repo_path /home/git/trash/`date +%s.$1`
echo "delete success!"
