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