changes to custom command invocation etc.; see below

- 'post-compile' subdir moved under 'commands/' but only for
    sanity; has no real significance now

  - new, internal use only, gitolite command run-all, as in

        gitolite run-all POST_COMPILE

    which runs all the commands in @{ $rc{POST_COMPILE} } in sequence.
    You can sdo this for any section of course, though this is the only
    one in the rc right now.

    (Future candidates: PRE_GIT, POST_GIT, PRE_CREATE, POST_CREATE)
This commit is contained in:
Sitaram Chamarty 2012-03-16 09:25:39 +05:30
parent efe37fb8a3
commit 876b554fb5
8 changed files with 79 additions and 59 deletions

View file

@ -30,25 +30,7 @@ sub post_update {
tsh_try("git checkout -f --quiet master");
}
_system("$ENV{GL_BINDIR}/gitolite compile");
# now run optional post-compile features
if ( exists $rc{POST_COMPILE} ) {
if ( ref( $rc{POST_COMPILE} ) ne 'ARRAY' ) {
_warn "bad syntax for specifying post compile scripts; see docs";
} else {
for my $s ( @{ $rc{POST_COMPILE} } ) {
# perl-ism; apart from keeping the full path separate from the
# simple name, this also protects %rc from change by implicit
# aliasing, which would happen if you touched $s itself
my $sfp = "$ENV{GL_BINDIR}/post-compile/$s";
_warn("skipped post-compile script '$s'"), next if not -x $sfp;
trace( 2, "post-compile $s" );
_system( $sfp, @ARGV ); # they better all return with 0 exit codes!
}
}
}
_system("$ENV{GL_BINDIR}/gitolite run-all POST_COMPILE");
exit 0;
}

View file

@ -196,13 +196,14 @@ __DATA__
# these will run in sequence after post-update
POST_COMPILE =>
[
'ssh-authkeys',
'post-compile/ssh-authkeys',
],
# comment out or uncomment as needed
# these are available to remote users
COMMANDS =>
{
'help' => 1,
'info' => 1,
},
);

View file

@ -36,7 +36,7 @@ sub setup {
setup_gladmin( $admin, $pubkey, $argv );
_system("$ENV{GL_BINDIR}/gitolite compile");
_system("$ENV{GL_BINDIR}/gitolite post-compile ssh-authkeys") if $pubkey;
_system("$ENV{GL_BINDIR}/gitolite run-all POST_COMPILE");
hook_repos(); # all of them, just to be sure
}

34
src/commands/help Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/perl
use strict;
use warnings;
use lib $ENV{GL_BINDIR};
use Gitolite::Rc;
use Gitolite::Common;
=for usage
Usage: gitolite help
Prints a list of custom commands available at this gitolite installation.
=cut
my $user = $ENV{GL_USER} || '';
print "hello" . ( $user ? " $user" : "") . ", this is gitolite3 " . version() . " on git " . substr( `git --version`, 12 ) . "\n";
_chdir("$ENV{GL_BINDIR}/commands");
print "list of " . ($user ? "remote" : "gitolite" ) . " commands available:\n\n";
for my $c (`find . -type f|sort`) {
chomp($c);
$c =~ s(^./)();
next unless -x $c;
# if it's from a remote client, show only what he is allowed
next if $user and not $rc{COMMANDS}{$c};
print "\t$c\n";
}
print "\n";
exit 0;

View file

