]> git.ipfire.org Git - ipfire-2.x.git/blame - src/pakfire/lib/functions.pl
Und wieder den Packfire erweitert. Diesesmal:
[ipfire-2.x.git] / src / pakfire / lib / functions.pl
CommitLineData
1bd42c89
MT
1#!/usr/bin/perl -w
2
3require "/opt/pakfire/etc/pakfire.conf";
4b122800 4require "/var/ipfire/general-functions.pl";
1bd42c89
MT
5
6use File::Basename;
7use File::Copy;
8use LWP::UserAgent;
4d504812 9use HTTP::Response;
a6d327a7
MT
10use HTTP::Headers;
11use HTTP::Message;
12use HTTP::Request;
1bd42c89
MT
13use Net::Ping;
14
15package Pakfire;
16
a6d327a7
MT
17my $final_data;
18my $total_size;
19my $bfile;
20
4b122800
MT
21my %pakfiresettings = ();
22&General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
23
1bd42c89
MT
24sub message {
25 my $message = shift;
26 print "$message\n";
27 logger("$message");
28}
29
30sub logger {
31 my $log = shift;
a6d327a7 32 system("logger -t pakfire \"$log\"") if "$log";
1bd42c89
MT
33}
34
5b2a12ff
MT
35sub usage {
36 &Pakfire::message("Usage: pakfire <install|remove> <pak(s)>");
37 &Pakfire::message(" <update> - Contacts the servers for new lists of paks.");
99e6df8e 38 &Pakfire::message(" <upgrade> - Installs the latest version of all paks.");
5b2a12ff 39 &Pakfire::message(" <list> - Outputs a short list with all available paks.");
99e6df8e 40 &Pakfire::message("");
5b2a12ff
MT
41 exit 1;
42}
43
1bd42c89
MT
44sub pinghost {
45 my $host = shift;
46
47 $p = Net::Ping->new();
48 if ($p->ping($host)) {
a6d327a7 49 logger("PING INFO: $host is alive");
1bd42c89
MT
50 return 1;
51 } else {
a6d327a7 52 logger("PING INFO: $host is unreachable");
1bd42c89
MT
53 return 0;
54 }
55 $p->close();
56}
57
58sub fetchfile {
4d504812
MT
59 my $getfile = shift;
60 my $gethost = shift;
61 my (@server, $host, $proto, $file, $allok, $i);
1bd42c89 62
a6d327a7 63 logger("DOWNLOAD STARTED: $getfile") unless ($bfile =~ /^counter\?.*/);
1bd42c89 64 use File::Basename;
4d504812 65 $bfile = basename("$getfile");
1bd42c89 66
4d504812
MT
67 $i = 0;
68 while (($allok == 0) && $i < 5) {
69 $i++;
70
71 if ("$gethost" eq "") {
72 @server = selectmirror();
73 $proto = $server[0];
74 $host = $server[1];
75 $file = "$server[2]/$getfile";
1bd42c89 76 } else {
4d504812 77 $host = $gethost;
afabe9f7 78 $file = $getfile;
1bd42c89 79 }
4d504812
MT
80
81 $proto = "HTTP" unless $proto;
82
a6d327a7
MT
83 unless ($bfile =~ /^counter\?.*/) {
84 logger("DOWNLOAD INFO: Host: $host ($proto) - File: $file");
85 #message("DOWNLOAD INFO: Loading $bfile from ($proto) $host...");
86 }
1bd42c89 87
4d504812
MT
88 my $ua = LWP::UserAgent->new;
89 $ua->agent("Pakfire/$Conf::version");
afabe9f7 90 $ua->timeout(5);
4b122800
MT
91
92 my %proxysettings=();
93 &General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
94
99e6df8e 95 if ($proxysettings{'UPSTREAM_PROXY'}) {
a6d327a7 96 logger("DOWNLOAD INFO: Upstream proxy: \"$proxysettings{'UPSTREAM_PROXY'}\"") unless ($bfile =~ /^counter\?.*/);
4b122800 97 if ($proxysettings{'UPSTREAM_USER'}) {
99e6df8e 98 $ua->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$proxysettings{'UPSTREAM_PROXY'}/");
a6d327a7 99 logger("DOWNLOAD INFO: Logging in with: \"$proxysettings{'UPSTREAM_USER'}\" - \"$proxysettings{'UPSTREAM_PASSWORD'}\"") unless ($bfile =~ /^counter\?.*/);
4b122800 100 } else {
99e6df8e 101 $ua->proxy("http","http://$proxysettings{'UPSTREAM_PROXY'}/");
4b122800
MT
102 }
103 }
a6d327a7
MT
104
105 $final_data = undef;
106 my $url = "http://$host/$file";
107 my $response;
108
109 unless ($bfile =~ /^counter\?.*/) {
110 my $result = $ua->head($url);
111 my $remote_headers = $result->headers;
112 $total_size = $remote_headers->content_length;
113 logger("DOWNLOAD INFO: $file has size of $total_size bytes");
114
115 $response = $ua->get($url, ':content_cb' => \&callback );
116 message("");
117 } else {
118 $response = $ua->get($url);
119 }
4d504812 120
4b122800
MT
121 my $code = $response->code();
122 my $log = $response->status_line;
a6d327a7 123 logger("DOWNLOAD INFO: HTTP-Status-Code: $code - $log");
4b122800
MT
124
125 if ( $code eq "500" ) {
e44b26cf 126 message("Giving up: There was no chance to get the file \"$getfile\" from any available server.\nThere was an error on the way. Please fix it.");
4b122800
MT
127 return 1;
128 }
129
4d504812 130 if ($response->is_success) {
186e3d2c 131 if (open(FILE, ">$Conf::tmpdir/$bfile")) {
a6d327a7 132 print FILE $final_data;
4d504812 133 close(FILE);
06209efc 134 unless ($bfile =~ /^counter\?.*/) { # Don't check out counterfile cause it's empty
a6d327a7 135 logger("DOWNLOAD INFO: File received. Start checking signature...");
06209efc 136 if (system("gpg --verify \"$Conf::tmpdir/$bfile\" &>/dev/null") eq 0) {
a6d327a7 137 logger("DOWNLOAD INFO: Signature of $bfile is fine.");
06209efc
MT
138 move("$Conf::tmpdir/$bfile","$Conf::cachedir/$bfile");
139 } else {
a6d327a7 140 message("DOWNLOAD ERROR: The downloaded file ($file) wasn't verified by IPFire.org. Sorry - Exiting...");
06209efc
MT
141 exit 1;
142 }
186e3d2c 143 }
a6d327a7 144 logger("DOWNLOAD FINISHED: $file") unless ($bfile =~ /^counter\?.*/);
4d504812
MT
145 $allok = 1;
146 return 0;
147 } else {
a6d327a7 148 logger("DOWNLOAD ERROR: Could not open $Conf::cachedir/$bfile for writing.");
4d504812
MT
149 }
150 } else {
a6d327a7 151 logger("DOWNLOAD ERROR: $log");
4d504812 152 }
1bd42c89 153 }
a6d327a7 154 message("DOWNLOAD ERROR: There was no chance to get the file \"$getfile\" from any available server.\nMay be you should run \"pakfire update\" to get some new servers.");
4d504812 155 return 1;
1bd42c89
MT
156}
157
158sub getmirrors {
159 use File::Copy;
160
a6d327a7 161 logger("MIRROR: Trying to get a mirror list.");
1bd42c89 162
06209efc
MT
163 fetchfile("$Conf::version/lists/server-list.db", "$Conf::mainserver");
164 move("$Conf::cachedir/server-list.db", "$Conf::dbdir/lists/server-list.db");
1bd42c89
MT
165}
166
167sub selectmirror {
168 ### Check if there is a current server list and read it.
169 # If there is no list try to get one.
170 my $count = 0;
06209efc 171 while (!(open(FILE, "<$Conf::dbdir/lists/server-list.db")) && ($count lt 5)) {
1bd42c89
MT
172 $count++;
173 getmirrors();
174 }
175 if ($count == 5) {
a6d327a7 176 message("MIRROR ERROR: Could not find or download a server list");
1bd42c89
MT
177 exit 1;
178 }
179 my @lines = <FILE>;
180 close(FILE);
181
182 ### Count the number of the servers in the list
183 my $scount = 0;
e44b26cf 184 my @newlines;
1bd42c89 185 foreach (@lines) {
e44b26cf
MT
186 if ("$_" =~ /.*;.*;.*;/ ) {
187 push(@newlines,$_);
188 $scount++;
189 }
1bd42c89 190 }
a6d327a7 191 logger("MIRROR INFO: $scount servers found in list");
1bd42c89
MT
192
193 ### Choose a random server and test if it is online
194 # If the check fails try a new server.
195 # This will never give up.
196 my $found = 0;
197 my $servers = 0;
198 while ($found == 0) {
199 $server = int(rand($scount) + 1);
200 $servers = 0;
201 my ($line, $proto, $path, $host);
202 my @templine;
e44b26cf 203 foreach $line (@newlines) {
1bd42c89
MT
204 $servers++;
205 if ($servers eq $server) {
206 @templine = split(/\;/, $line);
207 $proto = $templine[0];
208 $host = $templine[1];
209 $path = $templine[2];
a08c3a2e 210 if (pinghost("$host")) {
1bd42c89
MT
211 $found = 1;
212 return ($proto, $host, $path);
213 }
214 }
215 }
4d504812 216 }
1bd42c89
MT
217}
218
219sub dbgetlist {
220 ### Update the database if the file is older than one day.
221 # If you pass &Pakfire::dbgetlist(force) the list will be downloaded.
222 # Usage is always with an argument.
223 my $force = shift;
224 my $age;
225
226 use File::Copy;
227
228 if ( -e "$Conf::dbdir/lists/packages_list.db" ) {
229 my @stat = stat("$Conf::dbdir/lists/packages_list.db");
230 my $time = time();
231 $age = $time - $stat[9];
232 } else {
233 # Force an update.
234 $age = "86401";
235 }
236
237 if (("$age" gt 86400) || ("$force" eq "force")) {
5b2a12ff 238 #cleanup();
1bd42c89
MT
239 fetchfile("lists/packages_list.db", "");
240 move("$Conf::cachedir/packages_list.db", "$Conf::dbdir/lists/packages_list.db");
241 }
242}
243
244sub dblist {
245 ### This subroutine lists the packages.
246 # You may also pass a filter: &Pakfire::dblist(filter)
247 # Usage is always with two arguments.
248 # filter may be: all, notinstalled, installed
249 my $filter = shift;
250 my $forweb = shift;
4b122800 251 my @meta;
99e6df8e 252 my @updatepaks;
4b122800
MT
253 my $file;
254 my $line;
255 my $prog;
256 my ($name, $version, $release);
257 my @templine;
1bd42c89
MT
258
259 ### Make sure that the list is not outdated.
260 dbgetlist("noforce");
261
262 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
263 my @db = <FILE>;
264 close(FILE);
4b122800
MT
265
266 if ("$filter" eq "upgrade") {
267 opendir(DIR,"$Conf::dbdir/meta");
268 my @files = readdir(DIR);
269 closedir(DIR);
270 foreach $file (@files) {
271 next if ( $file eq "." );
272 next if ( $file eq ".." );
273 open(FILE, "<$Conf::dbdir/meta/$file");
274 @meta = <FILE>;
275 close(FILE);
276 foreach $line (@meta) {
277 @templine = split(/\: /,$line);
278 if ("$templine[0]" eq "Name") {
279 $name = $templine[1];
280 chomp($name);
281 } elsif ("$templine[0]" eq "ProgVersion") {
282 $version = $templine[1];
283 chomp($version);
284 } elsif ("$templine[0]" eq "Release") {
285 $release = $templine[1];
286 chomp($release);
287 }
288 }
289 foreach $prog (@db) {
290 @templine = split(/\;/,$prog);
291 if (("$name" eq "$templine[0]") && ("$release" < "$templine[2]" )) {
99e6df8e 292 push(@updatepaks,$name);
4b122800
MT
293 if ("$forweb" eq "forweb") {
294 print "<option value=\"$name\">Update: $name -- Version: $version -> $templine[1] -- Release: $release -> $templine[2]</option>\n";
295 } else {
296 print "Update: $name\nVersion: $version -> $templine[1]\nRelease: $release -> $templine[2]\n\n";
297 }
298 }
299 }
5b2a12ff 300 }
99e6df8e 301 return @updatepaks;
4b122800
MT
302 } else {
303 my $line;
304 my @templine;
305 foreach $line (sort @db) {
06209efc 306 next unless ($line =~ /.*;.*;.*;/ );
4b122800
MT
307 @templine = split(/\;/,$line);
308 if ("$filter" eq "notinstalled") {
309 next if ( -e "$Conf::dbdir/installed/meta-$templine[0]" );
310 } elsif ("$filter" eq "installed") {
311 next unless ( -e "$Conf::dbdir/installed/meta-$templine[0]" );
312 }
313 if ("$forweb" eq "forweb") {
314 print "<option value=\"$templine[0]\">$templine[0]-$templine[1]-$templine[2]</option>\n";
315 } else {
316 print "Name: $templine[0]\nProgVersion: $templine[1]\nRelease: $templine[2]\n\n";
317 }
1bd42c89
MT
318 }
319 }
320}
321
322sub resolvedeps {
323 my $pak = shift;
324
325 getmetafile("$pak");
326
186e3d2c
MT
327 message("");
328 message("## Resolving dependencies for $pak...");
1bd42c89
MT
329
330 open(FILE, "<$Conf::dbdir/meta/meta-$pak");
331 my @file = <FILE>;
332 close(FILE);
333
334 my $line;
186e3d2c 335 my (@templine, @deps, @tempdeps, @all);
1bd42c89
MT
336 foreach $line (@file) {
337 @templine = split(/\: /,$line);
338 if ("$templine[0]" eq "Dependencies") {
339 @deps = split(/ /, $templine[1]);
340 }
341 }
342 chomp (@deps);
343 foreach (@deps) {
344 if ($_) {
186e3d2c
MT
345 my $return = &isinstalled($_);
346 if ($return eq 0) {
347 message("### Dependency is already installed: $_");
348 } else {
349 message("### Need to install dependency: $_");
350 push(@tempdeps,$_);
351 push(@all,$_);
352 }
1bd42c89
MT
353 }
354 }
e44b26cf 355
1bd42c89
MT
356 foreach (@tempdeps) {
357 if ($_) {
358 my @newdeps = resolvedeps("$_");
359 foreach(@newdeps) {
360 unless (($_ eq " ") || ($_ eq "")) {
186e3d2c
MT
361 my $return = &isinstalled($_);
362 if ($return eq 0) {
363 message("### Dependency is already installed: $_");
364 } else {
365 message("### Need to install dependency: $_");
366 push(@all,$_);
367 }
1bd42c89
MT
368 }
369 }
370 }
371 }
186e3d2c
MT
372 chomp (@all);
373 return @all;
1bd42c89
MT
374}
375
376sub cleanup {
377 my $dir = shift;
378 my $path;
379
380 if ( "$dir" eq "meta" ) {
381 $path = "$Conf::dbdir/meta";
382 } elsif ( "$dir" eq "tmp" ) {
383 $path = "$Conf::tmpdir";
384 }
385 chdir("$path");
386 opendir(DIR,".");
387 my @files = readdir(DIR);
388 closedir(DIR);
389 foreach (@files) {
390 unless (($_ eq ".") || ($_ eq "..")) {
391 system("rm -rf $_");
392 }
393 }
394}
395
396sub getmetafile {
397 my $pak = shift;
398
1bd42c89
MT
399 unless ( -e "$Conf::dbdir/meta/meta-$pak") {
400 fetchfile("meta/meta-$pak", "");
401 move("$Conf::cachedir/meta-$pak", "$Conf::dbdir/meta/meta-$pak");
402 }
403
404 open(FILE, "<$Conf::dbdir/meta/meta-$pak");
405 my @line = <FILE>;
406 close(FILE);
407
408 open(FILE, ">$Conf::dbdir/meta/meta-$pak");
409 foreach (@line) {
410 my $string = $_;
411 $string =~ s/\r\n/\n/g;
412 print FILE $string;
413 }
414 close(FILE);
415 return 1;
416}
417
418sub getsize {
419 my $pak = shift;
420
421 getmetafile("$pak");
422
423 open(FILE, "<$Conf::dbdir/meta/meta-$pak");
424 my @file = <FILE>;
425 close(FILE);
426
427 my $line;
428 my @templine;
429 foreach $line (@file) {
430 @templine = split(/\: /,$line);
431 if ("$templine[0]" eq "Size") {
432 chomp($templine[1]);
433 return $templine[1];
434 }
435 }
4b122800 436 return 0;
1bd42c89
MT
437}
438
439sub decryptpak {
440 my $pak = shift;
441
442 cleanup("tmp");
443
444 my $file = getpak("$pak", "noforce");
445
a6d327a7
MT
446 logger("DECRYPT STARTED: $pak");
447 my $return = system("cd $Conf::tmpdir/ && gpg -d < $Conf::cachedir/$file | tar x &>/dev/null");
99e6df8e 448 $return %= 255;
a6d327a7 449 logger("DECRYPT FINISHED: $pak - Status: $return");
cde0e116 450 if ($return != 0) { exit 1; }
1bd42c89
MT
451}
452
453sub getpak {
454 my $pak = shift;
455 my $force = shift;
456
457 getmetafile("$pak");
458
459 open(FILE, "<$Conf::dbdir/meta/meta-$pak");
460 my @file = <FILE>;
461 close(FILE);
462
463 my $line;
464 my $file;
465 my @templine;
466 foreach $line (@file) {
467 @templine = split(/\: /,$line);
468 if ("$templine[0]" eq "File") {
469 chomp($templine[1]);
470 $file = $templine[1];
471 }
472 }
473
474 unless ($file) {
475 message("No filename given in meta-file. Please phone the developers.");
476 exit 1;
477 }
478
1bd42c89
MT
479 unless ( "$force" eq "force" ) {
480 if ( -e "$Conf::cachedir/$file" ) {
1bd42c89
MT
481 return $file;
482 }
483 }
484
485 fetchfile("paks/$file", "");
486 return $file;
487}
488
489sub setuppak {
490 my $pak = shift;
491
186e3d2c
MT
492 message("################################################################################");
493 message("# --> Installing: $pak");
494 message("################################################################################");
1bd42c89
MT
495
496 decryptpak("$pak");
497
99e6df8e 498 my $return = system("cd $Conf::tmpdir && NAME=$pak ./install.sh >> $Conf::logdir/install-$pak.log 2>&1");
cde0e116 499 $return %= 255;
e44b26cf
MT
500 if ($pakfiresettings{'UUID'} ne "off") {
501 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&ipak=$pak&return=$return", "$Conf::mainserver");
502 }
1bd42c89
MT
503 if ($return == 0) {
504 move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
505 cleanup("tmp");
4d504812 506 copy("$Conf::dbdir/meta/meta-$pak","$Conf::dbdir/installed/");
1bd42c89 507 message("Setup completed. Congratulations!");
186e3d2c 508 message("################################################################################");
1bd42c89
MT
509 } else {
510 message("Setup returned: $return. Sorry. Please search our forum to find a solution for this problem.");
511 exit $return;
512 }
a08c3a2e 513 return $return;
1bd42c89
MT
514}
515
186e3d2c
MT
516sub isinstalled {
517 my $pak = shift;
518 if ( open(FILE,"<$Conf::dbdir/installed/meta-$pak") ) {
519 close(FILE);
520 return 0;
521 } else {
522 return 1;
523 }
524}
525
99e6df8e 526sub upgradepak {
1bd42c89
MT
527 my $pak = shift;
528
99e6df8e 529 message("We are going to upgrade: $pak");
1bd42c89
MT
530
531 decryptpak("$pak");
532
99e6df8e
MT
533 my $return = system("cd $Conf::tmpdir && NAME=$pak ./update.sh >> $Conf::logdir/update-$pak.log 2>&1");
534 $return %= 255;
e44b26cf
MT
535 if ($pakfiresettings{'UUID'} ne "off") {
536 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&upak=$pak&return=$return", "$Conf::mainserver");
537 }
1bd42c89
MT
538 if ($return == 0) {
539 move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
540 cleanup("tmp");
99e6df8e
MT
541 copy("$Conf::dbdir/meta/meta-$pak","$Conf::dbdir/installed/");
542 message("Upgrade completed. Congratulations!");
1bd42c89
MT
543 } else {
544 message("Setup returned: $return. Sorry. Please search our forum to find a solution for this problem.");
545 exit $return;
546 }
8e58bd37 547 return $return;
1bd42c89
MT
548}
549
550sub removepak {
551 my $pak = shift;
552
553 message("We are going to uninstall: $pak");
554
555 decryptpak("$pak");
556
99e6df8e
MT
557 my $return = system("cd $Conf::tmpdir && NAME=$pak ./uninstall.sh >> $Conf::logdir/uninstall-$pak.log 2>&1");
558 $return %= 255;
e44b26cf
MT
559 if ($pakfiresettings{'UUID'} ne "off") {
560 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&dpak=$pak&return=$return", "$Conf::mainserver");
561 }
1bd42c89
MT
562 if ($return == 0) {
563 open(FILE, "<$Conf::dbdir/rootfiles/$pak");
564 my @file = <FILE>;
565 close(FILE);
a6d327a7 566 message("Removing files...");
1bd42c89
MT
567 foreach (@file) {
568 my $line = $_;
569 chomp($line);
570 system("echo \"Removing: $line\" >> $Conf::logdir/uninstall-$pak.log 2>&1");
571 system("cd / && rm -rf $line >> $Conf::logdir/uninstall-$pak.log 2>&1");
572 }
573 unlink("$Conf::dbdir/rootfiles/$pak");
a6d327a7
MT
574 unlink("$Conf::dbdir/installed/meta-$pak");
575 message("Finished removing files!");
1bd42c89
MT
576 cleanup("tmp");
577 message("Uninstall completed. Congratulations!");
578 } else {
579 message("Setup returned: $return. Sorry. Please search our forum to find a solution for this problem.");
580 exit $return;
581 }
8e58bd37 582 return $return;
1bd42c89
MT
583}
584
585sub beautifysize {
586 my $size = shift;
a08c3a2e
MT
587 $size = $size / 1024;
588 my $unit;
1bd42c89
MT
589
590 if ($size > 1023) {
a08c3a2e
MT
591 $size = ($size / 1024);
592 $unit = "MB";
1bd42c89 593 } else {
a08c3a2e 594 $unit = "KB";
1bd42c89 595 }
a08c3a2e
MT
596 $size = sprintf("%.2f" , $size);
597 my $string = "$size $unit";
598 return $string;
1bd42c89
MT
599}
600
8e58bd37
MT
601sub makeuuid {
602 unless ( -e "$Conf::dbdir/uuid" ) {
8e58bd37
MT
603 open(FILE, "</proc/sys/kernel/random/uuid");
604 my @line = <FILE>;
605 close(FILE);
606
607 open(FILE, ">$Conf::dbdir/uuid");
608 foreach (@line) {
609 print FILE $_;
610 }
611 close(FILE);
612 }
613}
614
615sub senduuid {
99e6df8e 616 if ($pakfiresettings{'UUID'} ne "off") {
4b122800
MT
617 unless("$Conf::uuid") {
618 $Conf::uuid = `cat $Conf::dbdir/uuid`;
619 }
620 logger("Sending my uuid: $Conf::uuid");
621 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid", "$Conf::mainserver");
06209efc 622 system("rm -f $Conf::tmpdir/counter* 2>/dev/null");
8e58bd37 623 }
8e58bd37 624}
1bd42c89 625
cde0e116 626sub checkcryptodb {
a6d327a7 627 logger("CRYPTO INFO: Checking GnuPG Database");
cde0e116
MT
628 my $myid = "64D96617"; # Our own gpg-key
629 my $trustid = "65D0FD58"; # Id of CaCert
630 my $ret = system("gpg --list-keys | grep -q $myid");
631 unless ( "$ret" eq "0" ) {
a6d327a7
MT
632 message("CRYPTO WARN: The GnuPG isn't configured corectly. Trying now to fix this.");
633 message("CRYPTO WARN: It's normal to see this on first execution.");
634 system("gpg --keyserver wwwkeys.de.pgp.net --always-trust --recv-key $myid &>>$Conf::logdir/gnupg-database.log");
635 system("gpg --keyserver wwwkeys.de.pgp.net --always-trust --recv-key $trustid &>>$Conf::logdir/gnupg-database.log");
636 } else {
637 logger("CRYPTO INFO: Database is okay");
cde0e116
MT
638 }
639}
640
a6d327a7
MT
641sub callback {
642 my ($data, $response, $protocol) = @_;
643 $final_data .= $data;
644 print progress_bar( length($final_data), $total_size, 25, '=' );
645}
646
647sub progress_bar {
648 my ( $got, $total, $width, $char ) = @_;
649 my $show_bfile;
650 $width ||= 25; $char ||= '=';
651 my $num_width = length $total;
652 my $len_bfile = length $bfile;
653 if ("$len_bfile" >= "12") {
654 $show_bfile = substr($bfile,0,12)."...";
655 } else {
656 $show_bfile = $bfile;
657 }
658 sprintf "$show_bfile [%-${width}s] Got %${num_width}s bytes of %s (%.2f%%)\r", $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/+$total;
659}
660
1bd42c89 6611;