#!/bin/sh

# Usage:    ssh git@host create <repo>
#
# Create wild repo.

die() { echo "$@" >&2; exit 1; }
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }
[ -z "$1" ] && usage
[ -z "$2" ] || usage
[ "$1" = "-h" ] && usage
[ -z "$GL_USER" ] && die GL_USER not set

# ----------------------------------------------------------------------
perms=$(gitolite git-config -r $1 gitolite-options.default.roles | sort | cut -f3 |
    perl -pe 's/(\s)CREATOR(\s|$)/$1$ENV{GL_USER}$1/')
echo "$perms" | $GL_BINDIR/commands/perms -c "$@"
