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 3.0.0alpha, released 8 Jul 2006.
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)
133 # the config files move to /etc/BackupPC and log files to /var/log:
135 # /etc/BackupPC/config.pl main config file (was $TopDir/conf/config.pl)
136 # /etc/BackupPC/hosts hosts file (was $TopDir/conf/hosts)
137 # /etc/BackupPC/pc/HOST.pl per-pc config file (was $TopDir/pc/HOST/config.pl)
138 # /var/log/BackupPC log files (was $TopDir/log)
139 # /var/log/BackupPC Pid, status and email info (was $TopDir/log)
143 # Check if this is an upgrade, in which case read the existing
144 # config file to get all the defaults.
147 my $ConfigFileOK = 1;
149 if ( $ConfigFileOK && -f "/etc/BackupPC/config.pl" ) {
150 $ConfigPath = "/etc/BackupPC/config.pl";
151 $opts{fhs} = 1 if ( !defined($opts{fhs}) );
154 Found /etc/BackupPC/config.pl, so this is an upgrade of an
155 existing BackupPC installation. We will verify some existing
156 information, but you will probably not need to make any
157 changes - just hit ENTER to each question.
162 Is this a new installation or upgrade for BackupPC? If this is
163 an upgrade please tell me the full path of the existing BackupPC
164 configuration file (eg: /etc/BackupPC/config.pl). Otherwise, just
168 $ConfigPath = prompt("--> Full path to existing main config.pl",
172 last if ( $ConfigPath eq ""
173 || ($ConfigPath =~ /^\// && -f $ConfigPath && -w $ConfigPath) );
174 my $problem = "is not an absolute path";
175 $problem = "is not writable" if ( !-w $ConfigPath );
176 $problem = "is not readable" if ( !-r $ConfigPath );
177 $problem = "is not a regular file" if ( !-f $ConfigPath );
178 $problem = "doesn't exist" if ( !-e $ConfigPath );
179 print("The file '$ConfigPath' $problem.\n");
180 if ( $opts{batch} ) {
181 print("Need to specify a valid --config-path for upgrade\n");
186 $opts{fhs} = 1 if ( !defined($opts{fhs}) && $ConfigPath eq "" );
187 $opts{fhs} = 0 if ( !defined($opts{fhs}) );
190 if ( $ConfigPath ne "" && -r $ConfigPath ) {
191 (my $confDir = $ConfigPath) =~ s{/[^/]+$}{};
192 die("BackupPC::Lib->new failed\n")
193 if ( !($bpc = BackupPC::Lib->new(".", ".", $confDir, 1)) );
194 %Conf = $bpc->Conf();
197 ($Conf{TopDir} = $ConfigPath) =~ s{/[^/]+/[^/]+$}{}
198 if ( $Conf{TopDir} eq '' );
199 $bpc->{LogDir} = $Conf{LogDir} = "$Conf{TopDir}/log"
200 if ( $Conf{LogDir} eq '' );
202 $bpc->{ConfDir} = $Conf{ConfDir} = $confDir;
203 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1);
207 BackupPC is running on $Conf{ServerHost}. You need to stop BackupPC
208 before you can upgrade the code. Depending upon your installation,
209 you could run "/etc/init.d/backuppc stop".
217 # Create defaults for FHS setup
220 $Conf{TopDir} ||= "/data/BackupPC";
221 $Conf{ConfDir} ||= $opts{"config-dir"} || "/etc/BackupPC";
222 $Conf{InstallDir} ||= "/usr/local/BackupPC";
223 $Conf{LogDir} ||= $opts{"log-dir"} || "/var/log/BackupPC";
227 # These are the programs whose paths we need to find
231 'gtar/tar' => "TarClientPath",
232 smbclient => "SmbClientPath",
233 nmblookup => "NmbLookupPath",
234 rsync => "RsyncClientPath",
237 'ssh/ssh2' => "SshPath",
238 sendmail => "SendmailPath",
239 hostname => "HostnamePath",
240 split => "SplitPath",
244 bzip2 => "Bzip2Path",
247 foreach my $prog ( sort(keys(%Programs)) ) {
249 foreach my $subProg ( split(/\//, $prog) ) {
250 $path = FindProgram("$ENV{PATH}:/bin:/usr/bin:/sbin:/usr/sbin",
251 $subProg) if ( !length($path) );
253 $Conf{$Programs{$prog}} = $path if ( !length($Conf{$Programs{$prog}}) );
259 I found the following locations for these programs:
262 foreach my $prog ( sort(keys(%Programs)) ) {
263 printf(" %-12s => %s\n", $prog, $Conf{$Programs{$prog}});
266 last if (prompt('--> Are these paths correct?', 'y') =~ /^y/i);
267 foreach my $prog ( sort(keys(%Programs)) ) {
268 $Conf{$Programs{$prog}} = prompt("--> $prog path",
269 $Conf{$Programs{$prog}});
273 my $Perl56 = system($Conf{PerlPath}
274 . q{ -e 'exit($^V && $^V ge v5.6.0 ? 1 : 0);'});
279 BackupPC needs perl version 5.6.0 or later. $Conf{PerlPath} appears
280 to be an older version. Please upgrade to a newer version of perl
281 and re-run this configure script.
289 Please tell me the hostname of the machine that BackupPC will run on.
292 chomp($Conf{ServerHost} = `$Conf{HostnamePath}`)
293 if ( defined($Conf{HostnamePath}) && !defined($Conf{ServerHost}) );
294 $Conf{ServerHost} = prompt("--> BackupPC will run on host",
300 BackupPC should run as a dedicated user with limited privileges. You
301 need to create a user. This user will need read/write permission on
302 the main data directory and read/execute permission on the install
303 directory (these directories will be setup shortly).
305 The primary group for this user should also be chosen carefully.
306 The data directories and files will have group read permission,
307 so group members can access backup files.
310 my($name, $passwd, $Uid, $Gid);
312 $Conf{BackupPCUser} = prompt("--> BackupPC should run as user",
313 $Conf{BackupPCUser} || "backuppc",
315 if ( $opts{"set-perms"} ) {
316 ($name, $passwd, $Uid, $Gid) = getpwnam($Conf{BackupPCUser});
317 last if ( $name ne "" );
320 getpwnam() says that user $Conf{BackupPCUser} doesn't exist. Please
321 check the name and verify that this user is in the passwd file.
324 exit(1) if ( $opts{batch} );
330 Please specify an install directory for BackupPC. This is where the
331 BackupPC scripts, library and documentation will be installed.
336 $Conf{InstallDir} = prompt("--> Install directory (full path)",
339 last if ( $Conf{InstallDir} =~ /^\// );
340 if ( $opts{batch} ) {
341 print("Need to specify --install-dir for new installation\n");
348 Please specify a data directory for BackupPC. This is where the
349 all the PC backup data is stored. This file system needs to be
350 big enough to accommodate all the PCs you expect to backup (eg:
351 at least several GB per machine).
356 $Conf{TopDir} = prompt("--> Data directory (full path)",
359 last if ( $Conf{TopDir} =~ /^\// );
360 if ( $opts{batch} ) {
361 print("Need to specify --data-dir for new installation\n");
366 $Conf{CompressLevel} = $opts{"compress-level"}
367 if ( defined($opts{"compress-level"}) );
369 if ( !defined($Conf{CompressLevel}) ) {
370 $Conf{CompressLevel} = BackupPC::FileZIO->compOk ? 3 : 0;
371 if ( $ConfigPath eq "" && $Conf{CompressLevel} ) {
374 BackupPC can compress pool files, providing around a 40% reduction in pool
375 size (your mileage may vary). Specify the compression level (0 turns
376 off compression, and 1 to 9 represent good/fastest to best/slowest).
377 The recommended values are 0 (off) or 3 (reasonable compression and speed).
378 Increasing the compression level to 5 will use around 20% more cpu time
379 and give perhaps 2-3% more compression.
382 } elsif ( $ConfigPath eq "" ) {
385 BackupPC can compress pool files, but it needs the Compress::Zlib
386 package installed (see www.cpan.org). Compression will provide around a
387 40% reduction in pool size, at the expense of cpu time. You can leave
388 compression off and run BackupPC without compression, in which case you
389 should leave the compression level at 0 (which means off). You could
390 install Compress::Zlib and turn compression on later, but read the
391 documentation first about how to do this. Or the better choice is
392 to quit, install Compress::Zlib, and re-run configure.pl.
395 } elsif ( $Conf{CompressLevel} ) {
396 $Conf{CompressLevel} = 0;
399 BackupPC now supports pool file compression. Since you are upgrading
400 BackupPC you probably have existing uncompressed backups. You have
401 several choices if you want to turn on compression. You can run
402 the script BackupPC_compressPool to convert everything to compressed
403 form. Or you can simply turn on compression, so that new backups
404 will be compressed. This will increase the pool storage requirement,
405 since both uncompressed and compressed copies of files will be stored.
406 But eventually the old uncompressed backups will expire, recovering
407 the pool storage. Please see the documentation for more details.
409 If you are not sure what to do, leave the Compression Level at 0,
410 which disables compression. You can always read the documentation
411 and turn it on later.
415 $Conf{CompressLevel} = 0;
418 BackupPC now supports pool file compression, but it needs the
419 Compress::Zlib module (see www.cpan.org). For now, leave
420 the compression level set at 0 to disable compression. If you
421 want you can install Compress::Zlib and turn compression on.
422 Please see the documentation for more details about converting
423 old backups to compressed form.
429 = prompt("--> Compression level", $Conf{CompressLevel});
430 last if ( $Conf{CompressLevel} =~ /^\d+$/ );
436 BackupPC has a powerful CGI perl interface that runs under Apache.
437 A single executable needs to be installed in a cgi-bin directory.
438 This executable needs to run as set-uid $Conf{BackupPCUser}, or
439 it can be run under mod_perl with Apache running as user $Conf{BackupPCUser}.
441 Leave this path empty if you don't want to install the CGI interface.
446 $Conf{CgiDir} = prompt("--> CGI bin directory (full path)",
449 last if ( $Conf{CgiDir} =~ /^\// || $Conf{CgiDir} eq "" );
450 if ( $opts{batch} ) {
451 print("Need to specify --cgi-dir for new installation\n");
456 if ( $Conf{CgiDir} ne "" ) {
460 BackupPC's CGI script needs to display various GIF images that
461 should be stored where Apache can serve them. They should be
462 placed somewher under Apache's DocumentRoot. BackupPC also
463 needs to know the URL to access these images. Example:
465 Apache image directory: /usr/local/apache/htdocs/BackupPC
466 URL for image directory: /BackupPC
468 The URL for the image directory should start with a slash.
472 $Conf{CgiImageDir} = prompt("--> Apache image directory (full path)",
475 last if ( $Conf{CgiImageDir} =~ /^\// );
476 if ( $opts{batch} ) {
477 print("Need to specify --html-dir for new installation\n");
482 $Conf{CgiImageDirURL} = prompt("--> URL for image directory (omit http://host; starts with '/')",
483 $Conf{CgiImageDirURL},
485 last if ( $Conf{CgiImageDirURL} =~ /^\// );
486 if ( $opts{batch} ) {
487 print("Need to specify --html-dir-url for new installation\n");
497 - install the binaries, lib and docs in $Conf{InstallDir},
498 - create the data directory $Conf{TopDir},
499 - create/update the config.pl file $Conf{ConfDir}/config.pl,
500 - optionally install the cgi-bin interface.
504 exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
507 # Create install directories
509 foreach my $dir ( qw(bin doc
517 next if ( -d "$DestDir$Conf{InstallDir}/$dir" );
518 mkpath("$DestDir$Conf{InstallDir}/$dir", 0, 0755);
519 if ( !-d "$DestDir$Conf{InstallDir}/$dir"
520 || !my_chown($Uid, $Gid, "$DestDir$Conf{InstallDir}/$dir") ) {
521 die("Failed to create or chown $DestDir$Conf{InstallDir}/$dir\n");
523 print("Created $DestDir$Conf{InstallDir}/$dir\n");
528 # Create CGI image directory
530 foreach my $dir ( ($Conf{CgiImageDir}) ) {
531 next if ( $dir eq "" || -d $dir );
532 mkpath("$DestDir$dir", 0, 0755);
533 if ( !-d "$DestDir$dir" || !my_chown($Uid, $Gid, "$DestDir$dir") ) {
534 die("Failed to create or chown $DestDir$dir");
536 print("Created $DestDir$dir\n");
541 # Create other directories
545 "$Conf{TopDir}/pool",
546 "$Conf{TopDir}/cpool",
548 "$Conf{TopDir}/trash",
552 mkpath("$DestDir/$dir", 0, 0750) if ( !-d "$DestDir/$dir" );
553 if ( !-d "$DestDir/$dir"
554 || !my_chown($Uid, $Gid, "$DestDir/$dir") ) {
555 die("Failed to create or chown $DestDir/$dir\n");
557 print("Created $DestDir/$dir\n");
561 printf("Installing binaries in $DestDir$Conf{InstallDir}/bin\n");
562 foreach my $prog ( qw(
563 __CONFIGURE_BIN_LIST__
565 InstallFile($prog, "$DestDir$Conf{InstallDir}/$prog", 0555);
568 printf("Installing library in $DestDir$Conf{InstallDir}/lib\n");
569 foreach my $lib ( qw(
570 __CONFIGURE_LIB_LIST__
572 InstallFile($lib, "$DestDir$Conf{InstallDir}/$lib", 0444);
575 if ( $Conf{CgiImageDir} ne "" ) {
576 printf("Installing images in $DestDir$Conf{CgiImageDir}\n");
577 foreach my $img ( <images/*> ) {
578 (my $destImg = $img) =~ s{^images/}{};
579 InstallFile($img, "$DestDir$Conf{CgiImageDir}/$destImg", 0444, 1);
583 # Install new CSS file, making a backup copy if necessary
585 my $cssBackup = "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css.pre-__VERSION__";
586 if ( -f "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css" && !-f $cssBackup ) {
587 rename("$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", $cssBackup);
589 InstallFile("conf/BackupPC_stnd.css",
590 "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", 0444, 0);
593 printf("Making init.d scripts\n");
594 foreach my $init ( qw(gentoo-backuppc gentoo-backuppc.conf linux-backuppc
595 solaris-backuppc debian-backuppc suse-backuppc
596 slackware-backuppc ) ) {
597 InstallFile("init.d/src/$init", "init.d/$init", 0444);
600 printf("Installing docs in $DestDir$Conf{InstallDir}/doc\n");
601 foreach my $doc ( qw(BackupPC.pod BackupPC.html) ) {
602 InstallFile("doc/$doc", "$DestDir$Conf{InstallDir}/doc/$doc", 0444);
605 printf("Installing config.pl and hosts in $DestDir$Conf{ConfDir}\n");
606 InstallFile("conf/hosts", "$DestDir$Conf{ConfDir}/hosts", 0644)
607 if ( !-f "$DestDir$Conf{ConfDir}/hosts" );
610 # Now do the config file. If there is an existing config file we
611 # merge in the new config file, adding any new configuration
612 # parameters and deleting ones that are no longer needed.
614 my $dest = "$DestDir$Conf{ConfDir}/config.pl";
615 my ($distConf, $distVars) = ConfigParse("conf/config.pl");
616 my ($oldConf, $oldVars);
617 my ($newConf, $newVars) = ($distConf, $distVars);
619 ($oldConf, $oldVars) = ConfigParse($dest);
620 ($newConf, $newVars) = ConfigMerge($oldConf, $oldVars, $distConf, $distVars);
624 # Update various config parameters. The old config is in Conf{}
625 # and the new config is an array in text form in $newConf->[].
627 $Conf{EMailFromUserName} ||= $Conf{BackupPCUser};
628 $Conf{EMailAdminUserName} ||= $Conf{BackupPCUser};
631 # Guess $Conf{CgiURL}
633 if ( !defined($Conf{CgiURL}) ) {
634 if ( $Conf{CgiDir} =~ m{cgi-bin(/.*)} ) {
635 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin$1/BackupPC_Admin'";
637 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin/BackupPC_Admin'";
642 # The smbclient commands have moved from hard-coded to the config file.
643 # $Conf{SmbClientArgs} no longer exists, so merge it into the new
644 # commands if it still exists.
646 if ( defined($Conf{SmbClientArgs}) ) {
647 if ( $Conf{SmbClientArgs} ne "" ) {
648 foreach my $param ( qw(SmbClientRestoreCmd SmbClientFullCmd
649 SmbClientIncrCmd) ) {
650 $newConf->[$newVars->{$param}]{text}
651 =~ s/(-E\s+-N)/$1 $Conf{SmbClientArgs}/;
654 delete($Conf{SmbClientArgs});
658 # CSS is now stored in a file rather than a big config variable.
660 delete($Conf{CSSstylesheet});
663 # The blackout timing settings are now stored in a list of hashes, rather
664 # than three scalar parameters.
666 if ( defined($Conf{BlackoutHourBegin}) ) {
667 $Conf{BlackoutPeriods} = [
669 hourBegin => $Conf{BlackoutHourBegin},
670 hourEnd => $Conf{BlackoutHourEnd},
671 weekDays => $Conf{BlackoutWeekDays},
674 delete($Conf{BlackoutHourBegin});
675 delete($Conf{BlackoutHourEnd});
676 delete($Conf{BlackoutWeekDays});
680 # $Conf{RsyncLogLevel} has been replaced by $Conf{XferLogLevel}
682 if ( defined($Conf{RsyncLogLevel}) ) {
683 $Conf{XferLogLevel} = $Conf{RsyncLogLevel};
684 delete($Conf{RsyncLogLevel});
688 # In 2.1.0 the default for $Conf{CgiNavBarAdminAllHosts} is now 1
690 $Conf{CgiNavBarAdminAllHosts} = 1;
693 # IncrFill should now be off
698 # Figure out sensible arguments for the ping command
700 if ( defined($Conf{PingArgs}) ) {
701 $Conf{PingCmd} = '$pingPath ' . $Conf{PingArgs};
702 } elsif ( !defined($Conf{PingCmd}) ) {
703 if ( $^O eq "solaris" || $^O eq "sunos" ) {
704 $Conf{PingCmd} = '$pingPath -s $host 56 1';
705 } elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
706 && !system("$Conf{PingPath} -c 1 -w 3 localhost") ) {
707 $Conf{PingCmd} = '$pingPath -c 1 -w 3 $host';
709 $Conf{PingCmd} = '$pingPath -c 1 $host';
711 delete($Conf{PingArgs});
715 # Figure out sensible arguments for the df command
717 if ( !defined($Conf{DfCmd}) ) {
718 if ( $^O eq "solaris" || $^O eq "sunos" ) {
719 $Conf{DfCmd} = '$dfPath -k $topDir';
724 # $Conf{SmbClientTimeout} is now $Conf{ClientTimeout}
726 if ( defined($Conf{SmbClientTimeout}) ) {
727 $Conf{ClientTimeout} = $Conf{SmbClientTimeout};
728 delete($Conf{SmbClientTimeout});
732 # Replace --devices with -D in RsyncArgs and RsyncRestoreArgs
734 foreach my $param ( qw(RsyncArgs RsyncRestoreArgs) ) {
735 next if ( !defined($newVars->{$param}) );
736 $newConf->[$newVars->{$param}]{text} =~ s/--devices/-D/g;
740 # Merge any new user-editable parameters into CgiUserConfigEdit
741 # by copying the old settings forward.
743 if ( defined($Conf{CgiUserConfigEdit}) ) {
745 # This is a real hack. The config file merging is done in text
746 # form without actually instantiating the new conf structure.
747 # So we need to extract the new hash of settings, update it,
748 # and merge the text. Ugh...
751 my $str = $distConf->[$distVars->{CgiUserConfigEdit}]{text};
753 $str =~ s/^\s*\$Conf\{.*?\}\s*=\s*/\$new = /m;
755 foreach my $p ( keys(%$new) ) {
756 $new->{$p} = $Conf{CgiUserConfigEdit}{$p}
757 if ( defined($Conf{CgiUserConfigEdit}{$p}) );
759 $Conf{CgiUserConfigEdit} = $new;
760 my $d = Data::Dumper->new([$new], [*value]);
763 my $value = $d->Dump;
764 $value =~ s/(.*)\n/$1;\n/s;
765 $newConf->[$newVars->{CgiUserConfigEdit}]{text}
766 =~ s/(\s*\$Conf\{.*?\}\s*=\s*).*/$1$value/s;
770 # Now backup and write the config file
772 my $confCopy = "$dest.pre-__VERSION__";
773 if ( -f $dest && !-f $confCopy ) {
775 # Make copy of config file, preserving ownership and modes
777 printf("Making backup copy of $dest -> $confCopy\n");
778 my @stat = stat($dest);
782 die("can't copy($dest, $confCopy)\n")
783 unless copy($dest, $confCopy);
784 die("can't chown $uid, $gid $confCopy\n")
785 unless my_chown($uid, $gid, $confCopy);
786 die("can't chmod $mode $confCopy\n")
787 unless my_chmod($mode, $confCopy);
789 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
792 foreach my $var ( @$newConf ) {
793 if ( length($blockComment)
794 && substr($var->{text}, 0, length($blockComment)) eq $blockComment ) {
795 $var->{text} = substr($var->{text}, length($blockComment));
796 $blockComment = undef;
798 $blockComment = $1 if ( $var->{text} =~ /^([\s\n]*#{70}.*#{70}[\s\n]+)/s );
799 $var->{text} =~ s/^\s*\$Conf\{(.*?)\}(\s*=\s*['"]?)(.*?)(['"]?\s*;)/
800 defined($Conf{$1}) && ref($Conf{$1}) eq ""
801 && $Conf{$1} ne $OrigConf{$1}
802 ? "\$Conf{$1}$2$Conf{$1}$4"
803 : "\$Conf{$1}$2$3$4"/emg;
804 print OUT $var->{text};
807 if ( !defined($oldConf) ) {
808 die("can't chmod 0640 mode $dest\n") unless my_chmod(0640, $dest);
809 die("can't chown $Uid, $Gid $dest\n") unless my_chown($Uid, $Gid, $dest);
812 if ( $Conf{CgiDir} ne "" ) {
813 printf("Installing cgi script BackupPC_Admin in $DestDir$Conf{CgiDir}\n");
814 mkpath("$DestDir$Conf{CgiDir}", 0, 0755);
815 InstallFile("cgi-bin/BackupPC_Admin", "$DestDir$Conf{CgiDir}/BackupPC_Admin",
821 Ok, it looks like we are finished. There are several more things you
824 - Browse through the config file, $Conf{ConfDir}/config.pl,
825 and make sure all the settings are correct. In particular,
826 you will need to set \$Conf{CgiAdminUsers} so you have
827 administration privileges in the CGI interface.
829 - Edit the list of hosts to backup in $Conf{ConfDir}/hosts.
831 - Read the documentation in $Conf{InstallDir}/doc/BackupPC.html.
832 Please pay special attention to the security section.
834 - Verify that the CGI script BackupPC_Admin runs correctly. You might
835 need to change the permissions or group ownership of BackupPC_Admin.
837 - BackupPC should be ready to start. Don't forget to run it
838 as user $Conf{BackupPCUser}! The installation also contains an
839 init.d/backuppc script that can be copied to /etc/init.d
840 so that BackupPC can auto-start on boot. This will also enable
841 administrative users to start the server from the CGI interface.
847 if ( `$Conf{PerlPath} -V` =~ /uselargefiles=undef/ ) {
850 Warning: your perl, $Conf{PerlPath}, does not support large files.
851 This means BackupPC won't be able to backup files larger than 2GB.
852 To solve this problem you should build/install a new version of perl
853 with large file support enabled. Use
855 $Conf{PerlPath} -V | egrep uselargefiles
857 to check if perl has large file support (undef means no support).
861 eval "use File::RsyncP;";
862 if ( !$@ && $File::RsyncP::VERSION < 0.52 ) {
863 print("\nWarning: you need to upgrade File::RsyncP;"
864 . " I found $File::RsyncP::VERSION and BackupPC needs 0.52\n");
869 ###########################################################################
871 ###########################################################################
875 my($prog, $dest, $mode, $binary) = @_;
877 my($uid, $gid) = ($Uid, $Gid);
881 # preserve ownership and modes of files that already exist
883 my @stat = stat($dest);
888 unlink($dest) if ( -f $dest );
890 die("can't copy($prog, $dest)\n") unless copy($prog, $dest);
892 open(PROG, $prog) || die("can't open $prog for reading\n");
893 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
897 s/__INSTALLDIR__/$Conf{InstallDir}/g;
898 s/__LOGDIR__/$Conf{LogDir}/g;
899 s/__CONFDIR__/$Conf{ConfDir}/g;
900 s/__TOPDIR__/$Conf{TopDir}/g;
901 s/^(\s*my \$useFHS\s*=\s*)\d;/${1}$opts{fhs};/
902 if ( $prog =~ /Lib.pm/ );
903 s/__BACKUPPCUSER__/$Conf{BackupPCUser}/g;
904 s/__CGIDIR__/$Conf{CgiDir}/g;
905 if ( $first && /^#.*bin\/perl/ ) {
907 # Fill in correct path to perl (no taint for >= 2.0.1).
909 print OUT "#!$Conf{PerlPath}\n";
918 die("can't chown $uid, $gid $dest") unless my_chown($uid, $gid, $dest);
919 die("can't chmod $mode $dest") unless my_chmod($mode, $dest);
924 my($path, $prog) = @_;
926 if ( defined($opts{"bin-path"}{$prog}) ) {
927 return $opts{"bin-path"}{$prog};
929 foreach my $dir ( split(/:/, $path) ) {
930 my $file = File::Spec->catfile($dir, $prog);
931 return $file if ( -x $file );
939 open(C, $file) || die("can't open $file");
941 my($out, @conf, $var);
946 if ( /^#/ && !defined($endLine) ) {
951 $allVars->{$var} = @conf if ( defined($var) );
961 } elsif ( /^\s*\$Conf\{([^}]*)/ ) {
963 if ( defined($var) ) {
964 $allVars->{$var} = @conf if ( defined($var) );
974 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<(.*);/ );
975 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<'(.*)';/ );
977 $endLine = undef if ( defined($endLine) && /^\Q$endLine[\n\r]*$/ );
982 $allVars->{$var} = @conf if ( defined($var) );
989 return (\@conf, $allVars);
994 my($old, $oldVars, $new, $newVars) = @_;
999 # Find which config parameters are not needed any longer
1001 foreach my $var ( @$old ) {
1002 next if ( !defined($var->{var}) || defined($newVars->{$var->{var}}) );
1003 #print(STDERR "Deleting old config parameter $var->{var}\n");
1007 # Find which config parameters are new
1009 foreach my $var ( @$new ) {
1010 next if ( !defined($var->{var}) );
1011 if ( defined($oldVars->{$var->{var}}) ) {
1012 $posn = $oldVars->{$var->{var}};
1014 #print(STDERR "New config parameter $var->{var}: $var->{text}\n");
1015 push(@{$old->[$posn]{new}}, $var);
1019 # Create merged config file
1021 foreach my $var ( @$old ) {
1022 next if ( $var->{delete} );
1024 foreach my $new ( @{$var->{new}} ) {
1028 for ( my $i = 0 ; $i < @$res ; $i++ ) {
1029 $resVars->{$res->[$i]{var}} = $i;
1031 return ($res, $resVars);
1036 my($uid, $gid, $file) = @_;
1038 return 1 if ( !$opts{"set-perms"} );
1039 return chown($uid, $gid, $file);
1044 my ($mode, $file) = @_;
1046 return 1 if ( !$opts{"set-perms"} );
1047 return chmod($mode, $file);
1052 my($question, $default, $option) = @_;
1054 $default = $opts{$option} if ( defined($opts{$option}) );
1055 if ( $opts{batch} ) {
1056 print("$question [$default]\n");
1059 print("$question [$default]? ");
1060 my $reply = <STDIN>;
1061 $reply =~ s/[\n\r]*//g;
1062 return $reply if ( $reply !~ /^$/ );
1070 configure.pl [options]
1074 configure.pl is a script that is used to install or upgrade a BackupPC
1075 installation. It is usually run interactively without arguments. It
1076 also supports a batch mode where all the options can be specified
1077 via the command-line.
1079 For upgrading BackupPC you need to make sure that BackupPC is not
1080 running prior to running BackupPC.
1082 Typically configure.pl needs to run as the super user (root).
1090 Run configure.pl in batch mode. configure.pl will run without
1091 prompting the user. The other command-line options are used
1092 to specify the settings that the user is usually prompted for.
1094 =item B<--backuppc-user=USER>
1096 Specify the BackupPC user name that owns all the BackupPC
1097 files and runs the BackupPC programs. Default is backuppc.
1099 =item B<--bin-path PROG=PATH>
1101 Specify the path for various external programs that BackupPC
1102 uses. Several --bin-path options may be specified. configure.pl
1103 usually finds sensible defaults based on searching the PATH.
1106 --bin-path PROG=PATH
1108 where PROG is one of perl, tar, smbclient, nmblookup, rsync, ping,
1109 df, ssh, sendmail, hostname, split, par2, cat, gzip, bzip2 and
1110 PATH is that full path to that program.
1114 --bin-path cat=/bin/cat --bin-path bzip2=/home/user/bzip2
1116 =item B<--compress-level=N>
1118 Set the configuration compression level to N. Default is 3
1119 if Compress::Zlib is installed.
1121 =item B<--config-dir CONFIG_DIR>
1123 Configuration directory for new installations. Defaults
1124 to /etc/BackupPC with FHS. Automatically extracted
1125 from --config-path for existing installations.
1127 =item B<--config-path CONFIG_PATH>
1129 Path to the existing config.pl configuration file for BackupPC.
1130 This option should be specified for batch upgrades to an
1131 existing installation. The option should be omitted when
1132 doing a batch new install.
1134 =item B<--cgi-dir CGI_DIR>
1136 Path to Apache's cgi-bin directory where the BackupPC_Admin
1137 script will be installed. This option only needs to be
1138 specified for a batch new install.
1140 =item B<--data-dir DATA_DIR>
1142 Path to the BackupPC data directory. This is where all the backup
1143 data is stored, and it should be on a large file system. This option
1144 only needs to be specified for a batch new install.
1148 --data-dir /data/BackupPC
1150 =item B<--dest-dir DEST_DIR>
1152 An optional prefix to apply to all installation directories.
1153 Usually this is not needed, but certain auto-installers like
1154 to stage an install in a temporary directory, and then copy
1155 the files to their real destination. This option can be used
1156 to specify the temporary directory prefix. Note that if you
1157 specify this option, BackupPC won't run correctly if you try
1158 to run it from below the --dest-dir directory, since all the
1159 paths are set assuming BackupPC is installed in the intended
1164 Use locations specified by the Filesystem Hierarchy Standard
1165 for installing BackupPC. This is enabled by default for new
1166 installatios. To use the pre-3.0 installation locations,
1171 Print a brief help message and exits.
1173 =item B<--hostname HOSTNAME>
1175 Host name (this machine's name) on which BackupPC is being installed.
1176 This option only needs to be specified for a batch new install.
1178 =item B<--html-dir HTML_DIR>
1180 Path to an Apache html directory where various BackupPC image files
1181 and the CSS files will be installed. This is typically a directory
1182 below Apache's DocumentRoot directory. This option only needs to be
1183 specified for a batch new install.
1187 --html-dir /usr/local/apache/htdocs/BackupPC
1189 =item B<--html-dir-url URL>
1191 The URL (without http://hostname) required to access the BackupPC html
1192 directory specified with the --html-dir option. This option only needs
1193 to be specified for a batch new install.
1197 --html-dir-url /BackupPC
1199 =item B<--install-dir INSTALL_DIR>
1201 Installation directory for BackupPC scripts, libraries, and
1202 documentation. This option only needs to be specified for a
1207 --install-dir /usr/local/BackupPC
1209 =item B<--log-dir LOG_DIR>
1211 Log directory. Defaults to /var/log/BackupPC with FHS.
1215 Prints the manual page and exits.
1217 =item B<--set-perms>
1219 When installing files and creating directories, chown them to
1220 the BackupPC user and chmod them too. This is enabled by default.
1221 To disable (for example, if staging a destination directory)
1222 then specify --no-set-perms.
1224 =item B<--uid-ignore>
1226 configure.pl verifies that the script is being run as the super user
1227 (root). Without the --uid-ignore option, in batch mode the script will
1228 exit with an error if not run as the super user, and in interactive mode
1229 the user will be prompted. Specifying this option will cause the script
1230 to continue even if the user id is not root.
1234 For a standard interactive install, run without arguments:
1238 For a batch new install you need to specify answers to all the
1239 questions that are normally prompted:
1243 --cgi-dir /var/www/cgi-bin/BackupPC \
1244 --data-dir /data/BackupPC \
1246 --html-dir /var/www/html/BackupPC \
1247 --html-dir-url /BackupPC \
1248 --install-dir /usr/local/BackupPC
1250 For a batch upgrade, you only need to specify the path to the
1253 configure.pl --batch --config-path /data/BackupPC/conf/config.pl
1257 Craig Barratt <cbarratt@users.sourceforge.net>
1261 Copyright (C) 2001-2006 Craig Barratt.
1263 This program is free software; you can redistribute it and/or modify
1264 it under the terms of the GNU General Public License as published by
1265 the Free Software Foundation; either version 2 of the License, or
1266 (at your option) any later version.