audb_core/features/
shell.rs

1// Shell command implementation for Aurora OS devices
2//
3// Execute arbitrary commands on remote devices, similar to adb shell.
4
5use crate::features::config::{device_store::DeviceStore, state::DeviceState};
6use crate::tools::{
7    session::DeviceSession,
8    types::DeviceIdentifier,
9};
10use anyhow::{anyhow, Context, Result};
11
12pub async fn execute(as_root: bool, command: String) -> Result<()> {
13    if command.is_empty() {
14        return Err(anyhow!("Command required. Usage: audb shell <command>"));
15    }
16
17    // Get device and establish session
18    let current_host = DeviceState::get_current()?;
19    let device_id = DeviceIdentifier::Host(current_host);
20    let device = DeviceStore::find(&device_id)?;
21
22    let mut session = DeviceSession::connect(&device)
23        .context("Failed to connect to device")?;
24
25    // Execute command
26    let output = if as_root {
27        session.exec_as_root(&command)
28            .context("Failed to execute command as root. Set root password using: audb device add")?
29    } else {
30        session.exec(&command)
31            .context("Failed to execute command")?
32    };
33
34    // Print output
35    for line in output {
36        println!("{}", line);
37    }
38
39    Ok(())
40}