root/modules/branches/2.9/publish.pl

Revision 10128, 12.2 kB (checked in by p_lindheimer, 3 years ago)

updated publish tools to 2.9 + trunk

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