]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/pakfire/lib/functions.pl
000b2cfc82ec270d47e44142c4e27dd849475f07
3 require "/opt/pakfire/etc/pakfire.conf" ;
21 system ( "logger -t pakfire \" $log \" " );
27 $p = Net
:: Ping
-> new ();
28 if ( $p -> ping ( $host )) {
29 logger
( " $host is alive." );
32 logger
( " $host is dead." );
41 my ( @server , $host , $proto , $file , $allok , $i );
44 $bfile = basename
( " $getfile " );
47 while (( $allok == 0 ) && $i < 5 ) {
50 if ( " $gethost " eq "" ) {
51 @server = selectmirror
();
54 $file = " $server [2]/ $getfile " ;
60 $proto = "HTTP" unless $proto ;
62 logger
( "Trying to get $file from $host ( $proto )." );
64 my $ua = LWP
:: UserAgent
-> new ;
65 $ua -> agent ( "Pakfire/ $Conf ::version" );
69 my $response = $ua -> get ( "http:// $host / $file " );
71 if ( $response -> is_success ) {
72 logger
( " $host sends file: $file ." );
73 if ( open ( FILE
, "> $Conf ::cachedir/ $bfile " )) {
74 print FILE
$response -> content ;
79 logger
( "Could not open $Conf ::cachedir/ $bfile for writing." );
82 my $log = $response -> status_line ;
83 logger
( "Download $file failed from $host ( $proto ): $log " );
86 message
( "Giving up: 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." );
93 logger
( "Try to get a mirror list." );
95 fetchfile
( "lists/ $Conf ::version-server-list" , " $Conf ::mainserver" );
96 move
( " $Conf ::cachedir/ $Conf ::version-server-list" , " $Conf ::dbdir/lists/ $Conf ::version-server-list" );
100 ### Check if there is a current server list and read it.
101 # If there is no list try to get one.
103 while (!( open ( FILE
, "< $Conf ::dbdir/lists/ $Conf ::version-server-list" )) && ( $count lt 5 )) {
108 message
( "Could not find or download a server list." );
114 ### Count the number of the servers in the list
119 logger
( " $scount servers found in list." );
121 ### Choose a random server and test if it is online
122 # If the check fails try a new server.
123 # This will never give up.
126 while ( $found == 0 ) {
127 $server = int ( rand ( $scount ) + 1 );
129 my ( $line , $proto , $path , $host );
131 foreach $line ( @lines ) {
133 if ( $servers eq $server ) {
134 @templine = split ( /\;/ , $line );
135 $proto = $templine [ 0 ];
136 $host = $templine [ 1 ];
137 $path = $templine [ 2 ];
138 if ( pinghost
( " $host " )) {
140 return ( $proto , $host , $path );
148 ### Update the database if the file is older than one day.
149 # If you pass &Pakfire::dbgetlist(force) the list will be downloaded.
150 # Usage is always with an argument.
156 if ( - e
" $Conf ::dbdir/lists/packages_list.db" ) {
157 my @stat = stat ( " $Conf ::dbdir/lists/packages_list.db" );
159 $age = $time - $stat [ 9 ];
165 if (( " $age " gt 86400 ) || ( " $force " eq "force" )) {
167 fetchfile
( "lists/packages_list.db" , "" );
168 move
( " $Conf ::cachedir/packages_list.db" , " $Conf ::dbdir/lists/packages_list.db" );
173 ### This subroutine lists the packages.
174 # You may also pass a filter: &Pakfire::dblist(filter)
175 # Usage is always with two arguments.
176 # filter may be: all, notinstalled, installed
180 ### Make sure that the list is not outdated.
181 dbgetlist
( "noforce" );
183 open ( FILE
, "< $Conf ::dbdir/lists/packages_list.db" );
189 foreach $line ( sort @db ) {
190 @templine = split ( /\;/ , $line );
192 if ( " $forweb " eq "forweb" ) {
193 print "<option value= \" $templine [0] \" > $templine [0]- $templine [1]- $templine [2]</option> \n " ;
195 print "Name: $templine [0] \n Version: $templine [1] \n Release: $templine [2] \n\n " ;
205 message
( " \n ## Resolving dependencies for $pak ..." );
207 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
212 my ( @templine , @deps , @tempdeps );
213 foreach $line ( @file ) {
214 @templine = split ( /\: / , $line );
215 if ( " $templine [0]" eq "Dependencies" ) {
216 @deps = split ( / / , $templine [ 1 ]);
222 message
( "### Found dependency: $_ " );
227 #my @tempdeps = @deps;
228 foreach ( @tempdeps ) {
230 my @newdeps = resolvedeps
( " $_ " );
232 unless (( $_ eq " " ) || ( $_ eq "" )) {
233 message
( "### Found dependency: $_ " );
247 if ( " $dir " eq "meta" ) {
248 $path = " $Conf ::dbdir/meta" ;
249 } elsif ( " $dir " eq "tmp" ) {
250 $path = " $Conf ::tmpdir" ;
254 my @files = readdir ( DIR
);
257 unless (( $_ eq "." ) || ( $_ eq ".." )) {
266 logger
( "Going to download meta- $pak ." );
268 unless ( - e
" $Conf ::dbdir/meta/meta- $pak " ) {
269 fetchfile
( "meta/meta- $pak " , "" );
270 move
( " $Conf ::cachedir/meta- $pak " , " $Conf ::dbdir/meta/meta- $pak " );
273 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
277 open ( FILE
, "> $Conf ::dbdir/meta/meta- $pak " );
280 $string =~ s/\r\n/\n/g ;
292 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
298 foreach $line ( @file ) {
299 @templine = split ( /\: / , $line );
300 if ( " $templine [0]" eq "Size" ) {
307 sub addsizes
{ ## Still not working
313 $paksize = getsize
( " $_ " );
314 $totalsize = ( $totalsize + $paksize ) ;
324 my $file = getpak
( " $pak " , "noforce" );
326 my $return = system ( "gpg -d < $Conf ::cachedir/ $file | tar xj -C $Conf ::tmpdir/" );
328 logger
( "Decryption process returned the following: $return " );
329 if ( $return != 1 ) { exit 1 ; }
338 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
345 foreach $line ( @file ) {
346 @templine = split ( /\: / , $line );
347 if ( " $templine [0]" eq "File" ) {
349 $file = $templine [ 1 ];
354 message
( "No filename given in meta-file. Please phone the developers." );
358 unless ( " $force " eq "force" ) {
359 if ( - e
" $Conf ::cachedir/ $file " ) {
364 fetchfile
( "paks/ $file " , "" );
371 message
( "We are going to install: $pak " );
375 my $return = system ( "cd $Conf ::tmpdir && ./install.sh >> $Conf ::logdir/install- $pak .log 2>&1" );
377 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
379 copy
( " $Conf ::dbdir/meta/meta- $pak " , " $Conf ::dbdir/installed/" );
380 message
( "Setup completed. Congratulations!" );
382 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
391 message
( "We are going to update: $pak " );
395 my $return = system ( "cd $Conf ::tmpdir && ./update.sh >> $Conf ::logdir/update- $pak .log 2>&1" );
397 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
399 message
( "Update completed. Congratulations!" );
401 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
410 message
( "We are going to uninstall: $pak " );
414 my $return = system ( "cd $Conf ::tmpdir && ./uninstall.sh >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
416 open ( FILE
, "< $Conf ::dbdir/rootfiles/ $pak " );
422 system ( "echo \" Removing: $line \" >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
423 system ( "cd / && rm -rf $line >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
425 unlink ( " $Conf ::dbdir/rootfiles/ $pak " );
427 message
( "Uninstall completed. Congratulations!" );
429 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
437 $size = $size / 1024 ;
441 $size = ( $size / 1024 );
446 $size = sprintf ( "%.2f" , $size );
447 my $string = " $size $unit " ;
452 unless ( - e
" $Conf ::dbdir/uuid" ) {
453 open ( FILE
, "</proc/sys/kernel/random/uuid" );
457 open ( FILE
, "> $Conf ::dbdir/uuid" );
466 unless ( " $Conf ::uuid" ) {
467 $Conf :: uuid
= `cat $Conf ::dbdir/uuid` ;
469 logger
( "Sending my uuid: $Conf ::uuid" );
470 fetchfile
( "cgi-bin/counter?ver= $Conf ::version&uuid= $Conf ::uuid" , " $Conf ::mainserver" );
471 system ( "rm -f $Conf ::cachedir/counter* 2>/dev/null" );