]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/pakfire/lib/functions.pl
Added option to disable ping check for mirrors.
[people/pmueller/ipfire-2.x.git] / src / pakfire / lib / functions.pl
index 2bce1922c14e9c450503993310c9d1f622835474..d2ad7e34a479ebc53850648a78e7437a316288cf 100644 (file)
@@ -93,8 +93,8 @@ sub message {
 sub logger {
        my $log = shift;
        if ($log) {
-               system("echo \"`date`: $log\" >> /var/log/pakfire.log");
-               #system("logger -t pakfire \"$log\"");
+               #system("echo \"`date`: $log\" >> /var/log/pakfire.log");
+               system("logger -t pakfire \"$log\"");
        }
 }
 
@@ -118,7 +118,7 @@ sub pinghost {
        
        $p = Net::Ping->new();
   if ($p->ping($host)) {
-       logger("PING INFO: $host is alive");
+        logger("PING INFO: $host is alive");
        return 1;
   } else {
                logger("PING INFO: $host is unreachable");
@@ -211,6 +211,9 @@ sub fetchfile {
                                                move("$Conf::tmpdir/$bfile","$Conf::cachedir/$bfile");
                                        } else {
                                                message("DOWNLOAD ERROR: The downloaded file ($file) wasn't verified by IPFire.org. Sorry - Exiting...");
+                                               my $ntp = `ntpdate -q -t 10 pool.ntp.org 2>/dev/null | tail -1`;
+                                               if ( $ntp !~ /time\ server(.*)offset(.*)/ ){message("TIME ERROR: Unable to get the nettime, this may lead to the verification error.");}
+                                               else { $ntp =~ /time\ server(.*)offset(.*)/; message("TIME INFO: Time Server$1has$2 offset to localtime.");}
                                                exit 1;
                                        }
                                        logger("DOWNLOAD FINISHED: $file");
@@ -308,6 +311,7 @@ sub selectmirror {
        #   This will never give up.
        my $found = 0;
        my $servers = 0;
+       my $pingdelay = 1;
        while ($found == 0) {
                $server = int(rand($scount) + 1);
                $servers = 0;
@@ -320,9 +324,20 @@ sub selectmirror {
                                $proto = $templine[0];
                                $host = $templine[1];
                                $path = $templine[2];
-                               if (pinghost("$host")) {
+                               if ($pakfiresettings{'HEALTHCHECK'} eq "off") {
+                                       logger("PING INFO: Healthcheck is disabled");
                                        $found = 1;
                                        return ($proto, $host, $path);
+                               elsif (pinghost("$host")) {
+                                       $found = 1;
+                                       return ($proto, $host, $path);
+                               }
+                               if ($found == 0) {
+                                       sleep($pingdelay);
+                                       $pingdelay=$pingdelay*2;
+                                       if ($pingdelay>1200) {
+                                               $pingdelay=1200;
+                                       }
                                }
                        }
                }
@@ -378,7 +393,7 @@ sub dblist {
        close(FILE);
 
        if ("$filter" eq "upgrade") {
-               getcoredb("noforce");
+               if ("$forweb" ne "forweb") {getcoredb("noforce");}
                eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
                if ("$core_release" > "$Conf::core_mine") {
                        if ("$forweb" eq "forweb") {
@@ -393,13 +408,14 @@ sub dblist {
                        }
                }
        
-               opendir(DIR,"$Conf::dbdir/meta");
+               opendir(DIR,"$Conf::dbdir/installed");
                my @files = readdir(DIR);
                closedir(DIR);
                foreach $file (@files) {
                        next if ( $file eq "." );
                        next if ( $file eq ".." );
-                       open(FILE, "<$Conf::dbdir/meta/$file");
+                       next if ( $file =~ /^old/ );
+                       open(FILE, "<$Conf::dbdir/installed/$file");
                        @meta = <FILE>;
                        close(FILE);
                        foreach $line (@meta) {
@@ -544,7 +560,12 @@ sub cleanup {
 sub getmetafile {
        my $pak = shift;
        
-       unless ( -e "$Conf::dbdir/meta/meta-$pak") {
+       unless ( -e "$Conf::dbdir/meta/meta-$pak" ) {
+               fetchfile("meta/meta-$pak", "");
+               move("$Conf::cachedir/meta-$pak", "$Conf::dbdir/meta/meta-$pak");
+       }
+       
+       if ( -z "$Conf::dbdir/meta/meta-$pak" ) {
                fetchfile("meta/meta-$pak", "");
                move("$Conf::cachedir/meta-$pak", "$Conf::dbdir/meta/meta-$pak");
        }