Openssl security update (0.9.8q).
[people/pmueller/ipfire-2.x.git] / src / pakfire / pakfire
CommitLineData
c3df33af 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
c1ae1ad6 21
accc9c30
MT
22 ### Clean up our environment
23 #
24 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
25 $< = $>;
26
1bd42c89
MT
27 require "/opt/pakfire/lib/functions.pl";
28
29 my $interactive = 1;
377560fb 30 my $force = "noforce";
1bd42c89 31
a6d327a7 32 &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
cde0e116 33 &Pakfire::checkcryptodb;
c1ae1ad6 34
1bd42c89
MT
35 ### Check if we are running as root
36 #
37 my $user = qx(whoami);
38 chomp($user);
39 unless ( "$user" eq "root" ) {
a6d327a7 40 &Pakfire::message("PAKFIRE ERROR: You must run pakfire as user root!");
1bd42c89
MT
41 exit 1;
42 }
43
7bc1b6ac
MT
44 unless ( -e "/var/ipfire/red/active" ) {
45 &Pakfire::message("PAKFIRE ERROR: You need to be online to run pakfire!");
46 exit 2;
47 }
48
06209efc
MT
49 ### Check if we are started by another name
50 #
51 if ( $0 =~ /pakfire-update$/ ) {
a6d327a7 52 &Pakfire::message("CRON INFO: Running an update");
fc4ac7ac 53 my $random = int(rand(60));
5d22ef4e
MT
54 &Pakfire::logger("CRON INFO: Waiting for $random seconds.");
55 sleep($random);
06209efc
MT
56 $ARGV[0] = "update";
57 $interactive = 0;
58 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
a6d327a7 59 &Pakfire::message("CRON INFO: Running an upgrade");
5d22ef4e
MT
60 my $random = int(rand(3600));
61 &Pakfire::logger("CRON INFO: Waiting for $random seconds.");
62 sleep($random);
06209efc
MT
63 $ARGV[0] = "upgrade";
64 $interactive = 0;
65 }
66
1bd42c89 67 unless (@ARGV) {
5b2a12ff 68 &Pakfire::usage;
1bd42c89 69 }
4b122800
MT
70
71 foreach (@ARGV) {
72 if ("$_" =~ "^-") {
750c1528 73 # Turn off interactive mode
4b122800
MT
74 $interactive = 0 if ("$_" eq "--non-interactive");
75 $interactive = 0 if ("$_" eq "-y");
750c1528
MT
76
77 # Turn off shell colors - Bad for displaying in webinterface
78 $Pakfire::enable_colors = 0 if ("$_" eq "--no-colors");
377560fb
MT
79
80 # Turn on force mode
81 $force = "force" if ("$_" eq "-f" );
82 $force = "force" if ("$_" eq "--force" );
4b122800
MT
83 }
84 }
c1ae1ad6 85
1bd42c89
MT
86 if ("$ARGV[0]" eq "install") {
87 shift;
99e6df8e
MT
88
89 ### Make sure that the list is not outdated.
90 &Pakfire::dbgetlist("noforce");
91
92 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
93 my @db = <FILE>;
94 close(FILE);
95
96 my $dep;
a08c3a2e 97 my @deps;
99e6df8e 98 my $pak;
a08c3a2e
MT
99 my @paks;
100 my @temp;
99e6df8e
MT
101 my @templine;
102 my $found = 0;
186e3d2c 103 my $return;
4b122800 104 my @all;
99e6df8e
MT
105 foreach $pak (@ARGV) {
106 unless ("$pak" =~ "^-") {
186e3d2c
MT
107 $return = &Pakfire::isinstalled($pak);
108 if ($return eq 0) {
a6d327a7 109 &Pakfire::message("PAKFIRE INFO: $pak is already installed");
186e3d2c
MT
110 next;
111 }
99e6df8e
MT
112 $found = 0;
113 foreach (@db) {
114 @templine = split(/;/,$_);
115 if ("$templine[0]" eq "$pak" ) {
116 push(@paks,$pak);
117 push(@all,$pak);
118 @temp = &Pakfire::resolvedeps("$pak");
119 foreach $dep (@temp) {
120 push(@deps,$dep) if $dep;
121 push(@all,$dep) if $dep;
122 }
123 $found = 1;
124 break;
125 }
126 }
a6d327a7
MT
127 if ($found == 0) {
128 &Pakfire::message("");
129 &Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
130 }
5b2a12ff 131 }
a08c3a2e 132 }
186e3d2c
MT
133
134 unless (@paks) {
a6d327a7 135 &Pakfire::message("PAKFIRE ERROR: No packages to install. Exiting...");
186e3d2c
MT
136 exit 1;
137 }
97520ed5 138
186e3d2c 139 if (@deps) {
519f8431 140 my %sort = map{ $_, 1 } @deps;
3a3c02ee 141 @deps = keys %sort;
186e3d2c 142 &Pakfire::message("");
a6d327a7 143 &Pakfire::message("PAKFIRE INFO: Packages to install for dependencies:");
186e3d2c 144 }
373e13c2 145 foreach $dep (@deps) {
186e3d2c 146 my $size = &Pakfire::getsize("$dep");
1bd42c89 147 $size = &Pakfire::beautifysize($size);
35f38a8b 148 &Pakfire::message("PAKFIRE INFO: $dep \t - $size");
1bd42c89 149 }
373e13c2
CS
150
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");
158 }
4b122800
MT
159
160 my $totalsize;
186e3d2c
MT
161 foreach $pak (@all) {
162 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
4b122800 163 }
1bd42c89 164 $totalsize = &Pakfire::beautifysize($totalsize);
186e3d2c 165 &Pakfire::message("");
a6d327a7 166 &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize");
186e3d2c 167 &Pakfire::message("");
1bd42c89
MT
168
169 if ($interactive) {
a6d327a7 170 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
1bd42c89
MT
171 my $ret = <STDIN>;
172 chomp($ret);
a6d327a7 173 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
1bd42c89 174 if ( $ret ne "y" ) {
a6d327a7 175 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
1bd42c89
MT
176 exit 1;
177 }
a6d327a7
MT
178 } else {
179 &Pakfire::logger("PAKFIRE INFO: Interaction skipped.");
1bd42c89 180 }
186e3d2c 181
373e13c2
CS
182# my %sort = map{ $_, 1 } @all;
183# @all = sort keys %sort;
a08c3a2e
MT
184
185 ### Download first
373e13c2 186 foreach $pak (@all) {
186e3d2c 187 &Pakfire::getpak("$pak", "");
a08c3a2e 188 }
c1ae1ad6 189
35f38a8b
MT
190 &Pakfire::message("");
191
373e13c2 192 foreach $pak (@deps) {
186e3d2c 193 &Pakfire::setuppak("$pak") if ($pak ne "");
1bd42c89 194 }
1bd42c89 195
373e13c2
CS
196
197 foreach $pak (@paks) {
198 &Pakfire::setuppak("$pak") if ($pak ne "");
199 }
200
201
1bd42c89 202 } elsif ("$ARGV[0]" eq "remove") {
e44b26cf
MT
203 shift;
204
205 my @paks;
206 my $pak;
e44b26cf
MT
207 foreach $pak (@ARGV) {
208 unless ("$pak" =~ "^-") {
209 $return = &Pakfire::isinstalled($pak);
210 if ($return ne 0) {
a6d327a7 211 &Pakfire::message("PAKFIRE WARN: $pak is not installed");
e44b26cf
MT
212 next;
213 }
e44b26cf 214 push(@paks, $pak);
e44b26cf
MT
215 }
216 }
217
218 unless (@paks) {
a6d327a7 219 &Pakfire::message("PAKFIRE ERROR: No packages to remove. Exiting...");
e44b26cf
MT
220 exit 1;
221 }
222
223 &Pakfire::message("");
224 &Pakfire::message("");
35f38a8b 225 &Pakfire::message("PAKFIRE INFO: Packages to remove:");
e44b26cf
MT
226 foreach $pak (sort @paks) {
227 my $size = &Pakfire::getsize("$pak");
228 $size = &Pakfire::beautifysize($size);
35f38a8b 229 &Pakfire::message("PAKFIRE INFO: $pak \t - $size");
e44b26cf
MT
230 }
231
232 if ($interactive) {
35f38a8b 233 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
e44b26cf
MT
234 my $ret = <STDIN>;
235 chomp($ret);
35f38a8b 236 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
e44b26cf 237 if ( $ret ne "y" ) {
35f38a8b 238 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
e44b26cf
MT
239 exit 1;
240 }
241 }
242
243 foreach $pak (@paks) {
244 &Pakfire::removepak("$pak");
245 }
1bd42c89
MT
246
247
248 } elsif ("$ARGV[0]" eq "update") {
8e58bd37
MT
249 &Pakfire::makeuuid();
250 &Pakfire::senduuid();
377560fb
MT
251 &Pakfire::getmirrors("$force");
252 &Pakfire::dbgetlist("$force");
253 &Pakfire::getcoredb("$force");
e3670217 254
4b122800 255 } elsif ("$ARGV[0]" eq "upgrade") {
2aa6d448 256 &Pakfire::upgradecore();
99e6df8e 257 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
4e4b54c5 258 my @temp, $pak;
99e6df8e
MT
259
260 foreach (@upgradepaks) {
261 @temp = &Pakfire::resolvedeps("$_");
262 foreach (@temp) { push(@upgradepaks,$_) if $_; }
263 }
264
265 if (@upgradepaks) {
266 &Pakfire::message("");
35f38a8b 267 &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above.");
99e6df8e 268 if ($interactive) {
35f38a8b 269 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
99e6df8e
MT
270 my $ret = <STDIN>;
271 chomp($ret);
35f38a8b 272 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
99e6df8e 273 if ( $ret ne "y" ) {
35f38a8b 274 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
99e6df8e
MT
275 exit 1;
276 }
277 }
278 }
279
280 ### Download first
373e13c2 281 foreach $pak (@upgradepaks) {
ff9545f8 282 #system("mv $Conf::dbdir/meta/meta-$pak $Conf::dbdir/meta/old-meta-$pak");
4e4b54c5 283 &Pakfire::getpak("$pak", "");
99e6df8e
MT
284 }
285
373e13c2 286 foreach $pak (@upgradepaks) {
4e4b54c5 287 if (&Pakfire::upgradepak("$pak")) {
ff9545f8 288 #system("mv $Conf::dbdir/meta/old-meta-$pak $Conf::dbdir/meta/meta-$pak");
4e4b54c5 289 }
99e6df8e 290 }
4b122800 291
afabe9f7 292 } elsif ("$ARGV[0]" eq "list") {
e3670217
MT
293 if ("$ARGV[1]" =~ /installed|notinstalled/) {
294 &Pakfire::dblist("$ARGV[1]", "noweb");
295 } else {
296 &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
297 &Pakfire::dblist("all", "noweb");
298 }
5b2a12ff
MT
299
300 } elsif ("$ARGV[0]" eq "resolvedeps") {
301 foreach (@ARGV) {
302 next if ("$_" eq "resolvedeps");
750c1528 303 next if ("$_" =~ "^-");
5b2a12ff
MT
304 &Pakfire::resolvedeps("$_");
305 }
377560fb
MT
306 } elsif ("$ARGV[0]" eq "enable") {
307 if ("$ARGV[1]" eq "updates") {
308 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-update");
37610d7b 309 } elsif ("$ARGV[1]" eq "upgrades") {
377560fb
MT
310 system("ln -s ../../opt/pakfire/pakfire /etc/fcron.daily/pakfire-upgrade");
311 }
312 } elsif ("$ARGV[0]" eq "disable") {
313 if ("$ARGV[1]" eq "updates") {
314 system("rm -f /etc/fcron.daily/pakfire-update");
37610d7b 315 } elsif ("$ARGV[1]" eq "upgrades") {
377560fb
MT
316 system("rm -f /etc/fcron.daily/pakfire-upgrade");
317 }
5b2a12ff
MT
318 } else {
319 &Pakfire::usage;
1bd42c89 320 }
a6d327a7 321
70df8302 322 &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing.");
35f38a8b 323
70df8302 324 exit 0;