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 Encode Pod::Usage
53 BackupPC::Lib BackupPC::FileZIO);
55 foreach my $pkg ( @Packages ) {
58 if ( $pkg =~ /BackupPC/ ) {
61 Error loading $pkg: $@
62 BackupPC cannot load the package $pkg, which is included in the
63 BackupPC distribution. This probably means you did not cd to the
64 unpacked BackupPC distribution before running configure.pl, eg:
66 cd BackupPC-__VERSION__
75 BackupPC needs the package $pkg. Please install $pkg
76 before installing BackupPC.
81 my $EncodeVersion = eval($Encode::VERSION);
82 if ( $EncodeVersion < 1.99 ) {
83 print("\nError: you need to upgrade the Encode package;"
84 . " I found $EncodeVersion and BackupPC needs >= 1.99\n\n");
89 $opts{"set-perms"} = 1;
114 pod2usage(1) if ( $opts{help} );
115 pod2usage(-exitstatus => 0, -verbose => 2) if $opts{man};
117 my $DestDir = $opts{"dest-dir"};
118 $DestDir = "" if ( $DestDir eq "/" );
120 if ( !$opts{"uid-ignore"} && $< != 0 ) {
123 This configure script should be run as root, rather than uid $<.
124 Provided uid $< has sufficient permissions to create the data and
125 install directories, then it should be ok to proceed. Otherwise,
126 please quit and restart as root.
129 exit(1) if ( prompt("--> Do you want to continue?",
131 exit(1) if ( $opts{batch} && !$opts{"uid-ignore"} );
135 # Whether we use the file system hierarchy conventions or not.
136 # Older versions did not. BackupPC used to be installed in
137 # two main directories (in addition to CGI and html pages)
139 # TopDir which includes subdirs conf, log, pc, pool, cpool
141 # InstallDir which includes subdirs bin, lib, doc
143 # With FHS enabled (which is the default for new installations)
144 # the config files move to /etc/BackupPC and log files to /var/log:
146 # /etc/BackupPC/config.pl main config file (was $TopDir/conf/config.pl)
147 # /etc/BackupPC/hosts hosts file (was $TopDir/conf/hosts)
148 # /etc/BackupPC/pc/HOST.pl per-pc config file (was $TopDir/pc/HOST/config.pl)
149 # /var/log/BackupPC log files (was $TopDir/log)
150 # /var/log/BackupPC Pid, status and email info (was $TopDir/log)
154 # Check if this is an upgrade, in which case read the existing
155 # config file to get all the defaults.
158 my $ConfigFileOK = 1;
160 if ( $ConfigFileOK && -f "/etc/BackupPC/config.pl" ) {
161 $ConfigPath = "/etc/BackupPC/config.pl";
162 $opts{fhs} = 1 if ( !defined($opts{fhs}) );
165 Found /etc/BackupPC/config.pl, so this is an upgrade of an
166 existing BackupPC installation. We will verify some existing
167 information, but you will probably not need to make any
168 changes - just hit ENTER to each question.
173 Is this a new installation or upgrade for BackupPC? If this is
174 an upgrade please tell me the full path of the existing BackupPC
175 configuration file (eg: /etc/BackupPC/config.pl). Otherwise, just
179 $ConfigPath = prompt("--> Full path to existing main config.pl",
183 last if ( $ConfigPath eq ""
184 || ($ConfigPath =~ /^\// && -f $ConfigPath && -w $ConfigPath) );
185 my $problem = "is not an absolute path";
186 $problem = "is not writable" if ( !-w $ConfigPath );
187 $problem = "is not readable" if ( !-r $ConfigPath );
188 $problem = "is not a regular file" if ( !-f $ConfigPath );
189 $problem = "doesn't exist" if ( !-e $ConfigPath );
190 print("The file '$ConfigPath' $problem.\n");
191 if ( $opts{batch} ) {
192 print("Need to specify a valid --config-path for upgrade\n");
197 $opts{fhs} = 1 if ( !defined($opts{fhs}) && $ConfigPath eq "" );
198 $opts{fhs} = 0 if ( !defined($opts{fhs}) );
201 if ( $ConfigPath ne "" && -r $ConfigPath ) {
202 (my $confDir = $ConfigPath) =~ s{/[^/]+$}{};
203 die("BackupPC::Lib->new failed\n")
204 if ( !($bpc = BackupPC::Lib->new(".", ".", $confDir, 1)) );
205 %Conf = $bpc->Conf();
208 ($Conf{TopDir} = $ConfigPath) =~ s{/[^/]+/[^/]+$}{}
209 if ( $Conf{TopDir} eq '' );
210 $bpc->{LogDir} = $Conf{LogDir} = "$Conf{TopDir}/log"
211 if ( $Conf{LogDir} eq '' );
213 $bpc->{ConfDir} = $Conf{ConfDir} = $confDir;
214 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1);
218 BackupPC is running on $Conf{ServerHost}. You need to stop BackupPC
219 before you can upgrade the code. Depending upon your installation,
220 you could run "/etc/init.d/backuppc stop".
228 # Create defaults for FHS setup
231 $Conf{TopDir} ||= "/data/BackupPC";
232 $Conf{ConfDir} ||= $opts{"config-dir"} || "/etc/BackupPC";
233 $Conf{InstallDir} ||= "/usr/local/BackupPC";
234 $Conf{LogDir} ||= $opts{"log-dir"} || "/var/log/BackupPC";
238 # These are the programs whose paths we need to find
242 'gtar/tar' => "TarClientPath",
243 smbclient => "SmbClientPath",
244 nmblookup => "NmbLookupPath",
245 rsync => "RsyncClientPath",
248 'ssh/ssh2' => "SshPath",
249 sendmail => "SendmailPath",
250 hostname => "HostnamePath",
251 split => "SplitPath",
255 bzip2 => "Bzip2Path",
258 foreach my $prog ( sort(keys(%Programs)) ) {
260 foreach my $subProg ( split(/\//, $prog) ) {
261 $path = FindProgram("$ENV{PATH}:/bin:/usr/bin:/sbin:/usr/sbin",
262 $subProg) if ( !length($path) );
264 $Conf{$Programs{$prog}} = $path if ( !length($Conf{$Programs{$prog}}) );
270 I found the following locations for these programs:
273 foreach my $prog ( sort(keys(%Programs)) ) {
274 printf(" %-12s => %s\n", $prog, $Conf{$Programs{$prog}});
277 last if (prompt('--> Are these paths correct?', 'y') =~ /^y/i);
278 foreach my $prog ( sort(keys(%Programs)) ) {
279 $Conf{$Programs{$prog}} = prompt("--> $prog path",
280 $Conf{$Programs{$prog}});
284 my $Perl58 = system($Conf{PerlPath}
285 . q{ -e 'exit($^V && $^V ge v5.8.0 ? 1 : 0);'});
290 BackupPC needs perl version 5.8.0 or later. $Conf{PerlPath} appears
291 to be an older version. Please upgrade to a newer version of perl
292 and re-run this configure script.
300 Please tell me the hostname of the machine that BackupPC will run on.
303 chomp($Conf{ServerHost} = `$Conf{HostnamePath}`)
304 if ( defined($Conf{HostnamePath}) && !defined($Conf{ServerHost}) );
305 $Conf{ServerHost} = prompt("--> BackupPC will run on host",
311 BackupPC should run as a dedicated user with limited privileges. You
312 need to create a user. This user will need read/write permission on
313 the main data directory and read/execute permission on the install
314 directory (these directories will be setup shortly).
316 The primary group for this user should also be chosen carefully.
317 The data directories and files will have group read permission,
318 so group members can access backup files.
321 my($name, $passwd, $Uid, $Gid);
323 $Conf{BackupPCUser} = prompt("--> BackupPC should run as user",
324 $Conf{BackupPCUser} || "backuppc",
326 if ( $opts{"set-perms"} ) {
327 ($name, $passwd, $Uid, $Gid) = getpwnam($Conf{BackupPCUser});
328 last if ( $name ne "" );
331 getpwnam() says that user $Conf{BackupPCUser} doesn't exist. Please
332 check the name and verify that this user is in the passwd file.
335 exit(1) if ( $opts{batch} );
341 Please specify an install directory for BackupPC. This is where the
342 BackupPC scripts, library and documentation will be installed.
347 $Conf{InstallDir} = prompt("--> Install directory (full path)",
350 last if ( $Conf{InstallDir} =~ /^\// );
351 if ( $opts{batch} ) {
352 print("Need to specify --install-dir for new installation\n");
359 Please specify a data directory for BackupPC. This is where all the
360 PC backup data is stored. This file system needs to be big enough to
361 accommodate all the PCs you expect to backup (eg: at least several GB
367 $Conf{TopDir} = prompt("--> Data directory (full path)",
370 last if ( $Conf{TopDir} =~ /^\// );
371 if ( $opts{batch} ) {
372 print("Need to specify --data-dir for new installation\n");
377 $Conf{CompressLevel} = $opts{"compress-level"}
378 if ( defined($opts{"compress-level"}) );
380 if ( !defined($Conf{CompressLevel}) ) {
381 $Conf{CompressLevel} = BackupPC::FileZIO->compOk ? 3 : 0;
382 if ( $ConfigPath eq "" && $Conf{CompressLevel} ) {
385 BackupPC can compress pool files, providing around a 40% reduction in pool
386 size (your mileage may vary). Specify the compression level (0 turns
387 off compression, and 1 to 9 represent good/fastest to best/slowest).
388 The recommended values are 0 (off) or 3 (reasonable compression and speed).
389 Increasing the compression level to 5 will use around 20% more cpu time
390 and give perhaps 2-3% more compression.
393 } elsif ( $ConfigPath eq "" ) {
396 BackupPC can compress pool files, but it needs the Compress::Zlib
397 package installed (see www.cpan.org). Compression will provide around a
398 40% reduction in pool size, at the expense of cpu time. You can leave
399 compression off and run BackupPC without compression, in which case you
400 should leave the compression level at 0 (which means off). You could
401 install Compress::Zlib and turn compression on later, but read the
402 documentation first about how to do this. Or the better choice is
403 to quit, install Compress::Zlib, and re-run configure.pl.
406 } elsif ( $Conf{CompressLevel} ) {
407 $Conf{CompressLevel} = 0;
410 BackupPC now supports pool file compression. Since you are upgrading
411 BackupPC you probably have existing uncompressed backups. You have
412 several choices if you want to turn on compression. You can run
413 the script BackupPC_compressPool to convert everything to compressed
414 form. Or you can simply turn on compression, so that new backups
415 will be compressed. This will increase the pool storage requirement,
416 since both uncompressed and compressed copies of files will be stored.
417 But eventually the old uncompressed backups will expire, recovering
418 the pool storage. Please see the documentation for more details.
420 If you are not sure what to do, leave the Compression Level at 0,
421 which disables compression. You can always read the documentation
422 and turn it on later.
426 $Conf{CompressLevel} = 0;
429 BackupPC now supports pool file compression, but it needs the
430 Compress::Zlib module (see www.cpan.org). For now, leave
431 the compression level set at 0 to disable compression. If you
432 want you can install Compress::Zlib and turn compression on.
433 Please see the documentation for more details about converting
434 old backups to compressed form.
440 = prompt("--> Compression level", $Conf{CompressLevel});
441 last if ( $Conf{CompressLevel} =~ /^\d+$/ );
447 BackupPC has a powerful CGI perl interface that runs under Apache.
448 A single executable needs to be installed in a cgi-bin directory.
449 This executable needs to run as set-uid $Conf{BackupPCUser}, or
450 it can be run under mod_perl with Apache running as user $Conf{BackupPCUser}.
452 Leave this path empty if you don't want to install the CGI interface.
457 $Conf{CgiDir} = prompt("--> CGI bin directory (full path)",
460 last if ( $Conf{CgiDir} =~ /^\// || $Conf{CgiDir} eq "" );
461 if ( $opts{batch} ) {
462 print("Need to specify --cgi-dir for new installation\n");
467 if ( $Conf{CgiDir} ne "" ) {
471 BackupPC's CGI script needs to display various GIF images that
472 should be stored where Apache can serve them. They should be
473 placed somewher under Apache's DocumentRoot. BackupPC also
474 needs to know the URL to access these images. Example:
476 Apache image directory: /usr/local/apache/htdocs/BackupPC
477 URL for image directory: /BackupPC
479 The URL for the image directory should start with a slash.
483 $Conf{CgiImageDir} = prompt("--> Apache image directory (full path)",
486 last if ( $Conf{CgiImageDir} =~ /^\// );
487 if ( $opts{batch} ) {
488 print("Need to specify --html-dir for new installation\n");
493 $Conf{CgiImageDirURL} = prompt("--> URL for image directory (omit http://host; starts with '/')",
494 $Conf{CgiImageDirURL},
496 last if ( $Conf{CgiImageDirURL} =~ /^\// );
497 if ( $opts{batch} ) {
498 print("Need to specify --html-dir-url for new installation\n");
508 - install the binaries, lib and docs in $Conf{InstallDir},
509 - create the data directory $Conf{TopDir},
510 - create/update the config.pl file $Conf{ConfDir}/config.pl,
511 - optionally install the cgi-bin interface.
515 exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
518 # Create install directories
520 foreach my $dir ( qw(bin doc
528 next if ( -d "$DestDir$Conf{InstallDir}/$dir" );
529 mkpath("$DestDir$Conf{InstallDir}/$dir", 0, 0755);
530 if ( !-d "$DestDir$Conf{InstallDir}/$dir"
531 || !my_chown($Uid, $Gid, "$DestDir$Conf{InstallDir}/$dir") ) {
532 die("Failed to create or chown $DestDir$Conf{InstallDir}/$dir\n");
534 print("Created $DestDir$Conf{InstallDir}/$dir\n");
539 # Create CGI image directory
541 foreach my $dir ( ($Conf{CgiImageDir}) ) {
542 next if ( $dir eq "" || -d $dir );
543 mkpath("$DestDir$dir", 0, 0755);
544 if ( !-d "$DestDir$dir" || !my_chown($Uid, $Gid, "$DestDir$dir") ) {
545 die("Failed to create or chown $DestDir$dir");
547 print("Created $DestDir$dir\n");
552 # Create other directories
556 "$Conf{TopDir}/pool",
557 "$Conf{TopDir}/cpool",
559 "$Conf{TopDir}/trash",
563 mkpath("$DestDir$dir", 0, 0750) if ( !-d "$DestDir$dir" );
564 if ( !-d "$DestDir$dir"
565 || !my_chown($Uid, $Gid, "$DestDir$dir") ) {
566 die("Failed to create or chown $DestDir$dir\n");
568 print("Created $DestDir$dir\n");
572 printf("Installing binaries in $DestDir$Conf{InstallDir}/bin\n");
573 foreach my $prog ( qw(
574 __CONFIGURE_BIN_LIST__
576 InstallFile($prog, "$DestDir$Conf{InstallDir}/$prog", 0555);
579 printf("Installing library in $DestDir$Conf{InstallDir}/lib\n");
580 foreach my $lib ( qw(
581 __CONFIGURE_LIB_LIST__
583 InstallFile($lib, "$DestDir$Conf{InstallDir}/$lib", 0444);
586 if ( $Conf{CgiImageDir} ne "" ) {
587 printf("Installing images in $DestDir$Conf{CgiImageDir}\n");
588 foreach my $img ( <images/*> ) {
589 (my $destImg = $img) =~ s{^images/}{};
590 InstallFile($img, "$DestDir$Conf{CgiImageDir}/$destImg", 0444, 1);
594 # Install new CSS file, making a backup copy if necessary
596 my $cssBackup = "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css.pre-__VERSION__";
597 if ( -f "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css" && !-f $cssBackup ) {
598 rename("$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", $cssBackup);
600 InstallFile("conf/BackupPC_stnd.css",
601 "$DestDir$Conf{CgiImageDir}/BackupPC_stnd.css", 0444, 0);
602 InstallFile("conf/BackupPC_stnd_orig.css",
603 "$DestDir$Conf{CgiImageDir}/BackupPC_stnd_orig.css", 0444, 0);
606 printf("Making init.d scripts\n");
607 foreach my $init ( qw(gentoo-backuppc gentoo-backuppc.conf linux-backuppc
608 solaris-backuppc debian-backuppc suse-backuppc
609 slackware-backuppc ) ) {
610 InstallFile("init.d/src/$init", "init.d/$init", 0444);
613 printf("Installing docs in $DestDir$Conf{InstallDir}/doc\n");
614 foreach my $doc ( qw(BackupPC.pod BackupPC.html) ) {
615 InstallFile("doc/$doc", "$DestDir$Conf{InstallDir}/doc/$doc", 0444);
618 printf("Installing config.pl and hosts in $DestDir$Conf{ConfDir}\n");
619 InstallFile("conf/hosts", "$DestDir$Conf{ConfDir}/hosts", 0644)
620 if ( !-f "$DestDir$Conf{ConfDir}/hosts" );
623 # Now do the config file. If there is an existing config file we
624 # merge in the new config file, adding any new configuration
625 # parameters and deleting ones that are no longer needed.
627 my $dest = "$DestDir$Conf{ConfDir}/config.pl";
628 my ($distConf, $distVars) = ConfigParse("conf/config.pl");
629 my ($oldConf, $oldVars);
630 my ($newConf, $newVars) = ($distConf, $distVars);
632 ($oldConf, $oldVars) = ConfigParse($dest);
633 ($newConf, $newVars) = ConfigMerge($oldConf, $oldVars, $distConf, $distVars);
637 # Update various config parameters. The old config is in Conf{}
638 # and the new config is an array in text form in $newConf->[].
640 $Conf{EMailFromUserName} ||= $Conf{BackupPCUser};
641 $Conf{EMailAdminUserName} ||= $Conf{BackupPCUser};
644 # Guess $Conf{CgiURL}
646 if ( !defined($Conf{CgiURL}) ) {
647 if ( $Conf{CgiDir} =~ m{cgi-bin(/.*)} ) {
648 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin$1/BackupPC_Admin'";
650 $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin/BackupPC_Admin'";
655 # The smbclient commands have moved from hard-coded to the config file.
656 # $Conf{SmbClientArgs} no longer exists, so merge it into the new
657 # commands if it still exists.
659 if ( defined($Conf{SmbClientArgs}) ) {
660 if ( $Conf{SmbClientArgs} ne "" ) {
661 foreach my $param ( qw(SmbClientRestoreCmd SmbClientFullCmd
662 SmbClientIncrCmd) ) {
663 $newConf->[$newVars->{$param}]{text}
664 =~ s/(-E\s+-N)/$1 $Conf{SmbClientArgs}/;
667 delete($Conf{SmbClientArgs});
671 # CSS is now stored in a file rather than a big config variable.
673 delete($Conf{CSSstylesheet});
676 # The blackout timing settings are now stored in a list of hashes, rather
677 # than three scalar parameters.
679 if ( defined($Conf{BlackoutHourBegin}) ) {
680 $Conf{BlackoutPeriods} = [
682 hourBegin => $Conf{BlackoutHourBegin},
683 hourEnd => $Conf{BlackoutHourEnd},
684 weekDays => $Conf{BlackoutWeekDays},
687 delete($Conf{BlackoutHourBegin});
688 delete($Conf{BlackoutHourEnd});
689 delete($Conf{BlackoutWeekDays});
693 # $Conf{RsyncLogLevel} has been replaced by $Conf{XferLogLevel}
695 if ( defined($Conf{RsyncLogLevel}) ) {
696 $Conf{XferLogLevel} = $Conf{RsyncLogLevel};
697 delete($Conf{RsyncLogLevel});
701 # In 2.1.0 the default for $Conf{CgiNavBarAdminAllHosts} is now 1
703 $Conf{CgiNavBarAdminAllHosts} = 1;
706 # IncrFill should now be off
711 # Figure out sensible arguments for the ping command
713 if ( defined($Conf{PingArgs}) ) {
714 $Conf{PingCmd} = '$pingPath ' . $Conf{PingArgs};
715 } elsif ( !defined($Conf{PingCmd}) ) {
716 if ( $^O eq "solaris" || $^O eq "sunos" ) {
717 $Conf{PingCmd} = '$pingPath -s $host 56 1';
718 } elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
719 && !system("$Conf{PingPath} -c 1 -w 3 localhost") ) {
720 $Conf{PingCmd} = '$pingPath -c 1 -w 3 $host';
722 $Conf{PingCmd} = '$pingPath -c 1 $host';
724 delete($Conf{PingArgs});
728 # Figure out sensible arguments for the df command
730 if ( !defined($Conf{DfCmd}) ) {
731 if ( $^O eq "solaris" || $^O eq "sunos" ) {
732 $Conf{DfCmd} = '$dfPath -k $topDir';
737 # $Conf{SmbClientTimeout} is now $Conf{ClientTimeout}
739 if ( defined($Conf{SmbClientTimeout}) ) {
740 $Conf{ClientTimeout} = $Conf{SmbClientTimeout};
741 delete($Conf{SmbClientTimeout});
745 # Replace --devices with -D in RsyncArgs and RsyncRestoreArgs
747 foreach my $param ( qw(RsyncArgs RsyncRestoreArgs) ) {
748 next if ( !defined($newVars->{$param}) );
749 $newConf->[$newVars->{$param}]{text} =~ s/--devices/-D/g;
753 # Merge any new user-editable parameters into CgiUserConfigEdit
754 # by copying the old settings forward.
756 if ( defined($Conf{CgiUserConfigEdit}) ) {
758 # This is a real hack. The config file merging is done in text
759 # form without actually instantiating the new conf structure.
760 # So we need to extract the new hash of settings, update it,
761 # and merge the text. Ugh...
764 my $str = $distConf->[$distVars->{CgiUserConfigEdit}]{text};
766 $str =~ s/^\s*\$Conf\{.*?\}\s*=\s*/\$new = /m;
768 foreach my $p ( keys(%$new) ) {
769 $new->{$p} = $Conf{CgiUserConfigEdit}{$p}
770 if ( defined($Conf{CgiUserConfigEdit}{$p}) );
772 $Conf{CgiUserConfigEdit} = $new;
773 my $d = Data::Dumper->new([$new], [*value]);
776 my $value = $d->Dump;
777 $value =~ s/(.*)\n/$1;\n/s;
778 $newConf->[$newVars->{CgiUserConfigEdit}]{text}
779 =~ s/(\s*\$Conf\{.*?\}\s*=\s*).*/$1$value/s;
783 # Now backup and write the config file
785 my $confCopy = "$dest.pre-__VERSION__";
786 if ( -f $dest && !-f $confCopy ) {
788 # Make copy of config file, preserving ownership and modes
790 printf("Making backup copy of $dest -> $confCopy\n");
791 my @stat = stat($dest);
795 die("can't copy($dest, $confCopy)\n")
796 unless copy($dest, $confCopy);
797 die("can't chown $uid, $gid $confCopy\n")
798 unless my_chown($uid, $gid, $confCopy);
799 die("can't chmod $mode $confCopy\n")
800 unless my_chmod($mode, $confCopy);
802 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
805 foreach my $var ( @$newConf ) {
806 if ( length($blockComment)
807 && substr($var->{text}, 0, length($blockComment)) eq $blockComment ) {
808 $var->{text} = substr($var->{text}, length($blockComment));
809 $blockComment = undef;
811 $blockComment = $1 if ( $var->{text} =~ /^([\s\n]*#{70}.*#{70}[\s\n]+)/s );
812 $var->{text} =~ s/^\s*\$Conf\{(.*?)\}(\s*=\s*['"]?)(.*?)(['"]?\s*;)/
813 defined($Conf{$1}) && ref($Conf{$1}) eq ""
814 && $Conf{$1} ne $OrigConf{$1}
815 ? "\$Conf{$1}$2$Conf{$1}$4"
816 : "\$Conf{$1}$2$3$4"/emg;
817 print OUT $var->{text};
820 if ( !defined($oldConf) ) {
821 die("can't chmod 0640 mode $dest\n") unless my_chmod(0640, $dest);
822 die("can't chown $Uid, $Gid $dest\n") unless my_chown($Uid, $Gid, $dest);
825 if ( $Conf{CgiDir} ne "" ) {
826 printf("Installing cgi script BackupPC_Admin in $DestDir$Conf{CgiDir}\n");
827 mkpath("$DestDir$Conf{CgiDir}", 0, 0755);
828 InstallFile("cgi-bin/BackupPC_Admin", "$DestDir$Conf{CgiDir}/BackupPC_Admin",
834 Ok, it looks like we are finished. There are several more things you
837 - Browse through the config file, $Conf{ConfDir}/config.pl,
838 and make sure all the settings are correct. In particular,
839 you will need to set \$Conf{CgiAdminUsers} so you have
840 administration privileges in the CGI interface.
842 - Edit the list of hosts to backup in $Conf{ConfDir}/hosts.
844 - Read the documentation in $Conf{InstallDir}/doc/BackupPC.html.
845 Please pay special attention to the security section.
847 - Verify that the CGI script BackupPC_Admin runs correctly. You might
848 need to change the permissions or group ownership of BackupPC_Admin.
850 - BackupPC should be ready to start. Don't forget to run it
851 as user $Conf{BackupPCUser}! The installation also contains an
852 init.d/backuppc script that can be copied to /etc/init.d
853 so that BackupPC can auto-start on boot. This will also enable
854 administrative users to start the server from the CGI interface.
860 if ( `$Conf{PerlPath} -V` =~ /uselargefiles=undef/ ) {
863 Warning: your perl, $Conf{PerlPath}, does not support large files.
864 This means BackupPC won't be able to backup files larger than 2GB.
865 To solve this problem you should build/install a new version of perl
866 with large file support enabled. Use
868 $Conf{PerlPath} -V | egrep uselargefiles
870 to check if perl has large file support (undef means no support).
874 eval "use File::RsyncP;";
875 if ( !$@ && $File::RsyncP::VERSION < 0.68 ) {
876 print("\nWarning: you need to upgrade File::RsyncP;"
877 . " I found $File::RsyncP::VERSION and BackupPC needs 0.68\n");
882 ###########################################################################
884 ###########################################################################
888 my($prog, $dest, $mode, $binary) = @_;
890 my($uid, $gid) = ($Uid, $Gid);
894 # preserve ownership and modes of files that already exist
896 my @stat = stat($dest);
901 unlink($dest) if ( -f $dest );
903 die("can't copy($prog, $dest)\n") unless copy($prog, $dest);
905 open(PROG, $prog) || die("can't open $prog for reading\n");
906 open(OUT, ">", $dest) || die("can't open $dest for writing\n");
910 s/__INSTALLDIR__/$Conf{InstallDir}/g;
911 s/__LOGDIR__/$Conf{LogDir}/g;
912 s/__CONFDIR__/$Conf{ConfDir}/g;
913 s/__TOPDIR__/$Conf{TopDir}/g;
914 s/^(\s*my \$useFHS\s*=\s*)\d;/${1}$opts{fhs};/
915 if ( $prog =~ /Lib.pm/ );
916 s/__BACKUPPCUSER__/$Conf{BackupPCUser}/g;
917 s/__CGIDIR__/$Conf{CgiDir}/g;
918 if ( $first && /^#.*bin\/perl/ ) {
920 # Fill in correct path to perl (no taint for >= 2.0.1).
922 print OUT "#!$Conf{PerlPath}\n";
931 die("can't chown $uid, $gid $dest") unless my_chown($uid, $gid, $dest);
932 die("can't chmod $mode $dest") unless my_chmod($mode, $dest);
937 my($path, $prog) = @_;
939 if ( defined($opts{"bin-path"}{$prog}) ) {
940 return $opts{"bin-path"}{$prog};
942 foreach my $dir ( split(/:/, $path) ) {
943 my $file = File::Spec->catfile($dir, $prog);
944 return $file if ( -x $file );
952 open(C, $file) || die("can't open $file");
954 my($out, @conf, $var);
959 if ( /^#/ && !defined($endLine) ) {
964 $allVars->{$var} = @conf if ( defined($var) );
974 } elsif ( /^\s*\$Conf\{([^}]*)/ ) {
976 if ( defined($var) ) {
977 $allVars->{$var} = @conf if ( defined($var) );
987 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<(.*);/ );
988 $endLine = $1 if ( /^\s*\$Conf\{[^}]*} *= *<<'(.*)';/ );
990 $endLine = undef if ( defined($endLine) && /^\Q$endLine[\n\r]*$/ );
995 $allVars->{$var} = @conf if ( defined($var) );
1002 return (\@conf, $allVars);
1007 my($old, $oldVars, $new, $newVars) = @_;
1012 # Find which config parameters are not needed any longer
1014 foreach my $var ( @$old ) {
1015 next if ( !defined($var->{var}) || defined($newVars->{$var->{var}}) );
1016 #print(STDERR "Deleting old config parameter $var->{var}\n");
1020 # Find which config parameters are new
1022 foreach my $var ( @$new ) {
1023 next if ( !defined($var->{var}) );
1024 if ( defined($oldVars->{$var->{var}}) ) {
1025 $posn = $oldVars->{$var->{var}};
1027 #print(STDERR "New config parameter $var->{var}: $var->{text}\n");
1028 push(@{$old->[$posn]{new}}, $var);
1032 # Create merged config file
1034 foreach my $var ( @$old ) {
1035 next if ( $var->{delete} );
1037 foreach my $new ( @{$var->{new}} ) {
1041 for ( my $i = 0 ; $i < @$res ; $i++ ) {
1042 $resVars->{$res->[$i]{var}} = $i;
1044 return ($res, $resVars);
1049 my($uid, $gid, $file) = @_;
1051 return 1 if ( !$opts{"set-perms"} );
1052 return chown($uid, $gid, $file);
1057 my ($mode, $file) = @_;
1059 return 1 if ( !$opts{"set-perms"} );
1060 return chmod($mode, $file);
1065 my($question, $default, $option) = @_;
1067 $default = $opts{$option} if ( defined($opts{$option}) );
1068 if ( $opts{batch} ) {
1069 print("$question [$default]\n");
1072 print("$question [$default]? ");
1073 my $reply = <STDIN>;
1074 $reply =~ s/[\n\r]*//g;
1075 return $reply if ( $reply !~ /^$/ );
1083 configure.pl [options]
1087 configure.pl is a script that is used to install or upgrade a BackupPC
1088 installation. It is usually run interactively without arguments. It
1089 also supports a batch mode where all the options can be specified
1090 via the command-line.
1092 For upgrading BackupPC you need to make sure that BackupPC is not
1093 running prior to running BackupPC.
1095 Typically configure.pl needs to run as the super user (root).
1103 Run configure.pl in batch mode. configure.pl will run without
1104 prompting the user. The other command-line options are used
1105 to specify the settings that the user is usually prompted for.
1107 =item B<--backuppc-user=USER>
1109 Specify the BackupPC user name that owns all the BackupPC
1110 files and runs the BackupPC programs. Default is backuppc.
1112 =item B<--bin-path PROG=PATH>
1114 Specify the path for various external programs that BackupPC
1115 uses. Several --bin-path options may be specified. configure.pl
1116 usually finds sensible defaults based on searching the PATH.
1119 --bin-path PROG=PATH
1121 where PROG is one of perl, tar, smbclient, nmblookup, rsync, ping,
1122 df, ssh, sendmail, hostname, split, par2, cat, gzip, bzip2 and
1123 PATH is that full path to that program.
1127 --bin-path cat=/bin/cat --bin-path bzip2=/home/user/bzip2
1129 =item B<--compress-level=N>
1131 Set the configuration compression level to N. Default is 3
1132 if Compress::Zlib is installed.
1134 =item B<--config-dir CONFIG_DIR>
1136 Configuration directory for new installations. Defaults
1137 to /etc/BackupPC with FHS. Automatically extracted
1138 from --config-path for existing installations.
1140 =item B<--config-path CONFIG_PATH>
1142 Path to the existing config.pl configuration file for BackupPC.
1143 This option should be specified for batch upgrades to an
1144 existing installation. The option should be omitted when
1145 doing a batch new install.
1147 =item B<--cgi-dir CGI_DIR>
1149 Path to Apache's cgi-bin directory where the BackupPC_Admin
1150 script will be installed. This option only needs to be
1151 specified for a batch new install.
1153 =item B<--data-dir DATA_DIR>
1155 Path to the BackupPC data directory. This is where all the backup
1156 data is stored, and it should be on a large file system. This option
1157 only needs to be specified for a batch new install.
1161 --data-dir /data/BackupPC
1163 =item B<--dest-dir DEST_DIR>
1165 An optional prefix to apply to all installation directories.
1166 Usually this is not needed, but certain auto-installers like
1167 to stage an install in a temporary directory, and then copy
1168 the files to their real destination. This option can be used
1169 to specify the temporary directory prefix. Note that if you
1170 specify this option, BackupPC won't run correctly if you try
1171 to run it from below the --dest-dir directory, since all the
1172 paths are set assuming BackupPC is installed in the intended
1177 Use locations specified by the Filesystem Hierarchy Standard
1178 for installing BackupPC. This is enabled by default for new
1179 installatios. To use the pre-3.0 installation locations,
1184 Print a brief help message and exits.
1186 =item B<--hostname HOSTNAME>
1188 Host name (this machine's name) on which BackupPC is being installed.
1189 This option only needs to be specified for a batch new install.
1191 =item B<--html-dir HTML_DIR>
1193 Path to an Apache html directory where various BackupPC image files
1194 and the CSS files will be installed. This is typically a directory
1195 below Apache's DocumentRoot directory. This option only needs to be
1196 specified for a batch new install.
1200 --html-dir /usr/local/apache/htdocs/BackupPC
1202 =item B<--html-dir-url URL>
1204 The URL (without http://hostname) required to access the BackupPC html
1205 directory specified with the --html-dir option. This option only needs
1206 to be specified for a batch new install.
1210 --html-dir-url /BackupPC
1212 =item B<--install-dir INSTALL_DIR>
1214 Installation directory for BackupPC scripts, libraries, and
1215 documentation. This option only needs to be specified for a
1220 --install-dir /usr/local/BackupPC
1222 =item B<--log-dir LOG_DIR>
1224 Log directory. Defaults to /var/log/BackupPC with FHS.
1228 Prints the manual page and exits.
1230 =item B<--set-perms>
1232 When installing files and creating directories, chown them to
1233 the BackupPC user and chmod them too. This is enabled by default.
1234 To disable (for example, if staging a destination directory)
1235 then specify --no-set-perms.
1237 =item B<--uid-ignore>
1239 configure.pl verifies that the script is being run as the super user
1240 (root). Without the --uid-ignore option, in batch mode the script will
1241 exit with an error if not run as the super user, and in interactive mode
1242 the user will be prompted. Specifying this option will cause the script
1243 to continue even if the user id is not root.
1247 For a standard interactive install, run without arguments:
1251 For a batch new install you need to specify answers to all the
1252 questions that are normally prompted:
1256 --cgi-dir /var/www/cgi-bin/BackupPC \
1257 --data-dir /data/BackupPC \
1259 --html-dir /var/www/html/BackupPC \
1260 --html-dir-url /BackupPC \
1261 --install-dir /usr/local/BackupPC
1263 For a batch upgrade, you only need to specify the path to the
1266 configure.pl --batch --config-path /data/BackupPC/conf/config.pl
1270 Craig Barratt <cbarratt@users.sourceforge.net>
1274 Copyright (C) 2001-2006 Craig Barratt.
1276 This program is free software; you can redistribute it and/or modify
1277 it under the terms of the GNU General Public License as published by
1278 the Free Software Foundation; either version 2 of the License, or
1279 (at your option) any later version.