init: initial commit of packager

This commit is contained in:
Didier Slof 2023-07-13 00:11:44 +02:00
commit 7964bb84fd
Signed by: didier
GPG key ID: 01E71F18AA4398E5
25 changed files with 478 additions and 0 deletions

29
bootpkg/src/args.rs Normal file
View file

@ -0,0 +1,29 @@
pub enum Command {
Strap,
Unpack,
None
}
impl From<String> for Command {
fn from(value: String) -> Self {
match value.to_lowercase().as_str() {
"strap" => Command::Strap,
"unpack" => Command::Unpack,
_ => Command::None
}
}
}
pub struct Args {
pub command: Command,
pub args: Vec<String>,
}
impl From<Vec<String>> for Args {
fn from(value: Vec<String>) -> Self {
Args {
command: Command::from(value[0].to_owned()),
args: value[1..].to_owned()
}
}
}

51
bootpkg/src/main.rs Normal file
View file

@ -0,0 +1,51 @@
use std::env;
use std::process::exit;
use pkgfile::PKGFile;
use crate::args::{Args, Command};
mod prelude;
mod args;
fn main() {
let args = Args::from(env::args().collect::<Vec<String>>()[1..].to_owned());
match args.command {
Command::Strap => {
if args.args.len() == 0 {
println!("no path/uri");
exit(0);
}
let uri = &args.args[0];
println!("!! Got package: \"{}\"", uri);
let re = r"[A-z]+://.+";
let data = if regex::Regex::new(re).unwrap().is_match(uri) {
println!("** detected uri.");
reqwest::blocking::get(uri)
.expect("Could not request file.")
.bytes()
.expect("Could not turn file into bytes.")
.to_vec()
} else {
if let Ok(d) = std::fs::read(uri) {
d
} else {
println!("Could not read file!");
exit(1);
}
};
let p = match PKGFile::try_from(data) {
Ok(p) => p,
Err(_) => {
println!("!! Could not interpret PKGFile...");
exit(1);
}
};
},
Command::Unpack => todo!(),
_ => {
println!("Unsupported command, allowed commands: strap/unpack.");
exit(1);
}
}
}

22
bootpkg/src/prelude.rs Normal file
View file

@ -0,0 +1,22 @@
use std::collections::HashMap;
use manifest::Manifest;
pub struct PKGR {
pub bootstrap: Option<Bootstrap>,
}
pub struct Bootstrap {}
pub fn def_manifest() {
Manifest::<Option<PKGR>> {
package: manifest::package::Package::default(),
bin: None,
build: None,
dependencies: HashMap::default(),
fs: manifest::fs::FS {
config: None,
data: None,
},
pkgr: Some(PKGR { bootstrap: None }),
};
}