Update peach-config to use configured paths
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
notplants 2022-05-12 12:47:33 +02:00
parent 5ea6a86700
commit 8202d4af5f
4 changed files with 21 additions and 20 deletions

2
Cargo.lock generated
View File

@ -1111,7 +1111,7 @@ dependencies = [
[[package]]
name = "golgi"
version = "0.1.1"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#77dd75bcd4649b7487069a61e2a8069b49f60a1d"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#77dd75bcd4649b7487069a61e2a8069b49f60a1d"
dependencies = [
"async-std",
"async-stream 0.3.3",

View File

@ -1,23 +1,27 @@
use lazy_static::lazy_static;
use peach_lib::config_manager::get_config_value;
use crate::error::PeachConfigError;
use crate::utils::cmd;
/// All configs are stored in this folder, and should be read/writeable by peach group
/// so they can be read and written by all PeachCloud services.
pub const CONFIGS_DIR: &str = "/var/lib/peachcloud";
pub const PEACH_WEB_DIR: &str = "/usr/share/peach-web";
pub const PEACH_HOME_DIR: &str = "/home/peach";
lazy_static! {
pub static ref CONFIGS_DIR: String = get_config_value("PEACH_CONFIG_DIR").expect("Failed to load config value for PEACH_CONFIG_DIR");
pub static ref PEACH_WEB_DIR: String = "/usr/share/peach-web".to_string();
pub static ref PEACH_HOME_DIR: String = "/home/peach".to_string();
}
/// Utility function to set correct file permissions on the PeachCloud device.
/// Accidentally changing file permissions is a fairly common thing to happen,
/// so this is a useful CLI function for quickly correcting anything that may be out of order.
pub fn set_permissions() -> Result<(), PeachConfigError> {
println!("[ UPDATING FILE PERMISSIONS ON PEACHCLOUD DEVICE ]");
cmd(&["chmod", "-R", "u+rwX,g+rwX", CONFIGS_DIR])?;
cmd(&["chown", "-R", "peach", CONFIGS_DIR])?;
cmd(&["chgrp", "-R", "peach", CONFIGS_DIR])?;
cmd(&["chmod", "-R", "u+rwX,g+rwX", PEACH_WEB_DIR])?;
cmd(&["chown", "-R", "peach:peach", PEACH_WEB_DIR])?;
cmd(&["chown", "-R", "peach:peach", PEACH_HOME_DIR])?;
cmd(&["chmod", "-R", "u+rwX,g+rwX", &CONFIGS_DIR])?;
cmd(&["chown", "-R", "peach:peach", &CONFIGS_DIR])?;
cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_WEB_DIR])?;
cmd(&["chown", "-R", "peach:peach", &PEACH_WEB_DIR])?;
cmd(&["chmod", "-R", "u+rwX,g+rwX", &PEACH_HOME_DIR])?;
cmd(&["chown", "-R", "peach:peach", &PEACH_HOME_DIR])?;
println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]");
Ok(())
}

View File

@ -59,7 +59,7 @@ pub fn get_peach_config_defaults() -> HashMap<String, String> {
("SSB_ADMIN_IDS", ""),
("ADMIN_PASSWORD_HASH", "47"),
("TEMPORARY_PASSWORD_HASH", ""),
("GO_SBOT_DATADIR", ""),
("GO_SBOT_DATADIR", "/home/peach/.ssb-go"),
("PEACH_CONFIGDIR", "/var/lib/peachcloud"),
]);
// convert HashMap<&str, &str> to HashMap<String, String> and return

View File

@ -3,6 +3,7 @@
use std::{fs, fs::File, io, io::Write, path::PathBuf, process::Command, str};
use serde::{Deserialize, Serialize};
use crate::config_manager::get_config_value;
use crate::error::PeachError;
@ -126,11 +127,8 @@ impl SbotStatus {
}
}
// determine path of user's home directory
let mut blobstore_path = dirs::home_dir().ok_or(PeachError::HomeDir)?;
// append the blobstore path
blobstore_path.push(".ssb-go/blobs/sha256");
// get path to blobstore
let blobstore_path = format!("{}/blobs/sha256", get_config_value("GO_SBOT_DATADIR")?);
// determine the size of the blobstore directory in bytes
status.blobstore = dir_size(blobstore_path).ok();
@ -220,8 +218,7 @@ impl SbotConfig {
let config_string = toml::to_string(&config)?;
// determine path of user's home directory
let mut config_path = dirs::home_dir().ok_or(PeachError::HomeDir)?;
config_path.push(".ssb-go/config.toml");
let config_path = format!("{}/config.toml", get_config_value("GO_SBOT_DATADIR")?);
// open config file for writing
let mut file = File::create(config_path)?;