forked from piCorePlayer/applet-jlcustomclock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.pl
More file actions
78 lines (62 loc) · 2.14 KB
/
release.pl
File metadata and controls
78 lines (62 loc) · 2.14 KB
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
#!/usr/bin/perl
# Usage: release.pl <repofile> <version> <zipfile> <url> <name>
# repofile: Path to repo.xml file
# version: Version string (e.g., "1.0.0")
# zipfile: Path to zip file to calculate SHA for
# url: Base URL (zip filename will be appended)
# name: Applet name identifier (e.g., "JLCustomClock")
#
# Examples:
# perl release.pl repo.xml 1.0.0 JLCustomClock.zip http://example.com JLCustomClock
# perl release.pl repo.xml 2.0.0 JLJiveApplet.zip http://example.com JLJiveApplet
use strict;
use XML::Simple;
use File::Basename;
use Digest::SHA;
my $repofile = $ARGV[0];
my $version = $ARGV[1];
my $zipfile = $ARGV[2];
my $url = $ARGV[3];
my $name = $ARGV[4];
# Name parameter is required
if (!defined $name || $name eq '') {
die "Error: Applet name parameter is required\n";
}
my $repo = XMLin($repofile, ForceArray => 1, KeepRoot => 0, KeyAttr => 0, NoAttr => 0);
# Ensure applets section exists
if (!exists $repo->{applets}) {
$repo->{applets} = [{ applet => [] }];
} elsif (!exists $repo->{applets}[0]->{applet}) {
$repo->{applets}[0]->{applet} = [];
}
# Find the applet with matching name, or create new one
my $applet_index = -1;
my $applets = $repo->{applets}[0]->{applet};
for (my $i = 0; $i < scalar(@$applets); $i++) {
if (exists $applets->[$i]->{name} && $applets->[$i]->{name} eq $name) {
$applet_index = $i;
last;
}
}
# If not found, add new applet entry
if ($applet_index == -1) {
push @$applets, { name => $name };
$applet_index = scalar(@$applets) - 1;
}
# Calculate SHA
open (my $fh, "<", $zipfile) or die $!;
binmode $fh;
my $digest = Digest::SHA->new;
$digest->addfile($fh);
close $fh;
# Update the applet entry
$applets->[$applet_index]->{name} = $name;
$applets->[$applet_index]->{version} = $version;
$applets->[$applet_index]->{sha}[0] = $digest->hexdigest;
$url .= "/$zipfile";
$applets->[$applet_index]->{url}[0] = $url;
print("name : $name\n");
print("version: $version\n");
print("sha : ", $digest->hexdigest, "\n");
print("url : $url\n");
XMLout($repo, RootName => 'extensions', NoSort => 1, XMLDecl => 1, KeyAttr => '', OutputFile => $repofile, NoAttr => 0);