summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-29 16:08:17 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-29 16:08:17 +0300
commitf3d98b21d0b66952501aed5403df6773716f9e0b (patch)
tree90eca38f0edbda3c7caa36d4175531bab0566469
parent11ccd034109224849fff54c12785e454deba6741 (diff)
Connected some functions to main.rs.
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml2
-rw-r--r--src/cfg/config.rs30
-rw-r--r--src/i2impl/mi2p.rs3
-rw-r--r--src/main.rs81
-rw-r--r--src/pkgtoolkit/pkgtools.rs10
6 files changed, 115 insertions, 23 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 40f70a3..2dbf9f0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1349,10 +1349,22 @@ dependencies = [
"mio",
"pin-project-lite",
"socket2",
+ "tokio-macros",
"windows-sys 0.61.2",
]
[[package]]
+name = "tokio-macros"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "toml"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 6173d2d..63d73e0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,9 +16,9 @@ log = "0.4.28"
sqlite = "0.37.0"
tar = "0.4.44"
emissary-core = "0.2.0"
-tokio = "1.48.0"
yosemite = "0.6.1"
cc = "1.2.48"
+tokio = { version = "1.48.0", features = ["macros", "rt"] }
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index 7c81e21..ffccbad 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -1,5 +1,4 @@
use std::fs;
-use std::env;
use serde::{Deserialize, Serialize};
use toml;
@@ -57,7 +56,7 @@ impl Config {
///
/// This function reads the /etc/mesk.toml file, parses it and returns the Config object.
pub fn parse() -> Result<Config, toml::de::Error> {
- let contents = fs::read_to_string("/etc/mesk.toml").unwrap();
+ let contents = fs::read_to_string("/etc/mesk/mesk.toml").unwrap();
let result: Config = toml::from_str(&contents)?;
Ok(result)
}
@@ -74,6 +73,7 @@ impl Config {
auto_update: true,
destination: (String::from("mesk"), String::from("mesk")),
// Its a hurt place, you need to generate destinations by i2pd and paste here (to mesk.toml)
+ // Better to leave it empty or set it to (mesk, mesk), now destination conn not implemented
},
log: Log {
log_file: String::from("/var/log/mesk.log"),
@@ -88,4 +88,28 @@ impl Config {
let toml_str = toml::to_string(&default)?;
Ok(toml_str)
}
-} \ No newline at end of file
+
+ pub fn generate(repo: &Option<String>, cachedir: &Option<String>, buildir: &Option<String>) -> Result<String, toml::ser::Error> {
+ let generator: Config = Config {
+ repo: Repo {
+ repo_url: if repo.is_none() { format!("https://mesk.anthrill.i2p/repo/{}/", std::env::consts::ARCH ) } else { repo.clone().unwrap() },
+ auto_update: true,
+ destination: (String::from("mesk"), String::from("mesk")),
+ },
+ log: Log {
+ log_file: String::from("/var/log/mesk.log"),
+ log_level: Loglevel::Info,
+ },
+ paths: Paths {
+ cache_dir: if cachedir.is_none() { String::from("/var/cache/mesk") } else { cachedir.clone().unwrap() },
+ build_dir: if buildir.is_none() { String::from("/var/cache/mesk/build") } else { buildir.clone().unwrap() },
+
+ /*
+ FIXME: I can leave this parameter, but I think it would be better to make the build
+ path in the /var/cache/mesk/$pkgname-$pkgver/BUILD/
+ */
+ },
+ };
+ Ok(toml::to_string(&generator)?)
+ }
+}
diff --git a/src/i2impl/mi2p.rs b/src/i2impl/mi2p.rs
index 9faef34..cf2b8e5 100644
--- a/src/i2impl/mi2p.rs
+++ b/src/i2impl/mi2p.rs
@@ -1,7 +1,6 @@
use crate::cfg::config::Config;
-use serde::de::value::StrDeserializer;
use tokio;
use emissary_core::runtime::{
AsyncRead,
@@ -45,7 +44,7 @@ impl I2PStatus {
}
*/
-struct I2P<Stream> {
+pub struct I2P<Stream> {
session: Option<Session<Stream>>,
connected: bool,
config: Config,
diff --git a/src/main.rs b/src/main.rs
index 1630c66..a3f69dd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,14 +2,19 @@ mod cfg;
mod i2impl;
mod pkgtoolkit;
-#[allow(unused_imports)]
use crate::cfg::config::Config;
#[allow(unused_imports)]
use crate::pkgtoolkit::pkgtools::Package;
#[allow(unused_imports)]
-use crate::i2impl::mi2p;
+use crate::i2impl::mi2p::I2P;
-use clap::{Parser, Subcommand, Args};
+use clap::{Args, Command, Parser, Subcommand};
+use yosemite::Stream;
+use std::io::Write;
+use std::path::Path;
+use std::fs::create_dir_all;
+use std::fs::File;
+use tokio;
#[derive(Parser)]
struct Cli {
@@ -23,6 +28,12 @@ enum Commands {
Validate {
pkgname: String,
},
+ #[command(about = "Update all repositories index")]
+ Update,
+ #[command(about = "Upgrade all packages or a specific package")]
+ Upgrade {
+ pkgname: Option<String>,
+ },
#[command(about = "Build package from .mesk ")]
Build{
pkgname: String,
@@ -30,6 +41,7 @@ enum Commands {
#[command(about = "Install package from remote or local sources")]
Install{
pkgname: String,
+ source: Option<String>,
},
#[command(about = "Uninstall package")]
Uninstall{
@@ -38,6 +50,12 @@ enum Commands {
#[command(about = "Get package source")]
GetSource{
pkgname: String
+ },
+ #[command(about = "Generator of config file")]
+ DefaultConfig {
+ repo: Option<String>,
+ cachedir: Option<String>,
+ buildir: Option<String>,
}
}
@@ -52,7 +70,8 @@ struct RemoteInstallArgs {
i2p: bool,
}
-fn main() -> Result<(), std::io::Error> {
+#[tokio::main]
+async fn main() -> Result<(), std::io::Error> {
let cli: Cli = Cli::parse();
// Plug in these functions only until the backend is ready for testing (Aplha versions)
@@ -66,7 +85,7 @@ fn main() -> Result<(), std::io::Error> {
println!("Building {}", pkgname);
return Ok(())
},
- Commands::Install { pkgname } => {
+ Commands::Install { pkgname, source} => {
println!("Installing {}", pkgname);
return Ok(())
},
@@ -77,8 +96,56 @@ fn main() -> Result<(), std::io::Error> {
Commands::GetSource { pkgname } => {
println!("Getting source of {}", pkgname);
return Ok(())
-
- }
+ },
+ Commands::DefaultConfig { repo, cachedir, buildir } => {
+ println!("Generating config file");
+ if cachedir.is_none() && repo.is_none() && buildir.is_none() {
+ let config = Config::default().unwrap();
+
+ println!("---- Start of generated config ----");
+ println!("{}", config);
+ println!("---- End of generated config ----");
+
+ log::warn!("Writing the default config to /etc/mesk/mesk.toml");
+
+ let path = Path::new("/etc/mesk/mesk.toml");
+ create_dir_all(path.parent().unwrap()).unwrap();
+ let mut file = File::create(path).unwrap();
+ file.write(config.as_bytes()).unwrap();
+ println!("Config tool ending work.");
+
+ } else {
+ let config = Config::generate(repo, cachedir, buildir).unwrap();
+
+ println!("---- Start of generated config ----");
+ println!("{:?}", config);
+ println!("---- End of generated config ----");
+
+ log::warn!("Writing the default config to /etc/mesk/mesk.toml");
+
+ let path = Path::new("/etc/mesk/mesk.toml");
+ create_dir_all(path.parent().unwrap()).unwrap();
+ let mut file = File::create(path).unwrap();
+ file.write_all(config.as_bytes()).unwrap();
+ println!("Config tool ending work.");
+
+ }
+ return Ok(())
+ },
+ Commands::Update => {
+ let config = Config::parse().unwrap();
+ println!("Updating index from {}", config.repo.repo_url);
+ let mut i2pd = I2P::new(config);
+ let _index= I2P::fetch_index(&mut i2pd).await?;
+ println!("Index updated");
+ return Ok(())
+ },
+ Commands::Upgrade { pkgname } => {
+ println!("Upgrading all packages");
+ return Ok(())
+ },
+
+
}
Ok(())
} \ No newline at end of file
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index f44a283..5acbd11 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -250,16 +250,6 @@ impl Package {
/// * Returns an error if INSTALL file is empty.
///
// TODO: Add meta-files validation here.
- /// Checks if the archive contains INSTALL, SETTS and BUILD files.
- ///
- /// Checks if INSTALL file exists and is not empty. If it does not exist or is empty, returns an error.
- ///
- /// Checks if SETTS and BUILD files exist and are not empty. If they do not exist or are empty, logs a warning.
- /// # Errors
- /// * Returns an error if INSTALL file does not exist or is empty.
- /// * Returns an error if INSTALL file is empty.
- ///
- // TODO: Add meta-files validation here.
pub fn check(path_to_archive: String) -> Result<bool, std::io::Error> {
// Call the new extraction function
Self::extract_archive(&path_to_archive)?;