]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/pakfire/pakfire
20344a0d955c46b723a258cbea0bdc3caa6b7970
[people/pmueller/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 require "/opt/pakfire/lib/functions.pl";
23
24 my $interactive = 1;
25 my $force = "noforce";
26
27 &Pakfire::logger("PAKFIRE INFO: IPFire Pakfire $Conf::version started!");
28 &Pakfire::checkcryptodb;
29
30 ### Check if we are running as root
31 #
32 my $user = qx(whoami);
33 chomp($user);
34 unless ( "$user" eq "root" ) {
35 &Pakfire::message("PAKFIRE ERROR: You must run pakfire as user root!");
36 exit 1;
37 }
38
39 unless ( -e "/var/ipfire/red/active" ) {
40 &Pakfire::message("PAKFIRE ERROR: You need to be online to run pakfire!");
41 exit 2;
42 }
43
44 ### Check if we are started by another name
45 #
46 if ( $0 =~ /pakfire-update$/ ) {
47 &Pakfire::message("CRON INFO: Running an update");
48 $ARGV[0] = "update";
49 $interactive = 0;
50 } elsif ( $0 =~ /pakfire-upgrade$/ ) {
51 &Pakfire::message("CRON INFO: Running an upgrade");
52 $ARGV[0] = "upgrade";
53 $interactive = 0;
54 }
55
56 unless (@ARGV) {
57 &Pakfire::usage;
58 }
59
60 foreach (@ARGV) {
61 if ("$_" =~ "^-") {
62 # Turn off interactive mode
63 $interactive = 0 if ("$_" eq "--non-interactive");
64 $interactive = 0 if ("$_" eq "-y");
65
66 # Turn off shell colors - Bad for displaying in webinterface
67 $Pakfire::enable_colors = 0 if ("$_" eq "--no-colors");
68
69 # Turn on force mode
70 $force = "force" if ("$_" eq "-f" );
71 $force = "force" if ("$_" eq "--force" );
72 }
73 }
74
75 if ("$ARGV[0]" eq "install") {
76 shift;
77
78 ### Make sure that the list is not outdated.
79 &Pakfire::dbgetlist("noforce");
80
81 open(FILE, "<$Conf::dbdir/lists/packages_list.db");
82 my @db = <FILE>;
83 close(FILE);
84
85 my $dep;
86 my @deps;
87 my $pak;
88 my @paks;
89 my @temp;
90 my @templine;
91 my $found = 0;
92 my $return;
93 my @all;
94 foreach $pak (@ARGV) {
95 unless ("$pak" =~ "^-") {
96 $return = &Pakfire::isinstalled($pak);
97 if ($return eq 0) {
98 &Pakfire::message("PAKFIRE INFO: $pak is already installed");
99 next;
100 }
101 $found = 0;
102 foreach (@db) {
103 @templine = split(/;/,$_);
104 if ("$templine[0]" eq "$pak" ) {
105 push(@paks,$pak);
106 push(@all,$pak);
107 @temp = &Pakfire::resolvedeps("$pak");
108 foreach $dep (@temp) {
109 push(@deps,$dep) if $dep;
110 push(@all,$dep) if $dep;
111 }
112 $found = 1;
113 break;
114 }
115 }
116 if ($found == 0) {
117 &Pakfire::message("");
118 &Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\".");
119 }
120 }
121 }
122
123 unless (@paks) {
124 &Pakfire::message("PAKFIRE ERROR: No packages to install. Exiting...");
125 exit 1;
126 }
127
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");
135 }
136
137 if (@deps) {
138 my %sort = map{ $_, 1 } @deps;
139 @deps = sort keys %sort;
140 &Pakfire::message("");
141 &Pakfire::message("PAKFIRE INFO: Packages to install for dependencies:");
142 }
143 foreach $dep (sort @deps) {
144 my $size = &Pakfire::getsize("$dep");
145 $size = &Pakfire::beautifysize($size);
146 &Pakfire::message("PAKFIRE INFO: $dep \t - $size");
147 }
148
149 my $totalsize;
150 foreach $pak (@all) {
151 $totalsize = ($totalsize + &Pakfire::getsize("$pak"));
152 }
153 $totalsize = &Pakfire::beautifysize($totalsize);
154 &Pakfire::message("");
155 &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize");
156 &Pakfire::message("");
157
158 if ($interactive) {
159 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
160 my $ret = <STDIN>;
161 chomp($ret);
162 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
163 if ( $ret ne "y" ) {
164 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
165 exit 1;
166 }
167 } else {
168 &Pakfire::logger("PAKFIRE INFO: Interaction skipped.");
169 }
170
171 my %sort = map{ $_, 1 } @all;
172 @all = sort keys %sort;
173
174 ### Download first
175 foreach $pak (sort @all) {
176 &Pakfire::getpak("$pak", "");
177 }
178
179 &Pakfire::message("");
180
181 foreach $pak (sort @all) {
182 &Pakfire::setuppak("$pak") if ($pak ne "");
183 }
184
185 } elsif ("$ARGV[0]" eq "remove") {
186 shift;
187
188 my @paks;
189 my $pak;
190 foreach $pak (@ARGV) {
191 unless ("$pak" =~ "^-") {
192 $return = &Pakfire::isinstalled($pak);
193 if ($return ne 0) {
194 &Pakfire::message("PAKFIRE WARN: $pak is not installed");
195 next;
196 }
197 push(@paks, $pak);
198 }
199 }
200
201 unless (@paks) {
202 &Pakfire::message("PAKFIRE ERROR: No packages to remove. Exiting...");
203 exit 1;
204 }
205
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");
213 }
214
215 if ($interactive) {
216 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
217 my $ret = <STDIN>;
218 chomp($ret);
219 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
220 if ( $ret ne "y" ) {
221 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
222 exit 1;
223 }
224 }
225
226 foreach $pak (@paks) {
227 &Pakfire::removepak("$pak");
228 }
229
230
231 } elsif ("$ARGV[0]" eq "update") {
232 &Pakfire::makeuuid();
233 &Pakfire::senduuid();
234 &Pakfire::getmirrors("$force");
235 &Pakfire::dbgetlist("$force");
236 &Pakfire::getcoredb("$force");
237
238 } elsif ("$ARGV[0]" eq "upgrade") {
239 &Pakfire::upgradecore();
240 my @upgradepaks = &Pakfire::dblist("upgrade", "noweb");
241 my @temp;
242
243 foreach (@upgradepaks) {
244 @temp = &Pakfire::resolvedeps("$_");
245 foreach (@temp) { push(@upgradepaks,$_) if $_; }
246 }
247
248 if (@upgradepaks) {
249 &Pakfire::message("");
250 &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above.");
251 if ($interactive) {
252 &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
253 my $ret = <STDIN>;
254 chomp($ret);
255 &Pakfire::logger("PAKFIRE INFO: Answer: $ret");
256 if ( $ret ne "y" ) {
257 &Pakfire::message("PAKFIRE ERROR: Installation aborted.");
258 exit 1;
259 }
260 }
261 }
262
263 ### Download first
264 foreach (sort @upgradepaks) {
265 &Pakfire::getpak("$_", "");
266 }
267
268 foreach (sort @upgradepaks) {
269 &Pakfire::upgradepak("$_");
270 }
271
272 } elsif ("$ARGV[0]" eq "list") {
273 if ("$ARGV[1]" =~ /installed|notinstalled/) {
274 &Pakfire::dblist("$ARGV[1]", "noweb");
275 } else {
276 &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);
277 &Pakfire::dblist("all", "noweb");
278 }
279
280 } elsif ("$ARGV[0]" eq "resolvedeps") {
281 foreach (@ARGV) {
282 next if ("$_" eq "resolvedeps");
283 next if ("$_" =~ "^-");
284 &Pakfire::resolvedeps("$_");
285 }
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");
291 }
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");
297 }
298 } else {
299 &Pakfire::usage;
300 }
301
302 &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing.");
303
304 exit 0;