mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
adds avahi base service to init function of mdns controller (#407)
* adds avahi base service to init function of mdns controller * Apply suggestions from code review * adds hostname set to startup sequence * Apply suggestions from code review Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
09c85b79c3
commit
1ff0db0b84
36
appmgr/src/hostname.rs
Normal file
36
appmgr/src/hostname.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use digest::Digest;
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::util::Invoke;
|
||||
use crate::{Error, ErrorKind};
|
||||
|
||||
pub async fn get_hostname() -> Result<String, Error> {
|
||||
let out = Command::new("hostname")
|
||||
.invoke(ErrorKind::ParseSysInfo)
|
||||
.await?;
|
||||
let out_string = String::from_utf8(out)?;
|
||||
Ok(out_string.trim().to_owned())
|
||||
}
|
||||
|
||||
pub async fn set_hostname(hostname: &str) -> Result<(), Error> {
|
||||
let _out = Command::new("hostnamectl")
|
||||
.arg("set-hostname")
|
||||
.arg(hostname)
|
||||
.invoke(ErrorKind::ParseSysInfo)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_product_key() -> Result<String, Error> {
|
||||
let out = tokio::fs::read_to_string("/boot/product_key.txt").await?;
|
||||
Ok(out.trim().to_owned())
|
||||
}
|
||||
|
||||
pub async fn sync_hostname() -> Result<(), Error> {
|
||||
let key = get_product_key().await?;
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
hasher.update(key.as_bytes());
|
||||
let res = hasher.finalize();
|
||||
set_hostname(&format!("start9-{}", hex::encode(&res[0..4]))).await?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user