]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/pakfire
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 ### Clean up our environment
24 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
27 require "/opt/pakfire/lib/functions.pl";
30 my $force = "noforce";
32 &Pakfire
::logger
("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
33 &Pakfire
::checkcryptodb
;
35 ### Check if we are running as root
37 my $user = qx(whoami
);
39 unless ( "$user" eq "root" ) {
40 &Pakfire
::message
("PAKFIRE ERROR: You must run pakfire as user root!");
44 unless ( -e
"/var/ipfire/red/active" ) {
45 &Pakfire
::message
("PAKFIRE ERROR: You need to be online to run pakfire!");
49 ### Check if we are started by another name
51 if ( $0 =~ /pakfire-update$/ ) {
52 &Pakfire
::message
("CRON INFO: Running an update");
53 my $random = int(rand(60));
54 &Pakfire
::logger
("CRON INFO: Waiting for $random seconds.");
58 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
59 &Pakfire
::message
("CRON INFO: Running an upgrade");
60 my $random = int(rand(3600));
61 &Pakfire
::logger
("CRON INFO: Waiting for $random seconds.");
73 # Turn off interactive mode
74 $interactive = 0 if ("$_" eq "--non-interactive");
75 $interactive = 0 if ("$_" eq "-y");
77 # Turn off shell colors - Bad for displaying in webinterface
78 $Pakfire::enable_colors
= 0 if ("$_" eq "--no-colors");
81 $force = "force" if ("$_" eq "-f" );
82 $force = "force" if ("$_" eq "--force" );
86 if ("$ARGV[0]" eq "install") {
89 ### Make sure that the list is not outdated.
90 &Pakfire
::dbgetlist
("noforce");
92 open(FILE
, "<$Conf::dbdir/lists/packages_list.db");
105 foreach $pak (@ARGV) {
106 unless ("$pak" =~ "^-") {
107 $return = &Pakfire
::isinstalled
($pak);
109 &Pakfire
::message
("PAKFIRE INFO: $pak is already installed");
114 @templine = split(/;/,$_);
115 if ("$templine[0]" eq "$pak" ) {
118 @temp = &Pakfire
::resolvedeps
("$pak");
119 foreach $dep (@temp) {
120 push(@deps,$dep) if $dep;
121 push(@all,$dep) if $dep;
128 &Pakfire
::message
("");
129 &Pakfire
::message
("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
135 &Pakfire
::message
("PAKFIRE ERROR: No packages to install. Exiting...");
140 my %sort = map{ $_, 1 } @deps;
142 &Pakfire
::message
("");
143 &Pakfire
::message
("PAKFIRE INFO: Packages to install for dependencies:");
145 foreach $dep (@deps) {
146 my $size = &Pakfire
::getsize
("$dep");
147 $size = &Pakfire
::beautifysize
($size);
148 &Pakfire
::message
("PAKFIRE INFO: $dep \t - $size");
151 &Pakfire
::message
("");
152 &Pakfire
::message
("");
153 &Pakfire
::message
("PAKFIRE INFO: Packages to install:");
154 foreach $pak (@paks) {
155 my $size = &Pakfire
::getsize
("$pak");
156 $size = &Pakfire
::beautifysize
($size);
157 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
161 foreach $pak (@all) {
162 $totalsize = ($totalsize + &Pakfire
::getsize
("$pak"));
164 $totalsize = &Pakfire
::beautifysize
($totalsize);
165 &Pakfire
::message
("");
166 &Pakfire
::message
("PAKFIRE INFO: Total size: \t ~ $totalsize");
167 &Pakfire
::message
("");
170 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
173 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
175 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
179 &Pakfire
::logger
("PAKFIRE INFO: Interaction skipped.");
182 # my %sort = map{ $_, 1 } @all;
183 # @all = sort keys %sort;
186 foreach $pak (@all) {
187 &Pakfire
::getpak
("$pak", "");
190 &Pakfire
::message
("");
192 foreach $pak (@deps) {
193 &Pakfire
::setuppak
("$pak") if ($pak ne "");
197 foreach $pak (@paks) {
198 &Pakfire
::setuppak
("$pak") if ($pak ne "");
202 } elsif ("$ARGV[0]" eq "remove") {
207 foreach $pak (@ARGV) {
208 unless ("$pak" =~ "^-") {
209 $return = &Pakfire
::isinstalled
($pak);
211 &Pakfire
::message
("PAKFIRE WARN: $pak is not installed");
219 &Pakfire
::message
("PAKFIRE ERROR: No packages to remove. Exiting...");
223 &Pakfire
::message
("");
224 &Pakfire
::message
("");
225 &Pakfire
::message
("PAKFIRE INFO: Packages to remove:");
226 foreach $pak (sort @paks) {
227 my $size = &Pakfire
::getsize
("$pak");
228 $size = &Pakfire
::beautifysize
($size);
229 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
233 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
236 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
238 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
243 foreach $pak (@paks) {
244 &Pakfire
::removepak
("$pak");
248 } elsif ("$ARGV[0]" eq "update") {
249 &Pakfire
::makeuuid
();
250 &Pakfire
::senduuid
();
251 &Pakfire
::getmirrors
("$force");
252 &Pakfire
::dbgetlist
("$force");
253 &Pakfire
::getcoredb
("$force");
255 } elsif ("$ARGV[0]" eq "upgrade") {
256 &Pakfire
::upgradecore
();
257 my @upgradepaks = &Pakfire
::dblist
("upgrade", "noweb");
260 foreach (@upgradepaks) {
261 @temp = &Pakfire
::resolvedeps
("$_");
262 foreach (@temp) { push(@upgradepaks,$_) if $_; }
266 &Pakfire
::message
("");
267 &Pakfire
::message
("PAKFIRE UPGR: We are going to install all packages listed above.");
269 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
272 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
274 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
281 foreach $pak (@upgradepaks) {
282 #system("mv $Conf::dbdir/meta/meta-$pak $Conf::dbdir/meta/old-meta-$pak");
283 &Pakfire
::getpak
("$pak", "");
286 foreach $pak (@upgradepaks) {
287 if (&Pakfire
::upgradepak
("$pak")) {
288 #system("mv $Conf::dbdir/meta/old-meta-$pak $Conf::dbdir/meta/meta-$pak");
292 } elsif ("$ARGV[0]" eq "list") {
293 if ("$ARGV[1]" =~ /installed|notinstalled/) {
294 &Pakfire
::dblist
("$ARGV[1]", "noweb");
296 &Pakfire
::message
("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
297 &Pakfire
::dblist
("all", "noweb");
300 } elsif ("$ARGV[0]" eq "resolvedeps") {
302 next if ("$_" eq "resolvedeps");
303 next if ("$_" =~ "^-");
304 &Pakfire
::resolvedeps
("$_");
306 } elsif ("$ARGV[0]" eq "enable") {
307 if ("$ARGV[1]" eq "updates") {
308 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
309 } elsif ("$ARGV[1]" eq "upgrades") {
310 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
312 } elsif ("$ARGV[0]" eq "disable") {
313 if ("$ARGV[1]" eq "updates") {
314 system("rm -f /etc/fcron.daily/pakfire-update");
315 } elsif ("$ARGV[1]" eq "upgrades") {
316 system("rm -f /etc/fcron.daily/pakfire-upgrade");
322 &Pakfire
::logger
("PAKFIRE INFO: Pakfire has finished. Closing.");