summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-26 19:21:00 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-26 19:21:00 +0300
commit2e86f06da02d2cbe0b16a90eab7e33fdcf50f5f7 (patch)
tree09148c18047f58cbefae71b37cd994673ce9b581 /src
parentecaa84ab50a8a492de35270cd50374809647da19 (diff)
Work on pkgtoolkit, validation and processing of the INSTALL installation script (+ metadata fields added to INSTALL). An example of the INSTALL examples file has also been added.
Diffstat (limited to 'src')
-rw-r--r--src/pkgtoolkit/pkgtools.rs187
1 files changed, 145 insertions, 42 deletions
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index fbbe624..e347625 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -1,25 +1,124 @@
use crate::cfg::config::Config;
use std::fs::{File, create_dir_all};
+use std::path::PathBuf;
use std::path::Path;
use flate2::read::GzDecoder;
+use serde::{Deserialize, Serialize};
use tar::Archive;
+use toml;
+#[derive(Serialize, Debug, Deserialize)]
pub enum archs {
- x86_64,
- aarch64,
- x86,
+ X86_64,
+ Aarch64,
+ X86,
}
+#[derive(Serialize, Debug, Deserialize)]
pub struct Package {
name: String,
version: String,
arch: archs,
- descr: String,
+ descr: Option<String>,
+}
+
+#[derive(Deserialize, Debug)]
+struct Install {
+ path: String,
+ user: String,
+ group: String,
+ mode: String,
+ //. Cancels the previous fields and installs them using the shell script
+ custom_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.
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if INSTALL file does not exist or is empty.
+ /// Returns an error if INSTALL file is empty.
+
+ 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,
+ }
+
+ // 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,
+ _ => {}
+ }
+ }
+ }
+
+ if !fstates.install {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::NotFound,
+ "File INSTALL not found in arch"
+ ));
+ }
+ /*
+ 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)
+
+ }
+
/// 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.
@@ -31,55 +130,55 @@ impl Package {
///
// TODO: Add meta-files validation here.
pub fn check(path_to_archive: String) -> Result<bool, std::io::Error> {
- let config: Config = Config::parse().unwrap();
+ let config: Config = Config::parse().unwrap();
- create_dir_all(&config.paths.cache_dir)?;
+ 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);
+ let file = File::open(&path_to_archive)?;
+ let gz = GzDecoder::new(file);
+ let mut archive = Archive::new(gz);
- archive.unpack(&config.paths.cache_dir)?;
+ 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");
+ 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",
- ));
- }
+ 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",
- ));
- }
+ 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 !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.");
+ 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)
-}
+ Ok(true)
+ }
pub fn build() -> Result<bool, std::io::Error> {
todo!();
@@ -87,4 +186,8 @@ impl Package {
pub fn install() -> Result<bool, std::io::Error> {
todo!();
}
+ pub fn gen_index() -> Result<bool, std::io::Error> {
+ todo!();
+
+ }
} \ No newline at end of file