Fixed small navigation bug in CGI Action_Browse for top-level directory.
[BackupPC.git] / makeDist
1 #!/bin/perl
2 #
3 # makeDist: Build a BackupPC distribution
4 #
5 # DESCRIPTION
6 #
7 #   This script should be run with no arguments to build a
8 #   distribution.  The $Version and $ReleaseDate should be
9 #   edited below to specify the version name and the release
10 #   date.  The distribution is createede in the sub-directory
11 #   dist.  The dsitribution is in the file name:
12 #
13 #           dist/BackupPC-$Version.tar.gz.
14 #
15 # AUTHOR
16 #   Craig Barratt <cbarratt@users.sourceforge.net>
17 #
18 # COPYRIGHT
19 #   Copyright (C) 2001-2003  Craig Barratt
20 #
21 #   This program is free software; you can redistribute it and/or modify
22 #   it under the terms of the GNU General Public License as published by
23 #   the Free Software Foundation; either version 2 of the License, or
24 #   (at your option) any later version.
25 #
26 #   This program is distributed in the hope that it will be useful,
27 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
28 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 #   GNU General Public License for more details.
30 #
31 #   You should have received a copy of the GNU General Public License
32 #   along with this program; if not, write to the Free Software
33 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34 #
35 #========================================================================
36 #
37
38 use strict;
39 use File::Path;
40 use File::Copy;
41
42 umask(0022);
43
44 my $Version     = "2.0.0_CVS";
45 my $ReleaseDate = "18 Jan 2003";
46 my $DistDir     = "dist/BackupPC-$Version";
47
48 my @PerlSrc = qw(
49     bin/BackupPC
50     bin/BackupPC_dump
51     bin/BackupPC_link
52     bin/BackupPC_nightly
53     bin/BackupPC_restore
54     bin/BackupPC_sendEmail
55     bin/BackupPC_serverMesg
56     bin/BackupPC_trashClean
57     bin/BackupPC_tarExtract
58     bin/BackupPC_tarCreate
59     bin/BackupPC_compressPool
60     bin/BackupPC_zipCreate
61     bin/BackupPC_zcat
62     lib/BackupPC/Attrib.pm
63     lib/BackupPC/FileZIO.pm
64     lib/BackupPC/Lib.pm
65     lib/BackupPC/Lang/en.pm
66     lib/BackupPC/Lang/fr.pm
67     lib/BackupPC/PoolWrite.pm
68     lib/BackupPC/View.pm
69     lib/BackupPC/Xfer/Smb.pm
70     lib/BackupPC/Xfer/Tar.pm
71     lib/BackupPC/Xfer/Rsync.pm
72     lib/BackupPC/Xfer/RsyncFileIO.pm
73     lib/BackupPC/Zip/FileMember.pm
74     cgi-bin/BackupPC_Admin
75 );
76
77 #
78 # Check config parameters
79 #
80 my $ConfVars = {};
81 my $errCnt;
82
83 $errCnt += CheckConfigParams("conf/config.pl", $ConfVars, 0);
84 $ConfVars->{BackupPCUser} = 2;
85 $ConfVars->{CgiDir} = 2;
86 $ConfVars->{InstallDir} = 2;
87 $ConfVars->{CgiImageDir} = 2;
88 foreach my $file ( @PerlSrc ) {
89     $errCnt += CheckConfigParams($file, $ConfVars, 1);
90 }
91 $errCnt += CheckLangUsage();
92 exit(1) if ( $errCnt );
93
94 foreach my $var ( sort(keys(%$ConfVars) ) ) {
95     next if ( $ConfVars->{$var} >= 2 || $var =~ /^\$/ );
96     printf("Unused config parameter $var\n");
97     $errCnt++;
98 }
99 exit(1) if ( $errCnt );
100
101 rmtree($DistDir, 0, 0);
102 mkpath($DistDir, 0, 0777);
103
104 foreach my $dir ( qw(bin lib/BackupPC/Xfer lib/BackupPC/Zip lib/BackupPC/Lang
105                      doc conf images init.d/src cgi-bin) ) {
106     mkpath("$DistDir/$dir", 0, 0777);
107 }
108
109 my %ConfName;
110 my $ConfPod = config2pod();
111 rmtree("doc", 0, 0);
112 mkpath("doc", 0, 0777);
113 InstallFile("doc-src/BackupPC.pod", "doc/BackupPC.pod");
114
115 use Pod::Html;
116 pod2html("doc/BackupPC.pod",
117         "--backlink=Back to Top",
118         "--header",
119         "--title=BackupPC",
120         "--outfile=doc/BackupPC.html");
121
122 foreach my $file ( (@PerlSrc,
123             <images/*>,
124             qw(
125                 conf/config.pl
126                 conf/hosts
127                 init.d/README
128                 init.d/src/debian-backuppc
129                 init.d/src/linux-backuppc
130                 init.d/src/solaris-backuppc
131                 doc/BackupPC.pod
132                 doc/BackupPC.html
133                 README
134                 LICENSE
135                 ChangeLog
136                 configure.pl
137         )) ) {
138     InstallFile("$file", "$DistDir/$file");
139 }
140 rmtree("doc", 0, 0);
141 system("cd dist ; tar zcf BackupPC-$Version.tar.gz BackupPC-$Version");
142 print("Distribution written to dist/BackupPC-$Version.tar.gz\n");
143 unlink("pod2htmd.x~~");
144 unlink("pod2htmi.x~~");
145
146 ###########################################################################
147 # Subroutines
148 ###########################################################################
149
150 sub InstallFile
151 {
152     my($file, $dest) = @_;
153
154     unlink($dest) if ( -d $dest );
155     if ( $file =~ /\.gif/ ) {
156         die("can't copy($file, $dest)\n") unless copy($file, $dest);
157     } else {
158         open(FILE, $file)   || die("can't open $file for reading\n");
159         open(OUT, ">$dest") || die("can't open $dest for writing\n");
160         while ( <FILE> ) {
161             s/^# *Version \d+\.\d+[\.\w]*, released \d+ \w+ \d{4}\.?/# Version __VERSION__, released __RELEASEDATE__./;
162             s/__VERSION__/$Version/g;
163             s/__RELEASEDATE__/$ReleaseDate/g;
164             if ( $file =~ /BackupPC\.html$/ && !/A NAME="item_%24Conf/ ) {
165                 s/\$Conf{([^}]*)}/
166                         defined($ConfName{$1})
167                             ? "<A HREF=\"#$ConfName{$1}\">\$Conf{$1}<\/A>"
168                             : "\$Conf{$1}"/eg;
169             }
170             if ( /__CONFIGPOD__/ ) {
171                 print OUT $ConfPod;
172             } elsif ( /^use lib ".*BackupPC\/lib";/
173                     || /^use lib "\/home\/pcbackup\/install\/lib";/ ) {
174                 print OUT "use lib \"__INSTALLDIR__/lib\";\n";
175             } elsif ( $file =~ /Lib.pm/ && /(.*TopDir *=> .*)'.*',/ ) {
176                 print OUT "$1'__TOPDIR__',\n";
177             } elsif ( $file =~ /Lib.pm/ && /(.*Version *=> .*)'[\w\d\.]+',/ ) {
178                 print OUT "$1'$Version',\n";
179             } elsif ( $file =~ /Lib.pm/ && /(.*BinDir *=> .*)'.*',/ ) {
180                 print OUT "$1'__INSTALLDIR__',\n";
181             } elsif ( $file =~ /Lib.pm/ && /(.*LibDir *=> .*)'.*',/ ) {
182                 print OUT "$1'__INSTALLDIR__',\n";
183             } else {
184                 print OUT;
185             }
186         }
187         close(FILE);
188         close(OUT);
189     }
190     if ( -x $file ) {
191         chmod(0555, $dest);
192     } else {
193         chmod(0444, $dest);
194     }
195 }
196
197 sub config2pod
198 {
199     open(C, "conf/config.pl") || die("can't open conf/config.pl");
200     my($str, $out, $getHdr, @conf);
201     my $first = 1;
202     while ( <C> ) {
203         chomp;
204         s/ +$//;
205         if ( /^#########################/ ) {
206             if ( $getHdr ) {
207                 $str =~ s/\n.*//sg;
208                 $out .= "=back\n\n" if ( !$first );
209                 $out .= "=head2 $str\n\n=over 4\n\n";
210                 $str = "";
211                 $first = 0;
212             }
213             $getHdr = !$getHdr;
214             next;
215         }
216         if ( /^#/ ) {
217             s/# ?//;
218             next if ( $str eq "" && /^$/ );
219             $str .= $_ . "\n";
220             $str .= "\n" if ( $str =~ /examples?:\n$/i );
221         } elsif ( /^\$Conf{([^}]*)/ ) {
222             my $var = $1;
223             s/  +/ /g;
224             s/;\s*#.*/;/;
225             if ( !s/\[$/[ ... ];/ && !s/<<'EOF'/.../ ) {
226                 s/([^;])\s*$/$1 .../;
227             }
228             push(@conf, $_);
229             my $text = $_;
230             $text =~ s/\s+/_/sg;
231             $text =~ s{(\W)}{sprintf("%%%02X", ord($1) )}gxe;
232             $text = substr($text, 0, 50);
233             $ConfName{$var} = "item_$text";
234         } elsif ( /^$/ ) {
235             if ( $str ne "" && @conf ) {
236                 $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
237                 $out .= $str;
238                 $out .= "\n" if ( $str !~ /\n$/ );
239             }
240             $str = "";
241             @conf = ();
242         }
243     }
244     if ( $str ne "" && @conf ) {
245         $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
246         $out .= $str;
247         $out .= "\n" if ( $str !~ /\n$/ );
248     }
249     $out .= "=back\n\n" if ( !$first );
250     return $out;
251 }
252
253 sub CheckConfigParams
254 {
255     my($file, $vars, $check) = @_;
256     my $errors;
257
258     open(F, $file) || die("can't open $file\n");
259     if ( $check ) {
260         while ( <F> ) {
261             s/\$(self|bpc)->{Conf}{([^}\$]+)}/if ( !defined($vars->{$2}) ) {
262                     print("Unexpected Conf var $2 in $file\n");
263                     $errors++;
264                 } else {
265                     $vars->{$2}++;
266                 }/eg;
267             s/\$[Cc]onf(?:->)?{([^}\$]+)}/if ( !defined($vars->{$1}) ) {
268                     print("Unexpected Conf var $1 in $file\n");
269                     $errors++;
270                 } else {
271                     $vars->{$1}++;
272                 }/eg;
273             s/UserCommandRun\("([^"]*)"\)/if ( !defined($vars->{$1}) ) {
274                     print("Unexpected Conf var $1 in $file\n");
275                     $errors++;
276                 } else {
277                     $vars->{$1}++;
278                 }/eg;
279         }
280     } else {
281         while ( <F> ) {
282             s/^[^#]*\$self->{Conf}{([^}]*)/$vars->{$1} = 1;/eg;
283             s/^[^#]*\$Conf{([^}]*)/$vars->{$1} = 1;/eg;
284         }
285     }
286     close(F);
287     return $errors;
288 }
289
290 #
291 # Make sure that every lang variable in cgi-bin/BackupPC_Admin matches
292 # the strings in each lib/BackupPC/Lang/*.pm file.  This makes sure
293 # we didn't miss any translations in any of the languages.
294 #
295 sub CheckLangUsage
296 {
297     my $errors;
298     my $vars = {};
299
300     open(F, "cgi-bin/BackupPC_Admin")
301                 || die("can't open cgi-bin/BackupPC_Admin\n");
302     while ( <F> ) {
303         s/\$Lang->{([^}]*)}/$vars->{$1} = 1;/eg;
304     }
305     close(F);
306     foreach my $f ( <lib/BackupPC/Lang/*.pm> ) {
307         my $done = {};
308         open(F, $f) || die("can't open $f\n");
309         while ( <F> ) {
310             s/#.*//g;
311             s/\$Lang{([^}]*)}/
312                     my $var = $1;
313                     next if ( $var =~ m{^(Reason_|Status_)} );
314                     if ( !defined($vars->{$var}) ) {
315                         print("Unexpected Lang var $var in $f\n");
316                         $errors++;
317                     } else {
318                         $done->{$var} = 1;
319                     }/eg;
320         }
321         close(F);
322         foreach my $v ( keys(%$vars) ) {
323             #
324             # skip "variables" with "$", since they are like expressions
325             #
326             next if ( $v =~ /\$/ );
327             if ( !defined($done->{$v}) ) {
328                 print("Lang var $v missing from $f\n");
329                 $errors++;
330             }
331         }
332     }
333     return $errors;
334 }