#!/usr/bin/perl -w use strict; use MGA::Git; use YAML; #use Data::Dump qw/dd/; my %actions = ( glconf => { run => \&glconf, descr => 'Print gitolite configuration', usage => < { run => \&glrun, descr => 'Update gitolite configuration', usage => < { run => \&usage, descr => 'Show usage informations for an action', usage => < { run => \&showconf, descr => 'Show YAML mgagit configuration', usage => <{usage}; } else { print STDERR "$0 [action] [options]\n"; print STDERR "$0 usage [action]\n\n"; print STDERR "Available actions:\n"; print STDERR map { " - $_ : $actions{$_}->{descr}\n" } keys %actions; } } sub usageexit { usage(@_); exit 1; } sub glconf { usageexit('usage', $_[0]) unless @_ <= 2; my %r; MGA::Git::load_gitrepos(\%r); MGA::Git::load_groups(\%r) if @_ == 1; MGA::Git::load_users(\%r); if (my $repo = $_[1]) { if (!$r{repos}{$repo}) { print STDERR "Cannot find repository $repo\n"; exit 1; } print MGA::Git::gitolite_repo_config(\%r, $repo); } else { print MGA::Git::gitolite_config(\%r), "\n"; } } sub glrun { usageexit('usage', $_[0]) unless @_ == 1; my %r; MGA::Git::load_gitrepos(\%r); MGA::Git::load_groups(\%r); MGA::Git::load_users(\%r); MGA::Git::dumpdb(\%r); MGA::Git::update_gitolite_keydir(\%r); MGA::Git::update_gitolite_config(\%r); MGA::Git::run_gitolite(\%r); } sub showconf { shift; my $res; my %r; MGA::Git::load_gitrepos(\%r); usageexit('usage', 'showconf') if @_ > 2; if (@_ == 1) { $res = YAML::Dump($r{repos}{$_[0]}); } elsif (@_ == 2) { $res = MGA::Git::repo_config(\%r, @_); $res .= "\n" if defined $res; } else { my $c = $MGA::Git::config; $c->{r} = \%r; $res = YAML::Dump($c); } print defined $res ? $res : "undef\n"; exit !defined $res; } if (@ARGV == 0 || !$actions{$ARGV[0]}) { usageexit(); } $actions{$ARGV[0]}->{run}->(@ARGV);