summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock43
-rw-r--r--Cargo.toml2
-rw-r--r--README.md1
-rw-r--r--src/cfg/config.rs27
-rw-r--r--src/main.rs4
-rw-r--r--src/pkgtoolkit/pkgtools.rs85
6 files changed, 144 insertions, 18 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4044f1d..0ce827d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,12 @@
version = 4
[[package]]
+name = "adler2"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
+
+[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -185,6 +191,15 @@ dependencies = [
]
[[package]]
+name = "crc32fast"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
+dependencies = [
+ "cfg-if 1.0.4",
+]
+
+[[package]]
name = "deranged"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -249,6 +264,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
[[package]]
+name = "flate2"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -399,8 +424,10 @@ name = "mesk"
version = "0.1.0"
dependencies = [
"clap 4.5.53",
+ "flate2",
"i2p",
"i2p_client",
+ "log 0.4.28",
"serde",
"sqlite",
"tar",
@@ -408,6 +435,16 @@ dependencies = [
]
[[package]]
+name = "miniz_oxide"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
+dependencies = [
+ "adler2",
+ "simd-adler32",
+]
+
+[[package]]
name = "nom"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -590,6 +627,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
+name = "simd-adler32"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
+
+[[package]]
name = "simple_logger"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 39c9dd9..d688553 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,8 +8,10 @@ authors = ["namilsk <namilsk@namilsk.tech>",
[dependencies]
clap = { version = "4.5.53", features = ["derive"] }
+flate2 = "1.1.5"
i2p = "0.0.1"
i2p_client = "0.2.9"
+log = "0.4.28"
serde = { version = "1.0.228", features = ["derive"] }
sqlite = "0.37.0"
tar = "0.4.44"
diff --git a/README.md b/README.md
index d54b1be..736cd0a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
# mesk
**Mesk is a source-based package manager based on i2p protocols, tailored for independence and the absence of spyware.**
-**Powered by I2P.**
# Package Structure
`.mesk` - **is a compressed gzip tarball containing information on how to build, configure and install it**.
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index 45be37d..8672433 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -13,39 +13,45 @@ pub enum Loglevel {
Error
}
+
+/// `mesk.toml` configuration fields here
#[derive(Deserialize, Debug, Serialize)]
pub struct Config {
- repo: Repo,
- log: Log,
- paths: Paths,
+ pub repo: Repo,
+ pub log: Log,
+ pub paths: Paths,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct Log {
#[serde(rename = "log_file")]
- log_file: String,
+ pub log_file: String,
#[serde(rename = "log_level")]
- log_level: Loglevel,
+ pub log_level: Loglevel,
}
// Rename needed for editing mesk.toml file fields but dont touch code.
#[derive(Deserialize, Debug, Serialize)]
pub struct Repo {
#[serde(rename = "repo_url")]
- repo_url: String,
+ pub repo_url: String,
#[serde(rename = "auto_update")]
- auto_update: bool,
+ pub auto_update: bool,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct Paths {
#[serde(rename = "cache_dir")]
- cache_dir: String,
+ pub cache_dir: String,
#[serde(rename = "build_dir")]
- build_dir: String,
+ pub build_dir: String,
}
impl Config {
+
+ /// Parse the /etc/mesk.toml file and return the Config object.
+ ///
+ /// 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 result: Config = toml::from_str(&contents)?;
@@ -53,6 +59,9 @@ impl Config {
}
+ /// Return the default configuration as a toml string.
+ ///
+ /// This function returns the default configuration as a toml string.
pub fn default() -> Result<String, toml::ser::Error> {
let default: Config = Config {
repo: Repo {
diff --git a/src/main.rs b/src/main.rs
index a2ca713..a2d4aa0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,8 @@ mod cfg;
mod i2impl;
mod pkgtoolkit;
-use crate::cfg::config;
-use crate::pkgtoolkit::pkgtools;
+use crate::cfg::config::Config;
+use crate::pkgtoolkit::pkgtools::Package;
use crate::i2impl::mi2p;
fn main() {
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index d124c2b..7197d9e 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -1,13 +1,86 @@
-use std::fs::File;
-use tar::Archive;
+use crate::cfg::config::Config;
-pub struct Package {
- BuildScript: String,
- Name: String,
- Version: String
+use std::fs::{File, create_dir_all};
+use std::path::Path;
+use flate2::read::GzDecoder;
+use tar::Archive;
+
+pub enum arch {
+ x86_64,
+ aarch64,
+ x86,
+}
+
+pub struct Package {
+ name: String,
+ version: String,
+ arch: arch,
+ descr: 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.
+ ///
+ /// * 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();
+
+ 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 install_path = Path::new(&config.paths.cache_dir).join("INSTALL");
+ let setts_path = Path::new(&config.paths.cache_dir).join("SETTS");
+ let build_path = Path::new(&config.paths.cache_dir).join("BUILD");
+
+ if !install_path.exists() {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::NotFound,
+ "INSTALL file not found in archive",
+ ));
+ }
+
+ let install_content = std::fs::read_to_string(&install_path)?;
+ if install_content.trim().is_empty() {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ "INSTALL file is empty",
+ ));
+ }
+
+ if !setts_path.exists() {
+ log::warn!("SETTS file not found in archive. Make sure you dont need this.");
+ } else {
+ let setts_content = std::fs::read_to_string(&setts_path)?;
+ if setts_content.trim().is_empty() {
+ log::warn!("SETTS file is empty. Make sure you dont need this.");
+ }
+ }
+
+ if !build_path.exists() {
+ log::warn!("BUILD file not found in archive. Make sure you dont need this.");
+ } else {
+ let build_content = std::fs::read_to_string(&build_path)?;
+ if build_content.trim().is_empty() {
+ log::warn!("BUILD file is empty. Make sure you dont need this.");
+ }
+ }
+
+ Ok(true)
+}
+
pub fn build() -> Result<bool, std::io::Error> {
todo!();
}