summaryrefslogtreecommitdiffstats
path: root/src/syntactic-sugar/keysubdirs-as-groups
blob: 0a3a9ae1c87e633045742d90361a5c3e43bb6a32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# vim: syn=perl:

# "sugar script" (syntactic sugar helper) for gitolite3

# Enabling this script in the rc file allows you to use subdirectories in
# keydir as group names.  The last component other than keydir itself will be
# taken as the group name.

sub sugar_script {
    Gitolite::Common::trace( 2, "running 'keysubdirs-as-groups' sugar script..." );
    my $lines = shift;

    my @out = @{$lines};
    unshift @out, groupnames();

    return \@out;
}

sub groupnames {
    my @out     = ();
    my %members = ();
    for my $pk (`find ../keydir/ -name "*.pub"`) {
        next unless $pk =~ m(.*/([^/]+)/([^/]+?)(?:@[^./]+)?\.pub$);
        next if $1 eq 'keydir';
        $members{$1} .= " $2";
    }
    for my $m ( sort keys %members ) {
        push @out, "\@$m =" . $members{$m};
    }

    return @out;
}