@ -14,7 +14,8 @@ $|++;
# arguments anyway, it hardly matters.
my $ab = `gitolite query-rc -n GL_ADMIN_BASE`;
_warn("'keydir' not found in '$ab'"), exit if not -d "$ab/keydir";
trace( 2, "'keydir' not found in '$ab'; exiting" ), exit if not -d "$ab/keydir";
my $akdir = "$ENV{HOME}/.ssh";
my $akfile = "$ENV{HOME}/.ssh/authorized_keys";
my $glshell = `gitolite query-rc -n GL_BINDIR` . "/gitolite-shell";
# XXX gl-time not yet coded (GL_PERFLOGT)
@ -58,11 +59,14 @@ if (@gl_keys) {
# ----------------------------------------------------------------------
sub sanity {
_warn "$akfile missing; creating a new one" if not -f $akfile;
_die "$glshell not found; this should NOT happen..." if not -f $glshell;
_die "$glshell found but not readable; this should NOT happen..." if not -r $glshell;
_die "$glshell found but not executable; this should NOT happen..." if not -x $glshell;
_warn "$akdir missing; creating a new one" if not -d $akdir;
_warn "$akfile missing; creating a new one" if not -f $akfile;
_mkdir($akdir, 0700) if not -d $akfile;
if ( not -f $akfile ) {
_print( $akfile, "" );
chmod 0700, $akfile;

View file

@ -6,14 +6,13 @@
=for args
Usage: gitolite [sub-command] [options]
The following subcommands are available; they should all respond to '-h' if
you want further details on each:
The following built-in subcommands are available; they should all respond to
'-h' if you want further details on each:
setup 1st run: initial setup; all runs: hook fixups
compile compile gitolite.conf
query-rc get values of rc variables
post-compile run a post-compile command
list-groups list all group names in conf
list-users list all users/user groups in conf
@ -26,6 +25,10 @@ Warnings:
- list-users is disk bound and could take a while on sites with 1000s of repos
- list-memberships does not check if the name is known; unknown names come
back with 2 answers: the name itself and '@all'
In addition, running 'gitolite help' should give you a list of custom commands
available. They may or may not respond to '-h', depending on how they were
written.
=cut
# ----------------------------------------------------------------------
@ -65,8 +68,8 @@ if ( $command eq 'setup' ) {
Gitolite::Conf->import;
compile(@args);
} elsif ( $command eq 'post-compile' ) {
post_compile(@args);
} elsif ( $command eq 'run-all' ) {
run_all(@args);
} elsif ( -x "$rc{GL_BINDIR}/commands/$command" ) {
trace( 2, "attempting gitolite command $command" );
@ -93,36 +96,32 @@ sub args {
# ----------------------------------------------------------------------
=for post_compile
Usage: gitolite post-compile [-l] [post-compile-scriptname] [script args...]
-l list currently available post-compile scripts
Run a post-compile script (which normally runs from the post-update hook in
the gitolite-admin repo).
=cut
sub post_compile {
usage() if ( not @_ or $_[0] eq '-h' );
run_subdir( 'post-compile', @_ );
}
sub run_command {
run_subdir( 'commands', @_ );
}
sub run_subdir {
my $subdir = shift;
if ( @_ and $_[0] eq '-l' ) {
_chdir("$ENV{GL_BINDIR}/$subdir");
map { say2($_) } grep { -x } glob("*");
exit 0;
}
my $pgm = shift;
my $fullpath = "$ENV{GL_BINDIR}/$subdir/$pgm";
my $fullpath = "$ENV{GL_BINDIR}/commands/$pgm";
_die "$pgm not found or not executable" if not -x $fullpath;
_system( $fullpath, @_ );
exit 0;
}
sub run_all {
my $rc_section = shift;
if ( exists $rc{$rc_section} ) {
if ( ref( $rc{$rc_section} ) ne 'ARRAY' ) {
_warn "$rc_section section in rc file is not a perl list";
} else {
for my $s ( @{ $rc{$rc_section} } ) {
# perl-ism; apart from keeping the full path separate from the
# simple name, this also protects %rc from change by implicit
# aliasing, which would happen if you touched $s itself
my $sfp = "$ENV{GL_BINDIR}/commands/$s";
_warn("skipped command '$s'"), next if not -x $sfp;
trace( 2, "command: $s" );
_system( $sfp, @ARGV ); # they better all return with 0 exit codes!
}
}
}
}

View file

@ -11,15 +11,15 @@ $ENV{GL_BINDIR} = "$ENV{PWD}/src";
my $ak = "$ENV{HOME}/.ssh/authorized_keys";
my $kd = `gitolite query-rc -n GL_ADMIN_BASE` . "/keydir";
try "plan 50";
try "plan 49";
my $pgm = "gitolite post-compile ssh-authkeys";
my $pgm = "gitolite post-compile/ssh-authkeys";
try "
# prep
rm -rf $ak; ok
$pgm; ok; /'keydir' not found/
$pgm; ok
mkdir $kd; ok
cd $kd; ok
$pgm; ok; /authorized_keys missing/

View file

@ -26,7 +26,7 @@ try "
cp $bd/../t/keys/*.pub $ab/keydir; ok or die 6
";
_system("gitolite post-compile ssh-authkeys");
_system("gitolite post-compile/ssh-authkeys");
# basic tests
# ----------------------------------------------------------------------