Fixed ServerMesg strings in BackupPC_Admin via en.pm and fr.pm
[BackupPC.git] / makeDist
1 #!/bin/perl
2 #
3 # Build a BackupPC distribution
4 #
5
6 use strict;
7 use File::Path;
8 use File::Copy;
9
10 umask(0022);
11
12 my $Version     = "1.5.0_CVS";
13 my $ReleaseDate = "17 Sep 2002";
14 my $DistDir     = "dist/BackupPC-$Version";
15
16 my @PerlSrc = qw(
17     bin/BackupPC
18     bin/BackupPC_dump
19     bin/BackupPC_link
20     bin/BackupPC_nightly
21     bin/BackupPC_restore
22     bin/BackupPC_sendEmail
23     bin/BackupPC_serverMesg
24     bin/BackupPC_trashClean
25     bin/BackupPC_tarExtract
26     bin/BackupPC_tarCreate
27     bin/BackupPC_compressPool
28     bin/BackupPC_zipCreate
29     bin/BackupPC_zcat
30     lib/BackupPC/Attrib.pm
31     lib/BackupPC/FileZIO.pm
32     lib/BackupPC/Lib.pm
33     lib/BackupPC/Lang/en.pm
34     lib/BackupPC/Lang/fr.pm
35     lib/BackupPC/PoolWrite.pm
36     lib/BackupPC/Xfer/Smb.pm
37     lib/BackupPC/Xfer/Tar.pm
38     lib/BackupPC/Zip/FileMember.pm
39     cgi-bin/BackupPC_Admin
40 );
41
42 #
43 # Check config parameters
44 #
45 my $ConfVars = {};
46 CheckConfigParams("conf/config.pl", $ConfVars, 0);
47 $ConfVars->{BackupPCUser} = 2;
48 $ConfVars->{CgiDir} = 2;
49 $ConfVars->{InstallDir} = 2;
50 $ConfVars->{CgiImageDir} = 2;
51 foreach my $file ( @PerlSrc ) {
52     CheckConfigParams($file, $ConfVars, 1);
53 }
54 my $errCnt;
55 foreach my $var ( sort(keys(%$ConfVars) ) ) {
56     next if ( $ConfVars->{$var} >= 2 || $var =~ /^\$/ );
57     printf("Unused config parameter $var\n");
58     $errCnt++;
59 }
60 exit(1) if ( $errCnt );
61
62 rmtree($DistDir, 0, 0);
63 mkpath($DistDir, 0, 0777);
64
65 foreach my $dir ( qw(bin lib/BackupPC/Xfer lib/BackupPC/Zip lib/BackupPC/Lang
66                      doc conf images init.d/src cgi-bin) ) {
67     mkpath("$DistDir/$dir", 0, 0777);
68 }
69
70 my %ConfName;
71 my $ConfPod = config2pod();
72 rmtree("doc", 0, 0);
73 mkpath("doc", 0, 0777);
74 InstallFile("doc-src/BackupPC.pod", "doc/BackupPC.pod");
75
76 use Pod::Html;
77 pod2html("doc/BackupPC.pod",
78         "--backlink=Back to Top",
79         "--header",
80         "--title=BackupPC",
81         "--outfile=doc/BackupPC.html");
82
83 foreach my $file ( (@PerlSrc,
84             <images/*>,
85             qw(
86                 conf/config.pl
87                 conf/hosts
88                 init.d/README
89                 init.d/src/debian-backuppc
90                 init.d/src/linux-backuppc
91                 init.d/src/solaris-backuppc
92                 doc/BackupPC.pod
93                 doc/BackupPC.html
94                 README
95                 LICENSE
96                 ChangeLog
97                 configure.pl
98         )) ) {
99     InstallFile("$file", "$DistDir/$file");
100 }
101 rmtree("doc", 0, 0);
102 system("cd dist ; tar zcf BackupPC-$Version.tar.gz BackupPC-$Version");
103
104 ###########################################################################
105 # Subroutines
106 ###########################################################################
107
108 sub InstallFile
109 {
110     my($file, $dest) = @_;
111
112     unlink($dest) if ( -d $dest );
113     if ( $file =~ /\.gif/ ) {
114         die("can't copy($file, $dest)\n") unless copy($file, $dest);
115     } else {
116         open(FILE, $file)   || die("can't open $file for reading\n");
117         open(OUT, ">$dest") || die("can't open $dest for writing\n");
118         while ( <FILE> ) {
119             s/^# *Version \d+\.\d+[\.\w]*, released \d+ \w+ \d{4}\.?/# Version __VERSION__, released __RELEASEDATE__./;
120             s/__VERSION__/$Version/g;
121             s/__RELEASEDATE__/$ReleaseDate/g;
122             if ( $file =~ /BackupPC\.html$/ && !/A NAME="item_%24Conf/ ) {
123                 s/\$Conf{([^}]*)}/
124                         defined($ConfName{$1})
125                             ? "<A HREF=\"#$ConfName{$1}\">\$Conf{$1}<\/A>"
126                             : "\$Conf{$1}"/eg;
127             }
128             if ( /__CONFIGPOD__/ ) {
129                 print OUT $ConfPod;
130             } elsif ( /^use lib ".*BackupPC\/lib";/
131                     || /^use lib "\/home\/pcbackup\/install\/lib";/ ) {
132                 print OUT "use lib \"__INSTALLDIR__/lib\";\n";
133             } elsif ( $file =~ /Lib.pm/ && /(.*TopDir *=> .*)'.*',/ ) {
134                 print OUT "$1'__TOPDIR__',\n";
135             } elsif ( $file =~ /Lib.pm/ && /(.*Version *=> .*)'[\w\d\.]+',/ ) {
136                 print OUT "$1'$Version',\n";
137             } elsif ( $file =~ /Lib.pm/ && /(.*BinDir *=> .*)'.*',/ ) {
138                 print OUT "$1'__INSTALLDIR__/bin',\n";
139             } elsif ( $file =~ /Lib.pm/ && /(.*LibDir *=> .*)'.*',/ ) {
140                 print OUT "$1'__INSTALLDIR__/lib',\n";
141             } else {
142                 print OUT;
143             }
144         }
145         close(FILE);
146         close(OUT);
147     }
148     if ( -x $file ) {
149         chmod(0555, $dest);
150     } else {
151         chmod(0444, $dest);
152     }
153 }
154
155 sub config2pod
156 {
157     open(C, "conf/config.pl") || die("can't open conf/config.pl");
158     my($str, $out, $getHdr, @conf);
159     my $first = 1;
160     while ( <C> ) {
161         chomp;
162         s/ +$//;
163         if ( /^#########################/ ) {
164             if ( $getHdr ) {
165                 $str =~ s/\n.*//sg;
166                 $out .= "=back\n\n" if ( !$first );
167                 $out .= "=head2 $str\n\n=over 4\n\n";
168                 $str = "";
169                 $first = 0;
170             }
171             $getHdr = !$getHdr;
172             next;
173         }
174         if ( /^#/ ) {
175             s/# ?//;
176             next if ( $str eq "" && /^$/ );
177             $str .= $_ . "\n";
178             $str .= "\n" if ( $str =~ /examples?:\n$/i );
179         } elsif ( /^\$Conf{([^}]*)/ ) {
180             my $var = $1;
181             s/  +/ /g;
182             s/;\s*#.*/;/;
183             if ( !s/\[$/[ ... ];/ && !s/<<'EOF'/.../ ) {
184                 s/([^;])\s*$/$1 .../;
185             }
186             push(@conf, $_);
187             my $text = $_;
188             $text =~ s/\s+/_/sg;
189             $text =~ s{(\W)}{sprintf("%%%02X", ord($1) )}gxe;
190             $text = substr($text, 0, 50);
191             $ConfName{$var} = "item_$text";
192         } elsif ( /^$/ ) {
193             if ( $str ne "" && @conf ) {
194                 $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
195                 $out .= $str;
196                 $out .= "\n" if ( $str !~ /\n$/ );
197             }
198             $str = "";
199             @conf = ();
200         }
201     }
202     if ( $str ne "" && @conf ) {
203         $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
204         $out .= $str;
205         $out .= "\n" if ( $str !~ /\n$/ );
206     }
207     $out .= "=back\n\n" if ( !$first );
208     return $out;
209 }
210
211 sub CheckConfigParams
212 {
213     my($file, $vars, $check) = @_;
214
215     open(F, $file) || die("can't open $file\n");
216     if ( $check ) {
217         while ( <F> ) {
218             s/\$self->{Conf}{([^}\$]+)}/if ( !defined($vars->{$1}) ) {
219                     print("Unexpected Conf var $1 in $file\n");
220                     exit(1);
221                 } else {
222                     $vars->{$1}++;
223                 }/eg;
224             s/\$[Cc]onf(?:->)?{([^}\$]+)}/if ( !defined($vars->{$1}) ) {
225                     print("Unexpected Conf var $1 in $file\n");
226                     exit(1);
227                 } else {
228                     $vars->{$1}++;
229                 }/eg;
230         }
231     } else {
232         while ( <F> ) {
233             s/^[^#]*\$self->{Conf}{([^}]*)/$vars->{$1} = 1;/eg;
234             s/^[^#]*\$Conf{([^}]*)/$vars->{$1} = 1;/eg;
235         }
236     }
237     close(F);
238 }