]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/lib/functions.pl
48c34e91050dff03add509166e91129f54d54c19
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 " ;
59 $proto = "HTTP" unless $proto ;
61 logger
( "Trying to get $file from $host ( $proto )." );
63 my $ua = LWP
:: UserAgent
-> new ;
64 $ua -> agent ( "Pakfire/ $Conf ::version" );
68 my $response = $ua -> get ( "http:// $host / $file " );
70 if ( $response -> is_success ) {
71 logger
( " $host sends file: $file ." );
72 if ( open ( FILE
, "> $Conf ::cachedir/ $bfile " )) {
73 print FILE
$response -> content ;
78 logger
( "Could not open $Conf ::cachedir/ $bfile for writing." );
81 my $log = $response -> status_line ;
82 logger
( "Download $file failed from $host ( $proto ): $log " );
85 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." );
92 logger
( "Try to get a mirror list." );
94 fetchfile
( "lists/ $Conf ::version-server-list" , " $Conf ::mainserver" );
95 move
( " $Conf ::cachedir/ $Conf ::version-server-list" , " $Conf ::dbdir/lists/ $Conf ::version-server-list" );
99 ### Check if there is a current server list and read it.
100 # If there is no list try to get one.
102 while (!( open ( FILE
, "< $Conf ::dbdir/lists/ $Conf ::version-server-list" )) && ( $count lt 5 )) {
107 message
( "Could not find or download a server list." );
113 ### Count the number of the servers in the list
118 logger
( " $scount servers found in list." );
120 ### Choose a random server and test if it is online
121 # If the check fails try a new server.
122 # This will never give up.
125 while ( $found == 0 ) {
126 $server = int ( rand ( $scount ) + 1 );
128 my ( $line , $proto , $path , $host );
130 foreach $line ( @lines ) {
132 if ( $servers eq $server ) {
133 @templine = split ( /\;/ , $line );
134 $proto = $templine [ 0 ];
135 $host = $templine [ 1 ];
136 $path = $templine [ 2 ];
137 if ( pinghost
( " $host " )) {
139 return ( $proto , $host , $path );
147 ### Update the database if the file is older than one day.
148 # If you pass &Pakfire::dbgetlist(force) the list will be downloaded.
149 # Usage is always with an argument.
155 if ( - e
" $Conf ::dbdir/lists/packages_list.db" ) {
156 my @stat = stat ( " $Conf ::dbdir/lists/packages_list.db" );
158 $age = $time - $stat [ 9 ];
164 if (( " $age " gt 86400 ) || ( " $force " eq "force" )) {
166 fetchfile
( "lists/packages_list.db" , "" );
167 move
( " $Conf ::cachedir/packages_list.db" , " $Conf ::dbdir/lists/packages_list.db" );
172 ### This subroutine lists the packages.
173 # You may also pass a filter: &Pakfire::dblist(filter)
174 # Usage is always with two arguments.
175 # filter may be: all, notinstalled, installed
179 ### Make sure that the list is not outdated.
180 dbgetlist
( "noforce" );
182 open ( FILE
, "< $Conf ::dbdir/lists/packages_list.db" );
188 foreach $line ( sort @db ) {
189 @templine = split ( /\;/ , $line );
191 if ( " $forweb " eq "forweb" ) {
192 print "<option value= \" $templine [0] \" > $templine [1]</option> \n " ;
194 print " $templine [0] $templine [1] \n " ;
204 message
( " \n ## Resolving dependencies for $pak ..." );
206 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
211 my ( @templine , @deps , @tempdeps );
212 foreach $line ( @file ) {
213 @templine = split ( /\: / , $line );
214 if ( " $templine [0]" eq "Dependencies" ) {
215 @deps = split ( / / , $templine [ 1 ]);
221 message
( "### Found dependency: $_ " );
226 #my @tempdeps = @deps;
227 foreach ( @tempdeps ) {
229 my @newdeps = resolvedeps
( " $_ " );
231 unless (( $_ eq " " ) || ( $_ eq "" )) {
232 message
( "### Found dependency: $_ " );
246 if ( " $dir " eq "meta" ) {
247 $path = " $Conf ::dbdir/meta" ;
248 } elsif ( " $dir " eq "tmp" ) {
249 $path = " $Conf ::tmpdir" ;
253 my @files = readdir ( DIR
);
256 unless (( $_ eq "." ) || ( $_ eq ".." )) {
265 logger
( "Going to download meta- $pak ." );
267 unless ( - e
" $Conf ::dbdir/meta/meta- $pak " ) {
268 fetchfile
( "meta/meta- $pak " , "" );
269 move
( " $Conf ::cachedir/meta- $pak " , " $Conf ::dbdir/meta/meta- $pak " );
272 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
276 open ( FILE
, "> $Conf ::dbdir/meta/meta- $pak " );
279 $string =~ s/\r\n/\n/g ;
291 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
297 foreach $line ( @file ) {
298 @templine = split ( /\: / , $line );
299 if ( " $templine [0]" eq "Size" ) {
306 sub addsizes
{ ## Still not working
312 $paksize = getsize
( " $_ " );
313 $totalsize = ( $totalsize + $paksize ) ;
323 my $file = getpak
( " $pak " , "noforce" );
325 my $return = system ( "gpg -d < $Conf ::cachedir/ $file | tar xj -C $Conf ::tmpdir/" );
327 logger
( "Decryption process returned the following: $return " );
328 if ( $return == 1 ) { exit 1 ; }
337 open ( FILE
, "< $Conf ::dbdir/meta/meta- $pak " );
344 foreach $line ( @file ) {
345 @templine = split ( /\: / , $line );
346 if ( " $templine [0]" eq "File" ) {
348 $file = $templine [ 1 ];
353 message
( "No filename given in meta-file. Please phone the developers." );
357 #message("\n## Downloading $file...");
359 unless ( " $force " eq "force" ) {
360 if ( - e
" $Conf ::cachedir/ $file " ) {
365 fetchfile
( "paks/ $file " , "" );
372 message
( "We are going to install: $pak " );
376 my $return = system ( "cd $Conf ::tmpdir && ./install.sh >> $Conf ::logdir/install- $pak .log 2>&1" );
378 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
380 copy
( " $Conf ::dbdir/meta/meta- $pak " , " $Conf ::dbdir/installed/" );
381 message
( "Setup completed. Congratulations!" );
383 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
392 message
( "We are going to update: $pak " );
396 my $return = system ( "cd $Conf ::tmpdir && ./update.sh >> $Conf ::logdir/update- $pak .log 2>&1" );
398 move
( " $Conf ::tmpdir/ROOTFILES" , " $Conf ::dbdir/rootfiles/ $pak " );
400 message
( "Update completed. Congratulations!" );
402 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
411 message
( "We are going to uninstall: $pak " );
415 my $return = system ( "cd $Conf ::tmpdir && ./uninstall.sh >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
417 open ( FILE
, "< $Conf ::dbdir/rootfiles/ $pak " );
423 system ( "echo \" Removing: $line \" >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
424 system ( "cd / && rm -rf $line >> $Conf ::logdir/uninstall- $pak .log 2>&1" );
426 unlink ( " $Conf ::dbdir/rootfiles/ $pak " );
428 message
( "Uninstall completed. Congratulations!" );
430 message
( "Setup returned: $return . Sorry. Please search our forum to find a solution for this problem." );
438 $size = $size / 1024 ;
442 $size = ( $size / 1024 );
447 $size = sprintf ( "%.2f" , $size );
448 my $string = " $size $unit " ;
453 unless ( - e
" $Conf ::dbdir/uuid" ) {
454 message
( "Creating a random key..." );
455 open ( FILE
, "</proc/sys/kernel/random/uuid" );
459 open ( FILE
, "> $Conf ::dbdir/uuid" );
468 unless ( " $Conf ::uuid" ) {
469 $Conf :: uuid
= `cat $Conf ::dbdir/uuid` ;
471 logger
( "Sending my uuid: $Conf ::uuid" );
472 fetchfile
( "cgi-bin/counter?ver= $Conf ::version&uuid= $Conf ::uuid" , " $Conf ::mainserver" );
473 system ( "rm -f $Conf ::cachedir/counter* 2>/dev/null" );