rollback makefile change

add ip addr command
This commit is contained in:
breadone 2024-08-12 23:35:29 +12:00
parent 8d6f07bc26
commit aaff62cbc6
No known key found for this signature in database
2 changed files with 15 additions and 3 deletions

View File

@ -12,7 +12,6 @@ release: clean
@cargo build --release
update: release
@git pull
ifeq ($(UNAME), Darwin)
cp target/release/bp ~/bin/
endif

View File

@ -6,6 +6,8 @@ use core::str;
pub enum SysCommand {
/// Reboot breadpi.
Reboot,
/// Returns the local IP address of breadpi.
Ip
}
pub async fn handle_sys(cmd: &SysCommand) {
@ -14,7 +16,8 @@ pub async fn handle_sys(cmd: &SysCommand) {
.expect("Could not connect to breadpi");
match cmd {
SysCommand::Reboot => { sys_reboot(&session).await; }
SysCommand::Reboot => { sys_reboot(&session).await; },
SysCommand::Ip => { ip_addr(&session).await; }
}
let _ = session.close();
@ -30,3 +33,13 @@ async fn sys_reboot(session: &Session) {
println!("Error: {:?}", String::from_utf8(cmd.stderr));
}
}
async fn ip_addr(session: &Session) {
let cmd = session.command("hostname")
.arg("-I")
.raw_arg("| grep -o '^[0-9.]*'")
.output().await.unwrap();
println!("{}", String::from_utf8(cmd.stdout).expect("nuh uh"));
}