-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyrus-versions
executable file
·119 lines (96 loc) · 2.88 KB
/
cyrus-versions
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env perl
use warnings;
use strict;
use File::Basename;
use File::Find;
use Digest::Pearson qw(pearson);
no warnings 'File::Find';
my @prefixes = (
@ENV{qw( CYRUSDEFAULT_PREFIX
CYRUSMURDER_PREFIX
CYRUSREPLICA_PREFIX )},
glob "/cyrus/*"
);
sub format_version
{
my ($version) = @_;
my (@branches, @tags);
if (not $version) {
print "unknown version\n";
return;
}
$version =~ s/^cyrus-imapd[- ]//;
if ($ENV{CYRUS_SOURCEDIR}
&& -d $ENV{CYRUS_SOURCEDIR}
&& $version =~ m/-g([0-9a-fA-F]*)(?:-dirty)?$/)
{
my $commit = $1;
my $branch_cmd = "(cd $ENV{CYRUS_SOURCEDIR}"
. " && git branch --points-at $commit) 2>/dev/null";
open my $in, '-|', $branch_cmd or die $!;
while (<$in>) {
if (m/^[* ] (.*)$/) {
push @branches, $1;
}
}
close $in;
my $tags_cmd = "(cd $ENV{CYRUS_SOURCEDIR}"
. " && git tag --points-at $commit) 2>/dev/null";
open $in, '-|', $tags_cmd or die $!;
while (<$in>) {
chomp;
push @tags, $_;
}
close $in;
}
if ($version !~ m/-g([0-9a-fA-F]*)(?:-dirty)?$/) {
# it's a recognisable release!
$version = "\033[1;33m$version\033[0m";
}
else {
no warnings 'portable'; # quiet 64 bit ints please
# colour sha1 sum
my $sha1 = $1;
my $colour = 17 + hex(substr($sha1, 0, 16)) % 214;
$version =~ s/(?<=g)${sha1}\b/\033[38;5;${colour}m${sha1}\033[0m/;
if ($version =~ m/^(\d+\.\d+\.\d+)/) {
# colour main part of version
my $match = $1;
$colour = 17 + pearson($match) % 214;
$version =~ s/^$match/\033[38;5;${colour}m${match}\033[0m/;
}
}
print $version;
if (scalar @branches) {
print " \033[92m" . join(q{ }, @branches) . "\033[0m";
}
if (scalar @tags) {
print " \033[93m" . join(q{ }, @tags) . "\033[0m";
}
print "\n";
}
sub master_version
{
return if basename($_) ne 'master';
return if not -x $_;
my $version = qx($_ -V 2>/dev/null);
chomp $version;
format_version($version);
}
my $whitespace = q{};
if ($ENV{CYRUS_SOURCEDIR} && -d $ENV{CYRUS_SOURCEDIR}) {
my $describe_cmd = "(cd $ENV{CYRUS_SOURCEDIR}"
. " && git describe --dirty=-dirty"
. " --match cyrus-imapd-*"
. ") 2>/dev/null";
my $version = qx($describe_cmd);
chomp $version;
print "$whitespace\033[1msource (and cassandane):\033[0m\n";
format_version($version);
$whitespace = qq{\n};
}
foreach my $p (grep { -d } @prefixes) {
print "$whitespace\033[1m$p:\033[0m\n";
find({ wanted => \&master_version, no_chdir => 1 }, $p);
$whitespace = qq{\n};
}