peach-workspace/peach-config/src/set_permissions.rs

28 lines
1.2 KiB
Rust

use lazy_static::lazy_static;
use peach_lib::config_manager::get_config_value;
use crate::error::PeachConfigError;
use crate::utils::cmd;
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: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(())
}