summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock5
-rw-r--r--Cargo.toml1
-rw-r--r--src/i2impl/mi2p.rs14
-rw-r--r--src/main.rs13
-rw-r--r--src/pkgtoolkit/pkgtools.rs136
5 files changed, 124 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c3d263d..40f70a3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -141,9 +141,9 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.2.47"
+version = "1.2.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cd405d82c84ff7f35739f175f67d8b9fb7687a0e84ccdc78bd3568839827cf07"
+checksum = "c481bdbf0ed3b892f6f806287d72acd515b352a4ec27a208489b8c1bc839633a"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -788,6 +788,7 @@ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
name = "mesk"
version = "0.1.0"
dependencies = [
+ "cc",
"clap",
"emissary-core",
"flate2",
diff --git a/Cargo.toml b/Cargo.toml
index e339616..6173d2d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,7 @@ tar = "0.4.44"
emissary-core = "0.2.0"
tokio = "1.48.0"
yosemite = "0.6.1"
+cc = "1.2.48"
diff --git a/src/i2impl/mi2p.rs b/src/i2impl/mi2p.rs
index 9fa05bf..9faef34 100644
--- a/src/i2impl/mi2p.rs
+++ b/src/i2impl/mi2p.rs
@@ -1,6 +1,7 @@
use crate::cfg::config::Config;
+use serde::de::value::StrDeserializer;
use tokio;
use emissary_core::runtime::{
AsyncRead,
@@ -44,14 +45,14 @@ impl I2PStatus {
}
*/
-struct I2P<S> {
- session: Option<Session<S>>,
+struct I2P<Stream> {
+ session: Option<Session<Stream>>,
connected: bool,
config: Config,
}
-impl<S> I2P<S> {
+impl I2P<Stream> {
/// Creates a new I2P object with the given configuration.
///
/// # Returns
@@ -73,6 +74,11 @@ impl<S> I2P<S> {
///
/// Returns an error if the repository URL is invalid or if the request fails.
///
+ /// # Shortcomings
+ /// - Currently, &str is used instead of Path.
+ /// - An incomplete I2P structure, the session is stored in the structure but
+ /// is recreated when called, perhaps the connection/disconnection methods should be encapsulated,
+ /// although the function is not used often so it will not carry major changes
pub async fn fetch_index(&mut self) -> Result<bool, std::io::Error> {
let repo_url_str = &self.config.repo.repo_url;
let cache_dir = &self.config.paths.cache_dir;
@@ -87,7 +93,7 @@ impl<S> I2P<S> {
// HTTP path
let request_path = format!("/repo{}{}", path_suffix, if path_suffix.ends_with(".tar.gz") { "" } else { "/INDEX.tar.gz" });
- let mut opts = SessionOptions::default();
+ let opts = SessionOptions::default();
// FIXME: Make sure, opts setted to I2P
// opts.set_host("127.0.0.1");
// opts.set_port(7656);
diff --git a/src/main.rs b/src/main.rs
index 4515896..1630c66 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,11 @@ 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 clap::{Parser, Subcommand, Args};
@@ -42,11 +45,11 @@ enum Commands {
#[derive(Args, Clone)]
#[command(about = "Remote install arguments")]
struct RemoteInstallArgs {
- Verbose: bool,
- Debug: bool,
- Bin: bool,
- Source: bool,
- I2P: bool,
+ verbose: bool,
+ debug: bool,
+ bin: bool,
+ source: bool,
+ i2p: bool,
}
fn main() -> Result<(), std::io::Error> {
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index 100c5e2..f44a283 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -1,19 +1,19 @@
// I think I should split this file into a few smaller ones.
use crate::cfg::config::Config;
-use core::arch;
-use std::{io,
- fs::{self, File, create_dir_all},
- str,
- path::Path,
- process::Command,};
-
-use emissary_core::i2np::tunnel::build;
-// use emissary_core::i2np::tunnel::build;
+use std::{
+ fs::{self, File, create_dir_all},
+ io,
+ path::Path,
+ process::Command,
+ str};
+
+ // use emissary_core::i2np::tunnel::build;
use flate2::read::GzDecoder;
use serde::{Deserialize, Serialize};
use tar::Archive;
use toml;
+use cc;
#[derive(Serialize, Debug, Deserialize, Clone)]
pub enum archs {
@@ -32,6 +32,7 @@ pub struct Package {
descr: Option<String>,
}
+#[allow(dead_code)]
#[derive(Deserialize, Debug, Clone)]
struct Install {
package: Package,
@@ -43,6 +44,7 @@ struct Install {
custom_script: Option<String>,
}
+#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct Setts {
env: Option<String>, // Export environment variables if this needed
@@ -57,7 +59,8 @@ pub enum BuildSystems {
Cargo
}
-#[derive(Deserialize, Debug)]
+#[allow(dead_code)]
+#[derive(Deserialize)]
struct Build {
build_system: BuildSystems,
env: Option<String>,
@@ -71,17 +74,76 @@ impl archs {
archs::Aarch64 => "aarch64",
archs::X86 => "x86",
archs::ArmV7 => "armv7",
- archs::ArmV8 => "armv8",
- _ => "unknown",
+ archs::ArmV8 => "armv8"
}
}
}
+#[allow(dead_code)]
impl Package {
- fn builder_backend(BuildParameters: Build) -> Result<bool, std::io::Error> {
- todo!()
+ fn builder_backend(&mut self) -> Result<bool, std::io::Error> {
+ let config: Config = Config::parse().unwrap();
+ let metadata = Self::loadmeta(self).unwrap();
+ let path = Path::new(&config.paths.cache_dir).join(format!("{}-{}/BUILD", metadata.0.package.name, metadata.0.package.version));
+ let _ = create_dir_all(&path);
+
+ if metadata.2.is_none() {
+ Err(std::io::Error::new(std::io::ErrorKind::NotFound, "BUILD file not found"))?
+ }
+
+ match metadata.2.unwrap().build_system {
+ BuildSystems::Make => {
+ let _setup = Command::new("make")
+ .arg("all")
+ .arg("all")
+ .output();
+ }
+
+ BuildSystems::CMake => {
+ let _setup = Command::new("cmake")
+ .arg("-S")
+ .arg(&path)
+ .arg("-B")
+ .arg(&path)
+ .output();
+
+ let _make = Command::new("make")
+ .arg("-C")
+ .arg(&path)
+ .output();
+ }
+
+ _ => {
+ Err(std::io::Error::new(std::io::ErrorKind::NotFound, "BUILD file not found"))?
+ }
+ }
+
+ Ok(true)
}
+ /// Extracts a .tar.gz archive to the cache directory specified in Config.
+ ///
+ /// This function handles opening the archive file, decompressing it with GzDecoder,
+ /// and unpacking the contents into the configured cache directory.
+ ///
+ /// # Arguments
+ /// * `path_to_archive` - A string representing the path to the .tar.gz file.
+ ///
+ /// # Returns
+ /// * `Ok(())` if the archive is successfully unpacked.
+ /// * `Err(std::io::Error)` if there's an issue opening, reading, or unpacking the archive.
+ fn extract_archive(path_to_archive: &str) -> Result<(), std::io::Error> {
+ let config = Config::parse().unwrap();
+ create_dir_all(&config.paths.cache_dir)?;
+
+ let file = File::open(path_to_archive)?;
+ let gz = GzDecoder::new(file);
+ let mut archive = Archive::new(gz);
+
+ // Unpack directly into the cache directory
+ archive.unpack(&config.paths.cache_dir)?;
+ Ok(())
+ }
/// Load meta information from the .mesk archive.
///
@@ -188,16 +250,21 @@ 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> {
- let config: Config = Config::parse().unwrap();
+ // Call the new extraction function
+ Self::extract_archive(&path_to_archive)?;
- create_dir_all(&config.paths.cache_dir)?;
-
- let file = File::open(&path_to_archive)?;
- let gz = GzDecoder::new(file);
- let mut archive = Archive::new(gz);
-
- archive.unpack(&config.paths.cache_dir)?;
+ let config = Config::parse().unwrap();
let install_path = Path::new(&config.paths.cache_dir).join("INSTALL");
let setts_path = Path::new(&config.paths.cache_dir).join("SETTS");
@@ -244,18 +311,19 @@ impl Package {
let install_content: Result<Install, toml::de::Error> = toml::from_str(&content);
log::info!("Validating arch...");
- if std::env::consts::ARCH != install_content.unwrap().package.arch.as_str() {
- log::error!("Arch mismatch. Package arch: {:?}, Host arch: {}", install_content.clone().unwrap().package.arch, std::env::consts::ARCH);
+ if std::env::consts::ARCH != install_content.as_ref().map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?.package.arch.as_str() {
+ let pkg_arch = &install_content.unwrap().package.arch; // Safe because of previous check/unwrap
+ log::error!("Arch mismatch. Package arch: {:?}, Host arch: {}", pkg_arch, std::env::consts::ARCH);
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Arch mismatch",
));
}
-
-
Ok(true)
}
+
+
/// Builds the package according to the BUILD file in the archive.
///
@@ -276,37 +344,37 @@ impl Package {
// BUILD NOT EMPTY. SOURCE: -> BUILD -> INSTALL -> SETTS
// BUILD EMPTY. BIN: -> INSTALL -> SETTS
- enum strategies {
+ enum Strategies {
BIN,
SOURCE
}
- let mut strategy = strategies::SOURCE; //default
+ let strategy; //default
if build_meta.is_none() {
log::info!("BUILD file is empty. Skipping build, preparing to install");
- strategy = strategies::BIN;
+ strategy = Strategies::BIN;
} else {
- strategy = strategies::SOURCE;
+ strategy = Strategies::SOURCE;
log::info!("BUILD file is not empty. Skipping install, preparing to build");
}
match strategy {
- strategies::BIN => {
+ Strategies::BIN => {
if install_meta.custom_script.is_none() {
log::info!("Strategy: BIN; No custom script. Running default install hook.");
} else {
log::info!("Strategy: BIN; Running custom script.");
let script = install_meta.custom_script.as_ref().unwrap();
if !script.starts_with("./") {
- let output = std::process::Command::new(format!("{}", script));
+ let _output = std::process::Command::new(format!("{}", script));
} else {
- let output = std::process::Command::new(format!("/bin/sh '{}'", script));
+ let _output = std::process::Command::new(format!("/bin/sh '{}'", script));
}
}
}
- strategies::SOURCE => {
+ Strategies::SOURCE => {
log::info!("Strategy: SOURCE; Running default build hook.");
todo!();
}