summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/i2impl/mi2p.rs2
-rw-r--r--src/pkgtoolkit/pkgtools.rs184
2 files changed, 110 insertions, 76 deletions
diff --git a/src/i2impl/mi2p.rs b/src/i2impl/mi2p.rs
index 6d095f9..9fa05bf 100644
--- a/src/i2impl/mi2p.rs
+++ b/src/i2impl/mi2p.rs
@@ -73,7 +73,7 @@ impl<S> I2P<S> {
///
/// Returns an error if the repository URL is invalid or if the request fails.
///
- async fn fetch_index(&mut self) -> Result<bool, std::io::Error> {
+ 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;
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index e347625..1577a50 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -1,8 +1,10 @@
use crate::cfg::config::Config;
-
-use std::fs::{File, create_dir_all};
-use std::path::PathBuf;
-use std::path::Path;
+use std::{io,
+ fs::{self, File, create_dir_all},
+ str,
+ path::Path};
+
+// use emissary_core::i2np::tunnel::build;
use flate2::read::GzDecoder;
use serde::{Deserialize, Serialize};
use tar::Archive;
@@ -25,6 +27,7 @@ pub struct Package {
#[derive(Deserialize, Debug)]
struct Install {
+ package: Package,
path: String,
user: String,
group: String,
@@ -33,91 +36,122 @@ struct Install {
custom_script: Option<String>,
}
+#[derive(Deserialize, Debug)]
+struct Setts {
+ env: Option<String>, // Export environment variables if this needed
+ test: Option<String>, // Test the package after installation
+}
+
+#[derive(Deserialize, Serialize, Debug)]
+pub enum BuildSystems {
+ Make,
+ CMake,
+ Meson,
+ Cargo
+}
+
+#[derive(Deserialize, Debug)]
+struct Build {
+ build_system: BuildSystems,
+ env: Option<String>,
+ script: Option<String>,
+}
+
impl Package {
- /// 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.
+ /// Load meta information from the .mesk archive.
///
+ /// This function parses the meta information from the .mesk archive,
+ /// which includes the package name, version, architecture, description,
+ /// installation path, user, group, mode, and custom installation script
+ /// and deserializing this information. Returns (Install, Option<Setts>, Option<Build>)
+ ///
+ /// The function expects the 'INSTALL', 'SETTS', and 'BUILD' files to be present
+ /// in the `config.paths.cache_dir`. It specifically requires the 'INSTALL' file.
+ ///
/// # Errors
///
- /// Returns an error if INSTALL file does not exist or is empty.
- /// Returns an error if INSTALL file is empty.
+ /// Returns an error if the `cache_dir` cannot be created, if the required 'INSTALL' file
+ /// is not found, or if the 'INSTALL' file is empty.
+ fn loadmeta(minimal_package_meta: Package) -> Result<(Install, Option<Setts>, Option<Build>), Box<dyn std::error::Error>> { // Changed return type for more flexibility
+ /*
+ Example INSTALL format:
+ [package]
+ name = "my-package"
+ version = "1.0.0"
+ arch = "X86_64"
+ descr = "Just example INSTALL script"
+
+ [install]
+ path = "/usr/bin/my-package"
+ user = "root"
+ group = "root"
+ mode = "755"
+
+ # Also [install] can be
+ # path = "/usr/bin/my-package"
+ # user = "root"
+ # group = "root"
+ # mode = "755"
+ # custom_script = "./install.sh" OR
+ # custom_script = """
+ # echo "Installing my-package"
+ # sudo apt-get install my-package
+ # """
+ */
- fn loadmeta() -> Result<bool, std::io::Error> {
- let config: Config = Config::parse().unwrap();
- create_dir_all(&config.paths.cache_dir)?;
-
- struct FileStates {
- install: bool,
- setts: bool,
- build: bool,
- }
+ let config = Config::parse()?; // Propagate error if parsing fails
+
+ // Ensure the cache directory exists
+ fs::create_dir_all(&config.paths.cache_dir)?;
+
- // for file in ["INSTALL", "SETTS", "BUILD"] {
- // let path = Path::new(&config.paths.cache_dir).join(file);
- // }
let cache_dir = &config.paths.cache_dir;
- let file_names = ["INSTALL", "SETTS", "BUILD"];
- let paths: Vec<PathBuf> = file_names
- .iter()
- .map(|file_name| Path::new(cache_dir).join(file_name))
- .collect();
-
- let mut fstates: FileStates = FileStates { install: false, setts: false, build: false };
-
- for (i, path) in paths.iter().enumerate() {
- if path.exists() {
- match i {
- 0 => fstates.install = true,
- 1 => fstates.setts = true,
- 2 => fstates.build = true,
- _ => {}
- }
- }
+ let install_path = Path::new(cache_dir).join(format!("{}/INSTALL", minimal_package_meta.name));
+ let setts_path = Path::new(cache_dir).join(format!("{}/SETTS", minimal_package_meta.name));
+ let build_path = Path::new(cache_dir).join(format!("{}/BUILD", minimal_package_meta.name));
+
+ // Check for required 'INSTALL' file
+ if !install_path.exists() {
+ return Err(io::Error::new(
+ io::ErrorKind::NotFound,
+ "File INSTALL not found in cache directory"
+ ).into()); // Convert to Box<dyn Error>
}
- if !fstates.install {
- return Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "File INSTALL not found in arch"
- ));
+ // Read and deserialize the INSTALL file
+ let install_content = fs::read_to_string(&install_path)?;
+ let install_meta: Install = toml::from_str(&install_content)?;
+
+ // Initialize optional structures as None
+ let mut setts_meta: Option<Setts> = None;
+ let mut build_meta: Option<Build> = None;
+
+ // Attempt to read and deserialize the SETTS file if it exists
+ if setts_path.exists() {
+ let setts_content = fs::read_to_string(&setts_path)?;
+ setts_meta = Some(toml::from_str(&setts_content)?);
+ }
+
+ // Attempt to read and deserialize the BUILD file if it exists
+ if build_path.exists() {
+ let build_content = fs::read_to_string(&build_path)?;
+ build_meta = Some(toml::from_str(&build_content)?);
+ }
+
+ // Log if custom script is present
+ if let Some(ref script) = install_meta.custom_script {
+ println!("Custom script found for package: {}", install_meta.package.name);
+ // Consider logging the script content or just its presence based on verbosity
+ // e.g., log::debug!("Custom script content: {}", script);
+ } else {
+ println!("No custom script for package: {}", install_meta.package.name);
}
- /*
- Example INSTALL format:
- [package]
- name = "my-package"
- version = "1.0.0"
- arch = "X86_64"
-
- [install]
- path = "/usr/bin/my-package"
- user = "root"
- group = "root"
- mode = "755"
-
- # Also [install] can be
- # path = "/usr/bin/my-package"
- # user = "root"
- # group = "root"
- # mode = "755"
- # custom_script = "./install.sh" OR
- # custom_script = """
- # echo "Installing my-package"
- # sudo apt-get install my-package
- # """
- */
- let inst_content = std::fs::read_to_string(paths[0..2].clone())?; // FIXME
- let validate = toml::from_str::<Package>(&inst_content.to_string());
-
- // TODO: Make the vector of file paths more explicit, and add this function as a whole.
- Ok(true)
+ Ok((install_meta, setts_meta, build_meta))
+ }
- }
/// Checks if the archive contains INSTALL, SETTS and BUILD files.
///