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