parsing packages, and find_package_in_repositories done ( i gotta commit more often lmao)
This commit is contained in:
parent
f2e78523ea
commit
fed7106c20
11 changed files with 111 additions and 54 deletions
53
Cargo.lock
generated
53
Cargo.lock
generated
|
@ -207,6 +207,21 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
|
@ -214,6 +229,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
|
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -222,6 +238,34 @@ version = "0.3.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
|
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
|
@ -240,10 +284,16 @@ version = "0.3.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
|
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -256,10 +306,11 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gaybsd_package_manager"
|
name = "gaypk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"futures",
|
||||||
"meowhash",
|
"meowhash",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cargo-features = ["strip"]
|
cargo-features = ["strip"]
|
||||||
[package]
|
[package]
|
||||||
name = "gaybsd_package_manager"
|
name = "gaypk"
|
||||||
description = "GayBSD Package Manager"
|
description = "GayBSD Package Manager"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -15,6 +15,7 @@ sled = "0.34.7"
|
||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
serde_derive = "1.0.136"
|
serde_derive = "1.0.136"
|
||||||
serde = "1.0.136"
|
serde = "1.0.136"
|
||||||
|
futures = "0.3.21"
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
mf-version = 100
|
gaypk-version = 100
|
||||||
name = "example-package"
|
name = "example-package"
|
||||||
version = 100
|
version = "1.0.0"
|
||||||
key = ""
|
revision = 0
|
||||||
[files]
|
pubkey = ""
|
||||||
"/opt/etc" = { match = "etc/*", tracked = false }
|
scripts=["*.gpksh"]
|
||||||
"/opt/etc/enby/manuals" = { path = "manual.gmi", name = "example-package.gmi"}
|
exclude=["scripts", "*.gpksh"]
|
||||||
"/opt/bin" = { file = "example-package.x86-64.elf", name = "example-package", bin = "x86-64-elf"}
|
[dependencies]
|
||||||
|
|
||||||
|
# GayPK doesn't care about this stuff
|
||||||
[locale.en_US]
|
[locale.en_US]
|
||||||
name = "Example Package"
|
name = "Example Package"
|
||||||
description = "Example Package for testing GayPackage format."
|
description = "Example Package for testing GayPackage format."
|
||||||
[locale.tp_XW]
|
[locale.tp_XW]
|
||||||
name = ""
|
name = ""
|
||||||
description = ""
|
description = ""
|
||||||
|
[launcher]
|
||||||
|
category = "system"
|
||||||
|
launch = "terminal"
|
||||||
|
binary = "/opt/bin/example-package"
|
|
@ -1 +0,0 @@
|
||||||
Hello world!
|
|
4
example-package/root/opt/etc/etc-file.gpksh
Normal file
4
example-package/root/opt/etc/etc-file.gpksh
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
OVERWRITE=false
|
||||||
|
cat etc-file.txt >> /opt/etc/etc-file.txt
|
1
example-package/root/opt/etc/etc-file.txt
Normal file
1
example-package/root/opt/etc/etc-file.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Hello world! (from GayPK)
|
10
src/main.rs
10
src/main.rs
|
@ -6,14 +6,13 @@ mod repository;
|
||||||
mod install;
|
mod install;
|
||||||
mod package;
|
mod package;
|
||||||
|
|
||||||
use meowhash::*;
|
use crate::repository::find_package_in_repositories;
|
||||||
use reqwest::*;
|
|
||||||
use sled::*;
|
|
||||||
use clap::*;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let operation = std::env::args().nth(1).expect("too few arguments!");
|
let operation = std::env::args().nth(1).expect("too few arguments!");
|
||||||
let args: String = std::env::args().collect();
|
let args: String = std::env::args().collect();
|
||||||
|
let package_data = crate::package::read_package(std::fs::read_to_string("example-package/Package.toml").expect("Failed to read file"));
|
||||||
|
dbg!(package_data);
|
||||||
match operation.as_str() {
|
match operation.as_str() {
|
||||||
"upgrade" | "u" => {
|
"upgrade" | "u" => {
|
||||||
|
|
||||||
|
@ -23,9 +22,10 @@ fn main() {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let package_name = std::env::args().nth(2).expect("too few arguments!");
|
let package_name = std::env::args().nth(2).expect("too few arguments!");
|
||||||
|
find_package_in_repositories(&package_name, None);
|
||||||
println!("Reading package list");
|
println!("Reading package list");
|
||||||
let package_list = sled::open("/var/gaypack/packages").expect("Failed to open package list");
|
let package_list = sled::open("/var/gaypack/packages").expect("Failed to open package list");
|
||||||
if package_list.contains_key(package_name).expect("Unexpected error") {
|
if package_list.contains_key(&package_name).expect("Unexpected error") {
|
||||||
println!("Package was found in package list, checking for updates");
|
println!("Package was found in package list, checking for updates");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,19 @@
|
||||||
use toml::map::Map;
|
use toml::value::{Array, Table};
|
||||||
use toml::value::Table;
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
/// Represents a Package.toml file.
|
/// Represents a Package.toml file.
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct PackageData {
|
pub struct PackageData {
|
||||||
manifest_verison: u64,
|
#[serde(rename(deserialize = "gaypk-version"))]
|
||||||
name: String,
|
pub gaypk_version: u64,
|
||||||
version: u64,
|
pub name: String,
|
||||||
key: String,
|
pub version: String,
|
||||||
files: Map<String, PackageFile>,
|
pub revision: u64,
|
||||||
|
pub pubkey: String,
|
||||||
|
pub scripts: Array,
|
||||||
|
pub exclude: Array,
|
||||||
|
pub dependencies: Table
|
||||||
}
|
}
|
||||||
#[derive(Deserialize)]
|
pub fn read_package(data: String) -> PackageData {
|
||||||
pub struct PackageFile {
|
toml::from_str(data.as_str()).expect("Parse failed!")
|
||||||
match_: Option<String>,
|
|
||||||
tracked: Option<bool>,
|
|
||||||
file: String,
|
|
||||||
folder: Option<bool>,
|
|
||||||
name: Option<String>,
|
|
||||||
bin: Option<String>
|
|
||||||
}
|
|
||||||
impl Default for PackageFile {
|
|
||||||
fn default() -> Self {
|
|
||||||
PackageFile {
|
|
||||||
match_: None,
|
|
||||||
tracked: Some(true),
|
|
||||||
file: "".to_string(),
|
|
||||||
folder: Some(false),
|
|
||||||
name: None,
|
|
||||||
bin: None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,23 +1,32 @@
|
||||||
use std::error::Error;
|
use std::collections::HashMap;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::File;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::path::Path;
|
use futures::executor::block_on;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use toml::toml;
|
|
||||||
|
|
||||||
pub async fn find_package_in_repositories(package: String, installed: Option<u64>) -> Vec<String> {
|
pub fn find_package_in_repositories(package: &str, installed: Option<u64>) -> Option<Vec<String>> {
|
||||||
let mut hits: Vec<String> = vec!();
|
let mut hits: Vec<String> = vec!();
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
|
let repo_file = File::open("/var/gaypack/repositories.list").expect("Failed to open repository list");
|
||||||
|
let mut candidates: HashMap<u64, String> = HashMap::new();
|
||||||
for repository in std::io::BufReader::new(repo_file).lines() {
|
for repository in std::io::BufReader::new(repo_file).lines() {
|
||||||
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
|
let repository = repository.expect("Unexpected error"); // i find this line kinda funny for some reason
|
||||||
let resp = client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send().await.unwrap();
|
let resp = block_on(client.get(format!("{}/gaypack/{}/latest/Package.toml", repository, package)).send()).expect("GET request failed");
|
||||||
|
let status = resp.status();
|
||||||
|
let text = block_on(resp.text()).expect("Failed to receive packet body");
|
||||||
if installed.is_some() {
|
if installed.is_some() {
|
||||||
let package_data: crate::package::PackageData = toml::from_str(resp.text().await.expect("Failed to read text").as_str()).expect("Failed to parse toml");
|
candidates.insert(installed.unwrap(), "installed".to_string());
|
||||||
}
|
}
|
||||||
if resp.status() == StatusCode::from_u16(200).unwrap() {
|
let package_data = &crate::package::read_package(text);
|
||||||
hits.push(repository);
|
dbg!(package_data);
|
||||||
|
if status == StatusCode::from_u16(200).unwrap() {
|
||||||
|
candidates.insert(package_data.revision, repository);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return hits;
|
let mut sorted: Vec<_> = candidates.iter().collect();
|
||||||
|
sorted.sort_by_key(|entry| entry.0);
|
||||||
|
for (_, repository) in sorted.iter() {
|
||||||
|
hits.push(repository.as_str().to_string());
|
||||||
|
}
|
||||||
|
return Some(hits);
|
||||||
}
|
}
|
Loading…
Reference in a new issue