]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/pakfire/pakfire
20344a0d955c46b723a258cbea0bdc3caa6b7970
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 require "/opt/pakfire/lib/functions.pl";
25 my $force = "noforce";
27 &Pakfire
::logger
("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
28 &Pakfire
::checkcryptodb
;
30 ### Check if we are running as root
32 my $user = qx(whoami
);
34 unless ( "$user" eq "root" ) {
35 &Pakfire
::message
("PAKFIRE ERROR: You must run pakfire as user root!");
39 unless ( -e
"/var/ipfire/red/active" ) {
40 &Pakfire
::message
("PAKFIRE ERROR: You need to be online to run pakfire!");
44 ### Check if we are started by another name
46 if ( $0 =~ /pakfire-update$/ ) {
47 &Pakfire
::message
("CRON INFO: Running an update");
50 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
51 &Pakfire
::message
("CRON INFO: Running an upgrade");
62 # Turn off interactive mode
63 $interactive = 0 if ("$_" eq "--non-interactive");
64 $interactive = 0 if ("$_" eq "-y");
66 # Turn off shell colors - Bad for displaying in webinterface
67 $Pakfire::enable_colors
= 0 if ("$_" eq "--no-colors");
70 $force = "force" if ("$_" eq "-f" );
71 $force = "force" if ("$_" eq "--force" );
75 if ("$ARGV[0]" eq "install") {
78 ### Make sure that the list is not outdated.
79 &Pakfire
::dbgetlist
("noforce");
81 open(FILE
, "<$Conf::dbdir/lists/packages_list.db");
94 foreach $pak (@ARGV) {
95 unless ("$pak" =~ "^-") {
96 $return = &Pakfire
::isinstalled
($pak);
98 &Pakfire
::message
("PAKFIRE INFO: $pak is already installed");
103 @templine = split(/;/,$_);
104 if ("$templine[0]" eq "$pak" ) {
107 @temp = &Pakfire
::resolvedeps
("$pak");
108 foreach $dep (@temp) {
109 push(@deps,$dep) if $dep;
110 push(@all,$dep) if $dep;
117 &Pakfire
::message
("");
118 &Pakfire
::message
("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
124 &Pakfire
::message
("PAKFIRE ERROR: No packages to install. Exiting...");
128 &Pakfire
::message
("");
129 &Pakfire
::message
("");
130 &Pakfire
::message
("PAKFIRE INFO: Packages to install:");
131 foreach $pak (sort @paks) {
132 my $size = &Pakfire
::getsize
("$pak");
133 $size = &Pakfire
::beautifysize
($size);
134 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
138 my %sort = map{ $_, 1 } @deps;
139 @deps = sort keys %sort;
140 &Pakfire
::message
("");
141 &Pakfire
::message
("PAKFIRE INFO: Packages to install for dependencies:");
143 foreach $dep (sort @deps) {
144 my $size = &Pakfire
::getsize
("$dep");
145 $size = &Pakfire
::beautifysize
($size);
146 &Pakfire
::message
("PAKFIRE INFO: $dep \t - $size");
150 foreach $pak (@all) {
151 $totalsize = ($totalsize + &Pakfire
::getsize
("$pak"));
153 $totalsize = &Pakfire
::beautifysize
($totalsize);
154 &Pakfire
::message
("");
155 &Pakfire
::message
("PAKFIRE INFO: Total size: \t ~ $totalsize");
156 &Pakfire
::message
("");
159 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
162 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
164 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
168 &Pakfire
::logger
("PAKFIRE INFO: Interaction skipped.");
171 my %sort = map{ $_, 1 } @all;
172 @all = sort keys %sort;
175 foreach $pak (sort @all) {
176 &Pakfire
::getpak
("$pak", "");
179 &Pakfire
::message
("");
181 foreach $pak (sort @all) {
182 &Pakfire
::setuppak
("$pak") if ($pak ne "");
185 } elsif ("$ARGV[0]" eq "remove") {
190 foreach $pak (@ARGV) {
191 unless ("$pak" =~ "^-") {
192 $return = &Pakfire
::isinstalled
($pak);
194 &Pakfire
::message
("PAKFIRE WARN: $pak is not installed");
202 &Pakfire
::message
("PAKFIRE ERROR: No packages to remove. Exiting...");
206 &Pakfire
::message
("");
207 &Pakfire
::message
("");
208 &Pakfire
::message
("PAKFIRE INFO: Packages to remove:");
209 foreach $pak (sort @paks) {
210 my $size = &Pakfire
::getsize
("$pak");
211 $size = &Pakfire
::beautifysize
($size);
212 &Pakfire
::message
("PAKFIRE INFO: $pak \t - $size");
216 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
219 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
221 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
226 foreach $pak (@paks) {
227 &Pakfire
::removepak
("$pak");
231 } elsif ("$ARGV[0]" eq "update") {
232 &Pakfire
::makeuuid
();
233 &Pakfire
::senduuid
();
234 &Pakfire
::getmirrors
("$force");
235 &Pakfire
::dbgetlist
("$force");
236 &Pakfire
::getcoredb
("$force");
238 } elsif ("$ARGV[0]" eq "upgrade") {
239 &Pakfire
::upgradecore
();
240 my @upgradepaks = &Pakfire
::dblist
("upgrade", "noweb");
243 foreach (@upgradepaks) {
244 @temp = &Pakfire
::resolvedeps
("$_");
245 foreach (@temp) { push(@upgradepaks,$_) if $_; }
249 &Pakfire
::message
("");
250 &Pakfire
::message
("PAKFIRE UPGR: We are going to install all packages listed above.");
252 &Pakfire
::message
("PAKFIRE INFO: Is this okay? [y/N]");
255 &Pakfire
::logger
("PAKFIRE INFO: Answer: $ret");
257 &Pakfire
::message
("PAKFIRE ERROR: Installation aborted.");
264 foreach (sort @upgradepaks) {
265 &Pakfire
::getpak
("$_", "");
268 foreach (sort @upgradepaks) {
269 &Pakfire
::upgradepak
("$_");
272 } elsif ("$ARGV[0]" eq "list") {
273 if ("$ARGV[1]" =~ /installed|notinstalled/) {
274 &Pakfire
::dblist
("$ARGV[1]", "noweb");
276 &Pakfire
::message
("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
277 &Pakfire
::dblist
("all", "noweb");
280 } elsif ("$ARGV[0]" eq "resolvedeps") {
282 next if ("$_" eq "resolvedeps");
283 next if ("$_" =~ "^-");
284 &Pakfire
::resolvedeps
("$_");
286 } elsif ("$ARGV[0]" eq "enable") {
287 if ("$ARGV[1]" eq "updates") {
288 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
289 elsif ("$ARGV[1]" eq "upgrades") {
290 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
292 } elsif ("$ARGV[0]" eq "disable") {
293 if ("$ARGV[1]" eq "updates") {
294 system("rm -f /etc/fcron.daily/pakfire-update");
295 elsif ("$ARGV[1]" eq "upgrades") {
296 system("rm -f /etc/fcron.daily/pakfire-upgrade");
302 &Pakfire
::logger
("PAKFIRE INFO: Pakfire has finished. Closing.");