2012-03-16 05:29:45 +01:00
|
|
|
package Gitolite::Rc;
|
|
|
|
|
|
|
|
# everything to do with 'rc'. Also defines some 'constants'
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
@EXPORT = qw(
|
|
|
|
%rc
|
|
|
|
glrc
|
|
|
|
query_rc
|
2012-03-15 14:44:40 +01:00
|
|
|
version
|
2012-03-19 03:01:09 +01:00
|
|
|
trigger
|
2012-03-16 05:29:45 +01:00
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
$REMOTE_COMMAND_PATT
|
2012-03-16 05:29:45 +01:00
|
|
|
$REF_OR_FILENAME_PATT
|
|
|
|
$REPONAME_PATT
|
|
|
|
$REPOPATT_PATT
|
|
|
|
$USERNAME_PATT
|
2012-03-16 09:59:45 +01:00
|
|
|
$UNSAFE_PATT
|
2012-03-16 05:29:45 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
use Exporter 'import';
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
use Gitolite::Common;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
our %rc;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
# variables that could be overridden by the rc file
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
$rc{GL_BINDIR} = $ENV{GL_BINDIR};
|
|
|
|
$rc{GL_REPO_BASE} = "$ENV{HOME}/repositories";
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
$rc{GL_ADMIN_BASE} = "$ENV{HOME}/.gitolite";
|
2012-03-17 16:43:28 +01:00
|
|
|
$rc{LOG_TEMPLATE} = "$ENV{HOME}/.gitolite/logs/gitolite-%y-%m.log";
|
2012-03-16 05:29:45 +01:00
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
# variables that should probably never be changed but someone will want to, I'll bet...
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
$REMOTE_COMMAND_PATT = qr(^[- 0-9a-zA-Z\@\%_=+:,./]*$);
|
2012-03-16 05:29:45 +01:00
|
|
|
$REF_OR_FILENAME_PATT = qr(^[0-9a-zA-Z][0-9a-zA-Z._\@/+ :,-]*$);
|
|
|
|
$REPONAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@/+-]*$);
|
|
|
|
$REPOPATT_PATT = qr(^\@?[0-9a-zA-Z[][\\^.$|()[\]*+?{}0-9a-zA-Z._\@/,-]*$);
|
|
|
|
$USERNAME_PATT = qr(^\@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$);
|
2012-03-16 09:59:45 +01:00
|
|
|
$UNSAFE_PATT = qr([`~#\$\&()|;<>]);
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
# find the rc file and 'do' it
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
my $current_data_version = "3.0";
|
|
|
|
|
|
|
|
my $rc = glrc('filename');
|
|
|
|
do $rc if -r $rc;
|
2012-03-10 16:00:14 +01:00
|
|
|
_die "$rc seems to be for older gitolite" if defined($GL_ADMINDIR);
|
2012-03-16 05:29:45 +01:00
|
|
|
# let values specified in rc file override our internal ones
|
|
|
|
@rc{ keys %RC } = values %RC;
|
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
# (testing only) testing sometimes requires all of it to be overridden
|
|
|
|
# silently; use an env var that is highly unlikely to appear in real life :)
|
2012-03-15 15:34:30 +01:00
|
|
|
do $ENV{G3T_RC} if exists $ENV{G3T_RC} and -r $ENV{G3T_RC};
|
2012-03-15 10:35:51 +01:00
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
# fix some env vars, setup gitolite internal "env" vars (aka rc vars)
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 04:08:50 +01:00
|
|
|
# fix PATH (TODO: do it only if 'gitolite' isn't in PATH)
|
|
|
|
$ENV{PATH} = "$ENV{GL_BINDIR}:$ENV{PATH}";
|
|
|
|
|
2012-03-17 16:43:28 +01:00
|
|
|
{
|
|
|
|
my ( $ts, $lfn ) = gen_ts_lfn( $rc{LOG_TEMPLATE} );
|
|
|
|
$rc{GL_LOGFILE} = $ENV{GL_LOGFILE} = $lfn;
|
|
|
|
$rc{GL_TS} = $ENV{GL_TS} = $ts;
|
|
|
|
}
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
my $glrc_default_text = '';
|
|
|
|
{
|
|
|
|
local $/ = undef;
|
|
|
|
$glrc_default_text = <DATA>;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub glrc {
|
|
|
|
my $cmd = shift;
|
|
|
|
if ( $cmd eq 'default-filename' ) {
|
|
|
|
return "$ENV{HOME}/.gitolite.rc";
|
|
|
|
} elsif ( $cmd eq 'default-text' ) {
|
|
|
|
return $glrc_default_text if $glrc_default_text;
|
|
|
|
_die "rc file default text not set; this should not happen!";
|
|
|
|
} elsif ( $cmd eq 'filename' ) {
|
|
|
|
# where is the rc file?
|
|
|
|
|
|
|
|
# search $HOME first
|
|
|
|
return "$ENV{HOME}/.gitolite.rc" if -f "$ENV{HOME}/.gitolite.rc";
|
|
|
|
|
|
|
|
# XXX for fedora, we can add the following line, but I would really prefer
|
|
|
|
# if ~/.gitolite.rc on each $HOME was just a symlink to /etc/gitolite.rc
|
|
|
|
# XXX return "/etc/gitolite.rc" if -f "/etc/gitolite.rc";
|
|
|
|
|
|
|
|
return '';
|
|
|
|
} elsif ( $cmd eq 'current-data-version' ) {
|
|
|
|
return $current_data_version;
|
|
|
|
} else {
|
|
|
|
_die "unknown argument to glrc: $cmd";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 03:01:09 +01:00
|
|
|
# exported functions
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
my $all = 0;
|
2012-03-11 17:15:07 +01:00
|
|
|
my $nonl = 0;
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
sub query_rc {
|
|
|
|
|
|
|
|
my @vars = args();
|
|
|
|
|
|
|
|
no strict 'refs';
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
if ($all) {
|
|
|
|
for my $e ( sort keys %rc ) {
|
|
|
|
print "$e=" . ( defined( $rc{$e} ) ? $rc{$e} : 'undef' ) . "\n";
|
2012-03-16 05:29:45 +01:00
|
|
|
}
|
2012-03-12 16:24:30 +01:00
|
|
|
exit 0;
|
2012-03-16 05:29:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
my @res = map { $rc{$_} } grep { $rc{$_} } @vars;
|
|
|
|
print join( "\t", @res ) . ( $nonl ? '' : "\n" ) if @res;
|
|
|
|
# shell truth
|
|
|
|
exit 0 if @res;
|
|
|
|
exit 1;
|
2012-03-16 05:29:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-15 14:44:40 +01:00
|
|
|
sub version {
|
|
|
|
my $version = '';
|
|
|
|
$version = '(unknown)';
|
|
|
|
for ("$rc{GL_ADMIN_BASE}/VERSION") {
|
|
|
|
$version = slurp($_) if -r $_;
|
|
|
|
}
|
|
|
|
chomp($version);
|
|
|
|
return $version;
|
|
|
|
}
|
|
|
|
|
2012-03-19 03:01:09 +01:00
|
|
|
sub trigger {
|
|
|
|
my $rc_section = shift;
|
|
|
|
|
|
|
|
if ( exists $rc{$rc_section} ) {
|
|
|
|
if ( ref( $rc{$rc_section} ) ne 'ARRAY' ) {
|
|
|
|
_die "$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, @_ ); # they better all return with 0 exit codes!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
trace( 2, "'$rc_section' not found in rc" );
|
|
|
|
}
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
=for args
|
|
|
|
Usage: gitolite query-rc -a
|
|
|
|
gitolite query-rc [-n] <list of rc variables>
|
|
|
|
|
|
|
|
-a print all variables and values
|
|
|
|
-n do not append a newline
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
gitolite query-rc GL_ADMIN_BASE UMASK
|
|
|
|
# prints "/home/git/.gitolite<tab>0077" or similar
|
|
|
|
|
|
|
|
gitolite query-rc -a
|
|
|
|
# prints all known variables and values, one per line
|
|
|
|
=cut
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
sub args {
|
|
|
|
my $help = 0;
|
|
|
|
|
|
|
|
GetOptions(
|
|
|
|
'all|a' => \$all,
|
2012-03-11 17:15:07 +01:00
|
|
|
'nonl|n' => \$nonl,
|
2012-03-16 05:29:45 +01:00
|
|
|
'help|h' => \$help,
|
|
|
|
) or usage();
|
|
|
|
|
|
|
|
usage("'-a' cannot be combined with other arguments") if $all and @ARGV;
|
|
|
|
usage() if not $all and not @ARGV or $help;
|
|
|
|
return @ARGV;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
# configuration variables for gitolite
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
# This file is in perl syntax. But you do NOT need to know perl to edit it --
|
2012-03-17 07:55:38 +01:00
|
|
|
# just mind the commas, use single quotes unless you know what you're doing,
|
|
|
|
# and make sure the brackets and braces stay matched up!
|
2012-03-11 17:03:15 +01:00
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
# (Tip: perl allows a comma after the last item in a list also!)
|
2012-03-16 05:29:45 +01:00
|
|
|
|
|
|
|
%RC = (
|
|
|
|
UMASK => 0077,
|
2012-03-17 07:55:38 +01:00
|
|
|
GIT_CONFIG_KEYS => '',
|
|
|
|
|
|
|
|
# add more roles (like MANAGER, TESTER, ...) here
|
|
|
|
ROLES =>
|
|
|
|
{
|
|
|
|
READERS => 1,
|
|
|
|
WRITERS => 1,
|
|
|
|
},
|
|
|
|
# uncomment (and change) this if you wish
|
|
|
|
# DEFAULT_ROLE_PERMS => 'READERS @all',
|
2012-03-10 15:13:42 +01:00
|
|
|
|
2012-03-11 17:03:15 +01:00
|
|
|
# comment out or uncomment as needed
|
2012-03-12 16:24:30 +01:00
|
|
|
# these will run in sequence during the conf file parse
|
2012-03-10 15:13:42 +01:00
|
|
|
SYNTACTIC_SUGAR =>
|
|
|
|
[
|
|
|
|
# 'continuation-lines',
|
2012-03-18 16:11:02 +01:00
|
|
|
'legacy-delegation-abort',
|
2012-03-11 17:03:15 +01:00
|
|
|
],
|
|
|
|
|
|
|
|
# comment out or uncomment as needed
|
2012-03-12 16:24:30 +01:00
|
|
|
# these will run in sequence after post-update
|
2012-03-11 17:03:15 +01:00
|
|
|
POST_COMPILE =>
|
|
|
|
[
|
2012-03-16 04:55:39 +01:00
|
|
|
'post-compile/ssh-authkeys',
|
2012-03-19 11:45:21 +01:00
|
|
|
'post-compile/update-git-configs',
|
2012-03-19 09:34:17 +01:00
|
|
|
'post-compile/update-gitweb-access-list',
|
|
|
|
'post-compile/update-git-daemon-access-list',
|
|
|
|
],
|
|
|
|
|
|
|
|
# comment out or uncomment as needed
|
|
|
|
# these will run in sequence after a new wild repo is created
|
|
|
|
POST_CREATE =>
|
|
|
|
[
|
2012-03-19 11:45:21 +01:00
|
|
|
# 'post-compile/update-git-configs',
|
2012-03-19 09:34:17 +01:00
|
|
|
# 'post-compile/update-gitweb-access-list',
|
|
|
|
# 'post-compile/update-git-daemon-access-list',
|
2012-03-11 17:03:15 +01:00
|
|
|
],
|
2012-03-12 16:24:30 +01:00
|
|
|
|
|
|
|
# comment out or uncomment as needed
|
|
|
|
# these are available to remote users
|
|
|
|
COMMANDS =>
|
|
|
|
{
|
2012-03-16 04:55:39 +01:00
|
|
|
'help' => 1,
|
2012-03-12 16:24:30 +01:00
|
|
|
'info' => 1,
|
2012-03-18 05:20:24 +01:00
|
|
|
'perms' => 1,
|
2012-03-12 16:24:30 +01:00
|
|
|
},
|
2012-03-16 05:29:45 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# per perl rules, this should be the last line in such a file:
|
|
|
|
1;
|
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: perl
|
|
|
|
# End:
|
|
|
|
# vim: set syn=perl:
|