]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/pakfire
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2021 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 ### Clean up our environment
24 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
28 $ENV{"GNUPGHOME"} = "/opt/pakfire/etc/.gnupg";
30 require "/opt/pakfire/lib/functions.pl";
33 my $force = "noforce";
36 &Pakfire
::logger
("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
38 ### Check if we are running as root
40 my $user = qx(whoami
);
42 unless ( "$user" eq "root" ) {
43 &Pakfire
::message
("PAKFIRE ERROR: You must run pakfire as user root!");
47 unless ( -e
"/var/ipfire/red/active" ) {
48 &Pakfire
::message
("PAKFIRE ERROR: You need to be online to run pakfire!");
52 # Check if a lockfile already exists.
53 if (-e
"$Pakfire::lockfile") {
54 &Pakfire
::message
("PAKFIRE ERROR: Another instance of pakfire is already running!");
59 open(LOCK
, ">$Pakfire::lockfile");
61 # Pakfire has locked in this session set locket to "1".
67 ### Check if we are started by another name
69 if ( $0 =~ /pakfire-update$/ ) {
70 &Pakfire
::message
("CRON INFO: Running an update");
71 my $random = int(rand(60));
72 &Pakfire
::logger
("CRON INFO: Waiting for $random seconds.");
76 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
77 &Pakfire
::message
("CRON INFO: Running an upgrade");
78 my $random = int(rand(3600));
79 &Pakfire
::logger
("CRON INFO: Waiting for $random seconds.");
91 # Turn off interactive mode
92 $interactive = 0 if ("$_" eq "--non-interactive");
93 $interactive = 0 if ("$_" eq "-y");
95 # Turn off shell colors - Bad for displaying in webinterface
96 $Pakfire::enable_colors
= 0 if ("$_" eq "--no-colors");
99 $force = "force" if ("$_" eq "-f" );
100 $force = "force" if ("$_" eq "--force" );
104 if ("$ARGV[0]" eq "install") {
107 ### Make sure that the list is not outdated.
108 &Pakfire
::dbgetlist
("noforce");
110 my %paklist = &Pakfire
::dblist
("all");
119 foreach $pak (@ARGV) {
120 unless ("$pak" =~ "^-") {
121 if (defined $paklist{$pak}) {
122 if ("$paklist{$pak}{'Installed'}" eq "yes") {
123 &Pakfire
::message
("PAKFIRE INFO: $pak is already installed");
128 @temp = &Pakfire
::resolvedeps
("$pak");
129 foreach $dep (@temp) {
130 push(@deps,$dep) if $dep;
131 push(@all,$dep) if $dep;
134 &Pakfire
::message
("");
135 &Pakfire
::message
("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
141 &Pakfire
::message
("PAKFIRE ERROR: No packages to install. Exiting...");
146 my %sort = map{ $_, 1 } @deps;
148 &Pakfire
::message
("");
149 &Pakfire
::message
("PAKFIRE INFO: Packages to install for dependencies:");
151 foreach $dep (@deps) {
152 my $size = &Pakfire
::getsize
("$dep");
153 $size = &Pakfire
::beautifysize
($size);
154 &Pakfire
::message
("PAKFIRE INFO: $dep \t - $size");
157 &Pakfire
::message
("");
158 &Pakfire
::message
("");
159 &Pakfire
::message
("PAKFIRE INFO: Packages to install:");
160 foreach $pak (@paks) {
161 my $size = &Pakfire
::getsize
("$pak");
162 $size = &Pakfire
::beautifysize
($size);
163 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
167 foreach $pak (@all) {
168 $totalsize = ($totalsize + &Pakfire
::getsize
("$pak"));
170 $totalsize = &Pakfire
::beautifysize
($totalsize);
171 &Pakfire
::message
("");
172 &Pakfire
::message
("PAKFIRE INFO: Total size: \t ~ $totalsize");
173 &Pakfire
::message
("");
176 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
179 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
181 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
185 &Pakfire
::logger
("PAKFIRE INFO: Interaction skipped.");
188 # my %sort = map{ $_, 1 } @all;
189 # @all = sort keys %sort;
192 foreach $pak (@all) {
193 &Pakfire
::getpak
("$pak", "");
196 &Pakfire
::message
("");
198 foreach $pak (@deps) {
199 &Pakfire
::setuppak
("$pak") if ($pak ne "");
203 foreach $pak (@paks) {
204 &Pakfire
::setuppak
("$pak") if ($pak ne "");
208 } elsif ("$ARGV[0]" eq "remove") {
213 foreach $pak (@ARGV) {
214 unless ("$pak" =~ "^-") {
215 $return = &Pakfire
::isinstalled
($pak);
217 &Pakfire
::message
("PAKFIRE WARN: $pak is not installed");
225 &Pakfire
::message
("PAKFIRE ERROR: No packages to remove. Exiting...");
229 &Pakfire
::message
("");
230 &Pakfire
::message
("");
231 &Pakfire
::message
("PAKFIRE INFO: Packages to remove:");
232 foreach $pak (sort @paks) {
233 my $size = &Pakfire
::getsize
("$pak");
234 $size = &Pakfire
::beautifysize
($size);
235 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
239 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
242 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
244 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
249 foreach $pak (@paks) {
250 &Pakfire
::removepak
("$pak");
254 } elsif ("$ARGV[0]" eq "update") {
255 &Pakfire
::makeuuid
();
256 &Pakfire
::getmirrors
("$force");
257 &Pakfire
::dbgetlist
("$force");
258 &Pakfire
::getcoredb
("$force");
260 } elsif ("$ARGV[0]" eq "upgrade") {
262 my $reset_color = "";
264 if ("$Pakfire::enable_colors" eq "1") {
265 $reset_color = "$Pakfire::color{'normal'}";
266 $use_color = "$Pakfire::color{'lightpurple'}";
269 &Pakfire
::message
("CORE INFO: Checking for Core-Updates...");
271 ### Make sure that the core db is not outdated.
272 &Pakfire
::getcoredb
("noforce");
273 my %coredb = &Pakfire
::coredbinfo
();
275 if (defined $coredb{'AvailableRelease'}) {
276 &Pakfire
::upgradecore
();
278 &Pakfire
::message
("CORE INFO: No new Core-Updates available. You are on release ".$coredb{'Release'});
281 &Pakfire
::message
("PAKFIRE INFO: Checking for package updates...");
282 ### Make sure that the package list is not outdated.
283 &Pakfire
::dbgetlist
("noforce");
286 if (my %upgradepaks = &Pakfire
::dblist
("upgrade")) {
287 # Resolve the dependencies of the to be upgraded packages
288 @deps = &Pakfire
::resolvedeps_recursive
(keys %upgradepaks);
290 foreach $pak (sort keys %upgradepaks) {
291 print "${use_color}Update: $pak\nVersion: $upgradepaks{$pak}{'ProgVersion'} -> $upgradepaks{$pak}{'AvailableProgVersion'}\n";
292 print "Release: $upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableRelease'}${reset_color}\n";
294 &Pakfire
::message
("");
295 &Pakfire
::message
("PAKFIRE UPGR: We are going to install all packages listed above.");
297 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
300 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
302 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
308 foreach $pak (sort keys %upgradepaks) {
309 &Pakfire
::getpak
("$pak", "");
312 # Download dependencies
313 foreach $pak (@deps) {
314 &Pakfire
::getpak
("$pak", "");
317 # Install dependencies first
318 foreach $pak (@deps) {
319 &Pakfire
::setuppak
("$pak");
322 # Install all upgrades
323 foreach $pak (sort keys %upgradepaks) {
324 &Pakfire
::upgradepak
("$pak");
327 &Pakfire
::message
("PAKFIRE WARN: No new package upgrades available.");
330 } elsif ("$ARGV[0]" eq "list") {
333 my $reset_color = "";
336 if ("$ARGV[1]" =~ /installed|notinstalled/) {
337 $filter = "$ARGV[1]";
339 &Pakfire
::message
("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
343 my %paklist = &Pakfire
::dblist
($filter);
345 if ("$Pakfire::enable_colors" eq "1") {
346 $reset_color = "$Pakfire::color{'normal'}";
347 $use_color = "$Pakfire::color{'lightgreen'}";
350 foreach $pak (sort keys %paklist) {
351 if ("$Pakfire::enable_colors" eq "1") {
352 if ("$paklist{$pak}{'Installed'}" eq "yes") {
353 if (defined $paklist{$pak}{'AvailableProgVersion'}) {
354 $use_color = "$Pakfire::color{'lightgreen'}";
356 $use_color = "$Pakfire::color{'green'}";
359 $use_color = "$Pakfire::color{'red'}";
363 print "${use_color}Name: $pak\nProgVersion: $paklist{$pak}{'ProgVersion'}\n";
364 print "Release: $paklist{$pak}{'Release'}\nInstalled: $paklist{$pak}{'Installed'}\n";
365 if (defined $paklist{$pak}{'AvailableProgVersion'}) {
366 print "Update available:\n Version: $paklist{$pak}{'ProgVersion'} -> $paklist{$pak}{'AvailableProgVersion'}\n Release: $paklist{$pak}{'Release'} -> $paklist{$pak}{'AvailableRelease'}\n";
368 print "${reset_color}\n";
372 $count = keys %paklist;
374 print "$count packages total.\n";
376 &Pakfire
::message
("PAKFIRE WARN: No packages where found using filter $filter.");
378 } elsif ("$ARGV[0]" eq "resolvedeps") {
380 next if ("$_" eq "resolvedeps");
381 next if ("$_" =~ "^-");
382 &Pakfire
::resolvedeps
("$_");
384 } elsif ("$ARGV[0]" eq "enable") {
385 if ("$ARGV[1]" eq "updates") {
386 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
387 } elsif ("$ARGV[1]" eq "upgrades") {
388 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
390 } elsif ("$ARGV[0]" eq "disable") {
391 if ("$ARGV[1]" eq "updates") {
392 system("rm -f /etc/fcron.daily/pakfire-update");
393 } elsif ("$ARGV[1]" eq "upgrades") {
394 system("rm -f /etc/fcron.daily/pakfire-upgrade");
396 } elsif ("$ARGV[0]" eq "status") {
402 &Pakfire
::logger
("PAKFIRE INFO: Pakfire has finished. Closing.");
405 # Check if pakfire has been locked in this session.
408 unlink($Pakfire::lockfile
);