commit 36c782a564e532391c58d7cd23b053791d103248 Author: Raine Date: Sat Oct 14 22:39:39 2023 +0200 init: initial commit of packager diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..972b0c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/target +**/Cargo.lock diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9fe00b2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pkgr.iml b/.idea/pkgr.iml new file mode 100644 index 0000000..c67ef27 --- /dev/null +++ b/.idea/pkgr.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e24755 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Packager + +> "A package manager and builder but like rust." +> -- Gandhi (2050) + +> ***not even close to done*** :) + +Packager is a simple yet powerful package manager \ No newline at end of file diff --git a/bootpkg/Cargo.toml b/bootpkg/Cargo.toml new file mode 100644 index 0000000..c48277f --- /dev/null +++ b/bootpkg/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "bootpkg" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +manifest = { path = "../manifest" } +pkgfile = { path = "../pkgfile" } +regex = "1.9.1" +reqwest = { version = "0.11.18", features = ["blocking"] } diff --git a/bootpkg/src/args.rs b/bootpkg/src/args.rs new file mode 100644 index 0000000..2f51141 --- /dev/null +++ b/bootpkg/src/args.rs @@ -0,0 +1,29 @@ +pub enum Command { + Strap, + Unpack, + None +} + +impl From 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, +} + +impl From> for Args { + fn from(value: Vec) -> Self { + Args { + command: Command::from(value[0].to_owned()), + args: value[1..].to_owned() + } + } +} \ No newline at end of file diff --git a/bootpkg/src/main.rs b/bootpkg/src/main.rs new file mode 100644 index 0000000..8339041 --- /dev/null +++ b/bootpkg/src/main.rs @@ -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::>()[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); + } + } +} diff --git a/bootpkg/src/prelude.rs b/bootpkg/src/prelude.rs new file mode 100644 index 0000000..4462619 --- /dev/null +++ b/bootpkg/src/prelude.rs @@ -0,0 +1,22 @@ +use std::collections::HashMap; +use manifest::Manifest; + +pub struct PKGR { + pub bootstrap: Option, +} + +pub struct Bootstrap {} + +pub fn def_manifest() { + Manifest::> { + 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 }), + }; +} \ No newline at end of file diff --git a/build-pkg.toml b/build-pkg.toml new file mode 100644 index 0000000..8c994d9 --- /dev/null +++ b/build-pkg.toml @@ -0,0 +1,14 @@ +[project] +package_file = "./package.toml" +package_dir = "./pkg" +increment_version = false + +[mappings.source] +ignore = ["target/"] + +[mappings.source.map] +"." = "/src" + +[mappings.bin.map] +"target/release/bin/pkgr" = "/bin/pkgr" + diff --git a/manifest/Cargo.toml b/manifest/Cargo.toml new file mode 100644 index 0000000..139b38f --- /dev/null +++ b/manifest/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "manifest" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +toml = "0.7.6" +serde = { version = "1.0.171", features = ["derive"] } \ No newline at end of file diff --git a/manifest/src/bin.rs b/manifest/src/bin.rs new file mode 100644 index 0000000..10d1ea1 --- /dev/null +++ b/manifest/src/bin.rs @@ -0,0 +1,7 @@ +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +pub struct Bin { + pub root: String, + +} \ No newline at end of file diff --git a/manifest/src/build.rs b/manifest/src/build.rs new file mode 100644 index 0000000..0ad59ec --- /dev/null +++ b/manifest/src/build.rs @@ -0,0 +1,10 @@ +use std::collections::HashMap; + +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +pub struct Build { + build_script: String, + install_script: String, + dependencies: HashMap +} \ No newline at end of file diff --git a/manifest/src/fs.rs b/manifest/src/fs.rs new file mode 100644 index 0000000..e02312f --- /dev/null +++ b/manifest/src/fs.rs @@ -0,0 +1,16 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct FS { + pub config: Option, + pub data: Option, +} + +impl Default for FS { + fn default() -> Self { + FS { + config: None, + data: None, + } + } +} diff --git a/manifest/src/lib.rs b/manifest/src/lib.rs new file mode 100644 index 0000000..fdc8cbc --- /dev/null +++ b/manifest/src/lib.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +pub mod package; +pub mod fs; +pub mod bin; +pub mod build; +pub mod pkgr; + +#[derive(Serialize, Deserialize)] +#[serde(default)] +pub struct Manifest

