foxygit / foxygit Log in
A tiny read-only git web frontend — browse bare repos with just PHP and git, no database, no framework.
commits tags

/server/git-shell-commands/create · 1.09 KB

raw
#!/bin/sh
# usage (over ssh, as the git user): ssh git@<host> create <reponame>
#
# Creates a new bare repo under $reposdir, initialized from $templatedir
# (currently empty -- no hooks are installed by default; foxygit reads bare
# repos live, no regeneration step needed). Paths below must match
# server/setup-server.sh.

reposdir="/var/git/repos"
templatedir="/var/git/templates"
sshhost="git.kristoffersson.info"	# must resolve unproxied (DNS-only in Cloudflare) — a
					# proxied record doesn't forward SSH (port 22)

name="$1"
if [ -z "$name" ]; then
	echo "usage: create <reponame>" >&2
	exit 1
fi

name=$(basename "$name" ".git")
case "$name" in
	*/* | .* | -*)
		echo "invalid repo name: $name" >&2
		exit 1
		;;
esac

dest="${reposdir}/${name}.git"
if [ -e "$dest" ]; then
	echo "repo already exists: ${name}.git" >&2
	exit 1
fi

git init --bare --template="$templatedir" -- "$dest" >/dev/null
git -C "$dest" config http.receivepack true	# allow push over authenticated HTTPS too, see server/setup-http-push.sh

echo "created repos/${name}.git"
echo "clone with: git clone git@${sshhost}:repos/${name}.git"