From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id AD1B9655C6 for ; Thu, 23 Jul 2020 11:22:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A8E402748E for ; Thu, 23 Jul 2020 11:22:25 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 1441327486 for ; Thu, 23 Jul 2020 11:22:25 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D361D43337 for ; Thu, 23 Jul 2020 11:22:24 +0200 (CEST) From: Thomas Lamprecht To: pbs-devel@lists.proxmox.com Date: Thu, 23 Jul 2020 11:22:07 +0200 Message-Id: <20200723092207.28110-1-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.007 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] applied: [PATCH backup] api: apt: support refreshing package index X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 09:22:55 -0000 Signed-off-by: Thomas Lamprecht --- src/api2/node/apt.rs | 64 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index 55d360f..c65e414 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -3,10 +3,13 @@ use anyhow::{Error, bail}; use serde_json::{json, Value}; use proxmox::{list_subdirs_api_method, const_regex}; -use proxmox::api::{api, Router, Permission, SubdirMap}; +use proxmox::api::{api, RpcEnvironment, RpcEnvironmentType, Permission}; +use proxmox::api::router::{Router, SubdirMap}; -use crate::config::acl::PRIV_SYS_AUDIT; -use crate::api2::types::{APTUpdateInfo, NODE_SCHEMA}; +use crate::server::WorkerTask; + +use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; +use crate::api2::types::{APTUpdateInfo, NODE_SCHEMA, UPID_SCHEMA}; const_regex! { VERSION_EPOCH_REGEX = r"^\d+:"; @@ -202,8 +205,61 @@ fn apt_update_available(_param: Value) -> Result { Ok(json!(ret)) } +#[api( + input: { + properties: { + node: { + schema: NODE_SCHEMA, + }, + quiet: { + description: "Only produces output suitable for logging, omitting progress indicators.", + type: bool, + default: false, + optional: true, + }, + }, + }, + returns: { + schema: UPID_SCHEMA, + }, + access: { + permission: &Permission::Privilege(&[], PRIV_SYS_MODIFY, false), + }, +)] +/// Update the APT database +pub fn apt_update_database( + quiet: Option, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { + + let username = rpcenv.get_user().unwrap(); + let to_stdout = if rpcenv.env_type() == RpcEnvironmentType::CLI { true } else { false }; + let quiet = quiet.unwrap_or(false); + + let upid_str = WorkerTask::new_thread("aptupdate", None, &username.clone(), to_stdout, move |worker| { + if !quiet { worker.log("starting apt-get update") } + + // TODO: set proxy /etc/apt/apt.conf.d/76pbsproxy like PVE + + let mut command = std::process::Command::new("apt-get"); + command.arg("update"); + + let output = crate::tools::run_command(command, None)?; + if !quiet { worker.log(output) } + + // TODO: add mail notify for new updates like PVE + + Ok(()) + })?; + + Ok(upid_str) +} + const SUBDIRS: SubdirMap = &[ - ("update", &Router::new().get(&API_METHOD_APT_UPDATE_AVAILABLE)), + ("update", &Router::new() + .get(&API_METHOD_APT_UPDATE_AVAILABLE) + .post(&API_METHOD_APT_UPDATE_DATABASE) + ), ]; pub const ROUTER: Router = Router::new() -- 2.27.0