You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reposman.pl 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/perl
  2. #
  3. # redMine is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. use strict;
  17. use SOAP::Lite;
  18. use Getopt::Long;
  19. Getopt::Long::Configure ("bundling", "no_auto_abbrev", "no_ignore_case");
  20. use Pod::Usage;
  21. use vars qw/$VERSION/;
  22. $VERSION = "1.0";
  23. my $warning = "This program is now deprecated. Use the reposman.rb for new features";
  24. print STDERR "*" x length($warning), "\n",
  25. $warning, "\n",
  26. "*" x length($warning), "\n\n";
  27. my %opts = (verbose => 0);
  28. GetOptions(\%opts, 'verbose|v+', 'version|V', 'help|h', 'man|m', 'quiet|q', 'svn-dir|s=s', 'redmine-host|r=s') or pod2usage(2);
  29. die "$VERSION\n" if $opts{version};
  30. pod2usage(1) if $opts{help};
  31. pod2usage( -verbose => 2 ) if $opts{man};
  32. my $repos_base = $opts{'svn-dir'};
  33. my $redmine_host = $opts{'redmine-host'};
  34. pod2usage(2) unless $repos_base and $redmine_host;
  35. unless (-d $repos_base) {
  36. Log(text => "$repos_base doesn't exist", exit => 1);
  37. }
  38. Log(level => 1, text => "querying redMine for projects...");
  39. my $wdsl = "http://$redmine_host/sys/service.wsdl";
  40. my $service = SOAP::Lite->service($wdsl);
  41. my $projects = $service->Projects('');
  42. my $project_count = @{$projects};
  43. Log(level => 1, text => "retrieved $project_count projects");
  44. foreach my $project (@{$projects}) {
  45. Log(level => 1, text => "treating project $project->{name}");
  46. my $repos_name = $project->{identifier};
  47. if ($repos_name eq "") {
  48. Log(text => "\tno identifier for project $project->{name}");
  49. next;
  50. }
  51. unless ($repos_name =~ /^[a-z0-9\-]+$/) {
  52. Log(text => "\tinvalid identifier for project $project->{name}");
  53. next;
  54. }
  55. my $repos_path = "$repos_base/$repos_name";
  56. if (-e $repos_path) {
  57. # check unix right and change them if needed
  58. my $other_read = (stat($repos_path))[2] & 00007;
  59. my $right;
  60. if ($project->{is_public} and not $other_read) {
  61. $right = "0775";
  62. } elsif (not $project->{is_public} and $other_read) {
  63. $right = "0770";
  64. } else {
  65. next;
  66. }
  67. # change mode
  68. system('chmod', '-R', $right, $repos_path) == 0 or
  69. warn("\tunable to change mode on $repos_path : $?\n"), next;
  70. Log(text => "\tmode change on $repos_path");
  71. } else {
  72. # change umask to suit the repository's privacy
  73. $project->{is_public} ? umask 0002 : umask 0007;
  74. # create the repository
  75. system('svnadmin', 'create', $repos_path) == 0 or
  76. warn("\tsystem svnadmin failed unable to create $repos_path\n"), next;
  77. # set the group owner
  78. system('chown', '-R', "root:$repos_name", $repos_path) == 0 or
  79. warn("\tunable to create $repos_path : $?\n"), next;
  80. Log(text => "\trepository $repos_path created");
  81. }
  82. }
  83. sub Log {
  84. my %args = (level => 0, text => '', @_);
  85. my $level = delete $args{level};
  86. my $text = delete $args{text};
  87. return unless $level <= $opts{verbose};
  88. return if $opts{quiet};
  89. print "$text\n";
  90. exit $args{exit}
  91. if defined $args{exit};
  92. }
  93. __END__
  94. =head1 NAME
  95. reposman - manages your svn repositories with redMine
  96. =head1 SYNOPSIS
  97. reposman [options] arguments
  98. example: reposman --svn-dir=/var/svn --redmine-host=redmine.mydomain.foo
  99. reposman -s /var/svn -r redmine.mydomain.foo
  100. =head1 ARGUMENTS
  101. -s, --svn-dir=DIR use DIR as base directory for svn repositories
  102. -r, --redmine-host=HOST assume redMine is hosted on HOST
  103. =head1 OPTIONS
  104. -v verbose
  105. -V print version and exit