1
0
Fork 0
forked from navos/sheepd

🎉 init

This commit is contained in:
JMARyA 2025-04-28 18:44:09 +02:00
commit 812c4adb15
Signed by untrusted user: jmarya
GPG key ID: 901B2ADDF27C2263
16 changed files with 4631 additions and 0 deletions
src/sheepd_core

37
src/sheepd_core/cmd.rs Normal file
View file

@ -0,0 +1,37 @@
use crate::{api, sheepd_core::config::AgentConfig};
use super::args::JoinCommand;
pub fn join(conf: JoinCommand) {
// TODO : check for root
// TODO : check if joined somewhere already
log::info!("Joining to {}", conf.home);
let url = format!("http://{}/join", conf.home);
println!("{url}");
let mut res = ureq::post(url)
.send_json(&api::JoinParams {
join_token: None,
machine_id: std::fs::read_to_string("/etc/machine-id").unwrap(),
hostname: std::fs::read_to_string("/etc/hostname").unwrap(),
})
.unwrap();
let res: serde_json::Value = res.body_mut().read_json().unwrap();
let token = res
.as_object()
.unwrap()
.get("ok")
.unwrap()
.as_str()
.unwrap();
log::info!("Joined {} successfully", conf.home);
std::fs::write(
"/etc/sheepd.toml",
toml::to_string(&AgentConfig::new(&conf.home, token)).unwrap(),
)
.unwrap();
}