| 1 |
#!/usr/bin/perl |
|---|
| 2 |
|
|---|
| 3 |
# Developers: Use $debug to keep all svn ci activity from occuring, messages will then be printed. All files will still be created |
|---|
| 4 |
# and module.xml modifications made since these can be reverted. Review carefully if you care concerned that it will |
|---|
| 5 |
# lose work. |
|---|
| 6 |
# |
|---|
| 7 |
system("which md5sum"); # typical linux format |
|---|
| 8 |
if ($? == 0) { |
|---|
| 9 |
$md5_command = 'md5sum'; |
|---|
| 10 |
} else { |
|---|
| 11 |
system("which md5"); # OSX format |
|---|
| 12 |
if ($? == 0) { |
|---|
| 13 |
$md5_command = 'md5 -r'; |
|---|
| 14 |
} else { |
|---|
| 15 |
die "no md5sum command\n"; |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
$debug = 0; |
|---|
| 20 |
$checkphp = 1; |
|---|
| 21 |
$rver = "2.7"; |
|---|
| 22 |
$fwbranch = "branches/2.7"; |
|---|
| 23 |
$framework = "framework"; |
|---|
| 24 |
$fw_fop = "fw_fop"; |
|---|
| 25 |
$fw_ari = "fw_ari"; |
|---|
| 26 |
$fw_langpacks = "fw_langpacks"; |
|---|
| 27 |
|
|---|
| 28 |
my $reldir = "release/"; |
|---|
| 29 |
|
|---|
| 30 |
while ($moddir = shift @ARGV) { |
|---|
| 31 |
next if (!-d $moddir); |
|---|
| 32 |
# Check the XML integrity using the FreePBX XML parser |
|---|
| 33 |
if (system("./check_xml.php $moddir")) { |
|---|
| 34 |
die "Fatal syntax error with $moddir module.xml file, aborting\n"; |
|---|
| 35 |
} |
|---|
| 36 |
if ($moddir =~ /$framework/) { |
|---|
| 37 |
|
|---|
| 38 |
# Framework module is special case. We export and pull in all the files of framework that we are going to want to udpate. For now this is |
|---|
| 39 |
# all files under htdocs, agi-bin and bin. We have not included astetc since such files should be done with core modules. We have also |
|---|
| 40 |
# temporarily chosen not to include FOP since it is likely FOP may be handled by a FOP module going forward. Othewise we will add it here. |
|---|
| 41 |
# |
|---|
| 42 |
# |
|---|
| 43 |
if (system("rm -rf $framework/agi-bin $framework/bin $framework/htdocs $framework/htdocs_panel $framework/upgrades $framework/libfreepbx.install.php $framework/CHANGES")) { |
|---|
| 44 |
die "FATAL: failed to remove previoulsly exported directories\n"; |
|---|
| 45 |
} |
|---|
| 46 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/agi-bin $framework/agi-bin")) { |
|---|
| 47 |
die "FATAL: failed to export agi-bin directory\n"; |
|---|
| 48 |
} |
|---|
| 49 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/bin $framework/bin")) { |
|---|
| 50 |
die "FATAL: failed to export bin directory\n"; |
|---|
| 51 |
} |
|---|
| 52 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/htdocs $framework/htdocs")) { |
|---|
| 53 |
die "FATAL: failed to export htdocs directory\n"; |
|---|
| 54 |
} |
|---|
| 55 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/upgrades $framework/upgrades")) { |
|---|
| 56 |
die "FATAL: failed to export upgrades directory\n"; |
|---|
| 57 |
} |
|---|
| 58 |
# svn doesn't seem to allow for a single file to be checked out so we need to do a kludgey workaround |
|---|
| 59 |
# this is what we wanted: |
|---|
| 60 |
# |
|---|
| 61 |
# if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/libfreepbx.install.php $framework/libfreepbx.install.php")) |
|---|
| 62 |
# |
|---|
| 63 |
if (system("svn co --non-recursive http://svn.freepbx.org/freepbx/$fwbranch $framework/tmp")) { |
|---|
| 64 |
die "FATAL: failed to checkout branch with libfreepbx.install.php\n"; |
|---|
| 65 |
} |
|---|
| 66 |
# Create the svnversion information for this framework snapshot |
|---|
| 67 |
# |
|---|
| 68 |
if (system("echo SVN VERSION: `svnversion $framework/tmp` > $framework/svnversion.txt")) { |
|---|
| 69 |
die "FATAL: svnversion failed to create svnversion.txt\n"; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
if (system("mv $framework/tmp/libfreepbx.install.php $framework/")) { |
|---|
| 73 |
die "FATAL: failed to mv libfreepbx.install.php to $framework\n"; |
|---|
| 74 |
} |
|---|
| 75 |
if (system("mv $framework/tmp/CHANGES $framework/")) { |
|---|
| 76 |
die "FATAL: failed to mv CHANGES to $framework\n"; |
|---|
| 77 |
} |
|---|
| 78 |
if (system("rm -rf $framework/tmp")) { |
|---|
| 79 |
die "FATAL: failed to remove $framework/tmp\n"; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
# Now we must remove a few files which users may have legitimately edited. For now, all of ARI moved to new module |
|---|
| 83 |
# ARI file used for editing paramters and options. |
|---|
| 84 |
# |
|---|
| 85 |
if (system("rm -rf $framework/htdocs/recordings")) { |
|---|
| 86 |
die "FATAL: failed to trim main.conf.php ARI file\n"; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
# Remove from htdocs root mainstyle.css and index.html as these are owned by root (need to investigate why these are there |
|---|
| 90 |
# and change that. Remove retrieve_op_conf_from_mysql.pl now handled by fw_fop. Also some others. |
|---|
| 91 |
# |
|---|
| 92 |
# TODO: check if these are stiff there and need to be special cased |
|---|
| 93 |
# |
|---|
| 94 |
if (system("rm -rf $framework/htdocs/mainstyle.css")) { |
|---|
| 95 |
die "FATAL: failed to trim htdocs/mainstyle.css\n"; |
|---|
| 96 |
} |
|---|
| 97 |
if (system("rm -rf $framework/htdocs/index.html")) { |
|---|
| 98 |
die "FATAL: failed to trim htdocs/index.html\n"; |
|---|
| 99 |
} |
|---|
| 100 |
if (system("rm -rf $framework/htdocs/robots.txt")) { |
|---|
| 101 |
die "FATAL: failed to trim htdocs/robots.txt\n"; |
|---|
| 102 |
} |
|---|
| 103 |
if (system("rm -rf $framework/htdocs/admin/modules/_cache")) { |
|---|
| 104 |
die "FATAL: failed to trim modules/_cache\n"; |
|---|
| 105 |
} |
|---|
| 106 |
if (system("rm -rf $framework/bin/retrieve_op_conf_from_mysql.pl")) { |
|---|
| 107 |
die "FATAL: failed to trim bin/retrieve_op_conf_from_mysql.pl\n"; |
|---|
| 108 |
} |
|---|
| 109 |
if (system("rm -rf $framework/bin/retrieve_op_conf_from_mysql.php")) { |
|---|
| 110 |
die "FATAL: failed to trim bin/retrieve_op_conf_from_mysql.php\n"; |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
if ($moddir =~ /$fw_fop/) { |
|---|
| 114 |
if (system("rm -rf $fw_fop/bin $fw_fop/htdocs_panel")) { |
|---|
| 115 |
die "FATAL: failed to remove previoulsly exported directories\n"; |
|---|
| 116 |
} |
|---|
| 117 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/htdocs_panel $fw_fop/htdocs_panel")) { |
|---|
| 118 |
die "FATAL: failed to export htdocs_panel directory\n"; |
|---|
| 119 |
} |
|---|
| 120 |
if (system("svn co --non-recursive http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/bin $fw_fop/tmp")) { |
|---|
| 121 |
die "FATAL: failed to checkout bin\n"; |
|---|
| 122 |
} |
|---|
| 123 |
if (system("mkdir $fw_fop/bin")) { |
|---|
| 124 |
die "FATAL: failed to create $fw_fop/bin\n"; |
|---|
| 125 |
} |
|---|
| 126 |
if (system("mv $fw_fop/tmp/retrieve_op_conf_from_mysql.pl $fw_fop/bin")) { |
|---|
| 127 |
die "FATAL: failed to mv retrieve_op_conf_from_mysql.pl to $fw_fop/bin\n"; |
|---|
| 128 |
} |
|---|
| 129 |
if (system("mv $fw_fop/tmp/retrieve_op_conf_from_mysql.php $fw_fop/bin")) { |
|---|
| 130 |
die "FATAL: failed to mv retrieve_op_conf_from_mysql.php to $fw_fop/bin\n"; |
|---|
| 131 |
} |
|---|
| 132 |
if (system("rm -rf $fw_fop/tmp")) { |
|---|
| 133 |
die "FATAL: failed to remove $fw_fop/tmp\n"; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
# Create the svnversion information for this framework snapshot |
|---|
| 137 |
# |
|---|
| 138 |
if (system("echo SVN VERSION: `svn log -q -r HEAD http://svn.freepbx.org/ | cut -s -f 1 -d ' ' | cut -b '2-'` > $fw_fop/svnversion.txt")) { |
|---|
| 139 |
die "FATAL: svnversion failed to create svnversion.txt\n"; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
} |
|---|
| 143 |
if ($moddir =~ /$fw_ari/) { |
|---|
| 144 |
|
|---|
| 145 |
if (system("rm -rf $fw_ari/htdocs_ari")) { |
|---|
| 146 |
die "FATAL: failed to remove previoulsly exported directories\n"; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
# Create the svnversion information for this framework snapshot |
|---|
| 150 |
# |
|---|
| 151 |
if (system("echo SVN VERSION: `svn log -q -r HEAD http://svn.freepbx.org/ | cut -s -f 1 -d ' ' | cut -b '2-'` > $fw_ari/svnversion.txt")) { |
|---|
| 152 |
die "FATAL: svnversion failed to create svnversion.txt\n"; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
if (system("svn export http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/htdocs/recordings $fw_ari/htdocs_ari")) { |
|---|
| 156 |
die "FATAL: failed to export htdocs directory\n"; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
# Now we must remove a few files which users may have legitimately edited. For now this is the main.conf.php file which is the current |
|---|
| 160 |
# ARI file used for editing paramters and options. |
|---|
| 161 |
# |
|---|
| 162 |
if (system("rm -rf $fw_ari/htdocs_ari/includes/main.conf.php")) { |
|---|
| 163 |
die "FATAL: failed to trim main.conf.php ARI file\n"; |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
} |
|---|
| 167 |
if ($moddir =~ /$fw_langpacks/) { |
|---|
| 168 |
|
|---|
| 169 |
my $module_url="http://svn.freepbx.org/modules/branches/$rver"; |
|---|
| 170 |
my $base_url="http://svn.freepbx.org/freepbx/$fwbranch/amp_conf/htdocs"; |
|---|
| 171 |
my $framework_url="$base_url/admin"; |
|---|
| 172 |
my $recordings_url="$base_url/recordings"; |
|---|
| 173 |
|
|---|
| 174 |
@modules=`svn list $module_url | grep '/'`; |
|---|
| 175 |
|
|---|
| 176 |
if (system("rm -rf $fw_langpacks/htdocs")) { |
|---|
| 177 |
die "FATAL: failed to remove old htdocs dir\n"; |
|---|
| 178 |
} |
|---|
| 179 |
if (system("mkdir -p $fw_langpacks/htdocs/admin/modules")) { |
|---|
| 180 |
die "FATAL: failed to create htdocs/admin/modules\n"; |
|---|
| 181 |
} |
|---|
| 182 |
if (system("mkdir -p $fw_langpacks/htdocs/recordings")) { |
|---|
| 183 |
die "FATAL: failed to create htdocs/recordings\n"; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
if (system("svn export $framework_url/i18n $fw_langpacks/htdocs/admin/i18n")) { |
|---|
| 187 |
die "FATAL: failed to export $framework_url/i18n\n"; |
|---|
| 188 |
} |
|---|
| 189 |
if (system("svn export $recordings_url/locale $fw_langpacks/htdocs/recordings/locale")) { |
|---|
| 190 |
die "FATAL: failed to export $recurdings_url/locale\n"; |
|---|
| 191 |
} |
|---|
| 192 |
foreach my $module ( @modules ) { |
|---|
| 193 |
chomp($module); |
|---|
| 194 |
if (system("rm -rf $fw_langpacks/i18n-tmp")) { |
|---|
| 195 |
die "FATAL: failed to remove temp i18n-tmp dir\n"; |
|---|
| 196 |
} |
|---|
| 197 |
system("svn export $module_url/$module"."i18n $fw_langpacks/i18n-tmp 2> /dev/null"); |
|---|
| 198 |
if (($? != -1) && (-d "$fw_langpacks/i18n-tmp")) { |
|---|
| 199 |
if (system("mkdir $fw_langpacks/htdocs/admin/modules/$module")) { |
|---|
| 200 |
die "FATAL: failed to create htdocs/admin/modules/$module\n"; |
|---|
| 201 |
} |
|---|
| 202 |
if (system("mv $fw_langpacks/i18n-tmp $fw_langpacks/htdocs/admin/modules/$module/i18n")) { |
|---|
| 203 |
die "FATAL: failed to move i18n-tmp to htdocs/admin/modules/$module/i18n\n"; |
|---|
| 204 |
} |
|---|
| 205 |
} else { |
|---|
| 206 |
print "No i18n files for $module"."\n"; |
|---|
| 207 |
} |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
# Create the svnversion information for this framework snapshot |
|---|
| 212 |
# |
|---|
| 213 |
if (system("echo SVN VERSION: `svn log -q -r HEAD http://svn.freepbx.org/ | cut -s -f 1 -d ' ' | cut -b '2-'` > $fw_langpacks/svnversion.txt")) { |
|---|
| 214 |
die "FATAL: svnversion failed to create svnversion.txt\n"; |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
open FH, "$moddir/module.xml"; |
|---|
| 220 |
$newxml = ""; |
|---|
| 221 |
$vers = "unset"; |
|---|
| 222 |
$rawname = "unset"; |
|---|
| 223 |
while (<FH>) { |
|---|
| 224 |
if ($vers == 'unset' && /<version>(.+)<\/version>/) { $vers = $1; } |
|---|
| 225 |
if (/<rawname>(.+)<\/rawname>/) { $rawname = $1; } |
|---|
| 226 |
$newxml .= $_; |
|---|
| 227 |
} |
|---|
| 228 |
close FH; |
|---|
| 229 |
die "Don't know version of $moddir" if ($vers eq "unset"); |
|---|
| 230 |
die "Don't know rawname of $moddir" if ($rawname eq "unset"); |
|---|
| 231 |
# Automatically check in any files that were modified but weren't checked into SVN |
|---|
| 232 |
chdir($moddir); |
|---|
| 233 |
@arr = <*>; |
|---|
| 234 |
$files = ""; |
|---|
| 235 |
if ($moddir =~ /$framework/) { |
|---|
| 236 |
while ($x = shift @arr) { |
|---|
| 237 |
# Excluding module.xml which gets checked in later.. |
|---|
| 238 |
next if ($x =~ /module.xml/); |
|---|
| 239 |
next if ($x =~ /agi-bin/); |
|---|
| 240 |
next if ($x =~ /bin/); |
|---|
| 241 |
next if ($x =~ /htdocs/); |
|---|
| 242 |
next if ($x =~ /htdocs_panel/); |
|---|
| 243 |
next if ($x =~ /upgrades/); |
|---|
| 244 |
next if ($x =~ /libfreepbx.install.php/); |
|---|
| 245 |
next if ($x =~ /svnversion.txt/); |
|---|
| 246 |
$files .= "$x "; |
|---|
| 247 |
if (-f $x && $checkphp) { |
|---|
| 248 |
if (system("php -l $x")) { |
|---|
| 249 |
die "FATAL: php syntax error detected in $x\n"; |
|---|
| 250 |
} |
|---|
| 251 |
} |
|---|
| 252 |
} |
|---|
| 253 |
} elsif ($moddir =~ /$fw_fop/) { |
|---|
| 254 |
while ($x = shift @arr) { |
|---|
| 255 |
next if ($x =~ /module.xml/); |
|---|
| 256 |
next if ($x =~ /htdocs_panel/); |
|---|
| 257 |
next if ($x =~ /svnversion.txt/); |
|---|
| 258 |
$files .= "$x "; |
|---|
| 259 |
if (-f $x && $checkphp) { |
|---|
| 260 |
if (system("php -l $x")) { |
|---|
| 261 |
die "FATAL: php syntax error detected in $x\n"; |
|---|
| 262 |
} |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
} elsif ($moddir =~ /$fw_ari/) { |
|---|
| 266 |
while ($x = shift @arr) { |
|---|
| 267 |
next if ($x =~ /module.xml/); |
|---|
| 268 |
next if ($x =~ /htdocs_ari/); |
|---|
| 269 |
next if ($x =~ /svnversion.txt/); |
|---|
| 270 |
$files .= "$x "; |
|---|
| 271 |
if (-f $x && $checkphp) { |
|---|
| 272 |
if (system("php -l $x")) { |
|---|
| 273 |
die "FATAL: php syntax error detected in $x\n"; |
|---|
| 274 |
} |
|---|
| 275 |
} |
|---|
| 276 |
} |
|---|
| 277 |
} elsif ($moddir =~ /$fw_langpacks/) { |
|---|
| 278 |
while ($x = shift @arr) { |
|---|
| 279 |
next if ($x =~ /module.xml/); |
|---|
| 280 |
next if ($x =~ /htdocs/); |
|---|
| 281 |
next if ($x =~ /svnversion.txt/); |
|---|
| 282 |
$files .= "$x "; |
|---|
| 283 |
if (-f $x && $checkphp) { |
|---|
| 284 |
if (system("php -l $x")) { |
|---|
| 285 |
die "FATAL: php syntax error detected in $x\n"; |
|---|
| 286 |
} |
|---|
| 287 |
} |
|---|
| 288 |
} |
|---|
| 289 |
} else { |
|---|
| 290 |
while ($x = shift @arr) { |
|---|
| 291 |
# Excluding module.xml which gets checked in later.. |
|---|
| 292 |
next if ($x =~ /module.xml/); |
|---|
| 293 |
$files .= "$x "; |
|---|
| 294 |
|
|---|
| 295 |
# Quick and dirty check for php syntax errors at the top level of module directories. Should probably |
|---|
| 296 |
# do this recursively in the future. Also - checks all files now but php -l seems to be ok with that. |
|---|
| 297 |
# |
|---|
| 298 |
if (-f $x && $checkphp) { |
|---|
| 299 |
if (!($x =~ /.*\.jar/) && system("php -l $x") ) { |
|---|
| 300 |
die "FATAL: php syntax error detected in $x\n"; |
|---|
| 301 |
} |
|---|
| 302 |
} |
|---|
| 303 |
} |
|---|
| 304 |
} |
|---|
| 305 |
if ($debug) { |
|---|
| 306 |
print "svn ci -m \"Auto Check-in of any outstanding patches\" $files\n"; |
|---|
| 307 |
} else { |
|---|
| 308 |
system("svn ci -m \"Auto Check-in of any outstanding patches\" $files"); |
|---|
| 309 |
} |
|---|
| 310 |
chdir(".."); |
|---|
| 311 |
# Now we know the version. Create the tar.gz |
|---|
| 312 |
$filename = "$rawname-$vers.tgz"; |
|---|
| 313 |
system("tar zcf $filename --exclude '.*' $rawname"); |
|---|
| 314 |
# Update the md5 info |
|---|
| 315 |
open MD5, "$md5_command $filename|"; |
|---|
| 316 |
$md5 = <MD5>; |
|---|
| 317 |
close MD5; |
|---|
| 318 |
($md5sum, $null) = split(/ /, $md5); |
|---|
| 319 |
|
|---|
| 320 |
unless ($newxml =~ s/<md5sum>.*<\/md5sum>/<md5sum>$md5sum<\/md5sum>/) |
|---|
| 321 |
{ |
|---|
| 322 |
$newxml =~ s|</module>|<md5sum>$md5sum></md5sum>\n</module>|; |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
unless ($newxml =~ s/<location>.*<\/location>/<location>$reldir$rver\/$filename<\/location>/) |
|---|
| 326 |
{ |
|---|
| 327 |
$newxml =~ s|</module>|<location>$reldir$rver></location>\n</module>|; |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
open FH, ">$moddir/module.xml"; |
|---|
| 331 |
print FH $newxml; |
|---|
| 332 |
close FH; |
|---|
| 333 |
|
|---|
| 334 |
system("svn update $rawname"); |
|---|
| 335 |
my $lastpublish = `svn info $rawname | grep Revision: | cut -f 2 -d ' '`; |
|---|
| 336 |
chomp($lastpublish); |
|---|
| 337 |
|
|---|
| 338 |
if ($debug) { |
|---|
| 339 |
print "mv $filename ../../release/$rver\n"; |
|---|
| 340 |
print "svn add ../../release/$rver/$filename\n"; |
|---|
| 341 |
print "svn ps svn:mime-type application/tgz ../../release/$rver/$filename\n"; |
|---|
| 342 |
print "svn ps lastpublish '$lastpublish' $moddir\n"; |
|---|
| 343 |
print "svn ci ../../release/$rver/$filename $rawname/module.xml -m \"Module Publish Script: $rawname $vers\"\n"; |
|---|
| 344 |
} else { |
|---|
| 345 |
system("mv $filename ../../release/$rver"); |
|---|
| 346 |
system("svn add ../../release/$rver/$filename"); |
|---|
| 347 |
system("svn ps svn:mime-type application/tgz ../../release/$rver/$filename"); |
|---|
| 348 |
system("svn ps lastpublish '$lastpublish' $rawname"); |
|---|
| 349 |
system("svn ci ../../release/$rver/$filename $rawname/module.xml ./$rawname -m \"Module Publish Script: $rawname $vers\""); |
|---|
| 350 |
} |
|---|
| 351 |
} |
|---|