/
build.pl
executable file
·66 lines (54 loc) · 1.46 KB
/
build.pl
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
#!/usr/bin/perl -w
use strict;
use Data::Dump;
use Digest::SHA;
use File::Spec::Functions;
use File::Slurp;
use LWP::Simple;
use XML::Simple;
use constant REPO => 'repo.xml';
use constant REPO_URL => 'http://ljungberg.github.io/sverigesradio/' . REPO;
my $dir = shift @ARGV;
if (-d $dir) {
my $file = "$dir.zip";
my $manifest = catfile($dir, 'install.xml');
my $version = '';
if (-f $manifest) {
my $xml = XMLin($manifest);
if ($xml && ($version = $xml->{version})) {
$file = "$dir-$version.zip";
}
}
print "\nCompressing '$dir' to '$file'...\n\n";
my @exclude = qw(
--exclude=*.git*
--exclude=*.DS_Store
--exclude=*.svn*
--exclude=*/.*
);
if (-e "$dir/exclude.lst") {
push @exclude, "--exclude=$dir/exclude.lst", "--exclude=\@$dir/exclude.lst";
}
system('zip', '-r9', @exclude, $file, $dir);
if ($?) {
warn "Something went wrong: $?\n";
}
else {
print "\nCalculating SHA checksum...\n";
my $sha = Digest::SHA->new(1)->addfile($file)->hexdigest;
print "$sha\t$file\n";
if ( my $repo = get(REPO_URL) ) {
print "\nWriting new repository file...";
$repo =~ s/(plugin name="$dir".*?sha>)[\da-f]+/$1$sha/si;
$repo =~ s/(plugin name="$dir".*?version=")[\d\.]+/$1$version/si;
$repo =~ s/($dir-?[\d\.]*\.zip)/$file/sig;
write_file(REPO, {binmode => ':utf8'}, $repo);
my ($newRepo) = $repo =~ /(\s*<plugin name="$dir.*?\/plugin>)/si;
print $newRepo;
}
print "\nDone!\n";
}
}
else {
warn "No '$dir' folder found\n";
}