Clean up codebase, use patch in hddtemp Nix store path #1
2 changed files with 33 additions and 50 deletions
|
@ -52,7 +52,6 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
||||||
(pkgs.rust-bin.stable.latest.default.override {
|
(pkgs.rust-bin.stable.latest.default.override {
|
||||||
extensions = [ "rust-src" ];
|
extensions = [ "rust-src" ];
|
||||||
})
|
})
|
||||||
openssl
|
|
||||||
bacon
|
bacon
|
||||||
];
|
];
|
||||||
inputsFrom = with self.packages.${system}; [ status_cloud ];
|
inputsFrom = with self.packages.${system}; [ status_cloud ];
|
||||||
|
@ -63,6 +62,9 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
buildAndTestSubdir = "status_cloud";
|
buildAndTestSubdir = "status_cloud";
|
||||||
cargoHash = "sha256-mMxHI/rU1Gd5UR+hZ+5+FnBrff8uF+SrEvGJT7wh5tI=";
|
cargoHash = "sha256-mMxHI/rU1Gd5UR+hZ+5+FnBrff8uF+SrEvGJT7wh5tI=";
|
||||||
|
preBuild = ''
|
||||||
|
sed -i 's/Command::new("hddtemp")/${nixpkgs.lib.escape [ "/" ] "Command::new(\"${pkgs.hddtemp}\")"}/g' status_cloud/src/main.rs
|
||||||
|
'';
|
||||||
meta = meta // {
|
meta = meta // {
|
||||||
description = "Server status saved to a nextcloud note service.";
|
description = "Server status saved to a nextcloud note service.";
|
||||||
};
|
};
|
||||||
|
@ -104,7 +106,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = ''
|
ExecStart = ''
|
||||||
${cfg.package}/bin/status_cloud --hddtemp-executable ${pkgs.hddtemp}/bin/hddtemp --config-file ${builtins.toString cfg.config_path}
|
${cfg.package}/bin/status_cloud --config-file ${builtins.toString cfg.config_path}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,42 +2,38 @@ use clap::Parser;
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::process::Command;
|
use std::{process::Command, path::PathBuf};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = CliArgs::parse();
|
let args = CliArgs::parse();
|
||||||
|
|
||||||
if args.debug {
|
simplelog::SimpleLogger::init(
|
||||||
let _ = simplelog::SimpleLogger::init(
|
match args.debug {
|
||||||
simplelog::LevelFilter::Debug,
|
true => simplelog::LevelFilter::Debug,
|
||||||
|
false => simplelog::LevelFilter::Info,
|
||||||
|
},
|
||||||
simplelog::Config::default(),
|
simplelog::Config::default(),
|
||||||
);
|
)?;
|
||||||
} else {
|
|
||||||
let _ = simplelog::SimpleLogger::init(
|
|
||||||
simplelog::LevelFilter::Info,
|
|
||||||
simplelog::Config::default(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Opening Config file: {}", args.config_file);
|
debug!("Opening Config file: {}", args.config_file.display());
|
||||||
debug!(
|
debug!(
|
||||||
"Config file exists: {}",
|
"Config file exists: {}",
|
||||||
std::fs::metadata(args.config_file.clone()).is_ok()
|
std::fs::metadata(&args.config_file).is_ok()
|
||||||
);
|
);
|
||||||
|
|
||||||
let file_contents = match std::fs::read_to_string(args.config_file) {
|
let file_contents = match std::fs::read_to_string(&args.config_file) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Could not read config file: {}", e.to_string());
|
error!("Could not read config file: {e}");
|
||||||
panic!("{}", e);
|
panic!("{e}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let cfg: Config = match toml::from_str(file_contents.as_str()) {
|
let cfg: Config = match toml::from_str(&file_contents) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Could not parse config file: {}", e.to_string());
|
error!("Could not parse config file: {e}");
|
||||||
panic!("{}", e);
|
panic!("{e}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,8 +54,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Error opening /dev/: {}", e.to_string());
|
error!("Error opening /dev/: {e}");
|
||||||
panic!("{}", e);
|
panic!("{e}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,15 +63,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut drive_temps: Vec<String> = vec![];
|
let mut drive_temps: Vec<String> = vec![];
|
||||||
|
|
||||||
for drive in drives {
|
for drive in drives {
|
||||||
let output = match Command::new(args.hddtemp_executable.clone())
|
let output = match Command::new("hddtemp")
|
||||||
.arg("--unit=F")
|
.arg("--unit=F")
|
||||||
.arg(drive.clone())
|
.arg(&drive)
|
||||||
.output()
|
.output()
|
||||||
{
|
{
|
||||||
Ok(val) => String::from_utf8_lossy(&val.stdout).into_owned(),
|
Ok(val) => String::from_utf8_lossy(&val.stdout).into_owned(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error running hddtemp: {}", e.to_string());
|
warn!("Error running hddtemp: {e}");
|
||||||
warn!("Drive was: '{}'", drive);
|
warn!("Drive was: '{drive}'");
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -87,23 +83,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body_content.push_str("## Hard Drive Temps\n");
|
body_content.push_str("## Hard Drive Temps\n");
|
||||||
body_content.push_str(drive_temps.join("\n").as_str());
|
body_content.push_str(&drive_temps.join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::new()
|
Client::new()
|
||||||
.put(format!(
|
.put(format!(
|
||||||
"https://{}/index.php/apps/notes/api/v1/notes/{}",
|
"https://{}/index.php/apps/notes/api/v1/notes/{}",
|
||||||
cfg.server_url.clone(),
|
&cfg.server_url,
|
||||||
cfg.note_id.clone()
|
&cfg.note_id
|
||||||
))
|
))
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
.basic_auth(&cfg.user, Some(&cfg.pswd))
|
||||||
.body(
|
.body(
|
||||||
serde_json::to_string(&NoteUpdate {
|
serde_json::to_string(&NoteUpdate {
|
||||||
content: body_content,
|
content: body_content,
|
||||||
})
|
})?,
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
|
@ -127,7 +122,7 @@ struct NoteUpdate {
|
||||||
content: String,
|
content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Default)]
|
||||||
struct Config {
|
struct Config {
|
||||||
user: String,
|
user: String,
|
||||||
pswd: String,
|
pswd: String,
|
||||||
|
@ -135,26 +130,12 @@ struct Config {
|
||||||
server_url: String,
|
server_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
user: "".to_string(),
|
|
||||||
pswd: "".to_string(),
|
|
||||||
note_id: "".to_string(),
|
|
||||||
server_url: "".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about=None)]
|
#[command(author, version, about, long_about=None)]
|
||||||
struct CliArgs {
|
struct CliArgs {
|
||||||
/// Path to config .toml file
|
/// Path to config .toml file
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
config_file: String,
|
config_file: PathBuf,
|
||||||
|
|
||||||
#[arg(short, long)]
|
|
||||||
hddtemp_executable: String,
|
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
|
|
Loading…
Reference in a new issue