]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/pakfire/lib/functions.pl
Merge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into next
[ipfire-2.x.git] / src / pakfire / lib / functions.pl
index 0d8e8af3762bffb5c4e6cd685e1120182974cd5e..6bf85afdca3895b7b4c32a2387e44cd5d66f0f0c 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+# Copyright (C) 2007-2015   IPFire Team   <info@ipfire.org>                   #
 #                                                                             #
 # 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        #
@@ -116,7 +116,7 @@ sub usage {
 sub pinghost {
        my $host = shift;
        
-       $p = Net::Ping->new();
+       $p = Net::Ping->new("icmp");
   if ($p->ping($host)) {
         logger("PING INFO: $host is alive");
        return 1;
@@ -220,7 +220,7 @@ sub fetchfile {
                                        $allok = 1;
                                        return 0;
                                } else {
-                                       logger("DOWNLOAD ERROR: Could not open $Conf::cachedir/$bfile for writing.");
+                                       logger("DOWNLOAD ERROR: Could not open $Conf::tmpdir/$bfile for writing.");
                                }
                        } else {
                                return 0;
@@ -305,7 +305,12 @@ sub selectmirror {
                }
        }
        logger("MIRROR INFO: $scount servers found in list");
-       
+
+       if ($scount eq 0) {
+               logger("MIRROR INFO: Could not find any servers. Falling back to main server $Conf::mainserver");
+               return ("HTTP", $Conf::mainserver, "/$Conf::version");
+       }
+
        ### Choose a random server and test if it is online
        #   If the check fails try a new server.
        #   This will never give up.
@@ -324,7 +329,12 @@ 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);
                                }
@@ -364,6 +374,52 @@ sub dbgetlist {
                fetchfile("lists/packages_list.db", "");
                move("$Conf::cachedir/packages_list.db", "$Conf::dbdir/lists/packages_list.db");
        }
+
+       # Update the meta database if new packages was in the package list
+       my @meta;
+       my $file;
+       my $line;
+       my $prog;
+       my ($name, $version, $release);
+       my @templine;
+
+       open(FILE, "<$Conf::dbdir/lists/packages_list.db");
+       my @db = <FILE>;
+       close(FILE);
+
+       opendir(DIR,"$Conf::dbdir/meta");
+       my @files = readdir(DIR);
+       closedir(DIR);
+       foreach $file (@files) {
+               next if ( $file eq "." );
+               next if ( $file eq ".." );
+               next if ( $file eq "meta-" );
+               next if ( $file =~ /^old/ );
+               open(FILE, "<$Conf::dbdir/meta/$file");
+               @meta = <FILE>;
+               close(FILE);
+               foreach $line (@meta) {
+                       @templine = split(/\: /,$line);
+                       if ("$templine[0]" eq "Name") {
+                               $name = $templine[1];
+                               chomp($name);
+                       } elsif ("$templine[0]" eq "ProgVersion") {
+                               $version = $templine[1];
+                               chomp($version);
+                       } elsif ("$templine[0]" eq "Release") {
+                               $release = $templine[1];
+                               chomp($release);
+                       }
+               }
+               foreach $prog (@db) {
+                       @templine = split(/\;/,$prog);
+                       if (("$name" eq "$templine[0]") && ("$release" ne "$templine[2]")) {
+                               move("$Conf::dbdir/meta/meta-$name","$Conf::dbdir/meta/old_meta-$name");
+                               fetchfile("meta/meta-$name", "");
+                               move("$Conf::cachedir/meta-$name", "$Conf::dbdir/meta/meta-$name");
+                       }
+               }
+       }
 }
 
 sub dblist {
@@ -389,11 +445,14 @@ sub dblist {
        close(FILE);
 
        if ("$filter" eq "upgrade") {
-               if ("$forweb" ne "forweb") {getcoredb("noforce");}
+               if ("$forweb" ne "forweb" && "$forweb" ne "notice" ) {getcoredb("noforce");}
                eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
                if ("$core_release" > "$Conf::core_mine") {
                        if ("$forweb" eq "forweb") {
                                print "<option value=\"core\">Core-Update -- $Conf::version -- Release: $Conf::core_mine -> $core_release</option>\n";
+                       }
+                       elsif ("$forweb" eq "notice") {
+                               print "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $Conf::core_mine $Lang::tr{'core notice 2'} $core_release $Lang::tr{'core notice 3'}</a>";
                        } else {
                                my $command = "Core-Update $Conf::version\nRelease: $Conf::core_mine -> $core_release\n";
                                if ("$Pakfire::enable_colors" eq "1") {
@@ -429,7 +488,7 @@ sub dblist {
                        }
                        foreach $prog (@db) {
                                @templine = split(/\;/,$prog);
-                               if (("$name" eq "$templine[0]") && ("$release" < "$templine[2]" )) {
+                               if (("$name" eq "$templine[0]") && ("$release" < "$templine[2]" && "$forweb" ne "notice")) {
                                        push(@updatepaks,$name);
                                        if ("$forweb" eq "forweb") {
                                                print "<option value=\"$name\">Update: $name -- Version: $version -> $templine[1] -- Release: $release -> $templine[2]</option>\n";
@@ -531,6 +590,25 @@ sub resolvedeps {
        return @all;
 }
 
+sub resolvedeps_recursive {
+       my @packages = shift;
+       my @result = ();
+
+       foreach my $pkg (@packages) {
+               my @deps = &Pakfire::resolvedeps($pkg);
+
+               foreach my $dep (@deps) {
+                       push(@result, $dep);
+               }
+       }
+
+       # Sort the result array and remove dupes
+       my %sort = map{ $_, 1 } @result;
+       @result = keys %sort;
+
+       return @result;
+}
+
 sub cleanup {
        my $dir = shift;
        my $path;
@@ -637,7 +715,7 @@ sub getpak {
        }
        
        unless ($file) {
-               message("No filename given in meta-file. Please phone the developers.");
+               message("No filename given in meta-file.");
                exit 1;
        }
        
@@ -812,7 +890,7 @@ sub checkcryptodb {
        unless ( "$ret" eq "0" ) {
                message("CRYPTO WARN: The GnuPG isn't configured corectly. Trying now to fix this.");
                message("CRYPTO WARN: It's normal to see this on first execution.");
-               my $command = "gpg --keyserver pgp.mit.edu --always-trust --status-fd 2";
+               my $command = "gpg --keyserver pgp.ipfire.org --always-trust --status-fd 2";
                system("$command --recv-key $myid >> $Conf::logdir/gnupg-database.log 2>&1");
                system("$command --recv-key $trustid >> $Conf::logdir/gnupg-database.log 2>&1");
        } else {