| 1 |
#!/usr/bin/perl |
|---|
| 2 |
|
|---|
| 3 |
system("which md5sum"); |
|---|
| 4 |
if ($? == 0) { |
|---|
| 5 |
$md5_command = 'md5sum'; |
|---|
| 6 |
} else { |
|---|
| 7 |
system("which md5"); |
|---|
| 8 |
if ($? == 0) { |
|---|
| 9 |
$md5_command = 'md5 -r'; |
|---|
| 10 |
} else { |
|---|
| 11 |
die "no md5sum command\n"; |
|---|
| 12 |
} |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
$debug = 0; |
|---|
| 16 |
|
|---|
| 17 |
my $reldir = "contributed_modules/release"; |
|---|
| 18 |
|
|---|
| 19 |
while ($moddir = shift @ARGV) { |
|---|
| 20 |
if (($moddir eq "-h") || ($moddir eq "-help") || ($moddir eq "--h") || ($moddir eq "--help")) { |
|---|
| 21 |
die "Usage: publish <moduledirectory> [moduledirectory]\n"; |
|---|
| 22 |
} |
|---|
| 23 |
next if (!-d $moddir); |
|---|
| 24 |
# Check the XML integrity using the FreePBX XML parser |
|---|
| 25 |
if (system("./check_xml.php $moddir")) { |
|---|
| 26 |
die "Fatal syntax error with $moddir module.xml file, aborting\n"; |
|---|
| 27 |
} |
|---|
| 28 |
open FH, "$moddir/module.xml"; |
|---|
| 29 |
$newxml = ""; |
|---|
| 30 |
$vers = "unset"; |
|---|
| 31 |
$rawname = "unset"; |
|---|
| 32 |
while (<FH>) { |
|---|
| 33 |
if ($vers == 'unset' && /<version>(.+)<\/version>/) { $vers = $1; } |
|---|
| 34 |
if (/<rawname>(.+)<\/rawname>/) { $rawname = $1; } |
|---|
| 35 |
$newxml .= $_; |
|---|
| 36 |
} |
|---|
| 37 |
close FH; |
|---|
| 38 |
die "Don't know version of $moddir" if ($vers eq "unset"); |
|---|
| 39 |
die "Don't know rawname of $moddir" if ($rawname eq "unset"); |
|---|
| 40 |
# Automatically check in any files that were modified but weren't checked into SVN |
|---|
| 41 |
chdir($moddir); |
|---|
| 42 |
@arr = <*>; |
|---|
| 43 |
$files = ""; |
|---|
| 44 |
while ($x = shift @arr) { |
|---|
| 45 |
# Excluding module.xml which gets checked in later.. |
|---|
| 46 |
next if ($x =~ /module.xml/); |
|---|
| 47 |
$files .= "$x "; |
|---|
| 48 |
} |
|---|
| 49 |
if ($debug) { |
|---|
| 50 |
print "svn ci -m \"Auto Check-in of any outstanding patches\" $files\n"; |
|---|
| 51 |
} else { |
|---|
| 52 |
system("svn ci -m \"Auto Check-in of any outstanding patches\" $files"); |
|---|
| 53 |
} |
|---|
| 54 |
chdir(".."); |
|---|
| 55 |
# Now we know the version. Create the tar.gz |
|---|
| 56 |
$filename = "$rawname-$vers.tgz"; |
|---|
| 57 |
system("tar zcf $filename --exclude .svn $rawname"); |
|---|
| 58 |
# Update the md5 info |
|---|
| 59 |
open MD5, "$md5_command $filename|"; |
|---|
| 60 |
$md5 = <MD5>; |
|---|
| 61 |
close MD5; |
|---|
| 62 |
($md5sum, $null) = split(/ /, $md5); |
|---|
| 63 |
|
|---|
| 64 |
unless ($newxml =~ s/<md5sum>.*<\/md5sum>/<md5sum>$md5sum<\/md5sum>/) |
|---|
| 65 |
{ |
|---|
| 66 |
$newxml =~ s|</module>|<md5sum>$md5sum</md5sum>\n</module>|; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
unless ($newxml =~ s/<location>.*<\/location>/<location>$reldir\/$filename<\/location>/) |
|---|
| 70 |
{ |
|---|
| 71 |
$newxml =~ s|</module>|<location>$reldir/$filename</location>\n</module>|; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
open FH, ">$moddir/module.xml"; |
|---|
| 75 |
print FH $newxml; |
|---|
| 76 |
close FH; |
|---|
| 77 |
if ($debug) { |
|---|
| 78 |
print "mv $filename ../release/\n"; |
|---|
| 79 |
print "svn add ../release/$filename\n"; |
|---|
| 80 |
print "svn ps svn:mime-type application/tgz ../release/$filename\n"; |
|---|
| 81 |
print "svn ci ../release/$filename $rawname/module.xml -m \"Module Publish Script: $rawname $vers\"\n"; |
|---|
| 82 |
} else { |
|---|
| 83 |
system("mv $filename ../release/"); |
|---|
| 84 |
system("svn add ../release/$filename"); |
|---|
| 85 |
system("svn ps svn:mime-type application/tgz ../release/$filename"); |
|---|
| 86 |
system("svn ci ../release/$filename $rawname/module.xml -m \"Module Publish Script: $rawname $vers\""); |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|