2 #============================================================= -*-perl-*-
4 # configure.pl: Configuration and installation program for BackupPC
8 # This script should be run as root:
12 # To read about the command-line options for this configure script:
14 # perldoc configure.pl
16 # The installation steps are described as the script runs.
19 # Craig Barratt <cbarratt@users.sourceforge.net>
22 # Copyright (C) 2001-2006 Craig Barratt
24 # This program is free software; you can redistribute it and/or modify
25 # it under the terms of the GNU General Public License as published by
26 # the Free Software Foundation; either version 2 of the License, or
27 # (at your option) any later version.
29 # This program is distributed in the hope that it will be useful,
30 # but WITHOUT ANY WARRANTY; without even the implied warranty of
31 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 # GNU General Public License for more details.
34 # You should have received a copy of the GNU General Public License
35 # along with this program; if not, write to the Free Software
36 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #========================================================================
40 # Version 2.1.0beta1, released 9 Apr 2004.
42 # See http://backuppc.sourceforge.net.
44 #========================================================================
48 use vars qw(%Conf %OrigConf);
51 my @Packages = qw(File::Path File::Spec File::Copy DirHandle Digest::MD5
52 Data::Dumper Getopt::Std Getopt::Long Pod::Usage
53 BackupPC::Lib BackupPC::FileZIO);
55 foreach my $pkg ( @Packages ) {
58 if ( $pkg =~ /BackupPC/ ) {
61 BackupPC cannot find the package $pkg, which is included in the
62 BackupPC distribution. This probably means you did not cd to the
63 unpacked BackupPC distribution before running configure.pl, eg:
65 cd BackupPC-__VERSION__
74 BackupPC needs the package $pkg. Please install $pkg
75 before installing BackupPC.
81 $opts{"set-perms"} = 1;
104 pod2usage(1) if ( $opts{help} );
105 pod2usage(-exitstatus => 0, -verbose => 2) if $opts{man};
107 my $DestDir = $opts{"dest-dir"};
109 if ( !$opts{"uid-ignore"} && $< != 0 ) {
112 This configure script should be run as root, rather than uid $<.
113 Provided uid $< has sufficient permissions to create the data and
114 install directories, then it should be ok to proceed. Otherwise,
115 please quit and restart as root.
118 exit(1) if ( prompt("--> Do you want to continue?",
120 exit(1) if ( $opts{batch} && !$opts{"uid-ignore"} );
124 # Whether we use the file system hierarchy conventions or not.
125 # Older versions did not. BackupPC used to be installed in
126 # two main directories (in addition to CGI and html pages)
128 # TopDir which includes subdirs conf, log, pc, pool, cpool
130 # InstallDir which includes subdirs bin, lib, doc
132 # With FHS enabled (which is the default for new installations):
134 # /etc/BackupPC/config.pl main config file (was $TopDir/conf/config.pl)
135 # /etc/BackupPC/hosts hosts file (was $TopDir/conf/hosts)
136 # /etc/BackupPC/pc/HOST.pl per-pc config file (was $TopDir/pc/HOST/config.pl)
137 # /var/log/BackupPC log files (was $TopDir/log)
138 # /var/lib/BackupPC Pid, status and email info (was $TopDir/log)
141 print <<EOF if ( !$opts{fhs} || !-f "/etc/BackupPC/config.pl" );
143 Is this a new installation or upgrade for BackupPC? If this is
144 an upgrade please tell me the full path of the existing BackupPC
145 configuration file (eg: /etc/BackupPC/config.pl). Otherwise, just
151 # Check if this is an upgrade, in which case read the existing
152 # config file to get all the defaults.
156 if ( -f "/etc/BackupPC/config.pl" ) {
157 $ConfigPath = "/etc/BackupPC/config.pl";
158 $opts{fhs} = 1 if ( !defined($opts{fhs}) );
160 $ConfigPath = prompt("--> Full path to existing main config.pl",
164 last if ( $ConfigPath eq ""
165 || ($ConfigPath =~ /^\// && -f $ConfigPath && -w $ConfigPath) );
166 my $problem = "is not an absolute path";
167 $problem = "is not writable" if ( !-w $ConfigPath );
168 $problem = "is not readable" if ( !-r $ConfigPath );
169 $problem = "is not a regular file" if ( !-f $ConfigPath );
170 $problem = "doesn't exist" if ( !-e $ConfigPath );
171 print("The file '$ConfigPath' $problem.\n");
172 if ( $opts{batch} ) {
173 print("Need to specify a valid --config-path for upgrade\n");
177 $opts{fhs} = 1 if ( !defined($opts{fhs}) && $ConfigPath eq "" );
178 $opts{fhs} = 0 if ( !defined($opts{fhs}) );
181 if ( $ConfigPath ne "" && -r $ConfigPath ) {
182 (my $confDir = $ConfigPath) =~ s{/[^/]+$}{};
183 die("BackupPC::Lib->new failed\n")
184 if ( !($bpc = BackupPC::Lib->new(".", ".", $confDir, 1)) );
185 %Conf = $bpc->Conf();
188 ($Conf{TopDir} = $ConfigPath) =~ s{/[^/]+/[^/]+$}{};
190 $Conf{ConfDir} = $confDir;
191 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1);
195 BackupPC is running on $Conf{ServerHost}. You need to stop BackupPC
196 before you can upgrade the code. Depending upon your installation,
197 you could run "/etc/init.d/backuppc stop".
205 # Create defaults for FHS setup
208 $Conf{TopDir} ||= "/data/BackupPC";
209 $Conf{ConfDir} ||= "/etc/BackupPC";
210 $Conf{InstallDir} ||= "/usr/local/BackupPC";
211 $Conf{LogDir} ||= "/var/log/BackupPC";
215 # These are the programs whose paths we need to find
219 'gtar/tar' => "TarClientPath",
220 smbclient => "SmbClientPath",
221 nmblookup => "NmbLookupPath",
222 rsync => "RsyncClientPath",
225 'ssh/ssh2' => "SshPath",
226 sendmail => "SendmailPath",
227 hostname => "HostnamePath",
228 split => "SplitPath",
232 bzip2 => "Bzip2Path",
235 foreach my $prog ( sort(keys(%Programs)) ) {
237 foreach my $subProg ( split(/\//, $prog) ) {
238 $path = FindProgram("$ENV{PATH}:/bin:/usr/bin:/sbin:/usr/sbin",
239 $subProg) if ( !length($path) );
241 $Conf{$Programs{$prog}} = $path if ( !length($Conf{$Programs{$prog}}) );
247 I found the following locations for these programs:
250 foreach my $prog ( sort(keys(%Programs)) ) {
251 printf(" %-12s => %s\n", $prog, $Conf{$Programs{$prog}});
254 last if (prompt('--> Are these paths correct?', 'y') =~ /^y/i);
255 foreach my $prog ( sort(keys(%Programs)) ) {
256 $Conf{$Programs{$prog}} = prompt("--> $prog path",
257 $Conf{$Programs{$prog}});
261 my $Perl56 = system($Conf{PerlPath}
262 . q{ -e 'exit($^V && $^V ge v5.6.0 ? 1 : 0);'});
267 BackupPC needs perl version 5.6.0 or later. $Conf{PerlPath} appears
268 to be an older version. Please upgrade to a newer version of perl
269 and re-run this configure script.
277 Please tell me the hostname of the machine that BackupPC will run on.
280 chomp($Conf{ServerHost} = `$Conf{HostnamePath}`)
281 if ( defined($Conf{HostnamePath}) && !defined($Conf{ServerHost}) );
282 $Conf{ServerHost} = prompt("--> BackupPC will run on host",
288 BackupPC should run as a dedicated user with limited privileges. You
289 need to create a user. This user will need read/write permission on
290 the main data directory and read/execute permission on the install
291 directory (these directories will be setup shortly).
293 The primary group for this user should also be chosen carefully.
294 By default the install directories will have group write permission.
295 The data directories and files will have group read permission but
299 my($name, $passwd, $Uid, $Gid);
301 $Conf{BackupPCUser} = prompt("--> BackupPC should run as user",
302 $Conf{BackupPCUser} || "backuppc",
304 if ( $opts{"set-perms"} ) {
305 ($name, $passwd, $Uid, $Gid) = getpwnam($Conf{BackupPCUser});
306 last if ( $name ne "" );
309 getpwnam() says that user $Conf{BackupPCUser} doesn't exist. Please
310 check the name and verify that this user is in the passwd file.
313 exit(1) if ( $opts{batch} );
319 Please specify an install directory for BackupPC. This is where the
320 BackupPC scripts, library and documentation will be installed.
325 $Conf{InstallDir} = prompt("--> Install directory (full path)",
328 last if ( $Conf{InstallDir} =~ /^\// );
329 if ( $opts{batch} ) {
330 print("Need to specify --install-dir for new installation\n");
337 Please specify a data directory for BackupPC. This is where the
338 all the PC backup data is stored. This file system needs to be
339 big enough to accommodate all the PCs you expect to backup (eg:
340 at least several GB per machine).
345 $Conf{TopDir} = prompt("--> Data directory (full path)",
348 last if ( $Conf{TopDir} =~ /^\// );
349 if ( $opts{batch} ) {
350 print("Need to specify --data-dir for new installation\n");
355 $Conf{CompressLevel} = $opts{"compress-level"}
356 if ( defined($opts{"compress-level"}) );
358 if ( !defined($Conf{CompressLevel}) ) {
359 $Conf{CompressLevel} = BackupPC::FileZIO->compOk ? 3 : 0;
360 if ( $ConfigPath eq "" && $Conf{CompressLevel} ) {
363 BackupPC can compress pool files, providing around a 40% reduction in pool
364 size (your mileage may vary). Specify the compression level (0 turns
365 off compression, and 1 to 9 represent good/fastest to best/slowest).
366 The recommended values are 0 (off) or 3 (reasonable compression and speed).
367 Increasing the compression level to 5 will use around 20% more cpu time
368 and give perhaps 2-3% more compression.
371 } elsif ( $ConfigPath eq "" ) {
374 BackupPC can compress pool files, but it needs the Compress::Zlib
375 package installed (see www.cpan.org). Compression will provide around a
376 40% reduction in pool size, at the expense of cpu time. You can leave
377 compression off and run BackupPC without compression, in which case you
378 should leave the compression level at 0 (which means off). You could
379 install Compress::Zlib and turn compression on later, but read the
380 documentation first about how to do this. Or the better choice is
381 to quit, install Compress::Zlib, and re-run configure.pl.
384 } elsif ( $Conf{CompressLevel} ) {
385 $Conf{CompressLevel} = 0;
388 BackupPC now supports pool file compression. Since you are upgrading
389 BackupPC you probably have existing uncompressed backups. You have
390 several choices if you want to turn on compression. You can run
391 the script BackupPC_compressPool to convert everything to compressed
392 form. Or you can simply turn on compression, so that new backups
393 will be compressed. This will increase the pool storage requirement,
394 since both uncompressed and compressed copies of files will be stored.
395 But eventually the old uncompressed backups will expire, recovering
396 the pool storage. Please see the documentation for more details.
398 If you are not sure what to do, leave the Compression Level at 0,
399 which disables compression. You can always read the documentation
400 and turn it on later.
404 $Conf{CompressLevel} = 0;
407 BackupPC now supports pool file compression, but it needs the
408 Compress::Zlib module (see www.cpan.org). For now, leave
409 the compression level set at 0 to disable compression. If you
410 want you can install Compress::Zlib and turn compression on.
411 Please see the documentation for more details about converting
412 old backups to compressed form.
418 = prompt("--> Compression level", $Conf{CompressLevel});
419 last if ( $Conf{CompressLevel} =~ /^\d+$/ );
425 BackupPC has a powerful CGI perl interface that runs under Apache.
426 A single executable needs to be installed in a cgi-bin directory.
427 This executable needs to run as set-uid $Conf{BackupPCUser}, or
428 it can be run under mod_perl with Apache running as user $Conf{BackupPCUser}.
430 Leave this path empty if you don't want to install the CGI interface.
435 $Conf{CgiDir} = prompt("--> CGI bin directory (full path)",
438 last if ( $Conf{CgiDir} =~ /^\// || $Conf{CgiDir} eq "" );
439 if ( $opts{batch} ) {
440 print("Need to specify --cgi-dir for new installation\n");
445 if ( $Conf{CgiDir} ne "" ) {
449 BackupPC's CGI script needs to display various GIF images that
450 should be stored where Apache can serve them. They should be
451 placed somewher under Apache's DocumentRoot. BackupPC also
452 needs to know the URL to access these images. Example:
454 Apache image directory: /usr/local/apache/htdocs/BackupPC
455 URL for image directory: /BackupPC
457 The URL for the image directory should start with a slash.
461 $Conf{CgiImageDir} = prompt("--> Apache image directory (full path)",
464 last if ( $Conf{CgiImageDir} =~ /^\// );
465 if ( $opts{batch} ) {
466 print("Need to specify --html-dir for new installation\n");
471 $Conf{CgiImageDirURL} = prompt("--> URL for image directory (omit http://host; starts with '/')",
472 $Conf{CgiImageDirURL},
474 last if ( $Conf{CgiImageDirURL} =~ /^\// );
475 if ( $opts{batch} ) {
476 print("Need to specify --html-dir-url for new installation\n");
486 - install the binaries, lib and docs in $Conf{InstallDir},
487 - create the data directory $Conf{TopDir},
488 - create/update the config.pl file $Conf{ConfDir}/config.pl,
489 - optionally install the cgi-bin interface.
493 exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
496 # Create install directories
498 foreach my $dir ( qw(bin doc
506 next if ( -d "$DestDir$Conf{InstallDir}/$dir" );
507 mkpath("$DestDir$Conf{InstallDir}/$dir", 0, 0775);
508 if ( !-d "$DestDir$Conf{InstallDir}/$dir"
509 || !my_chown($Uid, $Gid, "$DestDir$Conf{InstallDir}/$dir") ) {
510 die("Failed to create or chown $DestDir$Conf{InstallDir}/$dir\n");
512 print("Created $DestDir$Conf{InstallDir}/$dir\n");
517 # Create CGI image directory
519 foreach my $dir ( ($Conf{CgiImageDir}) ) {
520 next if ( $dir eq "" || -d $dir );
521 mkpath("$DestDir$dir", 0, 0775);
522 if ( !-d "$DestDir$dir" || !my_chown($Uid, $Gid, "$DestDir$dir") ) {
523 die("Failed to create or chown $DestDir$dir");
525 print("Created $DestDir$dir\n");
530 # Create other directories
534 "$Conf{TopDir}/pool",
535 "$Conf{TopDir}/cpool",
537 "$Conf{TopDir}/trash",
541 mkpath("$DestDir/$dir", 0, 0750) if ( !-d "$DestDir/$dir" );
542 if ( !-d "$DestDir/$dir"
543 || !my_chown($Uid, $Gid, "$DestDir/$dir") ) {
544 die("Failed to create or chown $DestDir/$dir\n");
546 print("Created $DestDir/$dir\n");
550 printf("Installing binaries in $DestDir$Conf{InstallDir}/bin\n");
551 foreach my $prog ( qw(BackupPC BackupPC_dump BackupPC_link BackupPC_nightly
552 BackupPC_sendEmail BackupPC_tarCreate BackupPC_trashClean
553 BackupPC_tarExtract BackupPC_compressPool BackupPC_zcat
554 BackupPC_archive BackupPC_archiveHost
555 BackupPC_restore BackupPC_serverMesg BackupPC_zipCreate ) ) {
556 InstallFile("bin/$prog", "$DestDir$Conf{InstallDir}/bin/$prog", 0555);
559 printf("Installing library in $DestDir$Conf{InstallDir}/lib\n");
560 foreach my $lib ( qw(
563 BackupPC/PoolWrite.pm
567 BackupPC/CGI/AdminOptions.pm
568 BackupPC/CGI/Archive.pm
569 BackupPC/CGI/ArchiveInfo.pm
570 BackupPC/CGI/Browse.pm
571 BackupPC/CGI/DirHistory.pm
572 BackupPC/CGI/EmailSummary.pm
573 BackupPC/CGI/GeneralInfo.pm
574 BackupPC/CGI/HostInfo.pm
576 BackupPC/CGI/LOGlist.pm
577 BackupPC/CGI/Queue.pm
578 BackupPC/CGI/ReloadServer.pm
579 BackupPC/CGI/RestoreFile.pm
580 BackupPC/CGI/RestoreInfo.pm
581 BackupPC/CGI/Restore.pm
582 BackupPC/CGI/StartServer.pm
583 BackupPC/CGI/StartStopBackup.pm
584 BackupPC/CGI/StopServer.pm
585 BackupPC/CGI/Summary.pm
587 BackupPC/Config/Meta.pm
594 BackupPC/Storage/Text.pm
595 BackupPC/Xfer/Archive.pm
596 BackupPC/Xfer/BackupPCd.pm
599 BackupPC/Xfer/Rsync.pm
600 BackupPC/Xfer/RsyncDigest.pm
601 BackupPC/Xfer/RsyncFileIO.pm
602 BackupPC/Zip/FileMember.pm
604 InstallFile("lib/$lib", "$DestDir$Conf{InstallDir}/lib/$lib", 0444);
607 if ( $Conf{CgiImageDir} ne "" ) {
608 printf("Installing images in $DestDir$Conf{CgiImageDir}\n");
609 foreach my $img ( <images/*> ) {
610 (my $destImg = $img) =~ s{^images/}{};
611 InstallFile($img, "$DestDir$Conf{CgiImageDir}/$destImg", 0444, 1);
615 # Install new CSS file, making a backup copy if necessary
617 my $cssBackup = "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css.pre-__VERSION__";
618 if ( -f "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css" && !-f $cssBackup ) {
619 rename("$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", $cssBackup);
621 InstallFile("conf/BackupPC_stnd.css",
622 "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", 0444, 0);
625 printf("Making init.d scripts\n");
626 foreach my $init ( qw(gentoo-backuppc gentoo-backuppc.conf linux-backuppc
627 solaris-backuppc debian-backuppc suse-backuppc
628 slackware-backuppc ) ) {
629 InstallFile("init.d/src/$init", "init.d/$init", 0444);
632 printf("Installing docs in $DestDir$Conf{InstallDir}/doc\n");
633 foreach my $doc ( qw(BackupPC.pod BackupPC.html) ) {
634 InstallFile("doc/$doc", "$DestDir$Conf{InstallDir}/doc/$doc", 0444);
637 printf("Installing config.pl and hosts in $DestDir$Conf{ConfDir}\n");
638 InstallFile("conf/hosts", "$DestDir$Conf{ConfDir}/hosts", 0644)
639 if ( !-f "$DestDir$Conf{ConfDir}/hosts" );
642 # Now do the config file. If there is an existing config file we
643 # merge in the new config file, adding any new configuration
644 # parameters and deleting ones that are no longer needed.
646 my $dest = "$DestDir$Conf{ConfDir}/config.pl";
647 my ($newConf, $newVars) = ConfigParse("conf/config.pl");
648 my ($oldConf, $oldVars);
650 ($oldConf, $oldVars) = ConfigParse($dest);
651 $newConf = ConfigMerge($oldConf, $oldVars, $newConf, $newVars);
653 $Conf{EMailFromUserName} ||= $Conf{BackupPCUser};
654 $Conf{EMailAdminUserName} ||= $Conf{BackupPCUser};
657 # Update various config parameters
661 # Guess $Conf{CgiURL}
663 if ( !defined($Conf{CgiURL}) ) {
664 if ( $Conf{CgiDir} =~ m{cgi-bin(/.*)} ) {
665 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin$1/BackupPC_Admin'";
667 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin/BackupPC_Admin'";
672 # The smbclient commands have moved from hard-coded to the config file.
673 # $Conf{SmbClientArgs} no longer exists, so merge it into the new
674 # commands if it still exists.
676 if ( defined($Conf{SmbClientArgs}) ) {
677 if ( $Conf{SmbClientArgs} ne "" ) {
678 foreach my $param ( qw(SmbClientRestoreCmd SmbClientFullCmd
679 SmbClientIncrCmd) ) {
680 $newConf->[$newVars->{$param}]{text}
681 =~ s/(-E\s+-N)/$1 $Conf{SmbClientArgs}/;
684 delete($Conf{SmbClientArgs});
688 # CSS is now stored in a file rather than a big config variable.
690 delete($Conf{CSSstylesheet});
693 # The blackout timing settings are now stored in a list of hashes, rather
694 # than three scalar parameters.
696 if ( defined($Conf{BlackoutHourBegin}) ) {
697 $Conf{BlackoutPeriods} = [
699 hourBegin => $Conf{BlackoutHourBegin},
700 hourEnd => $Conf{BlackoutHourEnd},
701 weekDays => $Conf{BlackoutWeekDays},
704 delete($Conf{BlackoutHourBegin});
705 delete($Conf{BlackoutHourEnd});
706 delete($Conf{BlackoutWeekDays});
710 # $Conf{RsyncLogLevel} has been replaced by $Conf{XferLogLevel}
712 if ( defined($Conf{RsyncLogLevel}) ) {
713 $Conf{XferLogLevel} = $Conf{RsyncLogLevel};
714 delete($Conf{RsyncLogLevel});
718 # In 2.1.0 the default for $Conf{CgiNavBarAdminAllHosts} is now 1
720 $Conf{CgiNavBarAdminAllHosts} = 1;
723 # IncrFill should now be off
728 # Figure out sensible arguments for the ping command
730 if ( defined($Conf{PingArgs}) ) {
731 $Conf{PingCmd} = '$pingPath ' . $Conf{PingArgs};
732 } elsif ( !defined($Conf{PingCmd}) ) {
733 if ( $^O eq "solaris" || $^O eq "sunos" ) {
734 $Conf{PingCmd} = '$pingPath -s $host 56 1';
735 } elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
736 && !system("$Conf{PingPath} -c 1 -w 3 localhost") ) {
737 $Conf{PingCmd} = '$pingPath -c 1 -w 3 $host';
739 $Conf{PingCmd} = '$pingPath -c 1 $host';
741 delete($Conf{PingArgs});
745 # Figure out sensible arguments for the df command
747 if ( !defined($Conf{DfCmd}) ) {
748 if ( $^O eq "solaris" || $^O eq "sunos" ) {
749 $Conf{DfCmd} = '$dfPath -k $topDir';
754 # $Conf{SmbClientTimeout} is now $Conf{ClientTimeout}
756 if ( defined($Conf{SmbClientTimeout}) ) {
757 $Conf{ClientTimeout} = $Conf{SmbClientTimeout};
758 delete($Conf{SmbClientTimeout});
761 my $confCopy = "$dest.pre-__VERSION__";
762 if ( -f $dest && !-f $confCopy ) {
764 # Make copy of config file, preserving ownership and modes
766 printf("Making backup copy of $dest -> $confCopy\n");
767 my @stat = stat($dest);
771 die("can't copy($dest, $confCopy)\n")
772 unless copy($dest, $confCopy);
773 die("can't chown $uid, $gid $confCopy\n")
774 unless my_chown($uid, $gid, $confCopy);
775 die("can't chmod $mode $confCopy\n")
776 unless my_chmod($mode, $confCopy);
778 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
781 foreach my $var ( @$newConf ) {
782 if ( length($blockComment)
783 && substr($var->{text}, 0, length($blockComment)) eq $blockComment ) {
784 $var->{text} = substr($var->{text}, length($blockComment));
785 $blockComment = undef;
787 $blockComment = $1 if ( $var->{text} =~ /^([\s\n]*#{70}.*#{70}[\s\n]+)/s );
788 $var->{text} =~ s/^\s*\$Conf\{(.*?)\}(\s*=\s*['"]?)(.*?)(['"]?\s*;)/
789 defined($Conf{$1}) && ref($Conf{$1}) eq ""
790 && $Conf{$1} ne $OrigConf{$1}
791 ? "\$Conf{$1}$2$Conf{$1}$4"
792 : "\$Conf{$1}$2$3$4"/emg;
793 print OUT $var->{text};
796 if ( !defined($oldConf) ) {
797 die("can't chmod 0640 mode $dest\n") unless my_chmod(0640, $dest);
798 die("can't chown $Uid, $Gid $dest\n") unless my_chown($Uid, $Gid, $dest);
801 if ( $Conf{CgiDir} ne "" ) {
802 printf("Installing cgi script BackupPC_Admin in $DestDir$Conf{CgiDir}\n");
803 mkpath("$DestDir$Conf{CgiDir}", 0, 0755);
804 InstallFile("cgi-bin/BackupPC_Admin", "$DestDir$Conf{CgiDir}/BackupPC_Admin",
810 Ok, it looks like we are finished. There are several more things you
813 - Browse through the config file, $Conf{ConfDir}/config.pl,
814 and make sure all the settings are correct. In particular, you
815 will need to set the smb share password and user name, backup
816 policies and check the email message headers and bodies.
818 - Edit the list of hosts to backup in $Conf{ConfDir}/hosts.
820 - Read the documentation in $Conf{InstallDir}/doc/BackupPC.html.
821 Please pay special attention to the security section.
823 - Verify that the CGI script BackupPC_Admin runs correctly. You might
824 need to change the permissions or group ownership of BackupPC_Admin.
826 - BackupPC should be ready to start. Don't forget to run it
827 as user $Conf{BackupPCUser}! The installation also contains an
828 init.d/backuppc script that can be copied to /etc/init.d
829 so that BackupPC can auto-start on boot. This will also enable
830 administrative users to start the server from the CGI interface.
836 if ( `$Conf{PerlPath} -V` =~ /uselargefiles=undef/ ) {
839 Warning: your perl, $Conf{PerlPath}, does not support large files.
840 This means BackupPC won't be able to backup files larger than 2GB.
841 To solve this problem you should build/install a new version of perl
842 with large file support enabled. Use
844 $Conf{PerlPath} -V | egrep uselargefiles
846 to check if perl has large file support (undef means no support).
850 eval "use File::RsyncP;";
851 if ( !$@ && $File::RsyncP::VERSION < 0.52 ) {
852 print("\nWarning: you need to upgrade File::RsyncP;"
853 . " I found $File::RsyncP::VERSION and BackupPC needs 0.52\n");
858 ###########################################################################
860 ###########################################################################
864 my($prog, $dest, $mode, $binary) = @_;
866 my($uid, $gid) = ($Uid, $Gid);
870 # preserve ownership and modes of files that already exist
872 my @stat = stat($dest);
877 unlink($dest) if ( -f $dest );
879 die("can't copy($prog, $dest)\n") unless copy($prog, $dest);
881 open(PROG, $prog) || die("can't open $prog for reading\n");
882 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
886 s/__INSTALLDIR__/$Conf{InstallDir}/g;
887 s/__LOGDIR__/$Conf{LogDir}/g;
888 s/__CONFDIR__/$Conf{ConfDir}/g;
889 s/__TOPDIR__/$Conf{TopDir}/g;
890 s/__USEFHS__/$opts{fhs}/g;
891 s/__BACKUPPCUSER__/$Conf{BackupPCUser}/g;
892 s/__CGIDIR__/$Conf{CgiDir}/g;
893 if ( $first && /^#.*bin\/perl/ ) {
895 # Fill in correct path to perl (no taint for >= 2.0.1).
897 print OUT "#!$Conf{PerlPath}\n";
906 die("can't chown $uid, $gid $dest") unless my_chown($uid, $gid, $dest);
907 die("can't chmod $mode $dest") unless my_chmod($mode, $dest);
912 my($path, $prog) = @_;
914 if ( defined($opts{"bin-path"}{$prog}) ) {
915 return $opts{"bin-path"}{$prog};
917 foreach my $dir ( split(/:/, $path) ) {
918 my $file = File::Spec->catfile($dir, $prog);
919 return $file if ( -x $file );
927 open(C, $file) || die("can't open $file");
929 my($out, @conf, $var);
934 if ( /^#/ && !defined($endLine) ) {
939 $allVars->{$var} = @conf if ( defined($var) );
949 } elsif ( /^\s*\$Conf\{([^}]*)/ ) {
951 if ( defined($var) ) {
952 $allVars->{$var} = @conf if ( defined($var) );
962 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<(.*);/ );
963 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<'(.*)';/ );
965 $endLine = undef if ( defined($endLine) && /^\Q$endLine[\n\r]*$/ );
970 $allVars->{$var} = @conf if ( defined($var) );
977 return (\@conf, $allVars);
982 my($old, $oldVars, $new, $newVars) = @_;
987 # Find which config parameters are not needed any longer
989 foreach my $var ( @$old ) {
990 next if ( !defined($var->{var}) || defined($newVars->{$var->{var}}) );
991 #print(STDERR "Deleting old config parameter $var->{var}\n");
995 # Find which config parameters are new
997 foreach my $var ( @$new ) {
998 next if ( !defined($var->{var}) );
999 if ( defined($oldVars->{$var->{var}}) ) {
1000 $posn = $oldVars->{$var->{var}};
1002 #print(STDERR "New config parameter $var->{var}: $var->{text}\n");
1003 push(@{$old->[$posn]{new}}, $var);
1007 # Create merged config file
1009 foreach my $var ( @$old ) {
1010 next if ( $var->{delete} );
1012 foreach my $new ( @{$var->{new}} ) {
1021 my($uid, $gid, $file) = @_;
1023 return 1 if ( !$opts{"set-perms"} );
1024 return chown($uid, $gid, $file);
1029 my ($mode, $file) = @_;
1031 return 1 if ( !$opts{"set-perms"} );
1032 return chmod($mode, $file);
1037 my($question, $default, $option) = @_;
1039 $default = $opts{$option} if ( defined($opts{$option}) );
1040 if ( $opts{batch} ) {
1041 print("$question [$default]\n");
1044 print("$question [$default]? ");
1045 my $reply = <STDIN>;
1046 $reply =~ s/[\n\r]*//g;
1047 return $reply if ( $reply !~ /^$/ );
1055 configure.pl [options]
1059 configure.pl is a script that is used to install or upgrade a BackupPC
1060 installation. It is usually run interactively without arguments. It
1061 also supports a batch mode where all the options can be specified
1062 via the command-line.
1064 For upgrading BackupPC you need to make sure that BackupPC is not
1065 running prior to running BackupPC.
1067 Typically configure.pl needs to run as the super user (root).
1075 Run configure.pl in batch mode. configure.pl will run without
1076 prompting the user. The other command-line options are used
1077 to specify the settings that the user is usually prompted for.
1079 =item B<--backuppc-user=USER>
1081 Specify the BackupPC user name that owns all the BackupPC
1082 files and runs the BackupPC programs. Default is backuppc.
1084 =item B<--bin-path PROG=PATH>
1086 Specify the path for various external programs that BackupPC
1087 uses. Several --bin-path options may be specified. configure.pl
1088 usually finds sensible defaults based on searching the PATH.
1091 --bin-path PROG=PATH
1093 where PROG is one of perl, tar, smbclient, nmblookup, rsync, ping,
1094 df, ssh, sendmail, hostname, split, par2, cat, gzip, bzip2 and
1095 PATH is that full path to that program.
1099 --bin-path cat=/bin/cat --bin-path bzip2=/home/user/bzip2
1101 =item B<--compress-level=N>
1103 Set the configuration compression level to N. Default is 3
1104 if Compress::Zlib is installed.
1106 =item B<--config-path CONFIG_PATH>
1108 Path to the existing config.pl configuration file for BackupPC.
1109 This option should be specified for batch upgrades to an
1110 existing installation. The option should be omitted when
1111 doing a batch new install.
1113 =item B<--cgi-dir CGI_DIR>
1115 Path to Apache's cgi-bin directory where the BackupPC_Admin
1116 script will be installed. This option only needs to be
1117 specified for a batch new install.
1119 =item B<--data-dir DATA_DIR>
1121 Path to the BackupPC data directory. This is where all the backup
1122 data is stored, and it should be on a large file system. This option
1123 only needs to be specified for a batch new install.
1127 --data-dir /data/BackupPC
1129 =item B<--dest-dir DEST_DIR>
1131 An optional prefix to apply to all installation directories.
1132 Usually this is not needed, but certain auto-installers like
1133 to stage an install in a temporary directory, and then copy
1134 the files to their real destination. This option can be used
1135 to specify the temporary directory prefix. Note that if you
1136 specify this option, BackupPC won't run correctly if you try
1137 to run it from below the --dest-dir directory, since all the
1138 paths are set assuming BackupPC is installed in the intended
1143 Use locations specified by the Filesystem Hierarchy Standard
1144 for installing BackupPC. This is enabled by default for new
1145 installatios. To use the pre-3.0 installation locations,
1150 Print a brief help message and exits.
1152 =item B<--hostname HOSTNAME>
1154 Host name (this machine's name) on which BackupPC is being installed.
1155 This option only needs to be specified for a batch new install.
1157 =item B<--html-dir HTML_DIR>
1159 Path to an Apache html directory where various BackupPC image files
1160 and the CSS files will be installed. This is typically a directory
1161 below Apache's DocumentRoot directory. This option only needs to be
1162 specified for a batch new install.
1166 --html-dir /usr/local/apache/htdocs/BackupPC
1168 =item B<--html-dir-url URL>
1170 The URL (without http://hostname) required to access the BackupPC html
1171 directory specified with the --html-dir option. This option only needs
1172 to be specified for a batch new install.
1176 --html-dir-url /BackupPC
1178 =item B<--install-dir INSTALL_DIR>
1180 Installation directory for BackupPC scripts, libraries, and
1181 documentation. This option only needs to be specified for a
1186 --install-dir /usr/local/BackupPC
1190 Prints the manual page and exits.
1192 =item B<--set-perms>
1194 When installing files and creating directories, chown them to
1195 the BackupPC user and chmod them too. This is enabled by default.
1196 To disable (for example, if staging a destination directory)
1197 then specify --no-set-perms.
1199 =item B<--uid-ignore>
1201 configure.pl verifies that the script is being run as the super user
1202 (root). Without the --uid-ignore option, in batch mode the script will
1203 exit with an error if not run as the super user, and in interactive mode
1204 the user will be prompted. Specifying this option will cause the script
1205 to continue even if the user id is not root.
1209 For a standard interactive install, run without arguments:
1213 For a batch new install you need to specify answers to all the
1214 questions that are normally prompted:
1218 --cgi-dir /var/www/cgi-bin/BackupPC \
1219 --data-dir /data/BackupPC \
1221 --html-dir /var/www/html/BackupPC \
1222 --html-dir-url /BackupPC \
1223 --install-dir /usr/local/BackupPC
1225 For a batch upgrade, you only need to specify the path to the
1228 configure.pl --batch --config-path /data/BackupPC/conf/config.pl
1232 Craig Barratt <cbarratt@users.sourceforge.net>
1236 Copyright (C) 2001-2004 Craig Barratt.
1238 This program is free software; you can redistribute it and/or modify
1239 it under the terms of the GNU General Public License as published by
1240 the Free Software Foundation; either version 2 of the License, or
1241 (at your option) any later version.