]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/lib/functions.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 require "/opt/pakfire/etc/pakfire.conf" ;
23 require "/var/ipfire/general-functions.pl" ;
39 my @VALID_KEY_FINGERPRINTS = (
41 "3ECA8AA4478208B924BB96206FEF7A8ED713594B" ,
43 "179740DC4D8C47DC63C099C74BDE364C64D96617" ,
46 # A small color-hash :D
48 $color { 'normal' } = " \033 [0m" ;
49 $color { 'black' } = " \033 [0;30m" ;
50 $color { 'darkgrey' } = " \033 [1;30m" ;
51 $color { 'blue' } = " \033 [0;34m" ;
52 $color { 'lightblue' } = " \033 [1;34m" ;
53 $color { 'green' } = " \033 [0;32m" ;
54 $color { 'lightgreen' } = " \033 [1;32m" ;
55 $color { 'cyan' } = " \033 [0;36m" ;
56 $color { 'lightcyan' } = " \033 [1;36m" ;
57 $color { 'red' } = " \033 [0;31m" ;
58 $color { 'lightred' } = " \033 [1;31m" ;
59 $color { 'purple' } = " \033 [0;35m" ;
60 $color { 'lightpurple' } = " \033 [1;35m" ;
61 $color { 'brown' } = " \033 [0;33m" ;
62 $color { 'lightgrey' } = " \033 [0;37m" ;
63 $color { 'yellow' } = " \033 [1;33m" ;
64 $color { 'white' } = " \033 [1;37m" ;
65 our $enable_colors = 1 ;
71 my %pakfiresettings = ();
72 & General
:: readhash
( "${General::swroot}/pakfire/settings" , \
%pakfiresettings );
75 $Conf :: version
= & make_version
();
78 our $lockfile = "/tmp/pakfire_lock" ;
84 if ( $enable_colors == 1 ) {
85 if ( " $message " =~ /ERROR/ ) {
86 $message = " $color {'red'} $message $color {'normal'}" ;
87 } elsif ( " $message " =~ /INFO/ ) {
88 $message = " $color {'cyan'} $message $color {'normal'}" ;
89 } elsif ( " $message " =~ /WARN/ ) {
90 $message = " $color {'yellow'} $message $color {'normal'}" ;
91 } elsif ( " $message " =~ /RESV/ ) {
92 $message = " $color {'purple'} $message $color {'normal'}" ;
93 } elsif ( " $message " =~ /INST/ ) {
94 $message = " $color {'green'} $message $color {'normal'}" ;
95 } elsif ( " $message " =~ /REMV/ ) {
96 $message = " $color {'lightred'} $message $color {'normal'}" ;
97 } elsif ( " $message " =~ /UPGR/ ) {
98 $message = " $color {'lightblue'} $message $color {'normal'}" ;
108 #system("echo \"`date`: $log\" >> /var/log/pakfire.log");
109 system ( "logger -t pakfire \" $log \" " );
114 & Pakfire
:: message
( "Usage: pakfire <install|remove> [options] <pak(s)>" );
115 & Pakfire
:: message
( " <update> - Contacts the servers for new lists of paks." );
116 & Pakfire
:: message
( " <upgrade> - Installs the latest version of all paks." );
117 & Pakfire
:: message
( " <list> - Outputs a short list with all available paks." );
118 & Pakfire
:: message
( " <status> - Outputs a summary about available core upgrades, updates and a required reboot" );
119 & Pakfire
:: message
( "" );
120 & Pakfire
:: message
( " Global options:" );
121 & Pakfire
:: message
( " --non-interactive --> Enables the non-interactive mode." );
122 & Pakfire
:: message
( " You won't see any question here." );
123 & Pakfire
:: message
( " -y --> Short for --non-interactive." );
124 & Pakfire
:: message
( " --no-colors --> Turns off the wonderful colors." );
125 & Pakfire
:: message
( "" );
132 my ( @server , $host , $proto , $file , $i );
136 $bfile = basename
( " $getfile " );
138 logger
( "DOWNLOAD STARTED: $getfile " );
141 while (( $allok == 0 ) && $i < 5 ) {
144 if ( " $gethost " eq "" ) {
145 @server = selectmirror
();
148 $file = " $server [2]/ $getfile " ;
154 $proto = "HTTPS" unless $proto ;
156 logger
( "DOWNLOAD INFO: Host: $host ( $proto ) - File: $file " );
158 # Init LWP::UserAgent, request SSL hostname verification
159 # and specify CA file.
160 my $ua = LWP
:: UserAgent
-> new (
162 SSL_ca_file
=> '/etc/ssl/cert.pem' ,
163 verify_hostname
=> 1 ,
166 $ua -> agent ( "Pakfire/ $Conf ::version" );
169 my %proxysettings =();
170 & General
:: readhash
( "${General::swroot}/proxy/advanced/settings" , \
%proxysettings );
172 if ( $proxysettings { 'UPSTREAM_PROXY' }) {
173 logger
( "DOWNLOAD INFO: Upstream proxy: \" $proxysettings {'UPSTREAM_PROXY'} \" " );
174 if ( $proxysettings { 'UPSTREAM_USER' }) {
175 $ua -> proxy ([ "http" , "https" ], "http:// $proxysettings {'UPSTREAM_USER'}: $proxysettings {'UPSTREAM_PASSWORD'}@" . " $proxysettings {'UPSTREAM_PROXY'}/" );
176 logger
( "DOWNLOAD INFO: Logging in with \" $proxysettings {'UPSTREAM_USER'} \" against \" $proxysettings {'UPSTREAM_PROXY'} \" " );
178 $ua -> proxy ([ "http" , "https" ], "http:// $proxysettings {'UPSTREAM_PROXY'}/" );
186 case
"HTTP" { $url = "http:// $host / $file " ; }
187 case
"HTTPS" { $url = "https:// $host / $file " ; }
189 # skip all lines with unknown protocols
190 logger
( "DOWNLOAD WARNING: Skipping Host: $host due to unknown protocol ( $proto ) in mirror database" );
195 my $result = $ua -> head ( $url );
196 my $remote_headers = $result -> headers ;
197 $total_size = $remote_headers -> content_length ;
198 logger
( "DOWNLOAD INFO: $file has size of $total_size bytes" );
200 my $response = $ua -> get ( $url , ':content_cb' => \
& callback
);
203 my $code = $response -> code ();
204 my $log = $response -> status_line ;
205 logger
( "DOWNLOAD INFO: HTTP-Status-Code: $code - $log " );
207 if ( $code eq "500" ) {
208 message
( "Giving up: There was no chance to get the file \" $getfile \" from any available server. \n There was an error on the way. Please fix it." );
212 if ( $response -> is_success ) {
213 if ( open ( FILE
, "> $Conf ::tmpdir/ $bfile " )) {
214 print FILE
$final_data ;
216 logger
( "DOWNLOAD INFO: File received. Start checking signature..." );
217 if (& valid_signature
( " $Conf ::tmpdir/ $bfile " )) {
218 logger
( "DOWNLOAD INFO: Signature of $bfile is fine." );
219 move
( " $Conf ::tmpdir/ $bfile " , " $Conf ::cachedir/ $bfile " );
221 message
( "DOWNLOAD ERROR: The downloaded file ( $file ) wasn't verified by IPFire.org. Sorry - Exiting..." );
222 my $ntp = `ntpdate -q -t 10 pool.ntp.org 2>/dev/null | tail -1` ;
223 if ( $ntp !~ /time\ server(.*)offset(.*)/ ){ message
( "TIME ERROR: Unable to get the nettime, this may lead to the verification error." );}
224 else { $ntp =~ /time\ server(.*)offset(.*)/ ; message
( "TIME INFO: Time Server $1has $2 offset to localtime." );}
227 logger
( "DOWNLOAD FINISHED: $file " );
231 logger
( "DOWNLOAD ERROR: Could not open $Conf ::tmpdir/ $bfile for writing." );
234 logger
( "DOWNLOAD ERROR: $log " );
237 message
( "DOWNLOAD ERROR: There was no chance to get the file \" $getfile \" from any available server. \n May be you should run \" pakfire update \" to get some new servers." );
247 if ( - e
" $Conf ::dbdir/lists/server-list.db" ) {
248 my @stat = stat ( " $Conf ::dbdir/lists/server-list.db" );
250 $age = $time - $stat [ 9 ];
251 $force = "force" if ( " $age " >= "3600" );
252 logger
( "MIRROR INFO: server-list.db is $age seconds old. - DEBUG: $force " );
258 if ( " $force " eq "force" ) {
259 if ( fetchfile
( " $Conf ::version/lists/server-list.db" , " $Conf ::mainserver" )) {
260 move
( " $Conf ::cachedir/server-list.db" , " $Conf ::dbdir/lists/server-list.db" );
261 } elsif (! - e
" $Conf ::dbdir/lists/server-list.db" ) {
262 # if we end up with no server-list at all, return failure
275 if ( - e
" $Conf ::dbdir/lists/core-list.db" ) {
276 my @stat = stat ( " $Conf ::dbdir/lists/core-list.db" );
278 $age = $time - $stat [ 9 ];
279 $force = "force" if ( " $age " >= "3600" );
280 logger
( "CORE INFO: core-list.db is $age seconds old. - DEBUG: $force " );
286 if ( " $force " eq "force" ) {
287 if ( fetchfile
( "lists/core-list.db" , "" )) {
288 move
( " $Conf ::cachedir/core-list.db" , " $Conf ::dbdir/lists/core-list.db" );
293 sub valid_signature
($) {
294 my $filename = shift ;
296 open ( my $cmd , "gpg --verify --status-fd 1 \" $filename \" 2>/dev/null |" );
298 # Process valid signature lines
299 if ( /VALIDSIG ([A-Z0-9]+)/ ) {
300 # Check if we know the key
301 foreach my $key ( @VALID_KEY_FINGERPRINTS ) {
303 return 1 if ( $key eq $1 );
309 # Signature is invalid
314 if ( defined ${ Conf
:: mirror
}) {
315 my $uri = URI
-> new ( "${Conf::mirror}" );
317 # Only accept HTTPS mirrors
318 if ( $uri -> scheme eq "https" ) {
319 return ( "HTTPS" , $uri -> host , $uri -> path . "/" . ${ Conf
:: version
});
321 message
( "MIRROR ERROR: Unsupported mirror: " . ${ Conf
:: mirror
});
325 ### Check if there is a current server list and read it.
326 # If there is no list try to get one.
327 unless ( open ( FILE
, "< $Conf ::dbdir/lists/server-list.db" )) {
328 unless ( getmirrors
( "noforce" )) {
329 message
( "MIRROR ERROR: Could not find or download a server list" );
337 ### Count the number of the servers in the list
341 if ( " $_ " =~ /.*;.*;.*;/ ) {
346 logger
( "MIRROR INFO: $scount servers found in list" );
349 logger
( "MIRROR INFO: Could not find any servers. Falling back to main server $Conf ::mainserver" );
350 return ( "HTTPS" , $Conf :: mainserver
, "/ $Conf ::version" );
353 ### Choose a random server and test if it is online
354 # If the check fails try a new server.
355 # This will never give up.
358 $server = int ( rand ( $scount ) + 1 );
360 my ( $line , $proto , $path , $host );
362 foreach $line ( @newlines ) {
364 if ( $servers eq $server ) {
365 @templine = split ( /\;/ , $line );
366 $proto = $templine [ 0 ];
367 $host = $templine [ 1 ];
368 $path = $templine [ 2 ];
370 return ( $proto , $host , $path );
377 ### Update the database if the file is older than one day.
378 # If you pass &Pakfire::dbgetlist(force) the list will be downloaded.
379 # Usage is always with an argument.
385 if ( - e
" $Conf ::dbdir/lists/packages_list.db" ) {
386 my @stat = stat ( " $Conf ::dbdir/lists/packages_list.db" );
388 $age = $time - $stat [ 9 ];
389 $force = "force" if ( " $age " >= "3600" );
390 logger
( "DB INFO: packages_list.db is $age seconds old. - DEBUG: $force " );
396 if ( " $force " eq "force" ) {
397 if ( fetchfile
( "lists/packages_list.db" , "" )) {
398 move
( " $Conf ::cachedir/packages_list.db" , " $Conf ::dbdir/lists/packages_list.db" );
399 } elsif ( - e
" $Conf ::dbdir/lists/packages_list.db" ) {
400 # If we end up with no db file after download error there
401 # is nothing more we can do here.
406 # Update the meta database if new packages was in the package list
413 open ( FILE
, "< $Conf ::dbdir/lists/packages_list.db" );
417 opendir ( DIR
, " $Conf ::dbdir/meta" );
418 my @files = readdir ( DIR
);
420 foreach $file ( @files ) {
421 next if ( $file eq "." );
422 next if ( $file eq ".." );
423 next if ( $file eq "meta-" );
424 next if ( $file =~ /^old/ );
425 %metadata = parsemetafile
( " $Conf ::dbdir/meta/ $file " );
427 foreach $prog ( @db ) {
428 @templine = split ( /\;/ , $prog );
429 if (( " $metadata {'Name'}" eq " $templine [0]" ) && ( " $metadata {'Release'}" ne " $templine [2]" )) {
430 move
( " $Conf ::dbdir/meta/meta- $metadata {'Name'}" , " $Conf ::dbdir/meta/old_meta- $metadata {'Name'}" );
431 getmetafile
( $metadata { 'Name' });
438 ### This subroutine lists the packages.
439 # You may also pass a filter: &Pakfire::dblist(filter)
440 # Usage is always with two arguments.
441 # filter may be: all, notinstalled, installed
451 ### Make sure that the list is not outdated.
452 #dbgetlist("noforce");
454 open ( FILE
, "< $Conf ::dbdir/lists/packages_list.db" );
458 if ( " $filter " eq "upgrade" ) {
459 if ( " $forweb " ne "forweb" && " $forweb " ne "notice" ) { getcoredb
( "noforce" );}
460 eval ( `grep "core_" $Conf ::dbdir/lists/core-list.db` );
461 if ( " $core_release " > " $Conf ::core_mine" ) {
462 if ( " $forweb " eq "forweb" ) {
463 print "<option value= \" core \" >Core-Update -- $Conf ::version -- Release: $Conf ::core_mine -> $core_release </option> \n " ;
465 elsif ( " $forweb " eq "notice" ) {
466 print "<br /><br /><br /><a href='pakfire.cgi'> $Lang ::tr{'core notice 1'} $Conf ::core_mine $Lang ::tr{'core notice 2'} $core_release $Lang ::tr{'core notice 3'}</a>" ;
468 my $command = "Core-Update $Conf ::version \n Release: $Conf ::core_mine -> $core_release \n " ;
469 if ( " $Pakfire ::enable_colors" eq "1" ) {
470 print " $color {'lila'} $command $color {'normal'} \n " ;
477 opendir ( DIR
, " $Conf ::dbdir/installed" );
478 my @files = readdir ( DIR
);
480 foreach $file ( @files ) {
481 next if ( $file eq "." );
482 next if ( $file eq ".." );
483 next if ( $file =~ /^old/ );
484 %metadata = parsemetafile
( " $Conf ::dbdir/installed/ $file " );
486 foreach $prog ( @db ) {
487 @templine = split ( /\;/ , $prog );
488 if (( " $metadata {'Name'}" eq " $templine [0]" ) && ( " $metadata {'Release'}" < " $templine [2]" && " $forweb " ne "notice" )) {
489 push ( @updatepaks , $metadata { 'Name' });
490 if ( " $forweb " eq "forweb" ) {
491 print "<option value= \" $metadata {'Name'} \" >Update: $metadata {'Name'} -- Version: $metadata {'ProgVersion'} -> $templine [1] -- Release: $metadata {'Release'} -> $templine [2]</option> \n " ;
493 my $command = "Update: $metadata {'Name'} \n Version: $metadata {'ProgVersion'} -> $templine [1] \n Release: $metadata {'Release'} -> $templine [2] \n " ;
494 if ( " $Pakfire ::enable_colors" eq "1" ) {
495 print " $color {'lila'} $command $color {'normal'} \n " ;
509 foreach $line ( sort @db ) {
510 next unless ( $line =~ /.*;.*;.*;/ );
512 @templine = split ( /\;/ , $line );
513 if ( " $filter " eq "notinstalled" ) {
514 next if ( - e
" $Conf ::dbdir/installed/meta- $templine [0]" );
515 } elsif ( " $filter " eq "installed" ) {
516 next unless ( - e
" $Conf ::dbdir/installed/meta- $templine [0]" );
519 if ( " $forweb " eq "forweb" )
521 if ( " $filter " eq "notinstalled" ) {
522 print "<option value= \" $templine [0] \" > $templine [0]- $templine [1]- $templine [2]</option> \n " ;
524 print "<option value= \" $templine [0] \" > $templine [0]</option> \n " ;
527 if ( " $Pakfire ::enable_colors" eq "1" ) {
528 if (& isinstalled
( " $templine [0]" )) {
529 $use_color = " $color {'red'}"
531 $use_color = " $color {'green'}"
534 print "${use_color}Name: $templine [0] \n ProgVersion: $templine [1] \n Release: $templine [2] $color {'normal'} \n\n " ;
537 print " $count packages total. \n " unless ( " $forweb " eq "forweb" );
541 sub resolvedeps_one
{
544 message
( "PAKFIRE RESV: $pak : Resolving dependencies..." );
546 unless ( getmetafile
( " $pak " )) {
547 message
( "PAKFIRE ERROR: Error retrieving dependency information on $pak . Unable to resolve dependencies." );
551 my %metadata = parsemetafile
( " $Conf ::dbdir/meta/meta- $pak " );
553 my @deps = split ( / / , $metadata { 'Dependencies' });
557 my $return = & isinstalled
( $_ );
559 message
( "PAKFIRE RESV: $pak : Dependency is already installed: $_ " );
561 message
( "PAKFIRE RESV: $pak : Need to install dependency: $_ " );
574 # Resolve all not yet installed dependencies of $pak
575 my @deps = & resolvedeps_one
( $pak );
578 # For each dependency, we check if more dependencies exist
580 my $dep = pop ( @deps );
582 my @subdeps = & resolvedeps_one
( $dep );
583 foreach my $subdep ( @subdeps ) {
584 # Skip the package we are currently resolving for
585 next if ( $pak eq $subdep );
587 # If the package is not already to be installed,
588 # we add it to the list (@all) and check if it has
589 # more dependencies on its own.
590 unless ( grep { $_ eq $subdep } @all ) {
591 push ( @deps , $subdep );
600 sub resolvedeps_recursive
{
604 foreach my $pkg ( @packages ) {
605 my @deps = & Pakfire
:: resolvedeps
( $pkg );
607 foreach my $dep ( @deps ) {
612 # Sort the result array and remove dupes
613 my %sort = map { $_ , 1 } @result ;
614 @result = keys %sort ;
623 logger
( "CLEANUP: $dir " );
625 if ( " $dir " eq "meta" ) {
626 $path = " $Conf ::dbdir/meta" ;
627 } elsif ( " $dir " eq "tmp" ) {
628 $path = " $Conf ::tmpdir" ;
632 my @files = readdir ( DIR
);
635 unless (( $_ eq "." ) || ( $_ eq ".." )) {
644 # Try to download meta-file if we don't have one yet, or it is empty for some reason
645 if ((! - e
" $Conf ::dbdir/meta/meta- $pak " ) || ( - z
" $Conf ::dbdir/meta/meta- $pak " )) {
646 return 0 unless ( fetchfile
( "meta/meta- $pak " , "" ));
647 move
( " $Conf ::cachedir/meta- $pak " , " $Conf ::dbdir/meta/meta- $pak " );
650 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
654 open ( FILE
, "> $Conf ::dbdir/meta/meta- $pak " );
657 $string =~ s/\r\n/\n/g ;
670 if ( my %metadata = parsemetafile
( " $Conf ::dbdir/meta/meta- $pak " )) {
671 return $metadata { 'Size' };
677 ### This subroutine returns a hash with the contents of a meta- file
678 # Pass path to metafile as argument: Pakfire::parsemetafile("$Conf::dbdir/meta/meta-$pak")
679 # Usage is always with an argument.
680 my $metafile = shift ;
687 if (! - e
$metafile ) {
691 open ( FILE
, "< $metafile " );
696 @templine = split ( /\: / , $_ );
699 $metadata { " $templine [0]" } = $templine [ 1 ];
711 my $file = getpak
( " $pak " , "noforce" );
713 logger
( "DECRYPT STARTED: $pak " );
714 my $return = system ( "cd $Conf ::tmpdir/ && gpg -d --batch --quiet --no-verbose --status-fd 2 --output - < $Conf ::cachedir/ $file 2>/dev/null | tar x" );
716 logger
( "DECRYPT FINISHED: $pak - Status: $return " );
717 if ( $return != 0 ) { exit 1 ; }
724 unless ( getmetafile
( " $pak " )) {
725 message
( "PAKFIRE ERROR: Unable to retrieve $pak metadata." );
729 my %metadata = parsemetafile
( " $Conf ::dbdir/meta/meta- $pak " );
730 my $file = $metadata { 'File' };
733 message
( "No filename given in meta-file." );
737 unless ( " $force " eq "force" ) {
738 if ( - e
" $Conf ::cachedir/ $file " ) {
743 unless ( fetchfile
( "paks/ $file " , "" )) {
744 message
( "PAKFIRE ERROR: Unable to download $pak ." );
753 message
( "PAKFIRE INST: $pak : Decrypting..." );
756 message
( "PAKFIRE INST: $pak : Copying files and running post-installation scripts..." );
757 my $return = system ( "cd $Conf ::tmpdir && NAME= $pak ./install.sh >> $Conf ::logdir/install- $pak .log 2>&1" );
760 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
762 copy
( " $Conf ::dbdir/meta/meta- $pak " , " $Conf ::dbdir/installed/" );
763 message
( "PAKFIRE INST: $pak : Finished." );
766 message
( "PAKFIRE ERROR: Returncode: $return . Sorry. Please search our forum to find a solution for this problem." );
773 getcoredb
( "noforce" );
774 eval ( `grep "core_" $Conf ::dbdir/lists/core-list.db` );
775 if ( " $core_release " > " $Conf ::core_mine" ) {
776 # Safety check for lazy testers:
777 # Before we upgrade to the latest release, we re-install the previous release
778 # to make sure that the tester has always been on the latest version.
779 my $tree = & get_tree
();
780 $Conf :: core_mine
-- if ( $tree eq "testing" || $tree eq "unstable" );
782 message
( "CORE UPGR: Upgrading from release $Conf ::core_mine to $core_release " );
784 my @seq = `seq $Conf ::core_mine $core_release ` ;
787 foreach $release ( @seq ) {
789 getpak
( "core-upgrade- $release " );
792 foreach $release ( @seq ) {
794 upgradepak
( "core-upgrade- $release " );
797 system ( "echo $core_release > $Conf ::coredir/mine" );
800 message
( "CORE INFO: No new upgrades available. You are on release $Conf ::core_mine." );
806 if ( open ( FILE
, "< $Conf ::dbdir/installed/meta- $pak " ) ) {
817 message
( "PAKFIRE UPGR: $pak : Decrypting..." );
820 message
( "PAKFIRE UPGR: $pak : Upgrading files and running post-upgrading scripts..." );
821 my $return = system ( "cd $Conf ::tmpdir && NAME= $pak ./update.sh >> $Conf ::logdir/update- $pak .log 2>&1" );
824 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
826 copy
( " $Conf ::dbdir/meta/meta- $pak " , " $Conf ::dbdir/installed/" );
827 message
( "PAKFIRE UPGR: $pak : Finished." );
830 message
( "PAKFIRE ERROR: Returncode: $return . Sorry. Please search our forum to find a solution for this problem." );
839 message
( "PAKFIRE REMV: $pak : Decrypting..." );
842 message
( "PAKFIRE REMV: $pak : Removing files and running post-removing scripts..." );
843 my $return = system ( "cd $Conf ::tmpdir && NAME= $pak ./uninstall.sh >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
846 unlink ( " $Conf ::dbdir/rootfiles/ $pak " );
847 unlink ( " $Conf ::dbdir/installed/meta- $pak " );
849 message
( "PAKFIRE REMV: $pak : Finished." );
852 message
( "PAKFIRE ERROR: Returncode: $return . Sorry. Please search our forum to find a solution for this problem." );
860 #$size = $size / 1024;
863 if ( $size > 1023 * 1024 ) {
864 $size = ( $size / ( 1024 * 1024 ));
866 } elsif ( $size > 1023 ) {
867 $size = ( $size / 1024 );
872 $size = sprintf ( "%.2f" , $size );
873 my $string = " $size $unit " ;
878 unless ( - e
" $Conf ::dbdir/uuid" ) {
879 open ( FILE
, "</proc/sys/kernel/random/uuid" );
883 open ( FILE
, "> $Conf ::dbdir/uuid" );
892 my ( $data , $response , $protocol ) = @_ ;
893 $final_data .= $data ;
894 print progress_bar
( length ( $final_data ), $total_size , 30 , '=' );
898 my ( $got , $total , $width , $char ) = @_ ;
900 $width ||= 30 ; $char ||= '=' ;
901 my $len_bfile = length $bfile ;
902 if ( " $len_bfile " >= "17" ) {
903 $show_bfile = substr ( $bfile , 0 , 17 ). "..." ;
905 $show_bfile = $bfile ;
907 $progress = sprintf ( "%.2f%%" , 100 * $got /+ $total );
908 sprintf " $color {'lightgreen'}%-20s %7s |%-${width}s| %10s $color {'normal'} \r " , $show_bfile , $progress , $char x
(( $width - 1 )* $got / $total ). '>' , beautifysize
( $got );
911 sub updates_available
{
912 # Get packets with updates available
913 my @upgradepaks = & Pakfire
:: dblist
( "upgrade" , "noweb" );
915 # Get the length of the returned array
916 my $updatecount = scalar @upgradepaks ;
918 return " $updatecount " ;
921 sub coreupdate_available
{
922 eval ( `grep "core_" $Conf ::dbdir/lists/core-list.db` );
923 if ( " $core_release " > " $Conf ::core_mine" ) {
924 return "yes ( $core_release )" ;
931 sub reboot_required
{
932 if ( - e
"/var/run/need_reboot" ) {
942 my $return = "Core-Version: $Conf ::version \n " ;
943 $return .= "Core-Update-Level: $Conf ::core_mine \n " ;
944 $return .= "Last update: " . & General
:: age
( "/opt/pakfire/db/core/mine" ) . " ago \n " ;
945 $return .= "Last core-list update: " . & General
:: age
( "/opt/pakfire/db/lists/core-list.db" ) . " ago \n " ;
946 $return .= "Last server-list update: " . & General
:: age
( "/opt/pakfire/db/lists/server-list.db" ) . " ago \n " ;
947 $return .= "Last packages-list update: " . & General
:: age
( "/opt/pakfire/db/lists/packages_list.db" ) . " ago \n " ;
949 # Get availability of core updates
950 $return .= "Core-Update available: " . & Pakfire
:: coreupdate_available
() . " \n " ;
952 # Get availability of package updates
953 $return .= "Package-Updates available: " . & Pakfire
:: updates_available
() . " \n " ;
955 # Test if reboot is required
956 $return .= "Reboot required: " . & Pakfire
:: reboot_required
() . " \n " ;
964 # Append architecture
965 my ( $sysname , $nodename , $release , $version , $machine ) = POSIX
:: uname
();
967 # We only support armv6l for 32 bit arm
968 if ( $machine =~ m/armv[67]/ ) {
976 # Return stable if nothing is set
977 return "stable" unless ( defined $pakfiresettings { 'TREE' });
979 return $pakfiresettings { 'TREE' };
985 # Open /etc/system-release
986 open ( RELEASE
, "</etc/system-release" );
987 my $release = < RELEASE
>;
990 # Add the main relase
991 if ( $release =~ m/IPFire ([\d\.]+)/ ) {
995 # Append suffix for tree
996 my $tree = & get_tree
();
997 if ( $tree eq "testing" ) {
999 } elsif ( $tree eq "unstable" ) {
1003 # Append architecture
1004 $version .= "-" . & get_arch
();