]>
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 open(FILE
, "<$Conf::dbdir/lists/packages_list.db");
123 foreach $pak (@ARGV) {
124 unless ("$pak" =~ "^-") {
125 $return = &Pakfire
::isinstalled
($pak);
127 &Pakfire
::message
("PAKFIRE INFO: $pak is already installed");
132 @templine = split(/;/,$_);
133 if ("$templine[0]" eq "$pak" ) {
136 @temp = &Pakfire
::resolvedeps
("$pak");
137 foreach $dep (@temp) {
138 push(@deps,$dep) if $dep;
139 push(@all,$dep) if $dep;
146 &Pakfire
::message
("");
147 &Pakfire
::message
("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
153 &Pakfire
::message
("PAKFIRE ERROR: No packages to install. Exiting...");
158 my %sort = map{ $_, 1 } @deps;
160 &Pakfire
::message
("");
161 &Pakfire
::message
("PAKFIRE INFO: Packages to install for dependencies:");
163 foreach $dep (@deps) {
164 my $size = &Pakfire
::getsize
("$dep");
165 $size = &Pakfire
::beautifysize
($size);
166 &Pakfire
::message
("PAKFIRE INFO: $dep \t - $size");
169 &Pakfire
::message
("");
170 &Pakfire
::message
("");
171 &Pakfire
::message
("PAKFIRE INFO: Packages to install:");
172 foreach $pak (@paks) {
173 my $size = &Pakfire
::getsize
("$pak");
174 $size = &Pakfire
::beautifysize
($size);
175 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
179 foreach $pak (@all) {
180 $totalsize = ($totalsize + &Pakfire
::getsize
("$pak"));
182 $totalsize = &Pakfire
::beautifysize
($totalsize);
183 &Pakfire
::message
("");
184 &Pakfire
::message
("PAKFIRE INFO: Total size: \t ~ $totalsize");
185 &Pakfire
::message
("");
188 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
191 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
193 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
197 &Pakfire
::logger
("PAKFIRE INFO: Interaction skipped.");
200 # my %sort = map{ $_, 1 } @all;
201 # @all = sort keys %sort;
204 foreach $pak (@all) {
205 &Pakfire
::getpak
("$pak", "");
208 &Pakfire
::message
("");
210 foreach $pak (@deps) {
211 &Pakfire
::setuppak
("$pak") if ($pak ne "");
215 foreach $pak (@paks) {
216 &Pakfire
::setuppak
("$pak") if ($pak ne "");
220 } elsif ("$ARGV[0]" eq "remove") {
225 foreach $pak (@ARGV) {
226 unless ("$pak" =~ "^-") {
227 $return = &Pakfire
::isinstalled
($pak);
229 &Pakfire
::message
("PAKFIRE WARN: $pak is not installed");
237 &Pakfire
::message
("PAKFIRE ERROR: No packages to remove. Exiting...");
241 &Pakfire
::message
("");
242 &Pakfire
::message
("");
243 &Pakfire
::message
("PAKFIRE INFO: Packages to remove:");
244 foreach $pak (sort @paks) {
245 my $size = &Pakfire
::getsize
("$pak");
246 $size = &Pakfire
::beautifysize
($size);
247 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
251 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
254 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
256 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
261 foreach $pak (@paks) {
262 &Pakfire
::removepak
("$pak");
266 } elsif ("$ARGV[0]" eq "update") {
267 &Pakfire
::makeuuid
();
268 &Pakfire
::getmirrors
("$force");
269 &Pakfire
::dbgetlist
("$force");
270 &Pakfire
::getcoredb
("$force");
272 } elsif ("$ARGV[0]" eq "upgrade") {
273 &Pakfire
::upgradecore
();
274 my @upgradepaks = &Pakfire
::dblist
("upgrade", "noweb");
278 # Resolve the dependencies of the to be upgraded packages
279 @deps = &Pakfire
::resolvedeps_recursive
(@upgradepaks);
281 &Pakfire
::message
("");
282 &Pakfire
::message
("PAKFIRE UPGR: We are going to install all packages listed above.");
284 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
287 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
289 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
296 foreach $pak (@upgradepaks) {
297 &Pakfire
::getpak
("$pak", "");
300 # Download dependencies
301 foreach $pak (@deps) {
302 &Pakfire
::getpak
("$pak", "");
305 # Install dependencies first
306 foreach $pak (@deps) {
307 &Pakfire
::setuppak
("$pak");
310 # Install all upgrades
311 foreach $pak (@upgradepaks) {
312 &Pakfire
::upgradepak
("$pak");
315 } elsif ("$ARGV[0]" eq "list") {
316 if ("$ARGV[1]" =~ /installed|notinstalled/) {
317 &Pakfire
::dblist
("$ARGV[1]", "noweb");
319 &Pakfire
::message
("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
320 &Pakfire
::dblist
("all", "noweb");
323 } elsif ("$ARGV[0]" eq "resolvedeps") {
325 next if ("$_" eq "resolvedeps");
326 next if ("$_" =~ "^-");
327 &Pakfire
::resolvedeps
("$_");
329 } elsif ("$ARGV[0]" eq "enable") {
330 if ("$ARGV[1]" eq "updates") {
331 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
332 } elsif ("$ARGV[1]" eq "upgrades") {
333 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
335 } elsif ("$ARGV[0]" eq "disable") {
336 if ("$ARGV[1]" eq "updates") {
337 system("rm -f /etc/fcron.daily/pakfire-update");
338 } elsif ("$ARGV[1]" eq "upgrades") {
339 system("rm -f /etc/fcron.daily/pakfire-upgrade");
341 } elsif ("$ARGV[0]" eq "status") {
347 &Pakfire
::logger
("PAKFIRE INFO: Pakfire has finished. Closing.");
350 # Check if pakfire has been locked in this session.
353 unlink($Pakfire::lockfile
);