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