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