]> git.ipfire.org Git - ipfire-2.x.git/blob - src/pakfire/pakfire
binutils: update to 2.18.
[ipfire-2.x.git] / src / pakfire / pakfire
1 #!/usr/bin/perl
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 ###############################################################################
21
22 ### Clean up our environment
23 #
24 delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)};
25 $< = $>;
26
27 require "/opt/pakfire/lib/functions.pl";
28
29 my $interactive = 1;
30 my $force = "noforce";
31
32 &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
33 &Pakfire::checkcryptodb;
34
35 ### Check if we are running as root
36 #
37 my $user = qx(whoami);
38 chomp($user);
39 unless ( "$user" eq "root" ) {
40 &Pakfire::message("PAKFIRE ERROR: You must run pakfire as user root!");
41 exit 1;
42 }
43
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
49 ### Check if we are started by another name
50 #
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.");
55 sleep($random);
56 $ARGV[0] = "update";
57 $interactive = 0;
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.");
62 sleep($random);
63 $ARGV[0] = "upgrade";
64 $interactive = 0;
65 }
66
67 unless (@ARGV) {
68 &Pakfire::usage;
69 }
70
71 foreach (@ARGV) {
72 if ("$_" =~ "^-") {
73 # Turn off interactive mode
74 $interactive = 0 if ("$_" eq "--non-interactive");
75 $interactive = 0 if ("$_" eq "-y");
76
77 # Turn off shell colors - Bad for displaying in webinterface
78 $Pakfire::enable_colors = 0 if ("$_" eq "--no-colors");
79
80 # Turn on force mode
81 $force = "force" if ("$_" eq "-f" );
82 $force = "force" if ("$_" eq "--force" );
83 }
84 }
85
86 if ("$ARGV[0]" eq "install") {
87 shift;
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;
97 my @deps;
98 my $pak;
99 my @paks;
100 my @temp;
101 my @templine;
102 my $found = 0;
103 my $return;
104 my @all;
105 foreach $pak (@ARGV) {
106 unless ("$pak" =~ "^-") {
107 $return = &Pakfire::isinstalled($pak);
108 if ($return eq 0) {
109 &Pakfire::message("PAKFIRE INFO: $pak is already installed");
110 next;
111 }
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 }
127 if ($found == 0) {
128 &Pakfire::message("");
129 &Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
130 }
131 }
132 }
133
134 unless (@paks) {
135 &Pakfire::message("PAKFIRE ERROR: No packages to install. Exiting...");
136 exit 1;
137 }
138
139 if (@deps) {
140 my %sort = map{ $_, 1 } @deps;
141 @deps = keys %sort;
142 &Pakfire::message("");
143 &Pakfire::message("PAKFIRE INFO: Packages to install for dependencies:");
144 }
145 foreach $dep (@deps) {
146 my $size = &Pakfire::getsize("$dep");
147 $size = &Pakfire::beautifysize($size);
148 &Pakfire::message("PAKFIRE INFO: $dep \t - $size");
149 }
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 }
159
160 my $totalsize;
161 foreach $pak (@all) {
162 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
163 }
164 $totalsize = &Pakfire::beautifysize($totalsize);
165 &Pakfire::message("");
166 &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize");
167 &Pakfire::message("");
168
169 if ($interactive) {
170 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
171 my $ret = <STDIN>;
172 chomp($ret);
173 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
174 if ( $ret ne "y" ) {
175 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
176 exit 1;
177 }
178 } else {
179 &Pakfire::logger("PAKFIRE INFO: Interaction skipped.");
180 }
181
182 # my %sort = map{ $_, 1 } @all;
183 # @all = sort keys %sort;
184
185 ### Download first
186 foreach $pak (@all) {
187 &Pakfire::getpak("$pak", "");
188 }
189
190 &Pakfire::message("");
191
192 foreach $pak (@deps) {
193 &Pakfire::setuppak("$pak") if ($pak ne "");
194 }
195
196
197 foreach $pak (@paks) {
198 &Pakfire::setuppak("$pak") if ($pak ne "");
199 }
200
201
202 } elsif ("$ARGV[0]" eq "remove") {
203 shift;
204
205 my @paks;
206 my $pak;
207 foreach $pak (@ARGV) {
208 unless ("$pak" =~ "^-") {
209 $return = &Pakfire::isinstalled($pak);
210 if ($return ne 0) {
211 &Pakfire::message("PAKFIRE WARN: $pak is not installed");
212 next;
213 }
214 push(@paks, $pak);
215 }
216 }
217
218 unless (@paks) {
219 &Pakfire::message("PAKFIRE ERROR: No packages to remove. Exiting...");
220 exit 1;
221 }
222
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");
230 }
231
232 if ($interactive) {
233 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
234 my $ret = <STDIN>;
235 chomp($ret);
236 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
237 if ( $ret ne "y" ) {
238 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
239 exit 1;
240 }
241 }
242
243 foreach $pak (@paks) {
244 &Pakfire::removepak("$pak");
245 }
246
247
248 } elsif ("$ARGV[0]" eq "update") {
249 &Pakfire::makeuuid();
250 &Pakfire::senduuid();
251 &Pakfire::getmirrors("$force");
252 &Pakfire::dbgetlist("$force");
253 &Pakfire::getcoredb("$force");
254
255 } elsif ("$ARGV[0]" eq "upgrade") {
256 &Pakfire::upgradecore();
257 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
258 my @temp, $pak;
259
260 foreach (@upgradepaks) {
261 @temp = &Pakfire::resolvedeps("$_");
262 foreach (@temp) { push(@upgradepaks,$_) if $_; }
263 }
264
265 if (@upgradepaks) {
266 &Pakfire::message("");
267 &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above.");
268 if ($interactive) {
269 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
270 my $ret = <STDIN>;
271 chomp($ret);
272 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
273 if ( $ret ne "y" ) {
274 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
275 exit 1;
276 }
277 }
278 }
279
280 ### Download first
281 foreach $pak (@upgradepaks) {
282 #system("mv $Conf::dbdir/meta/meta-$pak $Conf::dbdir/meta/old-meta-$pak");
283 &Pakfire::getpak("$pak", "");
284 }
285
286 foreach $pak (@upgradepaks) {
287 if (&Pakfire::upgradepak("$pak")) {
288 #system("mv $Conf::dbdir/meta/old-meta-$pak $Conf::dbdir/meta/meta-$pak");
289 }
290 }
291
292 } elsif ("$ARGV[0]" eq "list") {
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 }
299
300 } elsif ("$ARGV[0]" eq "resolvedeps") {
301 foreach (@ARGV) {
302 next if ("$_" eq "resolvedeps");
303 next if ("$_" =~ "^-");
304 &Pakfire::resolvedeps("$_");
305 }
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");
311 }
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");
317 }
318 } else {
319 &Pakfire::usage;
320 }
321
322 &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing.");
323
324 exit 0;