MCPcopy Create free account
hub / github.com/clawshell/clawshell / cmd_onboard

Function cmd_onboard

src/main.rs:1405–1762  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1403}
1404
1405fn 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

Callers 1

mainFunction · 0.85

Calls 15

print_bannerFunction · 0.85
print_calloutFunction · 0.85
ensure_config_migratedFunction · 0.85
print_warningFunction · 0.85
print_stepFunction · 0.85
print_step_doneFunction · 0.85
print_errorFunction · 0.85
prompt_confirmFunction · 0.85

Tested by

no test coverage detected