]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/pakfire/lib/functions.pl
Pakfire und startklips Fixes.
[people/pmueller/ipfire-2.x.git] / src / pakfire / lib / functions.pl
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 # A small color-hash :D
18 my %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
37 my $final_data;
38 my $total_size;
39 my $bfile;
40
41 my %pakfiresettings = ();
42 &General::readhash("${General::swroot}/pakfire/settings", \%pakfiresettings);
43
44 sub message {
45 my $message = shift;
46
47 logger("$message");
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
65 }
66
67 sub logger {
68 my $log = shift;
69 if ($log) {
70 system("echo \"`date`: $log\" >> /var/log/pakfire.log");
71 #system("logger -t pakfire \"$log\"");
72 }
73 }
74
75 sub usage {
76 &Pakfire::message("Usage: pakfire <install|remove> <pak(s)>");
77 &Pakfire::message(" <update> - Contacts the servers for new lists of paks.");
78 &Pakfire::message(" <upgrade> - Installs the latest version of all paks.");
79 &Pakfire::message(" <list> - Outputs a short list with all available paks.");
80 &Pakfire::message("");
81 exit 1;
82 }
83
84 sub pinghost {
85 my $host = shift;
86
87 $p = Net::Ping->new();
88 if ($p->ping($host)) {
89 logger("PING INFO: $host is alive");
90 return 1;
91 } else {
92 logger("PING INFO: $host is unreachable");
93 return 0;
94 }
95 $p->close();
96 }
97
98 sub fetchfile {
99 my $getfile = shift;
100 my $gethost = shift;
101 my (@server, $host, $proto, $file, $allok, $i);
102
103 logger("DOWNLOAD STARTED: $getfile") unless ($bfile =~ /^counter\?.*/);
104 use File::Basename;
105 $bfile = basename("$getfile");
106
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";
116 } else {
117 $host = $gethost;
118 $file = $getfile;
119 }
120
121 $proto = "HTTP" unless $proto;
122
123 unless ($bfile =~ /^counter\?.*/) {
124 logger("DOWNLOAD INFO: Host: $host ($proto) - File: $file");
125 #message("DOWNLOAD INFO: Loading $bfile from ($proto) $host...");
126 }
127
128 my $ua = LWP::UserAgent->new;
129 $ua->agent("Pakfire/$Conf::version");
130 $ua->timeout(5);
131
132 my %proxysettings=();
133 &General::readhash("${General::swroot}/proxy/advanced/settings", \%proxysettings);
134
135 if ($proxysettings{'UPSTREAM_PROXY'}) {
136 logger("DOWNLOAD INFO: Upstream proxy: \"$proxysettings{'UPSTREAM_PROXY'}\"") unless ($bfile =~ /^counter\?.*/);
137 if ($proxysettings{'UPSTREAM_USER'}) {
138 $ua->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$proxysettings{'UPSTREAM_PROXY'}/");
139 logger("DOWNLOAD INFO: Logging in with: \"$proxysettings{'UPSTREAM_USER'}\" - \"$proxysettings{'UPSTREAM_PASSWORD'}\"") unless ($bfile =~ /^counter\?.*/);
140 } else {
141 $ua->proxy("http","http://$proxysettings{'UPSTREAM_PROXY'}/");
142 }
143 }
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 }
160
161 my $code = $response->code();
162 my $log = $response->status_line;
163 logger("DOWNLOAD INFO: HTTP-Status-Code: $code - $log");
164
165 if ( $code eq "500" ) {
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.");
167 return 1;
168 }
169
170 if ($response->is_success) {
171 unless ($bfile =~ /^counter\?.*/) {
172 if (open(FILE, ">$Conf::tmpdir/$bfile")) {
173 print FILE $final_data;
174 close(FILE);
175 logger("DOWNLOAD INFO: File received. Start checking signature...");
176 if (system("gpg --verify \"$Conf::tmpdir/$bfile\" &>/dev/null") eq 0) {
177 logger("DOWNLOAD INFO: Signature of $bfile is fine.");
178 move("$Conf::tmpdir/$bfile","$Conf::cachedir/$bfile");
179 } else {
180 message("DOWNLOAD ERROR: The downloaded file ($file) wasn't verified by IPFire.org. Sorry - Exiting...");
181 exit 1;
182 }
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.");
188 }
189 } else {
190 return 0;
191 }
192 } else {
193 logger("DOWNLOAD ERROR: $log");
194 }
195 }
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.");
197 return 1;
198 }
199
200 sub getmirrors {
201 use File::Copy;
202
203 logger("MIRROR: Trying to get a mirror list.");
204
205 fetchfile("$Conf::version/lists/server-list.db", "$Conf::mainserver");
206 move("$Conf::cachedir/server-list.db", "$Conf::dbdir/lists/server-list.db");
207 }
208
209 sub 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;
213 while (!(open(FILE, "<$Conf::dbdir/lists/server-list.db")) && ($count lt 5)) {
214 $count++;
215 getmirrors();
216 }
217 if ($count == 5) {
218 message("MIRROR ERROR: Could not find or download a server list");
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;
226 my @newlines;
227 foreach (@lines) {
228 if ("$_" =~ /.*;.*;.*;/ ) {
229 push(@newlines,$_);
230 $scount++;
231 }
232 }
233 logger("MIRROR INFO: $scount servers found in list");
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;
245 foreach $line (@newlines) {
246 $servers++;
247 if ($servers eq $server) {
248 @templine = split(/\;/, $line);
249 $proto = $templine[0];
250 $host = $templine[1];
251 $path = $templine[2];
252 if (pinghost("$host")) {
253 $found = 1;
254 return ($proto, $host, $path);
255 }
256 }
257 }
258 }
259 }
260
261 sub 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
279 if (("$age" gt "86400") || ("$force" eq "force")) {
280 fetchfile("lists/packages_list.db", "");
281 move("$Conf::cachedir/packages_list.db", "$Conf::dbdir/lists/packages_list.db");
282 }
283 }
284
285 sub 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;
292 my @meta;
293 my @updatepaks;
294 my $file;
295 my $line;
296 my $prog;
297 my ($name, $version, $release);
298 my @templine;
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);
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]" )) {
333 push(@updatepaks,$name);
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 }
341 }
342 return @updatepaks;
343 } else {
344 my $line;
345 my @templine;
346 foreach $line (sort @db) {
347 next unless ($line =~ /.*;.*;.*;/ );
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 }
359 }
360 }
361 }
362
363 sub resolvedeps {
364 my $pak = shift;
365
366 getmetafile("$pak");
367
368 message("PAKFIRE RESV: $pak: Resolving dependencies...");
369
370 open(FILE, "<$Conf::dbdir/meta/meta-$pak");
371 my @file = <FILE>;
372 close(FILE);
373
374 my $line;
375 my (@templine, @deps, @tempdeps, @all);
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 ($_) {
385 my $return = &isinstalled($_);
386 if ($return eq 0) {
387 message("PAKFIRE RESV: $pak: Dependency is already installed: $_");
388 } else {
389 message("PAKFIRE RESV: $pak: Need to install dependency: $_");
390 push(@tempdeps,$_);
391 push(@all,$_);
392 }
393 }
394 }
395
396 foreach (@tempdeps) {
397 if ($_) {
398 my @newdeps = resolvedeps("$_");
399 foreach(@newdeps) {
400 unless (($_ eq " ") || ($_ eq "")) {
401 my $return = &isinstalled($_);
402 if ($return eq 0) {
403 message("PAKFIRE RESV: $pak: Dependency is already installed: $_");
404 } else {
405 message("PAKFIRE RESV: $pak: Need to install dependency: $_");
406 push(@all,$_);
407 }
408 }
409 }
410 }
411 }
412 message("");
413 chomp (@all);
414 return @all;
415 }
416
417 sub cleanup {
418 my $dir = shift;
419 my $path;
420
421 logger("CLEANUP: $dir");
422
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
439 sub getmetafile {
440 my $pak = shift;
441
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
461 sub 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 }
479 return 0;
480 }
481
482 sub decryptpak {
483 my $pak = shift;
484
485 cleanup("tmp");
486
487 my $file = getpak("$pak", "noforce");
488
489 logger("DECRYPT STARTED: $pak");
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");
491 $return %= 255;
492 logger("DECRYPT FINISHED: $pak - Status: $return");
493 if ($return != 0) { exit 1; }
494 }
495
496 sub 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
522 unless ( "$force" eq "force" ) {
523 if ( -e "$Conf::cachedir/$file" ) {
524 return $file;
525 }
526 }
527
528 fetchfile("paks/$file", "");
529 return $file;
530 }
531
532 sub setuppak {
533 my $pak = shift;
534
535 message("PAKFIRE INST: $pak: Decrypting...");
536 decryptpak("$pak");
537
538 message("PAKFIRE INST: $pak: Copying files and running post-installation scripts...");
539 my $return = system("cd $Conf::tmpdir && NAME=$pak ./install.sh >> $Conf::logdir/install-$pak.log 2>&1");
540 $return %= 255;
541 if ($pakfiresettings{'UUID'} ne "off") {
542 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&ipak=$pak&return=$return", "$Conf::mainserver");
543 }
544 if ($return == 0) {
545 move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
546 cleanup("tmp");
547 copy("$Conf::dbdir/meta/meta-$pak","$Conf::dbdir/installed/");
548 message("PAKFIRE INST: $pak: Finished.");
549 message("");
550 } else {
551 message("PAKFIRE ERROR: Returncode: $return. Sorry. Please search our forum to find a solution for this problem.");
552 exit $return;
553 }
554 return $return;
555 }
556
557 sub 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
567 sub upgradepak {
568 my $pak = shift;
569
570 message("PAKFIRE UPGR: $pak: Decrypting...");
571 decryptpak("$pak");
572
573 message("PAKFIRE UPGR: $pak: Upgrading files and running post-upgrading scripts...");
574 my $return = system("cd $Conf::tmpdir && NAME=$pak ./update.sh >> $Conf::logdir/update-$pak.log 2>&1");
575 $return %= 255;
576 if ($pakfiresettings{'UUID'} ne "off") {
577 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&upak=$pak&return=$return", "$Conf::mainserver");
578 }
579 if ($return == 0) {
580 move("$Conf::tmpdir/ROOTFILES", "$Conf::dbdir/rootfiles/$pak");
581 cleanup("tmp");
582 copy("$Conf::dbdir/meta/meta-$pak","$Conf::dbdir/installed/");
583 message("PAKFIRE UPGR: $pak: Finished.");
584 message("");
585 } else {
586 message("PAKFIRE ERROR: Returncode: $return. Sorry. Please search our forum to find a solution for this problem.");
587 exit $return;
588 }
589 return $return;
590 }
591
592 sub removepak {
593 my $pak = shift;
594
595 message("PAKFIRE REMV: $pak: Decrypting...");
596 decryptpak("$pak");
597
598 message("PAKFIRE REMV: $pak: Removing files and running post-removing scripts...");
599 my $return = system("cd $Conf::tmpdir && NAME=$pak ./uninstall.sh >> $Conf::logdir/uninstall-$pak.log 2>&1");
600 $return %= 255;
601 if ($pakfiresettings{'UUID'} ne "off") {
602 fetchfile("cgi-bin/counter?ver=$Conf::version&uuid=$Conf::uuid&dpak=$pak&return=$return", "$Conf::mainserver");
603 }
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");
615 unlink("$Conf::dbdir/installed/meta-$pak");
616 cleanup("tmp");
617 message("PAKFIRE REMV: $pak: Finished.");
618 message("");
619 } else {
620 message("PAKFIRE ERROR: Returncode: $return. Sorry. Please search our forum to find a solution for this problem.");
621 exit $return;
622 }
623 return $return;
624 }
625
626 sub beautifysize {
627 my $size = shift;
628 #$size = $size / 1024;
629 my $unit;
630
631 if ($size > 1023*1024) {
632 $size = ($size / (1024*1024));
633 $unit = "MB";
634 } elsif ($size > 1023) {
635 $size = ($size / 1024);
636 $unit = "KB";
637 } else {
638 $unit = "B";
639 }
640 $size = sprintf("%.2f" , $size);
641 my $string = "$size $unit";
642 return $string;
643 }
644
645 sub makeuuid {
646 unless ( -e "$Conf::dbdir/uuid" ) {
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
659 sub senduuid {
660 if ($pakfiresettings{'UUID'} ne "off") {
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");
666 system("rm -f $Conf::tmpdir/counter* 2>/dev/null");
667 }
668 }
669
670 sub checkcryptodb {
671 logger("CRYPTO INFO: Checking GnuPG Database");
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" ) {
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.");
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");
680 } else {
681 logger("CRYPTO INFO: Database is okay");
682 }
683 }
684
685 sub callback {
686 my ($data, $response, $protocol) = @_;
687 $final_data .= $data;
688 print progress_bar( length($final_data), $total_size, 30, '=' );
689 }
690
691 sub progress_bar {
692 my ( $got, $total, $width, $char ) = @_;
693 my $show_bfile;
694 $width ||= 30; $char ||= '=';
695 my $len_bfile = length $bfile;
696 if ("$len_bfile" >= "17") {
697 $show_bfile = substr($bfile,0,17)."...";
698 } else {
699 $show_bfile = $bfile;
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);
703 }
704
705 1;