()
| 1403 | } |
| 1404 | |
| 1405 | fn cmd_onboard() -> Result<(), Box<dyn std::error::Error>> { |
| 1406 | use crate::onboard; |
| 1407 | |
| 1408 | const TOTAL_STEPS: usize = ONBOARD_TOTAL_STEPS; |
| 1409 | |
| 1410 | tui::print_banner("Onboarding"); |
| 1411 | |
| 1412 | // Check if running as root |
| 1413 | if !nix::unistd::getuid().is_root() { |
| 1414 | tui::print_callout( |
| 1415 | "Administrative Privileges Required", |
| 1416 | &[ |
| 1417 | "This process needs to set secure permissions on sensitive", |
| 1418 | "files such as API keys and configuration.", |
| 1419 | "", |
| 1420 | "Please re-run with sudo:", |
| 1421 | "", |
| 1422 | " $ sudo clawshell onboard", |
| 1423 | ], |
| 1424 | ); |
| 1425 | std::process::exit(1); |
| 1426 | } |
| 1427 | |
| 1428 | let existing_config = process::default_config_path(); |
| 1429 | if existing_config.exists() { |
| 1430 | ensure_config_migrated(&existing_config)?; |
| 1431 | } |
| 1432 | |
| 1433 | tui::print_warning("Administrative privileges in use — securing sensitive files."); |
| 1434 | println!(); |
| 1435 | |
| 1436 | // Step 1: Create the clawshell user if it doesn't exist |
| 1437 | tui::print_step(1, TOTAL_STEPS, "Checking for 'clawshell' system user..."); |
| 1438 | |
| 1439 | let user_exists = std::process::Command::new("id") |
| 1440 | .arg("clawshell") |
| 1441 | .stdout(std::process::Stdio::null()) |
| 1442 | .stderr(std::process::Stdio::null()) |
| 1443 | .status() |
| 1444 | .map(|s| s.success()) |
| 1445 | .unwrap_or(false); |
| 1446 | |
| 1447 | if user_exists { |
| 1448 | tui::print_step_done(1, TOTAL_STEPS, "System user already exists"); |
| 1449 | } else { |
| 1450 | if let Err(error) = platform::create_system_user("clawshell") { |
| 1451 | tui::print_error(&format!("Failed to create 'clawshell' user: {error}")); |
| 1452 | std::process::exit(1); |
| 1453 | } |
| 1454 | tui::print_step_done(1, TOTAL_STEPS, "System user created"); |
| 1455 | } |
| 1456 | |
| 1457 | // Step 2: Create necessary directories |
| 1458 | let config_dir = PathBuf::from("/etc/clawshell"); |
| 1459 | let log_dir_path = PathBuf::from("/var/log/clawshell"); |
| 1460 | |
| 1461 | tui::print_step(2, TOTAL_STEPS, "Setting up directories..."); |
| 1462 |
no test coverage detected