warn about unknown triggers
[gitolite.git] / convert-gitosis-conf
blob9b92f6857da6d6629b1b6cb889a0d87909bcc1ae
1 #!/usr/bin/perl -w
3 # migrate gitosis.conf to gitolite.conf format
5 # Based on gl-conf-convert by: Sitaram Chamarty
6 # Rewritten by: Behan Webster <behanw@websterwood.com>
9 use strict;
10 use warnings;
12 if (not @ARGV and -t or @ARGV and $ARGV[0] eq '-h') {
13 print "Usage:\n gl-conf-convert < gitosis.conf > gitolite.conf\n(please see the documentation for details)\n";
14 exit 1;
17 my @comments = ();
18 my $groupname;
19 my %groups;
20 my $reponame;
21 my %repos;
23 while (<>)
25 # not supported
26 if (/^repositories *=/ or /^map /) {
27 print STDERR "not supported: $_";
28 s/^/NOT SUPPORTED: /;
29 print;
30 next;
33 # normalise whitespace to help later regexes
34 chomp;
35 s/\s+/ /g;
36 s/ ?= ?/ = /;
37 s/^ //;
38 s/ $//;
40 if (/^\s*$/ and @comments > 1) {
41 @{$repos{$reponame}{comments}} = @comments if $reponame;
42 @{$groups{$groupname}{comments}} = @comments if $groupname;
43 @comments = ();
44 } elsif (/^\s*#/) {
45 push @comments, $_;
46 } elsif (/^\[repo\s+(.*?)\]$/) {
47 $groupname = '';
48 $reponame = $1;
49 $reponame =~ s/\.git$//;
50 } elsif (/^\[gitosis\]$/) {
51 $groupname = '';
52 $reponame = '@all';
53 } elsif (/^gitweb\s*=\s*yes/i) {
54 push @{$repos{$reponame}{R}}, 'gitweb';
55 } elsif (/^daemon\s*=\s*yes/i) {
56 push @{$repos{$reponame}{R}}, 'daemon';
57 } elsif (/^description\s*=\s*(.+?)$/) {
58 $repos{$reponame}{desc} = $1;
59 } elsif (/^owner\s*=\s*(.+?)$/) {
60 $repos{$reponame}{owner} = $1;
61 } elsif (/^\[group\s+(.*)\]$/) {
62 $reponame = '';
63 $groupname = $1;
64 } elsif (/^members\s*=\s*(.*)/) {
65 push @{$groups{$groupname}{users}}, map {s/\@([^.]+)$/_$1/g; $_} split(' ', $1);
66 } elsif (/^write?able\s*=\s*(.*)/) {
67 foreach my $repo (split(' ', $1)) {
68 $repo =~ s/\.git$//;
69 push @{$repos{$repo}{RW}}, "\@$groupname";
71 } elsif (/^readonly\s*=\s*(.*)/) {
72 foreach my $repo (split(' ', $1)) {
73 $repo =~ s/\.git$//;
74 push @{$repos{$repo}{R}}, "\@$groupname";
79 #use Data::Dumper;
80 #print Dumper(\%repos);
81 #print Dumper(\%groups);
83 # Groups
84 print "#\n# Groups\n#\n\n";
85 foreach my $grp (sort keys %groups) {
86 next unless @{$groups{$grp}{users}};
87 printf join("\n", @{$groups{$grp}{comments}})."\n" if $groups{$grp}{comments};
88 printf "\@%-19s = %s\n", $grp, join(' ', @{$groups{$grp}{users}});
91 # Gitweb
92 print "\n#\n# Gitweb\n#\n\n";
93 foreach my $repo (sort keys %repos) {
94 if ($repos{$repo}{desc}) {
95 @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});
96 print $repo;
97 print " \"$repos{$repo}{owner}\"" if $repos{$repo}{owner};
98 print " = \"$repos{$repo}{desc}\"\n";
102 # Repos
103 print "\n#\n# Repos\n#\n";
104 foreach my $repo (sort keys %repos) {
105 print "\n";
106 printf join("\n", @{$repos{$repo}{comments}})."\n" if $repos{$repo}{comments};
107 #if ($repos{$repo}{desc}) {
108 # @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});
110 print "repo\t$repo\n";
111 foreach my $access (qw(RW+ RW R)) {
112 next unless $repos{$repo}{$access};
113 my @keys;
114 foreach my $key (@{$repos{$repo}{$access}}) {
115 if ($key =~ /^\@(.*)/) {
116 next unless defined $groups{$1} and @{$groups{$1}{users}};
118 push @keys, $key;
120 printf "\t$access\t= %s\n", join(' ', @keys) if @keys;
122 #if ($repos{$repo}{desc}) {
123 # print $repo;
124 # print " \"$repos{$repo}{owner}\"" if $repos{$repo}{owner};
125 # print " = \"$repos{$repo}{desc}\"\n";