(adc) "common functions" and examples for adc usage

This commit is contained in:
Sitaram Chamarty 2010-04-24 23:00:38 +05:30
parent 9d0a208b26
commit 0b1d31fad4
4 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,17 @@
#!/bin/bash
# please make sure this file is NOT chmod +x
die() { echo "$@"; exit 1; }
get_rights_and_owner() {
local ans
ans=$(perl -I$HOME/.gitolite/src -Mgitolite -e 'cli_repo_rights("'$1'")')
# set shell variables as needed
owner=${ans#* }
rights=${ans% *}
[[ $rights =~ C ]] && perm_create=yes || perm_create=
[[ $rights =~ R ]] && perm_read=yes || perm_read=
[[ $rights =~ W ]] && perm_write=yes || perm_write=
}

22
contrib/adc/fork Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
from=$1
to=$2
. $(dirname $0)/adc.common-functions
# we cannot just say "cd $GL_REPO_BASE_ABS; git clone $from.git $to.git". That
# won't set up the hooks or the gl-creater file that gitolite needs. So we now
# have a new "git-init" command!
get_rights_and_owner $from
[[ -z $perm_read ]] && die "no read permissions on $from"
get_rights_and_owner $to
[[ -z $perm_create ]] && die "no create permissions on $to"
# let gitolite create the repo first
SSH_ORIGINAL_COMMAND="git-init '$to'" $GL_BINDIR/gl-auth-command $GL_USER
# then copy the refs from $from
cd $GL_REPO_BASE_ABS/$to.git
git fetch $GL_REPO_BASE_ABS/$from.git refs/*:refs/*

11
contrib/adc/restrict-admin Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
. $(dirname $0)/adc.common-functions
get_rights_and_owner gitolite-admin
[[ -z $perm_write ]] && die "just *what* are you trying to pull, young man?"
# and here you let them do the dangerous stuff
echo "+rm -rf $GL_REPO_BASE_ABS"
sleep 2
echo ...just kidding!

11
contrib/adc/rmrepo Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
. $(dirname $0)/adc.common-functions
delete=$1
get_rights_and_owner $delete
[[ $owner == $GL_USER ]] || die "$delete is not yours to delete!"
cd $GL_REPO_BASE_ABS
rm -rf $delete.git