diff --git a/chrono_track/src/main.rs b/chrono_track/src/main.rs index 5bb244b..ed3210e 100644 --- a/chrono_track/src/main.rs +++ b/chrono_track/src/main.rs @@ -8,7 +8,7 @@ use lettre::{ use log::{debug, error}; use reqwest::blocking::Client; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{path::PathBuf, process::Command}; fn main() -> Result<(), Box> { // --- Loading and setup --- @@ -46,6 +46,7 @@ fn main() -> Result<(), Box> { // --- END Loading and setup --- let mut do_email_summary: bool = false; + let mut do_headscale_reset: bool = false; // --- Get checked and unchecked --- let primary_note = Client::new() @@ -69,6 +70,9 @@ fn main() -> Result<(), Box> { do_email_summary = true; continue; } + if line.starts_with("- [x] Restart Headscale :(") { + do_headscale_reset = true; + } if line.starts_with("- [ ] Send Summary") { continue; } @@ -195,9 +199,14 @@ fn main() -> Result<(), Box> { if do_email_summary { debug!("Send email selected"); - reset_email_checkbox(&cfg); + reset_checkboxes(&cfg); send_email_summary(&cfg, body_content, &args); } + if do_headscale_reset { + debug!("Restarting Headscale"); + reset_checkboxes(&cfg); + reset_headscale(); + } Ok(()) } @@ -243,11 +252,15 @@ struct CliArgs { debug: bool, } +fn reset_headscale() { + let _ = Command::new("systemctl").arg("restart").arg("headscale").output(); +} + // All unwraps are unrecoverable errors // All calls after depend on the success of the one before, and cannot run // without. So it would be too much work to make an error type to handle an error // that would cause a crash anyways -fn reset_email_checkbox(config: &Config) { +fn reset_checkboxes(config: &Config) { let primary_note = Client::new() .get(format!( "https://{}/index.php/apps/notes/api/v1/notes/{}", @@ -268,6 +281,8 @@ fn reset_email_checkbox(config: &Config) { for line in primary_note_lines.iter() { if line.starts_with("- [x] Send Summary") { body_content.push("- [ ] Send Summary"); + } else if line.starts_with("- [x] Restart Headscale :(") { + body_content.push("- [ ] Restart Headscale :(") } else { body_content.push(line); }