use base qw(PVE::RESTHandler);
-my $SAUPDATE = '/usr/bin/sa-update';
-
__PACKAGE__->register_method ({
name => 'index',
path => '',
}
# call sa-update to see if updates are available
- my $cmd = "$SAUPDATE -v --checkonly --channel $channel";
+ my $cmd = "sa-update -v --checkonly --channel $channel";
PVE::Tools::run_command($cmd, noerr => 1, logfunc => sub {
my ($line) = @_;
$ENV{http_proxy} = $http_proxy;
}
- my $cmd = "$SAUPDATE -v";
+ my $cmd = "sa-update -v";
PVE::Tools::run_command($cmd, noerr => 1);
+
+ PMG::Utils::update_local_spamassassin_channels(1);
};
return $rpcenv->fork_worker('saupdate', undef, $authuser, $realcmd);
return $res;
}
+sub update_local_spamassassin_channels {
+ my ($verbose) = @_;
+ # import all configured channel's gpg-keys to sa-update's keyring
+ my $localchannels = PMG::Utils::local_spamassassin_channels();
+ for my $channel (@$localchannels) {
+ my $importcmd = ['sa-update', '--import', $channel->{filename}];
+ push @$importcmd, '-v' if $verbose;
+
+ print "Importing gpg key from $channel->{filename}\n" if $verbose;
+ PVE::Tools::run_command($importcmd);
+ }
+
+ my $fresh_updates = 0;
+
+ for my $channel (@$localchannels) {
+ my $cmd = ['sa-update', '--channel', $channel->{channelurl}, '--gpgkey', $channel->{keyid}];
+ push @$cmd, '-v' if $verbose;
+
+ print "Updating $channel->{channelurl}\n" if $verbose;
+ my $ret = PVE::Tools::run_command($cmd, noerr => 1);
+ die "updating $channel->{channelurl} failed - sa-update exited with $ret\n" if $ret >= 2;
+
+ $fresh_updates = 1 if $ret == 0;
+ }
+
+ return $fresh_updates
+}
+
1;