2 #============================================================= -*-perl-*-
4 # configure.pl: Configuration and installation program for BackupPC
8 # This script should be run as root:
12 # The installation steps are described as the script runs.
15 # Craig Barratt <cbarratt@users.sourceforge.net>
18 # Copyright (C) 2001-2003 Craig Barratt
20 # This program is free software; you can redistribute it and/or modify
21 # it under the terms of the GNU General Public License as published by
22 # the Free Software Foundation; either version 2 of the License, or
23 # (at your option) any later version.
25 # This program is distributed in the hope that it will be useful,
26 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 # GNU General Public License for more details.
30 # You should have received a copy of the GNU General Public License
31 # along with this program; if not, write to the Free Software
32 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #========================================================================
36 # Version 2.0.0_CVS, released 18 Jan 2003.
38 # See http://backuppc.sourceforge.net.
40 #========================================================================
44 use vars qw(%Conf %OrigConf);
47 my @Packages = qw(ExtUtils::MakeMaker File::Path File::Spec File::Copy
48 DirHandle Digest::MD5 Data::Dumper Getopt::Std
49 BackupPC::Lib BackupPC::FileZIO);
51 foreach my $pkg ( @Packages ) {
56 BackupPC needs the package $pkg. Please install $pkg
57 before installing BackupPC.
65 This configure script should be run as root, rather than uid $<.
66 Provided uid $< has sufficient permissions to create the data and
67 install directories, then it should be ok to proceed. Otherwise,
68 please quit and restart as root.
71 exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
76 Is this a new installation or upgrade for BackupPC? If this is
77 an upgrade please tell me the full path of the existing BackupPC
78 configuration file (eg: /xxxx/conf/config.pl). Otherwise, just
84 # Check if this is an upgrade, in which case read the existing
85 # config file to get all the defaults.
89 $ConfigPath = prompt("--> Full path to existing conf/config.pl",
91 last if ( $ConfigPath eq ""
92 || ($ConfigPath =~ /^\// && -r $ConfigPath && -w $ConfigPath) );
93 my $problem = "is not an absolute path";
94 $problem = "is not writable" if ( !-w $ConfigPath );
95 $problem = "is not readable" if ( !-r $ConfigPath );
96 $problem = "doesn't exist" if ( !-f $ConfigPath );
97 print("The file '$ConfigPath' $problem.\n");
100 if ( $ConfigPath ne "" && -r $ConfigPath ) {
101 (my $topDir = $ConfigPath) =~ s{/[^/]+/[^/]+$}{};
102 die("BackupPC::Lib->new failed\n")
103 if ( !($bpc = BackupPC::Lib->new($topDir, ".", 1)) );
104 %Conf = $bpc->Conf();
106 $Conf{TopDir} = $topDir;
107 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1);
111 BackupPC is running on $Conf{ServerHost}. You need to stop BackupPC
112 before you can upgrade the code. Depending upon your installation,
113 you could run "/etc/init.d/backuppc stop".
121 # These are the programs whose paths we need to find
125 'gtar/tar' => "TarClientPath",
126 smbclient => "SmbClientPath",
127 nmblookup => "NmbLookupPath",
128 rsync => "RsyncClientPath",
131 'ssh/ssh2' => "SshPath",
132 sendmail => "SendmailPath",
133 hostname => "HostnamePath",
136 foreach my $prog ( sort(keys(%Programs)) ) {
138 foreach my $subProg ( split(/\//, $prog) ) {
139 $path ||= FindProgram("$ENV{PATH}:/bin:/usr/bin:/sbin:/usr/sbin",
142 $Conf{$Programs{$prog}} ||= $path;
148 I found the following locations for these programs:
151 foreach my $prog ( sort(keys(%Programs)) ) {
152 printf(" %-11s => %s\n", $prog, $Conf{$Programs{$prog}});
155 last if (prompt('--> Are these paths correct?', 'y') =~ /^y/i);
156 foreach my $prog ( sort(keys(%Programs)) ) {
157 $Conf{$Programs{$prog}} = prompt("--> $prog path",
158 $Conf{$Programs{$prog}});
162 my $Perl56 = system($Conf{PerlPath}
163 . q{ -e 'exit($^V && $^V ge v5.6.0 ? 1 : 0);'});
168 BackupPC needs perl version 5.6.0 or later. $Conf{PerlPath} appears
169 to be an older version. Please upgrade to a newer version of perl
170 and re-run this configure script.
178 Please tell me the hostname of the machine that BackupPC will run on.
181 chomp($Conf{ServerHost} = `$Conf{HostnamePath}`)
182 if ( defined($Conf{HostnamePath}) && !defined($Conf{ServerHost}) );
183 $Conf{ServerHost} = prompt("--> BackupPC will run on host", $Conf{ServerHost});
187 BackupPC should run as a dedicated user with limited privileges. You
188 need to create a user. This user will need read/write permission on
189 the main data directory and read/execute permission on the install
190 directory (these directories will be setup shortly).
192 The primary group for this user should also be chosen carefully.
193 By default the install directories will have group write permission.
194 The data directories and files will have group read permission but
198 my($name, $passwd, $Uid, $Gid);
200 $Conf{BackupPCUser} = prompt("--> BackupPC should run as user",
201 $Conf{BackupPCUser} || "backuppc");
202 ($name, $passwd, $Uid, $Gid) = getpwnam($Conf{BackupPCUser});
203 last if ( $name ne "" );
206 getpwnam() says that user $Conf{BackupPCUser} doesn't exist. Please check the
207 name and verify that this user is in the passwd file.
214 Please specify an install directory for BackupPC. This is where the
215 BackupPC scripts, library and documentation will be installed.
220 $Conf{InstallDir} = prompt("--> Install directory (full path)",
222 last if ( $Conf{InstallDir} =~ /^\// );
227 Please specify a data directory for BackupPC. This is where the
228 configuration files, LOG files and all the PC backups are stored.
229 This file system needs to be big enough to accommodate all the
230 PCs you expect to backup (eg: at least 1-2GB per machine).
235 $Conf{TopDir} = prompt("--> Data directory (full path)", $Conf{TopDir});
236 last if ( $Conf{TopDir} =~ /^\// );
239 if ( !defined($Conf{CompressLevel}) ) {
240 $Conf{CompressLevel} = BackupPC::FileZIO->compOk ? 3 : 0;
241 if ( $ConfigPath eq "" && $Conf{CompressLevel} ) {
244 BackupPC can compress pool files, providing around a 40% reduction in pool
245 size (your mileage may vary). Specify the compression level (0 turns
246 off compression, and 1 to 9 represent good/fastest to best/slowest).
247 The recommended values are 0 (off) or 3 (reasonable compression and speed).
248 Increasing the compression level to 5 will use around 20% more cpu time
249 and give perhaps 2-3% more compression.
252 } elsif ( $ConfigPath eq "" ) {
255 BackupPC can compress pool files, but it needs the Compress::Zlib
256 package installed (see www.cpan.org). Compression will provide around a
257 40% reduction in pool size, at the expense of cpu time. You can leave
258 compression off and run BackupPC without compression, in which case you
259 should leave the compression level at 0 (which means off). You could
260 install Compress::Zlib and turn compression on later, but read the
261 documentation first about how to do this. Or the better choice is
262 to quit, install Compress::Zlib, and re-run configure.pl.
265 } elsif ( $Conf{CompressLevel} ) {
266 $Conf{CompressLevel} = 0;
269 BackupPC now supports pool file compression. Since you are upgrading
270 BackupPC you probably have existing uncompressed backups. You have
271 several choices if you want to turn on compression. You can run
272 the script BackupPC_compressPool to convert everything to compressed
273 form. Or you can simply turn on compression, so that new backups
274 will be compressed. This will increase the pool storage requirement,
275 since both uncompressed and compressed copies of files will be stored.
276 But eventually the old uncompressed backups will expire, recovering
277 the pool storage. Please see the documentation for more details.
279 If you are not sure what to do, leave the Compression Level at 0,
280 which disables compression. You can always read the documentation
281 and turn it on later.
285 $Conf{CompressLevel} = 0;
288 BackupPC now supports pool file compression, but it needs the
289 Compress::Zlib module (see www.cpan.org). For now, leave
290 the compression level set at 0 to disable compression. If you
291 want you can install Compress::Zlib and turn compression on.
292 Please see the documentation for more details about converting
293 old backups to compressed form.
299 = prompt("--> Compression level", $Conf{CompressLevel});
300 last if ( $Conf{CompressLevel} =~ /^\d+$/ );
306 BackupPC has a powerful CGI perl interface that runs under Apache.
307 A single executable needs to be installed in a cgi-bin directory.
308 This executable needs to run as set-uid $Conf{BackupPCUser}, or
309 it can be run under mod_perl with Apache running as user $Conf{BackupPCUser}.
311 Leave this path empty if you don't want to install the CGI interface.
316 $Conf{CgiDir} = prompt("--> CGI bin directory (full path)", $Conf{CgiDir});
317 last if ( $Conf{CgiDir} =~ /^\// || $Conf{CgiDir} eq "" );
320 if ( $Conf{CgiDir} ne "" ) {
324 BackupPC's CGI script needs to display various GIF images that
325 should be stored where Apache can serve them. They should be
326 placed somewher under Apache's DocumentRoot. BackupPC also
327 needs to know the URL to access these images. Example:
329 Apache image directory: /usr/local/apache/htdocs/BackupPC
330 URL for image directory: /BackupPC
332 The URL for the image directory should start with a slash.
336 $Conf{CgiImageDir} = prompt("--> Apache image directory (full path)",
338 last if ( $Conf{CgiImageDir} =~ /^\// );
341 $Conf{CgiImageDirURL} = prompt("--> URL for image directory (omit http://host; starts with '/')",
342 $Conf{CgiImageDirURL});
343 last if ( $Conf{CgiImageDirURL} =~ /^\// );
351 - install the binaries, lib and docs in $Conf{InstallDir},
352 - create the data directory $Conf{TopDir},
353 - create/update the config.pl file $Conf{TopDir}/conf,
354 - optionally install the cgi-bin interface.
358 exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
361 # Create install directories
363 foreach my $dir ( qw(bin lib/BackupPC/Xfer lib/BackupPC/Zip
364 lib/BackupPC/Lang doc) ) {
365 next if ( -d "$Conf{InstallDir}/$dir" );
366 mkpath("$Conf{InstallDir}/$dir", 0, 0775);
367 if ( !-d "$Conf{InstallDir}/$dir"
368 || !chown($Uid, $Gid, "$Conf{InstallDir}/$dir") ) {
369 die("Failed to create or chown $Conf{InstallDir}/$dir\n");
371 print("Created $Conf{InstallDir}/$dir\n");
376 # Create CGI image directory
378 foreach my $dir ( ($Conf{CgiImageDir}) ) {
379 next if ( $dir eq "" || -d $dir );
380 mkpath($dir, 0, 0775);
381 if ( !-d $dir || !chown($Uid, $Gid, $dir) ) {
382 die("Failed to create or chown $dir");
384 print("Created $dir\n");
389 # Create $TopDir's top-level directories
391 foreach my $dir ( qw(. conf pool cpool pc trash log) ) {
392 mkpath("$Conf{TopDir}/$dir", 0, 0750) if ( !-d "$Conf{TopDir}/$dir" );
393 if ( !-d "$Conf{TopDir}/$dir"
394 || !chown($Uid, $Gid, "$Conf{TopDir}/$dir") ) {
395 die("Failed to create or chown $Conf{TopDir}/$dir\n");
397 print("Created $Conf{TopDir}/$dir\n");
401 printf("Installing binaries in $Conf{InstallDir}/bin\n");
402 foreach my $prog ( qw(BackupPC BackupPC_dump BackupPC_link BackupPC_nightly
403 BackupPC_sendEmail BackupPC_tarCreate BackupPC_trashClean
404 BackupPC_tarExtract BackupPC_compressPool BackupPC_zcat
405 BackupPC_restore BackupPC_serverMesg BackupPC_zipCreate ) ) {
406 InstallFile("bin/$prog", "$Conf{InstallDir}/bin/$prog", 0555);
410 # Remove unused binaries from older versions
412 unlink("$Conf{InstallDir}/bin/BackupPC_queueAll");
414 printf("Installing library in $Conf{InstallDir}/lib\n");
415 foreach my $lib ( qw(BackupPC/Lib.pm BackupPC/FileZIO.pm BackupPC/Attrib.pm
416 BackupPC/PoolWrite.pm BackupPC/View.pm BackupPC/Xfer/Tar.pm
417 BackupPC/Xfer/Smb.pm BackupPC/Xfer/Rsync.pm
418 BackupPC/Xfer/RsyncFileIO.pm BackupPC/Zip/FileMember.pm
419 BackupPC/Lang/en.pm BackupPC/Lang/fr.pm BackupPC/Lang/es.pm
422 InstallFile("lib/$lib", "$Conf{InstallDir}/lib/$lib", 0444);
425 if ( $Conf{CgiImageDir} ne "" ) {
426 printf("Installing images in $Conf{CgiImageDir}\n");
427 foreach my $img ( <images/*> ) {
428 (my $destImg = $img) =~ s{^images/}{};
429 InstallFile($img, "$Conf{CgiImageDir}/$destImg", 0444, 1);
433 printf("Making init.d scripts\n");
434 foreach my $init ( qw(gentoo-backuppc gentoo-backuppc.conf linux-backuppc
435 solaris-backuppc debian-backuppc suse-backuppc) ) {
436 InstallFile("init.d/src/$init", "init.d/$init", 0444);
439 printf("Installing docs in $Conf{InstallDir}/doc\n");
440 foreach my $doc ( qw(BackupPC.pod BackupPC.html) ) {
441 InstallFile("doc/$doc", "$Conf{InstallDir}/doc/$doc", 0444);
444 printf("Installing config.pl and hosts in $Conf{TopDir}/conf\n");
445 InstallFile("conf/hosts", "$Conf{TopDir}/conf/hosts", 0644)
446 if ( !-f "$Conf{TopDir}/conf/hosts" );
449 # Now do the config file. If there is an existing config file we
450 # merge in the new config file, adding any new configuration
451 # parameters and deleting ones that are no longer needed.
453 my $dest = "$Conf{TopDir}/conf/config.pl";
454 my ($newConf, $newVars) = ConfigParse("conf/config.pl");
455 my ($oldConf, $oldVars);
457 ($oldConf, $oldVars) = ConfigParse($dest);
458 $newConf = ConfigMerge($oldConf, $oldVars, $newConf, $newVars);
460 $Conf{EMailFromUserName} ||= $Conf{BackupPCUser};
461 $Conf{EMailAdminUserName} ||= $Conf{BackupPCUser};
464 # Update various config parameters
468 # Guess $Conf{CgiURL}
470 if ( !defined($Conf{CgiURL}) ) {
471 if ( $Conf{CgiDir} =~ m{cgi-bin(/.*)} ) {
472 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin$1/BackupPC_Admin'";
474 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin/BackupPC_Admin'";
479 # The smbclient commands have moved from hard-coded to the config file.
480 # $Conf{SmbClientArgs} no longer exists, so merge it into the new
481 # commands if it still exists.
483 if ( defined($Conf{SmbClientArgs}) ) {
484 if ( $Conf{SmbClientArgs} ne "" ) {
485 foreach my $param ( qw(SmbClientRestoreCmd SmbClientFullCmd
486 SmbClientIncrCmd) ) {
487 $newConf->[$newVars->{$param}]{text}
488 =~ s/(-E\s+-N)/$1 $Conf{SmbClientArgs}/;
491 delete($Conf{SmbClientArgs});
495 # IncrFill should now be off
500 # Figure out sensible arguments for the ping command
502 if ( defined($Conf{PingArgs}) ) {
503 $Conf{PingCmd} = '$pingPath ' . $Conf{PingArgs};
504 } elsif ( !defined($Conf{PingCmd}) ) {
505 if ( $^O eq "solaris" || $^O eq "sunos" ) {
506 $Conf{PingCmd} = '$pingPath -s $host 56 1';
507 } elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
508 && !system("$Conf{PingClientPath} -c 1 -w 3 localhost") ) {
509 $Conf{PingCmd} = '$pingPath -c 1 -w 3 $host';
511 $Conf{PingCmd} = '$pingPath -c 1 $host';
513 delete($Conf{PingArgs});
517 # Figure out sensible arguments for the df command
519 if ( !defined($Conf{DfCmd}) ) {
520 if ( $^O eq "solaris" || $^O eq "sunos" ) {
521 $Conf{DfCmd} = '$dfPath -k $topDir';
526 # $Conf{SmbClientTimeout} is now $Conf{ClientTimeout}
528 if ( defined($Conf{SmbClientTimeout}) ) {
529 $Conf{ClientTimeout} = $Conf{SmbClientTimeout};
530 delete($Conf{SmbClientTimeout});
533 my $confCopy = "$dest.pre-__VERSION__";
534 if ( -f $dest && !-f $confCopy ) {
536 # Make copy of config file, preserving ownership and modes
538 printf("Making backup copy of $dest -> $confCopy\n");
539 my @stat = stat($dest);
543 die("can't copy($dest, $confCopy)\n") unless copy($dest, $confCopy);
544 die("can't chown $uid, $gid $confCopy\n")
545 unless chown($uid, $gid, $confCopy);
546 die("can't chmod $mode $confCopy\n") unless chmod($mode, $confCopy);
548 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
551 foreach my $var ( @$newConf ) {
552 if ( length($blockComment)
553 && substr($var->{text}, 0, length($blockComment)) eq $blockComment ) {
554 $var->{text} = substr($var->{text}, length($blockComment));
555 $blockComment = undef;
557 $blockComment = $1 if ( $var->{text} =~ /^([\s\n]*#{70}.*#{70}[\s\n]+)/s );
558 $var->{text} =~ s/^\s*\$Conf\{(.*?)\}(\s*=\s*['"]?)(.*?)(['"]?\s*;)/
559 defined($Conf{$1}) && ref($Conf{$1}) eq ""
560 && $Conf{$1} ne $OrigConf{$1}
561 ? "\$Conf{$1}$2$Conf{$1}$4"
562 : "\$Conf{$1}$2$3$4"/emg;
563 print OUT $var->{text};
566 if ( !defined($oldConf) ) {
567 die("can't chmod 0640 mode $dest\n") unless chmod(0640, $dest);
568 die("can't chown $Uid, $Gid $dest\n") unless chown($Uid, $Gid, $dest);
571 if ( $Conf{CgiDir} ne "" ) {
572 printf("Installing cgi script BackupPC_Admin in $Conf{CgiDir}\n");
573 mkpath("$Conf{CgiDir}", 0, 0755);
574 InstallFile("cgi-bin/BackupPC_Admin", "$Conf{CgiDir}/BackupPC_Admin",
580 Ok, it looks like we are finished. There are several more things you
583 - Browse through the config file, $Conf{TopDir}/conf/config.pl,
584 and make sure all the settings are correct. In particular, you
585 will need to set the smb share password and user name, backup
586 policies and check the email message headers and bodies.
588 - Edit the list of hosts to backup in $Conf{TopDir}/conf/hosts.
590 - Read the documentation in $Conf{InstallDir}/doc/BackupPC.html.
591 Please pay special attention to the security section.
593 - Verify that the CGI script BackupPC_Admin runs correctly. You might
594 need to change the permissions or group ownership of BackupPC_Admin.
596 - BackupPC should be ready to start. Don't forget to run it
597 as user $Conf{BackupPCUser}! The installation also contains an
598 init.d/backuppc script that can be copied to /etc/init.d
599 so that BackupPC can auto-start on boot. See init.d/README.
604 if ( $ENV{LANG} =~ /utf/i && $^V ge v5.8.0 ) {
607 WARNING: Your LANG environment variable is set to $ENV{LANG}, which
608 doesn't behave well with this version of perl. Please set the
609 LANG environment variable to en_US before running BackupPC.
611 On RH-8 this setting is in the file /etc/sysconfig/i18n, or you
612 could set it in BackupPC's init.d script.
618 ###########################################################################
620 ###########################################################################
624 my($prog, $dest, $mode, $binary) = @_;
626 my($uid, $gid) = ($Uid, $Gid);
630 # preserve ownership and modes of files that already exist
632 my @stat = stat($dest);
637 unlink($dest) if ( -f $dest );
639 die("can't copy($prog, $dest)\n") unless copy($prog, $dest);
641 open(PROG, $prog) || die("can't open $prog for reading\n");
642 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
646 s/__INSTALLDIR__/$Conf{InstallDir}/g;
647 s/__TOPDIR__/$Conf{TopDir}/g;
648 s/__BACKUPPCUSER__/$Conf{BackupPCUser}/g;
649 s/__CGIDIR__/$Conf{CgiDir}/g;
650 if ( $first && /^#.*bin\/perl/ ) {
653 # perl56 and later is taint ok
655 print OUT "#!$Conf{PerlPath} -T\n";
658 # prior to perl56, File::Find fails taint checks,
659 # so we run without -T. It's still safe.
661 print OUT "#!$Conf{PerlPath}\n";
671 die("can't chown $uid, $gid $dest") unless chown($uid, $gid, $dest);
672 die("can't chmod $mode $dest") unless chmod($mode, $dest);
677 my($path, $prog) = @_;
678 foreach my $dir ( split(/:/, $path) ) {
679 my $file = File::Spec->catfile($dir, $prog);
680 return $file if ( -x $file );
687 open(C, $file) || die("can't open $file");
689 my($out, @conf, $var);
698 $allVars->{$var} = @conf if ( defined($var) );
708 } elsif ( /^\s*\$Conf\{([^}]*)/ ) {
710 if ( defined($var) ) {
711 $allVars->{$var} = @conf if ( defined($var) );
726 $allVars->{$var} = @conf if ( defined($var) );
733 return (\@conf, $allVars);
738 my($old, $oldVars, $new, $newVars) = @_;
743 # Find which config parameters are not needed any longer
745 foreach my $var ( @$old ) {
746 next if ( !defined($var->{var}) || defined($newVars->{$var->{var}}) );
747 #print(STDERR "Deleting old config parameter $var->{var}\n");
751 # Find which config parameters are new
753 foreach my $var ( @$new ) {
754 next if ( !defined($var->{var}) );
755 if ( defined($oldVars->{$var->{var}}) ) {
756 $posn = $oldVars->{$var->{var}};
758 #print(STDERR "New config parameter $var->{var}: $var->{text}\n");
759 push(@{$old->[$posn]{new}}, $var);
763 # Create merged config file
765 foreach my $var ( @$old ) {
766 next if ( $var->{delete} );
768 foreach my $new ( @{$var->{new}} ) {