#!/bin/perl $root = "/home/boenzlip/sourceforge_mirror"; # source repos $repos_source = "$root/orxonox"; # destination repos $repos_dest = "$root/sourceforge"; $repos_source_root = "/var/svn/orxonox"; $repos_url_source = "http://svn.orxonox.net/orxonox/"; # local config script $config = "$root/svn_mirror.conf"; print "updateing repositories:\n"; update_repos($repos_source); update_repos($repos_dest); $repos_source_curr_rev = get_curr_revision($repos_source); $repos_dest_curr_rev = get_curr_revision($repos_dest); if(! -e $config ) { settings_create(); } print "last repos sync:\n"; $repos_source_last_rev = get_last_revision(); print " last source revision: $repos_source_last_rev\n"; for( $i = $repos_source_last_rev + 1; $i <= $repos_source_curr_rev; $i++) { print "processing revision: $i\n"; # create patches create_patch($i); # create changes create_changes($i); apply_patch($i); apply_change($i); } # now get the svn diffs #print "creating diff..."; #$patch_name = "$root/patch_$repos_source_last_rev\_to_$repos_source_curr_rev"; #open( DIFF, "svn diff -r$repos_source_last_rev:$repos_source_curr_rev > $patch_name $repos_url_source |"); #print "done.\n"; #close(DIFF); #print "patch -p0 -d $repos_dest -i $patch_name\n"; #print "applying diff as patch..."; #open( APPLY, "patch -p0 -d $repos_dest -i $patch_name |"); #print "done.\n"; #close (APPLY); #print "\nchecking in changes..."; #open( CI, "svn ci -m \"automatic repository synchronization. visit dev.orxonox.net for more informations\" $repos_dest |"); #close(CI); #print "done\n"; #print "\nwriting config files..."; #open(CONF, ">$config") or die "couldn't open file $config for writing\n"; #print CONF "last update at: $repos_source_curr_rev\n"; #close(CONF); print "\n\nrepos synchronized\n"; ######################################################################################### ## FUNCTIONS ######################################################################################### sub apply_patch { my $repos = $_[0]; my $patch = "$root/patch\_$repos"; #print "patch -p0 -d $repos_dest -i $patch\n"; print "applying diff as patch..."; open( APPLY, "patch -p0 -d $repos_dest -i $patch |"); print "patch -p0 -d $repos_dest -i $patch_name |\n"; print "done.\n"; close (APPLY); } sub apply_change { my $repos = $_[0]; my $changes = "$root/changes\_$repos"; print "$changes\n"; open(FILE, "<$changes"); foreach $line () { # $line =~ m/(\w)\s+(.+)/; # removing source if( $1 eq "D") { print "Deleting: $2\n"; } # adding source if( $1 eq "A") { print "Adding: $2\n"; } } close(FILE); } sub create_patch { my $repos = $_[0]; my $patch = "$root/patch\_$repos"; open(PATCH, "svnlook diff -r $repos $repos_source_root > $patch |"); close(PATCH); } sub create_changes { my $repos = $_[0]; my $changes = "$root/changes\_$repos"; open(CHANGED, "svnlook changed -r $repos $repos_source_root > $changes |"); close(CHANGED); } # # create settings # sub settings_create { open(CONF, ">$config") or die "couldn't open file $config for writing\n"; print CONF "last update at: 0\n"; close(CONF); } # # read last revision from the settings # sub get_last_revision { open( CONF, "<$config") or die "couldn't open file $config for reading\n"; foreach $line () { my $w = "(.+)"; chomp($line); $line =~ m/$w: $w/; # check for special sections: if( $1 eq "last update at") { return $2; } } } # # gets current revision of the repository # sub get_curr_revision { my $repos = $_[0]; open(COMMAND, "svn info $repos |"); foreach $line () { my $w = "(.+)"; chomp($line); $line =~ m/$w: $w/; if( $1 eq "Revision") { return $2; } } } # # # sub update_repos { my $repos = $_[0]; if( $repos eq $repos_source) { print " source repos..."; } if( $repos eq $repos_dest) { print " dest repos..." } open(COMMAND, "svn up $repos |"); foreach $line () { my $w = "(.+)"; chomp($line); $line =~ m/At revision (\d*)/; print "done, got revision $1\n"; } }