X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=src%2Fpakfire%2Flib%2Ffunctions.pl;h=d2ad7e34a479ebc53850648a78e7437a316288cf;hp=dc38c00b12c33c82d5e588bff514f1cd9f550a77;hb=d59b02f177dce0e077da5256eee68d2cf10b2bfd;hpb=4e4b54c591c80f75e3aff05de96b1b9d56d95419
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
index dc38c00b12..d2ad7e34a4 100644
--- a/src/pakfire/lib/functions.pl
+++ b/src/pakfire/lib/functions.pl
@@ -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");
@@ -160,16 +160,16 @@ sub fetchfile {
my $ua = LWP::UserAgent->new;
$ua->agent("Pakfire/$Conf::version");
- $ua->timeout(5);
+ $ua->timeout(20);
my %proxysettings=();
&General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
if ($proxysettings{'UPSTREAM_PROXY'}) {
- logger("DOWNLOAD INFO: Upstream proxy: \"$proxysettings{'UPSTREAM_PROXY'}\"") unless ($bfile =~ /^counter\?.*/);
+ logger("DOWNLOAD INFO: Upstream proxy: \"$proxysettings{'UPSTREAM_PROXY'}\"") unless ($bfile =~ /^counter.py\?.*/);
if ($proxysettings{'UPSTREAM_USER'}) {
$ua->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$proxysettings{'UPSTREAM_PROXY'}/");
- logger("DOWNLOAD INFO: Logging in with: \"$proxysettings{'UPSTREAM_USER'}\" - \"$proxysettings{'UPSTREAM_PASSWORD'}\"") unless ($bfile =~ /^counter\?.*/);
+ logger("DOWNLOAD INFO: Logging in with: \"$proxysettings{'UPSTREAM_USER'}\" - \"$proxysettings{'UPSTREAM_PASSWORD'}\"") unless ($bfile =~ /^counter.py\?.*/);
} else {
$ua->proxy("http","http://$proxysettings{'UPSTREAM_PROXY'}/");
}
@@ -179,7 +179,7 @@ sub fetchfile {
my $url = "http://$host/$file";
my $response;
- unless ($bfile =~ /^counter\?.*/) {
+ unless ($bfile =~ /^counter.py\?.*/) {
my $result = $ua->head($url);
my $remote_headers = $result->headers;
$total_size = $remote_headers->content_length;
@@ -201,7 +201,7 @@ sub fetchfile {
}
if ($response->is_success) {
- unless ($bfile =~ /^counter\?.*/) {
+ unless ($bfile =~ /^counter.py\?.*/) {
if (open(FILE, ">$Conf::tmpdir/$bfile")) {
print FILE $final_data;
close(FILE);
@@ -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,10 +324,21 @@ 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,9 +393,9 @@ 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" gt "$Conf::core_mine") {
+ if ("$core_release" > "$Conf::core_mine") {
if ("$forweb" eq "forweb") {
print "\n";
} else {
@@ -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 = ;
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");
}
@@ -644,7 +665,7 @@ sub setuppak {
my $return = system("cd $Conf::tmpdir && NAME=$pak ./install.sh >> $Conf::logdir/install-$pak.log 2>&1");
$return %= 255;
if ($pakfiresettings{'UUID'} ne "off") {
- fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&ipak=$pak&return=$return", "$Conf::mainserver");
+ fetchfile("counter.py?ver=$Conf::version&uuid=$Conf::uuid&ipak=$pak&return=$return", "$Conf::mainserver");
}
if ($return == 0) {
move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
@@ -662,7 +683,7 @@ sub setuppak {
sub upgradecore {
getcoredb("noforce");
eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
- if ("$core_release" gt "$Conf::core_mine") {
+ if ("$core_release" > "$Conf::core_mine") {
message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release");
my @seq = `seq $Conf::core_mine $core_release`;
@@ -705,7 +726,7 @@ sub upgradepak {
my $return = system("cd $Conf::tmpdir && NAME=$pak ./update.sh >> $Conf::logdir/update-$pak.log 2>&1");
$return %= 255;
if ($pakfiresettings{'UUID'} ne "off") {
- fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&upak=$pak&return=$return", "$Conf::mainserver");
+ fetchfile("counter.py?ver=$Conf::version&uuid=$Conf::uuid&upak=$pak&return=$return", "$Conf::mainserver");
}
if ($return == 0) {
move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
@@ -730,18 +751,9 @@ sub removepak {
my $return = system("cd $Conf::tmpdir && NAME=$pak ./uninstall.sh >> $Conf::logdir/uninstall-$pak.log 2>&1");
$return %= 255;
if ($pakfiresettings{'UUID'} ne "off") {
- fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&dpak=$pak&return=$return", "$Conf::mainserver");
+ fetchfile("counter.py?ver=$Conf::version&uuid=$Conf::uuid&dpak=$pak&return=$return", "$Conf::mainserver");
}
if ($return == 0) {
- open(FILE, "<$Conf::dbdir/rootfiles/$pak");
- my @file = ;
- close(FILE);
- foreach (@file) {
- my $line = $_;
- chomp($line);
- system("echo \"Removing: $line\" >> $Conf::logdir/uninstall-$pak.log 2>&1");
- system("cd / && rm -rf $line >> $Conf::logdir/uninstall-$pak.log 2>&1");
- }
unlink("$Conf::dbdir/rootfiles/$pak");
unlink("$Conf::dbdir/installed/meta-$pak");
cleanup("tmp");
@@ -793,7 +805,7 @@ sub senduuid {
$Conf::uuid = `cat $Conf::dbdir/uuid`;
}
logger("Sending my uuid: $Conf::uuid");
- fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid", "$Conf::mainserver");
+ fetchfile("counter.py?ver=$Conf::version&uuid=$Conf::uuid", "$Conf::mainserver");
system("rm -f $Conf::tmpdir/counter* 2>/dev/null");
}
}