forked from swelljoe/usermin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-update.pl
executable file
·103 lines (91 loc) · 2.98 KB
/
create-update.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
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
#!/usr/local/bin/perl
# create_update.pl
@ARGV == 3 || @ARGV ==2 ||
die "usage: create_update.pl <module> <subversion> [description]";
chdir("/usr/local/useradmin");
$updates_dir = "/home/jcameron/webmin.com/uupdates";
open(VERSION, "version");
chop($version = <VERSION>);
close(VERSION);
$version = sprintf("%.2f0", $version);
if (&read_file($ifile = "$ARGV[0]/module.info", \%minfo)) {
$ext = "wbm";
}
elsif (&read_file($ifile = "$ARGV[0]/theme.info", \%minfo)) {
$ext = "wbt";
}
else {
die "Module or theme $ARGV[0] not found";
}
if (-r "$updates_dir/$ARGV[0]-$version-$ARGV[1].$ext.gz") {
die "Update $ARGV[0]-$version-$ARGV[1].$ext.gz already exists";
}
$uversion = $version + $ARGV[1]/1000.0;
system("./create-module.pl $updates_dir/$ARGV[0]-$version-$ARGV[1].$ext.gz $ARGV[0]/$uversion") && die "tar failed";
if ($ARGV[2]) {
$os_support = $minfo{'os_support'} ? $minfo{'os_support'} : "0";
open(UPDATES, "$updates_dir/uupdates.txt");
@updates = <UPDATES>;
close(UPDATES);
open(UPDATES, ">$updates_dir/uupdates.txt");
$vn = ($version + $ARGV[1]/1000.0);
print UPDATES $ARGV[0],"\t",$vn,"\t","$ARGV[0]-$version-$ARGV[1].$ext.gz","\t",$os_support,"\t",$ARGV[2],"\n";
print UPDATES @updates;
close(UPDATES);
open(UPDATES, "$updates_dir/../uupdates.html");
@updates = <UPDATES>;
close(UPDATES);
open(UPDATES, ">$updates_dir/../uupdates.html");
foreach $u (@updates) {
print UPDATES $u;
if ($u =~ /<!--\s+new\s+update/i) {
print UPDATES "<tr class=mainbody> <td>$minfo{'desc'}</td> <td>$version</td> <td>$ARGV[2]</td> <td nowrap><a href=uupdates/$ARGV[0]-$version-$ARGV[1].$ext.gz>New module</a></td> </tr>\n\n";
}
}
close(UPDATES);
# Send off an email for Martin
#open(MAIL, "| /usr/lib/sendmail -t -fjcameron\@webmin.com");
#print MAIL "To: mm\@usermin.org\n";
#print MAIL "Subject: Module $ARGV[0] updated\n";
#print MAIL "From: jcameron\@webmin.com\n";
#print MAIL "X-RSS-Webmin: update\n";
#print MAIL "X-RSS-Version: usermin\n";
#print MAIL "X-RSS-Module: $ARGV[0]\n";
#print MAIL "X-RSS-Version: $vn\n";
#print MAIL "\n";
#print MAIL "<item>\n";
#print MAIL "<title>$ARGV[0] version $vn : $ARGV[2]</title>\n";
#print MAIL "<link>http://webmin.mamemu.de/updates.html</link>\n";
#print MAIL "</item>\n";
#close(MAIL);
}
# read_file(file, &assoc, [&order], [lowercase])
# Fill an associative array with name=value pairs from a file
sub read_file
{
open(ARFILE, $_[0]) || return 0;
while(<ARFILE>) {
s/\r|\n//g;
if (!/^#/ && /^([^=]*)=(.*)$/) {
$_[1]->{$_[3] ? lc($1) : $1} = $2;
push(@{$_[2]}, $1) if ($_[2]);
}
}
close(ARFILE);
return 1;
}
# write_file(file, array)
# Write out the contents of an associative array as name=value lines
sub write_file
{
local(%old, @order);
&read_file($_[0], \%old, \@order);
open(ARFILE, ">$_[0]");
foreach $k (@order) {
print ARFILE $k,"=",$_[1]->{$k},"\n" if (exists($_[1]->{$k}));
}
foreach $k (keys %{$_[1]}) {
print ARFILE $k,"=",$_[1]->{$k},"\n" if (!exists($old{$k}));
}
close(ARFILE);
}