* A failed full dump is now saved as a partial (incomplete) dump,
[BackupPC.git] / configure.pl
index b7a427a..0abc9a7 100755 (executable)
@@ -15,7 +15,7 @@
 #   Craig Barratt <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001  Craig Barratt
+#   Copyright (C) 2001-2003  Craig Barratt
 #
 #   This program is free software; you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #
 #========================================================================
 #
-# Version __VERSION__, released __RELEASEDATE__.
+# Version 2.0.0_CVS, released 18 Jan 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
+no  utf8;
 use vars qw(%Conf %OrigConf);
 use lib "./lib";
 
@@ -99,11 +100,11 @@ my $bpc;
 if ( $ConfigPath ne "" && -r $ConfigPath ) {
     (my $topDir = $ConfigPath) =~ s{/[^/]+/[^/]+$}{};
     die("BackupPC::Lib->new failed\n")
-            if ( !($bpc = BackupPC::Lib->new($topDir, ".")) );
+            if ( !($bpc = BackupPC::Lib->new($topDir, ".", 1)) );
     %Conf = $bpc->Conf();
     %OrigConf = %Conf;
     $Conf{TopDir} = $topDir;
-    my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1); 
+    my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}, 1);
     if ( $err eq "" ) {
         print <<EOF;
 
@@ -127,7 +128,7 @@ my %Programs = (
     rsync      => "RsyncClientPath",
     ping       => "PingPath",
     df         => "DfPath",
-    'ssh2/ssh' => "SshPath",
+    'ssh/ssh2' => "SshPath",
     sendmail   => "SendmailPath",
     hostname   => "HostnamePath",
 );
@@ -359,8 +360,12 @@ exit unless prompt("--> Do you want to continue?", "y") =~ /y/i;
 #
 # Create install directories
 #
-foreach my $dir ( qw(bin lib/BackupPC/Xfer lib/BackupPC/Zip
-                    lib/BackupPC/Lang doc) ) {
+foreach my $dir ( qw(bin doc
+                    lib/BackupPC/CGI
+                    lib/BackupPC/Lang
+                    lib/BackupPC/Xfer
+                    lib/BackupPC/Zip
+                ) ) {
     next if ( -d "$Conf{InstallDir}/$dir" );
     mkpath("$Conf{InstallDir}/$dir", 0, 0775);
     if ( !-d "$Conf{InstallDir}/$dir"
@@ -411,11 +416,35 @@ foreach my $prog ( qw(BackupPC BackupPC_dump BackupPC_link BackupPC_nightly
 unlink("$Conf{InstallDir}/bin/BackupPC_queueAll");
 
 printf("Installing library in $Conf{InstallDir}/lib\n");
-foreach my $lib ( qw(BackupPC/Lib.pm BackupPC/FileZIO.pm BackupPC/Attrib.pm
-        BackupPC/PoolWrite.pm BackupPC/View.pm BackupPC/Xfer/Tar.pm
-        BackupPC/Xfer/Smb.pm BackupPC/Xfer/Rsync.pm
-        BackupPC/Xfer/RsyncFileIO.pm BackupPC/Zip/FileMember.pm
-        BackupPC/Lang/en.pm BackupPC/Lang/fr.pm
+foreach my $lib ( qw(
+       BackupPC/Lib.pm
+       BackupPC/FileZIO.pm
+       BackupPC/Attrib.pm
+        BackupPC/PoolWrite.pm
+       BackupPC/View.pm
+       BackupPC/Xfer/Tar.pm
+        BackupPC/Xfer/Smb.pm
+       BackupPC/Xfer/Rsync.pm
+        BackupPC/Xfer/RsyncFileIO.pm
+       BackupPC/Zip/FileMember.pm
+        BackupPC/Lang/en.pm
+       BackupPC/Lang/fr.pm
+       BackupPC/Lang/es.pm
+        BackupPC/Lang/de.pm
+       BackupPC/CGI/Browse.pm
+       BackupPC/CGI/DirHistory.pm
+       BackupPC/CGI/EmailSummary.pm
+       BackupPC/CGI/GeneralInfo.pm
+       BackupPC/CGI/HostInfo.pm
+       BackupPC/CGI/Lib.pm
+       BackupPC/CGI/LOGlist.pm
+       BackupPC/CGI/Queue.pm
+       BackupPC/CGI/RestoreFile.pm
+       BackupPC/CGI/RestoreInfo.pm
+       BackupPC/CGI/Restore.pm
+       BackupPC/CGI/StartStopBackup.pm
+       BackupPC/CGI/Summary.pm
+       BackupPC/CGI/View.pm
     ) ) {
     InstallFile("lib/$lib", "$Conf{InstallDir}/lib/$lib", 0444);
 }
@@ -429,7 +458,8 @@ if ( $Conf{CgiImageDir} ne "" ) {
 }
 
 printf("Making init.d scripts\n");
-foreach my $init ( qw(linux-backuppc solaris-backuppc debian-backuppc) ) {
+foreach my $init ( qw(gentoo-backuppc gentoo-backuppc.conf linux-backuppc
+                     solaris-backuppc debian-backuppc suse-backuppc) ) {
     InstallFile("init.d/src/$init", "init.d/$init", 0444);
 }
 
@@ -456,20 +486,75 @@ if ( -f $dest ) {
 }
 $Conf{EMailFromUserName}  ||= $Conf{BackupPCUser};
 $Conf{EMailAdminUserName} ||= $Conf{BackupPCUser};
+
+#
+# Update various config parameters
+#
+
+#
+# Guess $Conf{CgiURL}
+#
+if ( !defined($Conf{CgiURL}) ) {
+    if ( $Conf{CgiDir} =~ m{cgi-bin(/.*)} ) {
+       $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin$1/BackupPC_Admin'";
+    } else {
+       $Conf{CgiURL} = "'http://$Conf{ServerHost}/cgi-bin/BackupPC_Admin'";
+    }
+}
+
+#
+# The smbclient commands have moved from hard-coded to the config file.
+# $Conf{SmbClientArgs} no longer exists, so merge it into the new
+# commands if it still exists.
+#
+if ( defined($Conf{SmbClientArgs}) ) {
+    if ( $Conf{SmbClientArgs} ne "" ) {
+        foreach my $param ( qw(SmbClientRestoreCmd SmbClientFullCmd
+                                SmbClientIncrCmd) ) {
+            $newConf->[$newVars->{$param}]{text}
+                            =~ s/(-E\s+-N)/$1 $Conf{SmbClientArgs}/;
+        }
+    }
+    delete($Conf{SmbClientArgs});
+}
+
 #
 # IncrFill should now be off
 #
 $Conf{IncrFill} = 0;
+
 #
 # Figure out sensible arguments for the ping command
 #
-if ( $^O eq "solaris" || $^O eq "sunos" ) {
-    $Conf{PingArgs} ||= '-s $host 56 1';
-} elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
-        && !system("$Conf{PingClientPath} -c 1 -w 3 localhost") ) {
-    $Conf{PingArgs} ||= '-c 1 -w 3 $host';
-} else {
-    $Conf{PingArgs} ||= '-c 1 $host';
+if ( defined($Conf{PingArgs}) ) {
+    $Conf{PingCmd} = '$pingPath ' . $Conf{PingArgs};
+} elsif ( !defined($Conf{PingCmd}) ) {
+    if ( $^O eq "solaris" || $^O eq "sunos" ) {
+       $Conf{PingCmd} = '$pingPath -s $host 56 1';
+    } elsif ( ($^O eq "linux" || $^O eq "openbsd" || $^O eq "netbsd")
+           && !system("$Conf{PingClientPath} -c 1 -w 3 localhost") ) {
+       $Conf{PingCmd} = '$pingPath -c 1 -w 3 $host';
+    } else {
+       $Conf{PingCmd} = '$pingPath -c 1 $host';
+    }
+    delete($Conf{PingArgs});
+}
+
+#
+# Figure out sensible arguments for the df command
+#
+if ( !defined($Conf{DfCmd}) ) {
+    if ( $^O eq "solaris" || $^O eq "sunos" ) {
+       $Conf{DfCmd} = '$dfPath -k $topDir';
+    }
+}
+
+#
+# $Conf{SmbClientTimeout} is now $Conf{ClientTimeout}
+#
+if ( defined($Conf{SmbClientTimeout}) ) {
+    $Conf{ClientTimeout} = $Conf{SmbClientTimeout};
+    delete($Conf{SmbClientTimeout});
 }
 
 my $confCopy = "$dest.pre-__VERSION__";
@@ -487,7 +572,8 @@ if ( -f $dest && !-f $confCopy ) {
                                            unless chown($uid, $gid, $confCopy);
     die("can't chmod $mode $confCopy\n")   unless chmod($mode, $confCopy);
 }
-open(OUT, ">$dest") || die("can't open $dest for writing\n");
+open(OUT, ">", $dest) || die("can't open $dest for writing\n");
+binmode(OUT);
 my $blockComment;
 foreach my $var ( @$newConf ) {
     if ( length($blockComment)
@@ -518,7 +604,7 @@ if ( $Conf{CgiDir} ne "" ) {
 
 print <<EOF;
 
-Ok, it looks we are finished.  There are several more things you
+Ok, it looks like we are finished.  There are several more things you
 will need to do:
 
   - Browse through the config file, $Conf{TopDir}/conf/config.pl,
@@ -542,6 +628,20 @@ will need to do:
 Enjoy!
 EOF
 
+if ( $ENV{LANG} =~ /utf/i && $^V ge v5.8.0 ) {
+    print <<EOF;
+
+WARNING: Your LANG environment variable is set to $ENV{LANG}, which
+doesn't behave well with this version of perl.  Please set the
+LANG environment variable to en_US before running BackupPC.
+
+On RH-8 this setting is in the file /etc/sysconfig/i18n, or you
+could set it in BackupPC's init.d script.
+EOF
+}
+
+exit(0);
+
 ###########################################################################
 # Subroutines
 ###########################################################################
@@ -565,8 +665,10 @@ sub InstallFile
     if ( $binary ) {
        die("can't copy($prog, $dest)\n") unless copy($prog, $dest);
     } else {
-       open(PROG, $prog)   || die("can't open $prog for reading\n");
-       open(OUT, ">$dest") || die("can't open $dest for writing\n");
+       open(PROG, $prog)     || die("can't open $prog for reading\n");
+       open(OUT, ">", $dest) || die("can't open $dest for writing\n");
+       binmode(PROG);
+       binmode(OUT);
        while ( <PROG> ) {
            s/__INSTALLDIR__/$Conf{InstallDir}/g;
            s/__TOPDIR__/$Conf{TopDir}/g;
@@ -610,11 +712,12 @@ sub ConfigParse
 {
     my($file) = @_;
     open(C, $file) || die("can't open $file");
+    binmode(C);
     my($out, @conf, $var);
     my $comment = 1;
     my $allVars = {};
     while ( <C> ) {
-        if ( /^\s*#/ ) {
+        if ( /^#/ ) {
             if ( $comment ) {
                 $out .= $_;
             } else {
@@ -635,7 +738,7 @@ sub ConfigParse
                 $allVars->{$var} = @conf if ( defined($var) );
                 push(@conf, {
                     text => $out,
-                var => $var,
+                    var => $var,
                 });
                 $out = $_;
             } else {