Add permissions function peach-config
This commit is contained in:
parent
94bac00664
commit
399af51ccc
|
@ -2415,7 +2415,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "peach-config"
|
||||
version = "0.1.14"
|
||||
version = "0.1.15"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger 0.6.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "peach-config"
|
||||
version = "0.1.14"
|
||||
version = "0.1.15"
|
||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
||||
edition = "2018"
|
||||
description = "Command line tool for installing, updating and configuring PeachCloud"
|
||||
|
|
|
@ -5,6 +5,7 @@ mod generate_manifest;
|
|||
mod setup_networking;
|
||||
mod setup_peach;
|
||||
mod setup_peach_deb;
|
||||
mod set_permissions;
|
||||
mod update;
|
||||
mod utils;
|
||||
|
||||
|
@ -17,6 +18,7 @@ use crate::change_password::set_peach_web_password;
|
|||
use crate::generate_manifest::generate_manifest;
|
||||
use crate::setup_peach::setup_peach;
|
||||
use crate::update::update;
|
||||
use crate::set_permissions::set_permissions;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(
|
||||
|
@ -50,6 +52,10 @@ enum PeachConfig {
|
|||
/// Changes the password for the peach-web interface
|
||||
#[structopt(name = "changepassword")]
|
||||
ChangePassword(ChangePasswordOpts),
|
||||
|
||||
/// Updates file permissions on PeachCloud device
|
||||
#[structopt(name = "permissions")]
|
||||
SetPermissions,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
|
@ -124,7 +130,7 @@ fn main() {
|
|||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
error!(
|
||||
"peach-config countered an error generating manifest: {}",
|
||||
"peach-config encountered an error generating manifest: {}",
|
||||
err
|
||||
)
|
||||
}
|
||||
|
@ -144,6 +150,15 @@ fn main() {
|
|||
)
|
||||
}
|
||||
},
|
||||
PeachConfig::SetPermissions => match set_permissions() {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
error!(
|
||||
"peach-config ecountered an error updating file permissions: {}",
|
||||
err
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
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";
|
||||
|
||||
/// 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", "660", CONFIGS_DIR])?;
|
||||
cmd(&["chown", "-R", "peach", CONFIGS_DIR])?;
|
||||
cmd(&["chgrp", "-R", "peach", CONFIGS_DIR])?;
|
||||
println!("[ PERMISSIONS SUCCESSFULLY UPDATED ]");
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue