added config

mistress
Lilly Rosaline 2 years ago
parent 7f616765b1
commit 13b6c2d111

@ -1,4 +1,3 @@
cargo-features = ["strip"]
[package]
name = "gaypk"
description = "GayBSD Package Manager"

@ -2,7 +2,6 @@ gaypk-version = 100
name = "example-package"
version = "1.0.0"
revision = 0
pubkey = ""
scripts=["*.gpksh"]
exclude=["scripts", "*.gpksh"]
[dependencies]
@ -10,7 +9,7 @@ exclude=["scripts", "*.gpksh"]
# GayPK doesn't care about this stuff
[locale.en_US]
name = "Example Package"
description = "Example Package for testing GayPackage format."
description = "Example Package for testing GayPK format."
[locale.tp_XW]
name = ""
description = ""

@ -1,4 +1,7 @@
#!/usr/bin/env fish
# shellcheck disable=SC2034
OVERWRITE=false
cat etc-file.txt >> /opt/etc/etc-file.txt
if $RUN
cat etc-file.txt >> /etc/etc-file.txt
end
export RUN=1

@ -0,0 +1,26 @@
use std::fs::File;
use toml::value::{Array, Table};
use serde_derive::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct Config {
pub(crate) base_package_path: String,
pub(crate) installation_path: String,
pub(crate) key_verification: bool
}
impl Default for Config {
fn default() -> Self {
Config {
base_package_path: "/packages".to_string(),
installation_path: "/var/gaypk/".to_string(),
key_verification: true
}
}
}
pub(crate) fn read_config() -> Config {
toml::from_str("/cfg/gaypk/config.toml").expect("Parse failed!")
}
pub(crate) fn write_config(cfg: Config) {
let file = File::create(crate::config::read_config().installation_path + "config.toml").expect("Failed to read file");
writeln!(file, toml::to_string_pretty(&cfg).expect("Write failed!"));
}

@ -5,6 +5,7 @@ mod remove;
mod repository;
mod install;
mod package;
mod config;
use crate::repository::find_package_in_repositories;
@ -21,7 +22,7 @@ fn main() {
let package_name = std::env::args().nth(2).expect("too few arguments!"); // Get the first package name
find_package_in_repositories(&package_name, None); // Go through and find the package
println!("Reading package list");
let package_list = sled::open("/var/gaypk/packages").expect("Failed to open package list");
let package_list = sled::open(crate::config::read_config().installation_path + "packages").expect("Failed to open package list");
if package_list.contains_key(&package_name).expect("Unexpected error") {
println!("Package was found in package list, checking for updates");
}

@ -9,7 +9,6 @@ pub struct PackageData {
pub name: String,
pub version: String,
pub revision: u64,
pub pubkey: String,
pub scripts: Array,
pub exclude: Array,
pub dependencies: Table

@ -8,7 +8,7 @@ use std::io::BufRead;
pub fn find_package_in_repositories(package: &str, installed: Option<u64>, ) -> Option<HashMap<String, u64>> {
let client = reqwest::Client::new(); // The reqwest client which will make GET requests to remove servers.
let repo_file =
File::open("/var/gaypk/repositories.list").expect("Failed to open repository list"); // The repositories.list file, which contains a list of all known and trusted repositories.
File::open(crate::config::read_config().installation_path + "repositories.list").expect("Failed to open repository list"); // The repositories.list file, which contains a list of all known and trusted repositories.
let mut candidates: HashMap<String, u64> = HashMap::new(); // This map will store a list of the repositories along with the latest version of the package they have.
if installed.is_some() {

Loading…
Cancel
Save