> { + pub package: package::Package, + pub dependencies: HashMap, + pub fs: fs::FS, + pub bin: Option, + pub build: Option, + pub pkgr: P +} + +impl Default for Manifest { + fn default() -> Self { + Manifest { + package: package::Package::default(), + dependencies: HashMap::default(), + fs: fs::FS::default(), + bin: None, + build: None, + pkgr: None + } + } +} diff --git a/manifest/src/package.rs b/manifest/src/package.rs new file mode 100644 index 0000000..3fa1626 --- /dev/null +++ b/manifest/src/package.rs @@ -0,0 +1,45 @@ +use std::str::FromStr; + +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub enum PackageType { + #[serde(rename = "application")] + Application, + #[serde(rename = "library")] + Library, + #[serde(rename = "meta")] + Meta +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(default)] +pub struct Package { + pub name: String, + pub description: String, + pub package_type: PackageType, + pub version: u64, + pub tags: Vec, + pub arch: String +} + +impl Default for Package { + fn default() -> Self { + Package { + name: String::default(), + description: String::default(), + package_type: PackageType::Application, + version: 0, + tags: Vec::default(), + arch: std::env::consts::ARCH.to_string() + } + } +} + +impl FromStr for Package { + type Err = toml::de::Error; + + fn from_str(s: &str) -> Result { + toml::from_str(s) + } +} \ No newline at end of file diff --git a/manifest/src/pkgr.rs b/manifest/src/pkgr.rs new file mode 100644 index 0000000..2ca5fd4 --- /dev/null +++ b/manifest/src/pkgr.rs @@ -0,0 +1,4 @@ +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +pub struct PKGR {} \ No newline at end of file diff --git a/package.toml b/package.toml new file mode 100644 index 0000000..fbc4070 --- /dev/null +++ b/package.toml @@ -0,0 +1,110 @@ +#* = required. + +[package] +name = "packager" #* +description = "A package installation tool" #* + +## package.version +# needs to be an int and be incremented every time +# if you use a custom version system and want to use that, you can use the tag system! +# the highest package.version on the server will be given the tag "latest" +version = 1 # this can automatically be incremented when publishing by running `pkgr publish -i ...` + +## package.tags +# you can add tags to a package to specify kinds +# there are some special tags: +# - latest +# automatically set on the last published version +# previous version will lose this tag +# - oldest +# assigned to the first version. +tags = [ + "prod", + "pkgr-spec-1" +] + +## package.type +# Supported types: +# - application +# this type specifies that this package is an application. +# - library +# this type specifies that this package is a library. +# - meta +# this type specifies that this package does not install anything upon the system except for dependencies. +type = "application" + +arch = "x86_64" # this is automatically filled by `pkgr publish ...` + +## dependencies +# you may use the following syntax +# "" or ",,..." +[dependencies] +example = { arch = "x86_64", tags = [ "stable" ], version = "v1" } +exnmbr2 = "v1,stable" + +## fs +# specify some directories for ease of use +[fs] +## fs.config +# specifiy the config path +config = "/etc/packager" +## fs.data +# specify the data path +data = "/var/lib/packager" +## replace "pacakger" with your package name to find the default value. + +## bin +# Used for systems that don't want to build pkgs. +[bin] # binary files root + +## bin.root +# ** RELATIVE TO PACKAGE ROOT ** +# bin.root specifies the root of the installed tree. +# anything in here will be overlayed on top of the system. +root = "/root" #* + +## bin.checksums +# ** KEYS are relative to BIN.ROOT ** +# ** VALUES are relative to PKG ROOT ** +# checksums is used to perform checksums before install +# values may be paths or a uri. You may include variables. +# supported variables: +# - @name +# - @version +# - @display_version +[bin.checksums] +"/usr/bin/pkgr" = "https://ixvd.net/checksums/packager/@version" + +## build +# Scripts will be copied to a custom root. +# After the pacakge is built, the install script is ran. +# After the install script the build directory will be deleted and an CTREE (changed tree) will be generated. +# Then the CTREE will be used to copy the files over. +[build] +build_script = "/scripts/build" # relative to pkg +install_script = "/scripts/install" # relative to pkg + +[build.dependencies] +base = "latest,stable" # selected by default + +## pkgr.* +# packager is the official client but you may use other clients supporting the "pkgr v1 spec". +# other clients may offer extra functionality this must be put under "pkgr.*" +[pkgr] + +## pkgr.bootstrap +# This section is used for bootpkg. An edition of packager that bootstraps the full version. +# This exists so that packager is easy to install on anything! +# and only 1 release channel for pkgr +[pkgr.bootstrap] +# any non-zero = installed +check_installed_commands = [ + "/scripts/check_installed" +] + +# any non-zero = fail +commands = [ + "/scripts/bootstrap/download_latest @version /tmp/pkgr.pkg", + "/scripts/bootstrap/dirty_install /tmp/pkgr.pkg", + "/scripts/bootstrap/check_install" +] diff --git a/pkgfile/Cargo.toml b/pkgfile/Cargo.toml new file mode 100644 index 0000000..5fb57fe --- /dev/null +++ b/pkgfile/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "pkgfile" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +manifest = { path = "../manifest" } +tar = "0.4.38" diff --git a/pkgfile/pkgfile.txt b/pkgfile/pkgfile.txt new file mode 100644 index 0000000..1592aaa --- /dev/null +++ b/pkgfile/pkgfile.txt @@ -0,0 +1,3 @@ +[pkgfile version (1 byte)][size manifest x256 (1 byte)][size manifest x1 (1 byte)] +[manifest] +[tar file] \ No newline at end of file diff --git a/pkgfile/src/lib.rs b/pkgfile/src/lib.rs new file mode 100644 index 0000000..a6b1d5e --- /dev/null +++ b/pkgfile/src/lib.rs @@ -0,0 +1,36 @@ +pub struct PKGFile { + pub manifest: String, + pub data: Vec, +} + +impl TryFrom> for PKGFile { + type Error = (); + + fn try_from(value: Vec) -> Result { + match value[0] { + 1 => { + let header: Vec = value[..3] + .iter() + .map(|v| u32::from(*v)) + .collect(); + let manifest_size: u32 = ((header[1] << 8) | header[2]); + if manifest_size > value.len() as u32 { + return Err(()); + } + Ok(PKGFile { + manifest: match String::from_utf8( + value[ + 3..(manifest_size as usize) + ].to_vec() + ) + { + Ok(s) => s, + _ => return Err(()) + }, + data: value[(manifest_size as usize)..].to_vec(), + }) + } + _ => Err(()) + } + } +} diff --git a/pkgr/Cargo.toml b/pkgr/Cargo.toml new file mode 100644 index 0000000..df095d2 --- /dev/null +++ b/pkgr/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "pkgr" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +manifest = { path = "../manifest" } \ No newline at end of file diff --git a/pkgr/src/main.rs b/pkgr/src/main.rs new file mode 100644 index 0000000..f79c691 --- /dev/null +++ b/pkgr/src/main.rs @@ -0,0 +1,2 @@ +fn main() { +}