summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'src/cfg')
-rw-r--r--src/cfg/config.rs95
1 files changed, 68 insertions, 27 deletions
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index ce9df87..eaa703c 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -14,10 +14,54 @@ pub enum Loglevel {
/// `mesk.toml` configuration fields here
#[derive(Deserialize, Debug, Serialize, Clone)]
+pub struct RouterConfig {
+ #[serde(default = "default_integrated_router")]
+ pub integrated_router: bool,
+ #[serde(default = "default_router_storage")]
+ pub storage_path: String,
+ #[serde(default = "default_http_proxy_port")]
+ pub http_proxy_port: u16,
+ #[serde(default = "default_socks_proxy_port")]
+ pub socks_proxy_port: u16,
+ #[serde(default = "default_auto_update")]
+ pub auto_update: bool,
+}
+
+fn default_integrated_router() -> bool {
+ false
+}
+fn default_router_storage() -> String {
+ "/var/lib/mesk/router/".to_string()
+}
+fn default_http_proxy_port() -> u16 {
+ 4445
+}
+fn default_socks_proxy_port() -> u16 {
+ 4446
+}
+fn default_auto_update() -> bool {
+ true
+}
+
+#[derive(Deserialize, Debug, Serialize, Clone)]
pub struct Config {
pub repo: Repo,
pub log: Log,
pub paths: Paths,
+ #[serde(default = "RouterConfig::default")]
+ pub router: RouterConfig,
+}
+
+impl Default for RouterConfig {
+ fn default() -> Self {
+ Self {
+ integrated_router: default_integrated_router(),
+ storage_path: default_router_storage(),
+ http_proxy_port: default_http_proxy_port(),
+ socks_proxy_port: default_socks_proxy_port(),
+ auto_update: default_auto_update(),
+ }
+ }
}
#[derive(Deserialize, Debug, Serialize, Clone)]
@@ -107,6 +151,7 @@ impl Config {
build_dir: String::from("/var/lib/mesk"),
installed_db: String::from("/var/lib/mesk/pkgdb"),
},
+ router: RouterConfig::default(),
};
let toml_str = toml::to_string(&default)?;
@@ -119,16 +164,21 @@ impl Config {
buildir: &Option<String>,
installed_db: &Option<String>,
) -> Result<String, toml::ser::Error> {
- let generator: Config = Config {
+ let config = Config {
repo: Repo {
- repo_url: if repo.is_none() {
- format!("https://mesk.anthrill.i2p/repo/{}/", std::env::consts::ARCH)
- } else {
- repo.clone().unwrap()
- },
+ repo_url: repo
+ .as_deref()
+ .unwrap_or(&format!(
+ "https://mesk.anthrill.i2p/repo/{}/",
+ std::env::consts::ARCH
+ ))
+ .to_string(),
auto_update: true,
destination: (String::from("mesk"), String::from("mesk")),
- repo_http_url: None,
+ repo_http_url: repo.as_ref().map(|r| {
+ r.replace("i2p", "http")
+ .replace("b32.i2p", "github.com/Anthrill/repo-mirror")
+ }),
i2p_http_proxy_port: 4444,
},
log: Log {
@@ -136,27 +186,18 @@ impl Config {
log_level: Loglevel::Info,
},
paths: Paths {
- cache_dir: if cachedir.is_none() {
- String::from("/var/cache/mesk")
- } else {
- cachedir.clone().unwrap()
- },
- build_dir: if buildir.is_none() {
- String::from("/var/cache/mesk/build")
- } else {
- buildir.clone().unwrap()
- },
- installed_db: if installed_db.is_none() {
- String::from("/var/cache/mesk/pkgdb")
- } else {
- installed_db.clone().unwrap()
- },
- /*
- FIXME: I can leave this parameter, but I think it would be better to make the build
- path in the /var/cache/mesk/$pkgname-$pkgver/BUILD/
- */
+ cache_dir: cachedir
+ .clone()
+ .unwrap_or_else(|| "/var/cache/mesk".to_string()),
+ build_dir: buildir
+ .clone()
+ .unwrap_or_else(|| "/var/tmp/mesk/build".to_string()),
+ installed_db: installed_db
+ .clone()
+ .unwrap_or_else(|| "/var/lib/mesk/installed.db".to_string()),
},
+ router: RouterConfig::default(),
};
- toml::to_string(&generator)
+ toml::to_string(&config)
}
}