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