(new mirroring) helpers, hostname, detect use of older RC variables, delete mirror-sync

This commit is contained in:
Sitaram Chamarty 2011-08-12 21:59:10 +05:30
parent b70cf05b43
commit 15db108e45
4 changed files with 53 additions and 38 deletions

View file

@ -67,6 +67,7 @@ $SVNSERVE = "";
# PLEASE USE SINGLE QUOTES ABOVE, NOT DOUBLE QUOTES # PLEASE USE SINGLE QUOTES ABOVE, NOT DOUBLE QUOTES
$GL_WILDREPOS_PERM_CATS = "READERS WRITERS"; $GL_WILDREPOS_PERM_CATS = "READERS WRITERS";
# $GL_SITE_INFO = "XYZ.COM DEVELOPERS: PLEASE SEE http://xyz.com/gitolite/help first"; # $GL_SITE_INFO = "XYZ.COM DEVELOPERS: PLEASE SEE http://xyz.com/gitolite/help first";
# $GL_HOSTNAME = "frodo"; # read doc/mirroring.mkd COMPLETELY before setting this
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# rarely changed variables # rarely changed variables

View file

@ -22,11 +22,16 @@ use Exporter 'import';
setup_git_configs setup_git_configs
setup_gitweb_access setup_gitweb_access
shell_out shell_out
slurp
special_cmd special_cmd
try_adc try_adc
wrap_chdir wrap_chdir
wrap_open wrap_open
wrap_print wrap_print
mirror_mode
mirror_listslaves
mirror_redirectOK
); );
@EXPORT_OK = qw( @EXPORT_OK = qw(
%repos %repos
@ -1182,6 +1187,47 @@ sub ext_cmd_svnserve
die "svnserve exec failed\n"; die "svnserve exec failed\n";
} }
# ----------------------------------------------------------------------------
# MIRRORING HELPERS
# ----------------------------------------------------------------------------
sub mirror_mode {
my $repo = shift;
# 'local' is the default if the config is empty or not set
my $gmm = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.master` || 'local';
chomp $gmm;
return 'local' if $gmm eq 'local';
return 'master' if $gmm eq ( $GL_HOSTNAME || '' );
return "slave of $gmm";
}
sub mirror_listslaves {
my $repo = shift;
return ( `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.slaves` || '' );
}
sub mirror_redirectOK {
my $repo = shift;
my $slave = shift || '';
my $gmrOK = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.redirectOK` || '';
chomp $gmrOK;
my $slavelist = mirror_listslaves($repo);
# if gmrOK is 'true', any valid slave can redirect
return 1 if $gmrOK eq 'true' and $slavelist =~ /(^|\s)$slave(\s|$)/;
# otherwise, gmrOK is a list of slaves who can redirect
return 1 if $gmrOK =~ /(^|\s)$slave(\s|$)/;
return 0;
# LATER/NEVER: include a call to an external program to override a 'true',
# based on, say, the time of day or network load etc. Cons: shelling out,
# deciding the name of the program (yet another rc var?)
}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file: # per perl rules, this should be the last line in such a file:
1; 1;

View file

@ -23,6 +23,7 @@ use Exporter 'import';
$GL_SLAVE_MODE $GL_WILDREPOS $GL_WILDREPOS_DEFPERMS $GL_SLAVE_MODE $GL_WILDREPOS $GL_WILDREPOS_DEFPERMS
$GL_WILDREPOS_PERM_CATS $HTPASSWD_FILE $PROJECTS_LIST $REPO_BASE $GL_WILDREPOS_PERM_CATS $HTPASSWD_FILE $PROJECTS_LIST $REPO_BASE
$REPO_UMASK $RSYNC_BASE $SVNSERVE $UPDATE_CHAINS_TO $AUTH_OPTIONS $REPO_UMASK $RSYNC_BASE $SVNSERVE $UPDATE_CHAINS_TO $AUTH_OPTIONS
$GL_HOSTNAME
$GL_HTTP_ANON_USER $GL_HTTP_ANON_USER
); );
@ -72,6 +73,11 @@ do $ENV{GL_RC} or die "error parsing $ENV{GL_RC}\n";
# fix up REPO_BASE # fix up REPO_BASE
$REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $REPO_BASE =~ m(^/); $REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $REPO_BASE =~ m(^/);
# <sigh> backward incompat detection for mirroring. Normally I wouldn't do
# this but this is *important*
die "$ABRT Mirroring has completely changed in this version.\tYou need to check the documentation for how to upgrade\n"
if (defined $GL_SLAVE_MODE or exists $ENV{GL_SLAVES});
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file: # per perl rules, this should be the last line in such a file:
1; 1;

View file

@ -1,38 +0,0 @@
#!/bin/bash
mirror=$1
[ -z "$1" ] && { echo need \"user@host\" or ssh hostalias; exit 1; }
ssh -o PasswordAuthentication=no $mirror echo hello-there | grep hello-there >/dev/null ||
{ echo I cant ssh to $mirror; exit 1; }
cd $HOME
REPO_BASE=`${0%/*}/gl-query-rc REPO_BASE`
cd $REPO_BASE
ssh $mirror cat \$HOME/.gitolite.rc | expand | egrep '^ *\$GL_SLAVE_MODE *= *1; *$' >/dev/null || {
echo $mirror does not seem to be in slave mode
exit 1;
}
find . -type d -name "*.git" -prune | cut -c3- | sort | while read r
do
cd $HOME; cd $REPO_BASE; cd $r
printf "$r "
if [ `git rev-parse HEAD` = "HEAD" ]
then
echo is empty\; skipping
continue
fi
# this is essentially the same code as in the post-receive hook
if git push --mirror $mirror:$r
then
:
else
ssh $mirror mkdir -p $r
ssh $mirror git init --bare $r
git push --mirror $mirror:$r ||
echo "WARNING: mirror push to $mirror failed"
fi < /dev/null
done