root/modules/branches/2.5/publish.pl

Revision 7531, 11.8 kB (checked in by p_lindheimer, 4 years ago)

skip php syntax checks on .jar files in publishing process, since they will fail

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