Compare commits

..

No commits in common. '3faccc1b999a965b88fbac567fc222243c49eedd' and 'a50efdeea06990eecdaa65ce4ef02f553cea1807' have entirely different histories.

160
Cargo.lock generated

@ -208,6 +208,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "confy"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37668cb35145dcfaa1931a5f37fde375eeae8068b4c0d2f289da28a270b2d2c"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -224,6 +236,26 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "directories"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "encoding_rs"
version = "0.8.32"
@ -233,12 +265,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.2"
@ -344,6 +370,17 @@ dependencies = [
"slab",
]
[[package]]
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "gimli"
version = "0.27.3"
@ -362,7 +399,7 @@ dependencies = [
"futures-sink",
"futures-util",
"http",
"indexmap 1.9.3",
"indexmap",
"slab",
"tokio",
"tokio-util",
@ -375,12 +412,6 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
[[package]]
name = "heck"
version = "0.4.1"
@ -504,17 +535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
]
[[package]]
name = "indexmap"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [
"equivalent",
"hashbrown 0.14.0",
"hashbrown",
]
[[package]]
@ -732,6 +753,15 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -741,6 +771,17 @@ dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall 0.2.16",
"thiserror",
]
[[package]]
name = "reqwest"
version = "0.11.18"
@ -866,15 +907,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@ -922,10 +954,10 @@ version = "0.1.0"
dependencies = [
"chrono",
"clap",
"confy",
"reqwest",
"serde",
"serde_json",
"toml",
]
[[package]]
@ -953,11 +985,31 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"redox_syscall 0.3.5",
"rustix",
"windows-sys",
]
[[package]]
name = "thiserror"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.1.45"
@ -1026,38 +1078,13 @@ dependencies = [
[[package]]
name = "toml"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.3"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a"
dependencies = [
"indexmap 2.0.0",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "tower-service"
version = "0.3.2"
@ -1328,15 +1355,6 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "winnow"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc"
dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.10.1"

@ -37,7 +37,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
rustSettings = with pkgs; {
src = ./.;
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl hddtemp ];
buildInputs = [ openssl ];
cargoHash = nixpkgs.lib.fakeHash;
};
meta = with nixpkgs.lib; {
@ -62,7 +62,7 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
pname = "status_cloud";
version = "0.1.0";
buildAndTestSubdir = "status_cloud";
cargoHash = "sha256-Z5JFg9OnCOO9jM/J5T9Tr64x21HOxNf8M4qJKiXiF54=";
cargoHash = "sha256-2eSCxWKf2VH9escaWUDFcozJyyo4xt9SCgBPxlwckTk=";
meta = meta // {
description = "Server status saved to a nextcloud note service.";
};
@ -93,12 +93,11 @@ rust-project TODO: write shell script for automatically updating `cargoHash`
cfg = config.services.status_cloud;
pkg = self.packages.${system}.status_cloud;
in lib.mkIf cfg.enable {
#description = pkg.meta.description;
description = "Status Cloud";
description = pkg.meta.description;
serviceConfig = {
Type = "oneshot";
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}
'';
};
};

@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
chrono = "0.4.26"
clap = { version = "4.4.0", features = ["derive"] }
confy = "0.5.1"
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
serde = { version = "1.0.184", features = ["serde_derive"] }
serde_json = "1.0.105"
toml = "0.7.6"

@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use reqwest::blocking::Client;
use toml;
use clap::Parser;
use confy;
use std::process::Command;
@ -12,38 +12,13 @@ use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = CliArgs::parse();
println!("Opening Config file: {}", args.config_file);
println!("File exists: {}", std::fs::metadata(args.config_file.clone()).is_ok());
let file_contents = match std::fs::read_to_string(args.config_file) {
Ok(val) => val,
Err(e) => {
println!("Could not read file: {}", e.to_string());
return Ok(());
}
};
let cfg: Config = match toml::from_str(file_contents.as_str()) {
Ok(val) => val,
Err(e) => {
println!("Could not parse file: {}", e.to_string());
return Ok(());
}
};
let cfg: Config = confy::load_path(args.config_file)?;
let mut body_content: String = format!("*Last Updated:* {} \n", chrono::Local::now().format("%D - %H:%M:%S"));
let mut drives: Vec<String> = vec![];
{
let rust_drives = match std::fs::read_dir("/dev/") {
Ok(val) => val,
Err(e) => {
println!("Error opening /dev/: {}", e.to_string());
return Ok(());
}
};
let rust_drives = std::fs::read_dir("/dev/").unwrap();
for path in rust_drives {
match path {
@ -60,35 +35,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
match Command::new(args.hddtemp_executable.clone()).output() {
Ok(val) => val,
Err(e) => {
println!("Error running hddtemp at all: {}", e.to_string());
println!("hddtemp = {}", args.hddtemp_executable.clone());
return Ok(());
}
};
{
let mut drive_temps: Vec<String> = vec![];
for drive in drives {
let output = match Command::new(args.hddtemp_executable.clone()).arg(drive.clone()).output() {
Ok(val) => val,
Err(e) => {
println!("Error running hddtemp: {}", e.to_string());
println!("Drive was: '{}'", drive);
return Ok(());
}
};
let output = Command::new("hddtemp").arg(drive).output()?;
let tmp = match std::str::from_utf8(&output.stdout) {
Ok(val) => val,
Err(e) => {
println!("Error parsing hddtemp output: {}", e.to_string());
return Ok(());
}
}.to_string();
let tmp = std::str::from_utf8(&output.stdout)?.to_string();
if !tmp.contains("sensor") {
drive_temps.push(tmp.replace("\n", "Not running as sudo?"));
@ -101,13 +55,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
Client::new()
.put(format!("https://{}/index.php/apps/notes/api/v1/notes/{}", cfg.server_url.clone(), cfg.note_id.clone()))
let update = Client::new()
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap())
.send()?;
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
//println!("{:#?}", update.send()?.json::<Note>()?);
Ok(())
}
@ -135,7 +90,6 @@ struct Config {
user: String,
pswd: String,
note_id: String,
server_url: String
}
impl Default for Config {
@ -144,7 +98,6 @@ impl Default for Config {
user: "".to_string(),
pswd: "".to_string(),
note_id: "".to_string(),
server_url: "".to_string(),
}
}
}
@ -155,7 +108,4 @@ struct CliArgs {
/// Path to config .toml file
#[arg(short, long)]
config_file: String,
#[arg(short, long)]
hddtemp_executable: String,
}

Loading…
Cancel
Save