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