#!/usr/bin/perl -w
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
require "/opt/pakfire/etc/pakfire.conf";
require "/var/ipfire/general-functions.pl";
package Pakfire;
+# GPG Keys
+my $myid = "64D96617"; # Our own gpg-key paks@ipfire.org
+my $trustid = "65D0FD58"; # gpg-key of CaCert
+
# A small color-hash :D
my %color;
$color{'normal'} = "\033[0m";
$color{'lightgrey'} = "\033[0;37m";
$color{'yellow'} = "\033[1;33m";
$color{'white'} = "\033[1;37m";
+our $enable_colors = 1;
my $final_data;
my $total_size;
my $message = shift;
logger("$message");
- if ("$message" =~ /ERROR/) {
- $message = "$color{'red'}$message$color{'normal'}";
- } elsif ("$message" =~ /INFO/) {
- $message = "$color{'cyan'}$message$color{'normal'}";
- } elsif ("$message" =~ /WARN/) {
- $message = "$color{'yellow'}$message$color{'normal'}";
- } elsif ("$message" =~ /RESV/) {
- $message = "$color{'purple'}$message$color{'normal'}";
- } elsif ("$message" =~ /INST/) {
- $message = "$color{'green'}$message$color{'normal'}";
- } elsif ("$message" =~ /REMV/) {
- $message = "$color{'lightred'}$message$color{'normal'}";
- } elsif ("$message" =~ /UPGR/) {
- $message = "$color{'lightblue'}$message$color{'normal'}";
+ if ( $enable_colors == 1 ) {
+ if ("$message" =~ /ERROR/) {
+ $message = "$color{'red'}$message$color{'normal'}";
+ } elsif ("$message" =~ /INFO/) {
+ $message = "$color{'cyan'}$message$color{'normal'}";
+ } elsif ("$message" =~ /WARN/) {
+ $message = "$color{'yellow'}$message$color{'normal'}";
+ } elsif ("$message" =~ /RESV/) {
+ $message = "$color{'purple'}$message$color{'normal'}";
+ } elsif ("$message" =~ /INST/) {
+ $message = "$color{'green'}$message$color{'normal'}";
+ } elsif ("$message" =~ /REMV/) {
+ $message = "$color{'lightred'}$message$color{'normal'}";
+ } elsif ("$message" =~ /UPGR/) {
+ $message = "$color{'lightblue'}$message$color{'normal'}";
+ }
}
print "$message\n";
}
sub usage {
- &Pakfire::message("Usage: pakfire <install|remove> <pak(s)>");
+ &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>");
&Pakfire::message(" <update> - Contacts the servers for new lists of paks.");
&Pakfire::message(" <upgrade> - Installs the latest version of all paks.");
&Pakfire::message(" <list> - Outputs a short list with all available paks.");
&Pakfire::message("");
+ &Pakfire::message(" Global options:");
+ &Pakfire::message(" --non-interactive --> Enables the non-interactive mode.");
+ &Pakfire::message(" You won't see any question here.");
+ &Pakfire::message(" -y --> Short for --non-interactive.");
+ &Pakfire::message(" --no-colors --> Turns off the wonderful colors.");
+ &Pakfire::message("");
exit 1;
}
sub fetchfile {
my $getfile = shift;
my $gethost = shift;
- my (@server, $host, $proto, $file, $allok, $i);
+ my (@server, $host, $proto, $file, $i);
+ my $allok = 0;
- logger("DOWNLOAD STARTED: $getfile") unless ($bfile =~ /^counter\?.*/);
use File::Basename;
$bfile = basename("$getfile");
+
+ logger("DOWNLOAD STARTED: $getfile") unless ($bfile =~ /^counter\?.*/);
$i = 0;
while (($allok == 0) && $i < 5) {
unless ($bfile =~ /^counter\?.*/) {
logger("DOWNLOAD INFO: Host: $host ($proto) - File: $file");
- #message("DOWNLOAD INFO: Loading $bfile from ($proto) $host...");
}
my $ua = LWP::UserAgent->new;
}
sub getmirrors {
+ my $force = shift;
+ my $age;
+
use File::Copy;
+
+ if ( -e "$Conf::dbdir/lists/server-list.db" ) {
+ my @stat = stat("$Conf::dbdir/lists/server-list.db");
+ my $time = time();
+ $age = $time - $stat[9];
+ $force = "force" if ("$age" >= "3600");
+ logger("MIRROR INFO: server-list.db is $age seconds old. - DEBUG: $force");
+ } else {
+ # Force an update.
+ $force = "force";
+ }
+
+ if ("$force" eq "force") {
+ fetchfile("$Conf::version/lists/server-list.db", "$Conf::mainserver");
+ move("$Conf::cachedir/server-list.db", "$Conf::dbdir/lists/server-list.db");
+ }
+}
- logger("MIRROR: Trying to get a mirror list.");
+sub getcoredb {
+ my $force = shift;
+ my $age;
+
+ use File::Copy;
+
+ if ( -e "$Conf::dbdir/lists/core-list.db" ) {
+ my @stat = stat("$Conf::dbdir/lists/core-list.db");
+ my $time = time();
+ $age = $time - $stat[9];
+ $force = "force" if ("$age" >= "3600");
+ logger("CORE INFO: core-list.db is $age seconds old. - DEBUG: $force");
+ } else {
+ # Force an update.
+ $force = "force";
+ }
- fetchfile("$Conf::version/lists/server-list.db", "$Conf::mainserver");
- move("$Conf::cachedir/server-list.db", "$Conf::dbdir/lists/server-list.db");
+ if ("$force" eq "force") {
+ fetchfile("lists/core-list.db", "");
+ move("$Conf::cachedir/core-list.db", "$Conf::dbdir/lists/core-list.db");
+ }
}
+
sub selectmirror {
### Check if there is a current server list and read it.
# If there is no list try to get one.
my $count = 0;
while (!(open(FILE, "<$Conf::dbdir/lists/server-list.db")) && ($count lt 5)) {
$count++;
- getmirrors();
+ getmirrors("noforce");
}
if ($count == 5) {
message("MIRROR ERROR: Could not find or download a server list");
my @stat = stat("$Conf::dbdir/lists/packages_list.db");
my $time = time();
$age = $time - $stat[9];
+ $force = "force" if ("$age" >= "3600");
+ logger("DB INFO: packages_list.db is $age seconds old. - DEBUG: $force");
} else {
# Force an update.
- $age = "86401";
+ $force = "force";
}
- if (("$age" gt "86400") || ("$force" eq "force")) {
+ if ("$force" eq "force") {
fetchfile("lists/packages_list.db", "");
move("$Conf::cachedir/packages_list.db", "$Conf::dbdir/lists/packages_list.db");
}
my @templine;
### Make sure that the list is not outdated.
- dbgetlist("noforce");
+ #dbgetlist("noforce");
open(FILE, "<$Conf::dbdir/lists/packages_list.db");
my @db = <FILE>;
close(FILE);
if ("$filter" eq "upgrade") {
+ getcoredb("noforce");
+ eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
+ if ("$core_release" gt "$Conf::core_mine") {
+ if ("$forweb" eq "forweb") {
+ print "<option value=\"core\">Core-Update -- $Conf::version -- Release: $Conf::core_mine -> $core_release</option>\n";
+ } else {
+ my $command = "Core-Update $Conf::version\nRelease: $Conf::core_mine -> $core_release\n";
+ if ("$Pakfire::enable_colors" eq "1") {
+ print "$color{'lila'}$command$color{'normal'}\n";
+ } else {
+ print "$command\n";
+ }
+ }
+ }
+
opendir(DIR,"$Conf::dbdir/meta");
my @files = readdir(DIR);
closedir(DIR);
if ("$forweb" eq "forweb") {
print "<option value=\"$name\">Update: $name -- Version: $version -> $templine[1] -- Release: $release -> $templine[2]</option>\n";
} else {
- print "Update: $name\nVersion: $version -> $templine[1]\nRelease: $release -> $templine[2]\n\n";
+ my $command = "Update: $name\nVersion: $version -> $templine[1]\nRelease: $release -> $templine[2]\n";
+ if ("$Pakfire::enable_colors" eq "1") {
+ print "$color{'lila'}$command$color{'normal'}\n";
+ } else {
+ print "$command\n";
+ }
}
}
}
return @updatepaks;
} else {
my $line;
+ my $use_color;
my @templine;
+ my $count;
foreach $line (sort @db) {
next unless ($line =~ /.*;.*;.*;/ );
+ $use_color = "";
+ $count++;
@templine = split(/\;/,$line);
if ("$filter" eq "notinstalled") {
next if ( -e "$Conf::dbdir/installed/meta-$templine[0]" );
if ("$forweb" eq "forweb") {
print "<option value=\"$templine[0]\">$templine[0]-$templine[1]-$templine[2]</option>\n";
} else {
- print "Name: $templine[0]\nProgVersion: $templine[1]\nRelease: $templine[2]\n\n";
+ if ("$Pakfire::enable_colors" eq "1") {
+ if (&isinstalled("$templine[0]")) {
+ $use_color = "$color{'red'}"
+ } else {
+ $use_color = "$color{'green'}"
+ }
+ }
+ print "${use_color}Name: $templine[0]\nProgVersion: $templine[1]\nRelease: $templine[2]$color{'normal'}\n\n";
}
}
+ print "$count packages total.\n" unless ("$forweb" eq "forweb");
}
}
return $return;
}
+sub upgradecore {
+ getcoredb("noforce");
+ eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
+ if ("$core_release" gt "$Conf::core_mine") {
+ message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release");
+
+ my @seq = `seq $Conf::core_mine $core_release`;
+ shift @seq;
+ my $release;
+ foreach $release (@seq) {
+ chomp($release);
+ getpak("core-upgrade-$release");
+ }
+
+ foreach $release (@seq) {
+ chomp($release);
+ upgradepak("core-upgrade-$release");
+ }
+
+ system("echo $core_release > $Conf::coredir/mine");
+
+ } else {
+ message("CORE ERROR: No new upgrades available. You are on release $Conf::core_mine.");
+ }
+}
+
sub isinstalled {
my $pak = shift;
if ( open(FILE,"<$Conf::dbdir/installed/meta-$pak") ) {
sub checkcryptodb {
logger("CRYPTO INFO: Checking GnuPG Database");
- my $myid = "64D96617"; # Our own gpg-key
- my $trustid = "65D0FD58"; # Id of CaCert
my $ret = system("gpg --list-keys | grep -q $myid");
unless ( "$ret" eq "0" ) {
message("CRYPTO WARN: The GnuPG isn't configured corectly. Trying now to fix this.");
message("CRYPTO WARN: It's normal to see this on first execution.");
- system("gpg --keyserver wwwkeys.de.pgp.net --always-trust --recv-key $myid &>>$Conf::logdir/gnupg-database.log");
- system("gpg --keyserver wwwkeys.de.pgp.net --always-trust --recv-key $trustid &>>$Conf::logdir/gnupg-database.log");
+ my $command = "gpg --keyserver pgp.mit.edu --always-trust --status-fd 2";
+ system("$command --recv-key $myid >> $Conf::logdir/gnupg-database.log 2>&1");
+ system("$command --recv-key $trustid >> $Conf::logdir/gnupg-database.log 2>&1");
} else {
logger("CRYPTO INFO: Database is okay");
}