Skip to content

Commit

Permalink
Add the ability to override the default root during setup using the c…
Browse files Browse the repository at this point in the history
…li utility #24
  • Loading branch information
TheAlexDev23 committed Oct 24, 2024
1 parent 1881702 commit 64a89aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
11 changes: 8 additions & 3 deletions crates/power-daemon-mgr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ struct Args {

#[derive(Debug, Clone, Subcommand)]
enum OpMode {
Setup,
Setup {
#[arg(default_value = "/")]
/// Use this parameter if you want to override the default root
/// installation directory
root: PathBuf,
},
GenerateBaseFiles {
#[arg(long)]
path: PathBuf,
Expand Down Expand Up @@ -95,13 +100,13 @@ async fn main() {
log::set_max_level(args.verbose.log_level_filter());

match args.mode {
OpMode::Setup => setup(),
OpMode::Setup { root } => setup(&root),
OpMode::Daemon => daemon().await,
OpMode::GenerateBaseFiles {
path,
program_path,
verbose_daemon,
} => generate_base_files(path, program_path, verbose_daemon),
} => generate_base_files(&path, &program_path, verbose_daemon),
OpMode::ListProfiles => {
println!(
"{:?}",
Expand Down
43 changes: 17 additions & 26 deletions crates/power-daemon-mgr/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
use std::{
fs,
path::{Path, PathBuf},
};
use std::{fs, path::Path};

use log::{debug, error, trace};
use nix::unistd::Uid;
use log::{debug, trace};
use power_daemon::{profiles_generator, Config, DefaultProfileType, SystemInfo};

pub fn setup() {
if !Uid::effective().is_root() {
error!("Root priviliges required");
return;
}

pub fn setup(root: &Path) {
let agreed = std::process::Command::new("yad").args([
"--selectable-labels",
"--title",
"Warning: do you want power-options to generate profiles?",
"--text",
"By default, power-options will generate profiles based on the features of your system, <b>and apply them</b>.\nPlease refer to the wiki (https://github.com/TheAlexDev23/power-options/wiki/Default-generated-settings) to be aware of potential issues that might arise.\nIf you click cancel, an empty default profile will be generated."
"By default, power-options will generate profiles based on the features of your system, <b>and it might apply them</b>.\nPlease refer to the wiki (https://github.com/TheAlexDev23/power-options/wiki/Default-generated-settings) to be aware of potential issues that might arise.\nIf you click cancel, an empty default profile will be generated."
]).spawn().expect("Could not spawn popup").wait().expect("Could not wait from popup").success();

if agreed {
generate_config_files("/".into());
generate_config_files(root);
} else {
generate_empty_config_files("/".into());
generate_empty_config_files(root);
}
}

pub fn generate_base_files(path: PathBuf, program_path: PathBuf, verbose_daemon: bool) {
generate_udev_file(&path, &program_path);
generate_acpi_file(&path, &program_path);
generate_dbus_file(&path);
genereate_systemd_file(&path, &program_path, verbose_daemon);
pub fn generate_base_files(path: &Path, program_path: &Path, verbose_daemon: bool) {
generate_udev_file(path, program_path);
generate_acpi_file(path, program_path);
generate_dbus_file(path);
genereate_systemd_file(path, program_path, verbose_daemon);
}

fn generate_config_files(path: PathBuf) {
create_config(&path, &Config::create_default());
generate_profiles(&path);
fn generate_config_files(path: &Path) {
create_config(path, &Config::create_default());
generate_profiles(path);
}

fn generate_empty_config_files(path: PathBuf) {
create_config(&path, &Config::create_empty());
generate_empty_profile(&path);
fn generate_empty_config_files(path: &Path) {
create_config(path, &Config::create_empty());
generate_empty_profile(path);
}

fn create_config(path: &Path, config: &Config) {
Expand Down

0 comments on commit 64a89aa

Please sign in to comment.