]>
Commit | Line | Data |
---|---|---|
21299915 DM |
1 | package PVE::API2::APT; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
8794761f DM |
5 | |
6 | use POSIX; | |
cd0bc36b | 7 | use File::stat (); |
a88002cf | 8 | use IO::File; |
d330e26f | 9 | use File::Basename; |
21299915 | 10 | |
f5ed75de DM |
11 | use LWP::UserAgent; |
12 | ||
8794761f | 13 | use PVE::pvecfg; |
21299915 | 14 | use PVE::Tools qw(extract_param); |
f5ed75de | 15 | use PVE::Cluster; |
21299915 DM |
16 | use PVE::SafeSyslog; |
17 | use PVE::INotify; | |
396c9e4a | 18 | use PVE::Exception; |
21299915 DM |
19 | use PVE::RESTHandler; |
20 | use PVE::RPCEnvironment; | |
446b9669 | 21 | use PVE::API2Tools; |
21299915 | 22 | |
cd0bc36b | 23 | use JSON; |
21299915 DM |
24 | use PVE::JSONSchema qw(get_standard_option); |
25 | ||
26 | use AptPkg::Cache; | |
21299915 | 27 | use AptPkg::PkgRecords; |
ee94b16a | 28 | use AptPkg::System; |
21299915 | 29 | |
21299915 DM |
30 | my $get_apt_cache = sub { |
31 | ||
c06e9cc8 | 32 | my $apt_cache = AptPkg::Cache->new() || die "unable to initialize AptPkg::Cache\n"; |
21299915 DM |
33 | |
34 | return $apt_cache; | |
35 | }; | |
36 | ||
37 | use base qw(PVE::RESTHandler); | |
38 | ||
39 | __PACKAGE__->register_method({ | |
40 | name => 'index', | |
41 | path => '', | |
42 | method => 'GET', | |
43 | description => "Directory index for apt (Advanced Package Tool).", | |
44 | permissions => { | |
45 | user => 'all', | |
46 | }, | |
47 | parameters => { | |
48 | additionalProperties => 0, | |
49 | properties => { | |
50 | node => get_standard_option('pve-node'), | |
51 | }, | |
52 | }, | |
53 | returns => { | |
54 | type => "array", | |
55 | items => { | |
56 | type => "object", | |
57 | properties => { | |
58 | id => { type => 'string' }, | |
59 | }, | |
60 | }, | |
61 | links => [ { rel => 'child', href => "{id}" } ], | |
62 | }, | |
63 | code => sub { | |
64 | my ($param) = @_; | |
65 | ||
66 | my $res = [ | |
21299915 | 67 | { id => 'changelog' }, |
8794761f DM |
68 | { id => 'update' }, |
69 | { id => 'versions' }, | |
21299915 DM |
70 | ]; |
71 | ||
72 | return $res; | |
73 | }}); | |
74 | ||
a972b69d DM |
75 | my $get_pkgfile = sub { |
76 | my ($veriter) = @_; | |
21299915 | 77 | |
a972b69d | 78 | foreach my $verfile (@{$veriter->{FileList}}) { |
00d48356 | 79 | my $pkgfile = $verfile->{File}; |
a972b69d DM |
80 | next if !$pkgfile->{Origin}; |
81 | return $pkgfile; | |
82 | } | |
83 | ||
84 | return undef; | |
85 | }; | |
86 | ||
87 | my $get_changelog_url =sub { | |
2ba6d822 | 88 | my ($pkgname, $info, $pkgver, $origin, $component) = @_; |
a972b69d DM |
89 | |
90 | my $changelog_url; | |
91 | my $base = dirname($info->{FileName}); | |
92 | if ($origin && $base) { | |
93 | $pkgver =~ s/^\d+://; # strip epoch | |
94 | my $srcpkg = $info->{SourcePkg} || $pkgname; | |
95 | if ($origin eq 'Debian') { | |
702ecae1 | 96 | $base =~ s!pool/updates/!pool/!; # for security channel |
a972b69d | 97 | $changelog_url = "http://packages.debian.org/changelogs/$base/" . |
09c67ebb DM |
98 | "${srcpkg}_${pkgver}/changelog"; |
99 | } elsif ($origin eq 'Proxmox') { | |
2ba6d822 DM |
100 | if ($component eq 'pve-enterprise') { |
101 | $changelog_url = "https://enterprise.proxmox.com/debian/$base/" . | |
8fd7134c | 102 | "${pkgname}_${pkgver}.changelog"; |
2ba6d822 DM |
103 | } else { |
104 | $changelog_url = "http://download.proxmox.com/debian/$base/" . | |
8fd7134c | 105 | "${pkgname}_${pkgver}.changelog"; |
2ba6d822 | 106 | } |
00d48356 DM |
107 | } |
108 | } | |
a972b69d | 109 | |
b688d438 DM |
110 | return $changelog_url; |
111 | }; | |
112 | ||
113 | my $assemble_pkginfo = sub { | |
114 | my ($pkgname, $info, $current_ver, $candidate_ver) = @_; | |
00d48356 | 115 | |
21299915 DM |
116 | my $data = { |
117 | Package => $info->{Name}, | |
118 | Title => $info->{ShortDesc}, | |
a972b69d | 119 | Origin => 'unknown', |
21299915 DM |
120 | }; |
121 | ||
a972b69d | 122 | if (my $pkgfile = &$get_pkgfile($candidate_ver)) { |
2ba6d822 DM |
123 | $data->{Origin} = $pkgfile->{Origin}; |
124 | if (my $changelog_url = &$get_changelog_url($pkgname, $info, $candidate_ver->{VerStr}, | |
125 | $pkgfile->{Origin}, $pkgfile->{Component})) { | |
a972b69d DM |
126 | $data->{ChangeLogUrl} = $changelog_url; |
127 | } | |
b688d438 | 128 | } |
00d48356 | 129 | |
21299915 DM |
130 | if (my $desc = $info->{LongDesc}) { |
131 | $desc =~ s/^.*\n\s?//; # remove first line | |
132 | $desc =~ s/\n / /g; | |
133 | $data->{Description} = $desc; | |
134 | } | |
135 | ||
136 | foreach my $k (qw(Section Arch Priority)) { | |
137 | $data->{$k} = $candidate_ver->{$k}; | |
138 | } | |
139 | ||
140 | $data->{Version} = $candidate_ver->{VerStr}; | |
93305404 | 141 | $data->{OldVersion} = $current_ver->{VerStr} if $current_ver; |
21299915 DM |
142 | |
143 | return $data; | |
144 | }; | |
145 | ||
4806bc69 DM |
146 | # we try to cache results |
147 | my $pve_pkgstatus_fn = "/var/lib/pve-manager/pkgupdates"; | |
148 | ||
745d942d DM |
149 | my $read_cached_pkgstatus = sub { |
150 | my $data = []; | |
151 | eval { | |
152 | my $jsonstr = PVE::Tools::file_get_contents($pve_pkgstatus_fn, 5*1024*1024); | |
153 | $data = decode_json($jsonstr); | |
154 | }; | |
155 | if (my $err = $@) { | |
156 | warn "error reading cached package status in $pve_pkgstatus_fn\n"; | |
157 | } | |
158 | return $data; | |
159 | }; | |
160 | ||
4806bc69 DM |
161 | my $update_pve_pkgstatus = sub { |
162 | ||
446f9217 DM |
163 | syslog('info', "update new package list: $pve_pkgstatus_fn"); |
164 | ||
745d942d DM |
165 | my $notify_status = {}; |
166 | my $oldpkglist = &$read_cached_pkgstatus(); | |
167 | foreach my $pi (@$oldpkglist) { | |
d97a4468 | 168 | $notify_status->{$pi->{Package}} = $pi->{NotifyStatus}; |
745d942d DM |
169 | } |
170 | ||
4806bc69 DM |
171 | my $pkglist = []; |
172 | ||
173 | my $cache = &$get_apt_cache(); | |
174 | my $policy = $cache->policy; | |
175 | my $pkgrecords = $cache->packages(); | |
176 | ||
177 | foreach my $pkgname (keys %$cache) { | |
178 | my $p = $cache->{$pkgname}; | |
2051816c | 179 | next if !$p->{SelectedState} || ($p->{SelectedState} ne 'Install'); |
26f876ce DM |
180 | my $current_ver = $p->{CurrentVer} || next; |
181 | my $candidate_ver = $policy->candidate($p) || next; | |
4806bc69 | 182 | |
396c9e4a | 183 | if ($current_ver->{VerStr} ne $candidate_ver->{VerStr}) { |
4806bc69 DM |
184 | my $info = $pkgrecords->lookup($pkgname); |
185 | my $res = &$assemble_pkginfo($pkgname, $info, $current_ver, $candidate_ver); | |
186 | push @$pkglist, $res; | |
93305404 DM |
187 | |
188 | # also check if we need any new package | |
189 | # Note: this is just a quick hack (not recursive as it should be), because | |
190 | # I found no way to get that info from AptPkg | |
191 | if (my $deps = $candidate_ver->{DependsList}) { | |
192 | my $found; | |
193 | my $req; | |
194 | for my $d (@$deps) { | |
195 | if ($d->{DepType} eq 'Depends') { | |
196 | $found = $d->{TargetPkg}->{SelectedState} eq 'Install' if !$found; | |
197 | $req = $d->{TargetPkg} if !$req; | |
198 | ||
199 | if (!($d->{CompType} & AptPkg::Dep::Or)) { | |
200 | if (!$found && $req) { # New required Package | |
201 | my $tpname = $req->{Name}; | |
202 | my $tpinfo = $pkgrecords->lookup($tpname); | |
203 | my $tpcv = $policy->candidate($req); | |
204 | if ($tpinfo && $tpcv) { | |
205 | my $res = &$assemble_pkginfo($tpname, $tpinfo, undef, $tpcv); | |
206 | push @$pkglist, $res; | |
207 | } | |
208 | } | |
209 | undef $found; | |
210 | undef $req; | |
211 | } | |
212 | } | |
213 | } | |
214 | } | |
4806bc69 DM |
215 | } |
216 | } | |
745d942d DM |
217 | |
218 | # keep notification status (avoid sending mails abou new packages more than once) | |
219 | foreach my $pi (@$pkglist) { | |
220 | if (my $ns = $notify_status->{$pi->{Package}}) { | |
221 | $pi->{NotifyStatus} = $ns if $ns eq $pi->{Version}; | |
222 | } | |
223 | } | |
224 | ||
4806bc69 DM |
225 | PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist)); |
226 | ||
227 | return $pkglist; | |
228 | }; | |
229 | ||
21299915 DM |
230 | __PACKAGE__->register_method({ |
231 | name => 'list_updates', | |
232 | path => 'update', | |
233 | method => 'GET', | |
234 | description => "List available updates.", | |
235 | permissions => { | |
236 | check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]], | |
237 | }, | |
238 | protected => 1, | |
239 | proxyto => 'node', | |
240 | parameters => { | |
241 | additionalProperties => 0, | |
242 | properties => { | |
243 | node => get_standard_option('pve-node'), | |
244 | }, | |
245 | }, | |
246 | returns => { | |
247 | type => "array", | |
248 | items => { | |
249 | type => "object", | |
250 | properties => {}, | |
251 | }, | |
252 | }, | |
253 | code => sub { | |
254 | my ($param) = @_; | |
255 | ||
cd0bc36b DM |
256 | if (my $st1 = File::stat::stat($pve_pkgstatus_fn)) { |
257 | my $st2 = File::stat::stat("/var/cache/apt/pkgcache.bin"); | |
258 | my $st3 = File::stat::stat("/var/lib/dpkg/status"); | |
259 | ||
446f9217 | 260 | if ($st2 && $st3 && $st2->mtime <= $st1->mtime && $st3->mtime <= $st1->mtime) { |
745d942d | 261 | if (my $data = &$read_cached_pkgstatus()) { |
cd0bc36b DM |
262 | return $data; |
263 | } | |
264 | } | |
265 | } | |
266 | ||
4806bc69 DM |
267 | my $pkglist = &$update_pve_pkgstatus(); |
268 | ||
269 | return $pkglist; | |
270 | }}); | |
271 | ||
272 | __PACKAGE__->register_method({ | |
273 | name => 'update_database', | |
274 | path => 'update', | |
275 | method => 'POST', | |
276 | description => "This is used to resynchronize the package index files from their sources (apt-get update).", | |
277 | permissions => { | |
278 | check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]], | |
279 | }, | |
280 | protected => 1, | |
281 | proxyto => 'node', | |
282 | parameters => { | |
283 | additionalProperties => 0, | |
284 | properties => { | |
285 | node => get_standard_option('pve-node'), | |
a88002cf DM |
286 | notify => { |
287 | type => 'boolean', | |
288 | description => "Send notification mail about new packages (to email address specified for user 'root\@pam').", | |
289 | optional => 1, | |
290 | default => 0, | |
291 | }, | |
2544e8d5 DM |
292 | quiet => { |
293 | type => 'boolean', | |
294 | description => "Only produces output suitable for logging, omitting progress indicators.", | |
295 | optional => 1, | |
296 | default => 0, | |
297 | }, | |
4806bc69 DM |
298 | }, |
299 | }, | |
300 | returns => { | |
301 | type => 'string', | |
302 | }, | |
303 | code => sub { | |
304 | my ($param) = @_; | |
305 | ||
306 | my $rpcenv = PVE::RPCEnvironment::get(); | |
21299915 | 307 | |
4806bc69 | 308 | my $authuser = $rpcenv->get_user(); |
21299915 | 309 | |
4806bc69 DM |
310 | my $realcmd = sub { |
311 | my $upid = shift; | |
21299915 | 312 | |
19ed44c0 DM |
313 | # setup proxy for apt |
314 | my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg'); | |
315 | ||
316 | my $aptconf = "// no proxy configured\n"; | |
317 | if ($dcconf->{http_proxy}) { | |
318 | $aptconf = "Acquire::http::Proxy \"$dcconf->{http_proxy}\";\n"; | |
319 | } | |
320 | my $aptcfn = "/etc/apt/apt.conf.d/76pveproxy"; | |
321 | PVE::Tools::file_set_contents($aptcfn, $aptconf); | |
322 | ||
4806bc69 | 323 | my $cmd = ['apt-get', 'update']; |
21299915 | 324 | |
a137235a | 325 | print "starting apt-get update\n" if !$param->{quiet}; |
4806bc69 | 326 | |
f460dc12 DM |
327 | if ($param->{quiet}) { |
328 | PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}); | |
329 | } else { | |
330 | PVE::Tools::run_command($cmd); | |
331 | } | |
4806bc69 | 332 | |
a88002cf DM |
333 | my $pkglist = &$update_pve_pkgstatus(); |
334 | ||
335 | if ($param->{notify} && scalar(@$pkglist)) { | |
336 | ||
337 | my $usercfg = PVE::Cluster::cfs_read_file("user.cfg"); | |
338 | my $rootcfg = $usercfg->{users}->{'root@pam'} || {}; | |
339 | my $mailto = $rootcfg->{email}; | |
340 | ||
341 | if ($mailto) { | |
342 | my $hostname = `hostname -f` || PVE::INotify::nodename(); | |
343 | chomp $hostname; | |
4b152656 | 344 | my $mailfrom = $dcconf->{email_from} || "root"; |
a88002cf DM |
345 | |
346 | my $data = "Content-Type: text/plain;charset=\"UTF8\"\n"; | |
347 | $data .= "Content-Transfer-Encoding: 8bit\n"; | |
4b152656 | 348 | $data .= "FROM: <$mailfrom>\n"; |
a88002cf DM |
349 | $data .= "TO: $mailto\n"; |
350 | $data .= "SUBJECT: New software packages available ($hostname)\n"; | |
351 | $data .= "\n"; | |
352 | ||
353 | $data .= "The following updates are available:\n\n"; | |
354 | ||
d97a4468 | 355 | my $count = 0; |
a88002cf | 356 | foreach my $p (sort {$a->{Package} cmp $b->{Package} } @$pkglist) { |
d97a4468 DM |
357 | next if $p->{NotifyStatus} && $p->{NotifyStatus} eq $p->{Version}; |
358 | $count++; | |
93305404 DM |
359 | if ($p->{OldVersion}) { |
360 | $data .= "$p->{Package}: $p->{OldVersion} ==> $p->{Version}\n"; | |
361 | } else { | |
362 | $data .= "$p->{Package}: $p->{Version} (new)\n"; | |
363 | } | |
a88002cf DM |
364 | } |
365 | ||
d97a4468 DM |
366 | return if !$count; |
367 | ||
4b152656 | 368 | my $fh = IO::File->new("|sendmail -B 8BITMIME -f $mailfrom $mailto") || |
a88002cf DM |
369 | die "unable to open 'sendmail' - $!"; |
370 | ||
371 | print $fh $data; | |
372 | ||
745d942d DM |
373 | $fh->close() || die "unable to close 'sendmail' - $!"; |
374 | ||
375 | foreach my $pi (@$pkglist) { | |
376 | $pi->{NotifyStatus} = $pi->{Version}; | |
377 | } | |
378 | PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist)); | |
a88002cf DM |
379 | } |
380 | } | |
4806bc69 DM |
381 | |
382 | return; | |
383 | }; | |
384 | ||
c2d3fbe0 | 385 | return $rpcenv->fork_worker('aptupdate', undef, $authuser, $realcmd); |
cd0bc36b | 386 | |
21299915 DM |
387 | }}); |
388 | ||
b688d438 DM |
389 | __PACKAGE__->register_method({ |
390 | name => 'changelog', | |
391 | path => 'changelog', | |
392 | method => 'GET', | |
393 | description => "Get package changelogs.", | |
394 | permissions => { | |
395 | check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]], | |
396 | }, | |
a25fa6e9 | 397 | proxyto => 'node', |
b688d438 DM |
398 | parameters => { |
399 | additionalProperties => 0, | |
400 | properties => { | |
401 | node => get_standard_option('pve-node'), | |
402 | name => { | |
403 | description => "Package name.", | |
404 | type => 'string', | |
405 | }, | |
406 | version => { | |
407 | description => "Package version.", | |
408 | type => 'string', | |
409 | optional => 1, | |
410 | }, | |
411 | }, | |
412 | }, | |
413 | returns => { | |
414 | type => "string", | |
415 | }, | |
416 | code => sub { | |
417 | my ($param) = @_; | |
418 | ||
419 | my $pkgname = $param->{name}; | |
420 | ||
421 | my $cache = &$get_apt_cache(); | |
422 | my $policy = $cache->policy; | |
423 | my $p = $cache->{$pkgname} || die "no such package '$pkgname'\n"; | |
424 | my $pkgrecords = $cache->packages(); | |
425 | ||
426 | my $ver; | |
427 | if ($param->{version}) { | |
428 | if (my $available = $p->{VersionList}) { | |
429 | for my $v (@$available) { | |
430 | if ($v->{VerStr} eq $param->{version}) { | |
431 | $ver = $v; | |
432 | last; | |
433 | } | |
434 | } | |
435 | } | |
436 | die "package '$pkgname' version '$param->{version}' is not avalable\n" if !$ver; | |
437 | } else { | |
438 | $ver = $policy->candidate($p) || die "no installation candidate for package '$pkgname'\n"; | |
439 | } | |
440 | ||
441 | my $info = $pkgrecords->lookup($pkgname); | |
442 | ||
a972b69d DM |
443 | my $pkgfile = &$get_pkgfile($ver); |
444 | my $url; | |
445 | ||
446 | die "changelog for '${pkgname}_$ver->{VerStr}' not available\n" | |
2ba6d822 | 447 | if !($pkgfile && ($url = &$get_changelog_url($pkgname, $info, $ver->{VerStr}, $pkgfile->{Origin}, $pkgfile->{Component}))); |
b688d438 DM |
448 | |
449 | my $data = ""; | |
450 | ||
f5ed75de DM |
451 | my $dccfg = PVE::Cluster::cfs_read_file('datacenter.cfg'); |
452 | my $proxy = $dccfg->{http_proxy}; | |
453 | ||
454 | my $ua = LWP::UserAgent->new; | |
455 | $ua->agent("PVE/1.0"); | |
456 | $ua->timeout(10); | |
457 | $ua->max_size(1024*1024); | |
2ba6d822 DM |
458 | $ua->ssl_opts(verify_hostname => 0); # don't care for changelogs |
459 | ||
f5ed75de | 460 | if ($proxy) { |
f494187f | 461 | $ua->proxy(['http', 'https'], $proxy); |
f5ed75de DM |
462 | } else { |
463 | $ua->env_proxy; | |
464 | } | |
465 | ||
2ba6d822 DM |
466 | my $username; |
467 | my $pw; | |
468 | ||
469 | if ($pkgfile->{Origin} eq 'Proxmox' && $pkgfile->{Component} eq 'pve-enterprise') { | |
470 | my $info = PVE::INotify::read_file('subscription'); | |
471 | if ($info->{status} eq 'Active') { | |
472 | $username = $info->{key}; | |
473 | $pw = PVE::API2Tools::get_hwaddress(); | |
474 | $ua->credentials("enterprise.proxmox.com:443", 'pve-enterprise-repository', | |
475 | $username, $pw); | |
476 | } | |
477 | } | |
478 | ||
f5ed75de | 479 | my $response = $ua->get($url); |
b688d438 | 480 | |
f5ed75de DM |
481 | if ($response->is_success) { |
482 | $data = $response->decoded_content; | |
483 | } else { | |
396c9e4a | 484 | PVE::Exception::raise($response->message, code => $response->code); |
f5ed75de | 485 | } |
b688d438 DM |
486 | |
487 | return $data; | |
488 | }}); | |
489 | ||
8794761f DM |
490 | __PACKAGE__->register_method({ |
491 | name => 'versions', | |
492 | path => 'versions', | |
493 | method => 'GET', | |
502a69ef | 494 | proxyto => 'node', |
8794761f DM |
495 | description => "Get package information for important Proxmox packages.", |
496 | permissions => { | |
497 | check => ['perm', '/nodes/{node}', [ 'Sys.Audit' ]], | |
498 | }, | |
499 | parameters => { | |
500 | additionalProperties => 0, | |
501 | properties => { | |
502 | node => get_standard_option('pve-node'), | |
503 | }, | |
504 | }, | |
505 | returns => { | |
506 | type => "array", | |
507 | items => { | |
508 | type => "object", | |
509 | properties => {}, | |
510 | }, | |
511 | }, | |
512 | code => sub { | |
513 | my ($param) = @_; | |
514 | ||
8794761f DM |
515 | my $cache = &$get_apt_cache(); |
516 | my $policy = $cache->policy; | |
517 | my $pkgrecords = $cache->packages(); | |
518 | ||
c861591b | 519 | # order most important things first |
97f6e029 | 520 | my @list = qw(proxmox-ve pve-manager); |
8794761f | 521 | |
ee94b16a FG |
522 | my $aptver = $AptPkg::System::_system->versioning(); |
523 | my $byver = sub { $aptver->compare($cache->{$b}->{CurrentVer}->{VerStr}, $cache->{$a}->{CurrentVer}->{VerStr}) }; | |
0459599d | 524 | push @list, sort $byver grep { /^pve-kernel-/ && $cache->{$_}->{CurrentState} eq 'Installed' } keys %$cache; |
c861591b TL |
525 | |
526 | my @opt_pack = qw( | |
527 | ceph | |
528 | gfs2-utils | |
529 | libpve-apiclient-perl | |
530 | openvswitch-switch | |
531 | pve-sheepdog | |
a7a65b02 | 532 | pve-zsync |
c861591b TL |
533 | zfsutils-linux |
534 | ); | |
535 | ||
536 | my @pkgs = qw( | |
537 | corosync | |
538 | criu | |
a7a65b02 | 539 | libjs-extjs |
c861591b TL |
540 | glusterfs-client |
541 | ksm-control-daemon | |
542 | libpve-access-control | |
543 | libpve-common-perl | |
544 | libpve-guest-common-perl | |
545 | libpve-http-server-perl | |
546 | libpve-storage-perl | |
547 | libqb0 | |
548 | lvm2 | |
549 | lxc-pve | |
550 | lxcfs | |
551 | novnc-pve | |
a7a65b02 | 552 | proxmox-widget-toolkit |
c861591b TL |
553 | pve-cluster |
554 | pve-container | |
555 | pve-docs | |
5d4bb1f7 | 556 | pve-edk2-firmware |
c861591b TL |
557 | pve-firewall |
558 | pve-firmware | |
559 | pve-ha-manager | |
a7a65b02 | 560 | pve-i18n |
c861591b TL |
561 | pve-libspice-server1 |
562 | pve-qemu-kvm | |
a7a65b02 | 563 | pve-xtermjs |
c861591b TL |
564 | qemu-server |
565 | smartmontools | |
a7a65b02 | 566 | spiceterm |
c861591b TL |
567 | vncterm |
568 | ); | |
569 | ||
570 | # add the rest ordered by name, easier to find for humans | |
571 | push @list, (sort @pkgs, @opt_pack); | |
8794761f DM |
572 | |
573 | my (undef, undef, $kernel_release) = POSIX::uname(); | |
574 | my $pvever = PVE::pvecfg::version_text(); | |
575 | ||
c861591b | 576 | my $pkglist = []; |
8794761f DM |
577 | foreach my $pkgname (@list) { |
578 | my $p = $cache->{$pkgname}; | |
579 | my $info = $pkgrecords->lookup($pkgname); | |
c0d696f9 | 580 | my $candidate_ver = defined($p) ? $policy->candidate($p) : undef; |
8794761f DM |
581 | my $res; |
582 | if (my $current_ver = $p->{CurrentVer}) { | |
583 | $res = &$assemble_pkginfo($pkgname, $info, $current_ver, | |
584 | $candidate_ver || $current_ver); | |
585 | } elsif ($candidate_ver) { | |
586 | $res = &$assemble_pkginfo($pkgname, $info, $candidate_ver, | |
587 | $candidate_ver); | |
588 | delete $res->{OldVersion}; | |
589 | } else { | |
590 | next; | |
591 | } | |
592 | $res->{CurrentState} = $p->{CurrentState}; | |
593 | ||
594 | # hack: add some useful information (used by 'pveversion -v') | |
595 | if ($pkgname eq 'pve-manager') { | |
596 | $res->{ManagerVersion} = $pvever; | |
97f6e029 | 597 | } elsif ($pkgname eq 'proxmox-ve') { |
8794761f DM |
598 | $res->{RunningKernel} = $kernel_release; |
599 | } | |
241c6f94 WL |
600 | if (grep( /^$pkgname$/, @opt_pack)) { |
601 | next if $res->{CurrentState} eq 'NotInstalled'; | |
602 | } | |
8794761f DM |
603 | |
604 | push @$pkglist, $res; | |
605 | } | |
606 | ||
607 | return $pkglist; | |
608 | }}); | |
609 | ||
21299915 | 610 | 1; |