]>
git.proxmox.com Git - pve-manager.git/blob - PVE/APLInfo.pm
8 use POSIX
qw(strftime);
12 use PVE
::Tools
qw(run_command);
15 my $logfile = "/var/log/pveam.log";
16 my $aplinfodir = "/var/lib/pve-manager/apl-info";
19 my ($logfd, $msg) = @_;
23 my $tstr = strftime
("%F %H:%M:%S", localtime);
25 foreach my $line (split (/\n/, $msg)) {
26 print $logfd "$tstr $line\n";
30 sub read_aplinfo_from_fh
{
31 my ($fh, $list, $source, $update) = @_;
35 while (my $rec = <$fh>) {
42 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
43 $res->{headline
} = $1;
48 $res->{description
} = $long;
49 } elsif ($rec =~ s/^Version:\s*(.*\S)\s*\n//i) {
51 if ($version =~ m/^(\d[a-zA-Z0-9\.\+\-\:\~]*)(-(\d+))?$/) {
52 $res->{version
} = $version;
54 my $msg = "unable to parse appliance record: version = '$version'\n";
55 $update ?
die $msg : warn $msg;
57 } elsif ($rec =~ s/^Type:\s*(.*\S)\s*\n//i) {
59 if ($type =~ m/^(openvz|lxc)$/) {
62 my $msg = "unable to parse appliance record: unknown type '$type'\n";
63 $update ?
die $msg : warn $msg;
65 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
68 my $msg = "unable to parse appliance record: $rec\n";
69 $update ?
die $msg : warn $msg;
75 if ($res->{'package'} eq 'pve-web-news' && $res->{description
}) {
76 $list->{'all'}->{$res->{'package'}} = $res;
80 $res->{section
} = 'unknown' if !$res->{section
};
82 if ($res->{'package'} && $res->{type
} && $res->{os
} && $res->{version
} &&
85 if ($res->{location
}) {
86 $template = $res->{location
};
87 $template =~ s
|.*/([^/]+$PVE::Storage
::vztmpl_extension_re
)$|$1|;
88 if ($res->{location
} !~ m
|^([a-zA-Z
]+)\
://|) {
89 # relative localtion (no http:// prefix)
90 $res->{location
} = "$source/$res->{location}";
93 my $arch = $res->{architecture
} || 'i386';
94 $template = "$res->{os}-$res->{package}_$res->{version}_$arch.tar.gz";
95 $template =~ s/$res->{os}-$res->{os}-/$res->{os}-/;
96 $res->{location
} = "$source/$res->{section}/$template";
98 $res->{source
} = $source;
99 $res->{template
} = $template;
100 $list->{$res->{section
}}->{$template} = $res;
101 $list->{'all'}->{$template} = $res;
103 my $msg = "found incomplete appliance records\n";
104 $update ?
die $msg : warn $msg;
110 my ($filename, $list, $source, $update) = @_;
112 my $fh = IO
::File-
>new("<$filename") ||
113 die "unable to open file '$filename' - $!\n";
115 eval { read_aplinfo_from_fh
($fh, $list, $source, $update); };
126 my ($ua, $url, $file, $logfh) = @_;
128 my $req = HTTP
::Request-
>new(GET
=> $url);
130 logmsg
($logfh, "start download $url");
131 my $res = $ua->request($req, $file);
133 if ($res->is_success) {
134 logmsg
($logfh, "download finished: " . $res->status_line);
138 logmsg
($logfh, "download failed: " . $res->status_line);
143 sub download_aplinfo
{
144 my ($ua, $aplinfo, $logfd) = @_;
146 my $aplsrcurl = "$aplinfo->{url}/$aplinfo->{file}.gz";
147 my $aplsigurl = "$aplinfo->{url}/$aplinfo->{file}.asc";
148 my $host = $aplinfo->{host
};
150 my $tmp = "$aplinfodir/pveam-${host}.tmp.$$";
151 my $tmpgz = "$tmp.gz";
152 my $sigfn = "$tmp.asc";
156 if (url_get
($ua, $aplsigurl, $sigfn, $logfd) != 0) {
157 die "update failed - no signature file '$sigfn'\n";
160 if (url_get
($ua, $aplsrcurl, $tmpgz, $logfd) != 0) {
161 die "update failed - no data file '$aplsrcurl'\n";
164 eval { run_command
(["gunzip", "-f", $tmpgz]) };
165 die "update failed: unable to unpack '$tmpgz'\n" if $@;
168 my $trustedkeyring = "/usr/share/doc/pve-manager/trustedkeys.gpg";
169 my $cmd = "/usr/bin/gpgv -q --keyring $trustedkeyring $sigfn $tmp";
171 my $logfunc = sub { logmsg
($logfd, "signature verification: $_[0]"); };
173 run_command
($cmd, outfunc
=> $logfunc, errfunc
=> $logfunc);
175 die "unable to verify signature - $@\n" if $@;
178 eval { read_aplinfo
($tmp, {}, $aplinfo->{url
}, 1) };
179 die "update failed: $@" if $@;
181 rename($tmp, "$aplinfodir/$host") or
182 die "update failed: unable to store data: $!\n";
184 logmsg
($logfd, "update successful");
196 sub get_apl_sources
{
199 host
=> "download.proxmox.com",
200 url
=> "http://download.proxmox.com/images",
201 file
=> 'aplinfo-pve-7.dat',
204 host
=> "releases.turnkeylinux.org",
205 url
=> "https://releases.turnkeylinux.org/pve",
206 file
=> 'aplinfo.dat',
217 if (($size = (-s
$logfile) || 0) > (1024*50)) {
218 rename($logfile, "$logfile.0");
220 my $logfd = IO
::File-
>new (">>$logfile");
221 logmsg
($logfd, "starting update");
223 my $ua = LWP
::UserAgent-
>new;
224 my $release = PVE
::pvecfg
::release
();
225 $ua->agent("PVE/$release");
228 $ua->proxy(['http', 'https'], $proxy);
233 my $sources = get_apl_sources
();
238 foreach my $info (@$sources) {
240 download_aplinfo
($ua, $info, $logfd);
243 logmsg
($logfd, $err);
244 push @dlerr, $info->{url
};
250 return 0 if scalar(@dlerr);
257 my $sources = get_apl_sources
();
260 foreach my $info (@$sources) {
262 my $host = $info->{host
};
263 read_aplinfo
("$aplinfodir/$host", $list, $info->{url
});