forked from LaryLoose/laryloose.xbmc-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_zips.pl
executable file
·60 lines (51 loc) · 1.61 KB
/
create_zips.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
#!/usr/bin/perl
use strict;
use File::Basename;
my $sourcepath = '.';
my $destpath = "$sourcepath/zips";
sub is_empty($)
{
my $var = shift;
return (!defined($var) || ($var eq ''));
}
sub get_addon_folder
{
my $actfolder = shift;
if (is_empty($actfolder)) { print "get_addon_folder(): actfolder is empty\n"; exit 1; }
return sort split("\n", `ls -d $actfolder/*.*.*`);
}
sub get_addon_details
{
my $xml = shift;
if (is_empty($xml)) { print "get_addon_details(): addonxml is empty\n"; exit 2; }
if (!open FILE, "<$xml") { print "cannot open xml file $xml\n"; exit 2; }
my ($id, $version);
while (<FILE>)
{
my $line = $_;
if ($line =~ m/(<addon.*?>)/i)
{
$line = $1;
if ($line =~ m/id="(.*?)"/i) { $id = $1; }
if ($line =~ m/version="(.*?)"/i) { $version = $1; }
last;
}
}
close FILE;
return ($id, $version);
}
foreach my $folder (get_addon_folder($sourcepath))
{
if ($folder =~ m/\/(plugin|repository)[^\/]*/i)
{
my ($id, $version) = get_addon_details("$folder/addon.xml");
my $actzipfolder = "$destpath/$id";
if ((!-e $actzipfolder) && !mkdir($actzipfolder)) { print "could not create dir $actzipfolder"; exit 3; }
my $zipfile = "$actzipfolder/$id-$version.zip";
my $changefile = "$folder/changelog.txt";
my $iconfile = "$folder/icon.png";
if (!-e $zipfile) { print "creating file $zipfile\n"; `zip -r $zipfile $folder`; }
if (-e $changefile) { print "copy file $changefile\n"; `cp $changefile $actzipfolder/changelog.txt`; }
if (-e $iconfile) { print "copy file $iconfile\n"; `cp $iconfile $actzipfolder/icon.png`; }
}
}