MCPcopy Create free account
hub / github.com/KingOfBugbounty/enumrust / configure_shell_path

Function configure_shell_path

src/main.rs:4497–4559  ·  view source on GitHub ↗

Configure PATH in shell configuration files (.bashrc, .zshrc, .profile)

(gobin: &str)

Source from the content-addressed store, hash-verified

4495 Ok(())
4496}
4497
4498/// Configure PATH in shell configuration files (.bashrc, .zshrc, .profile)
4499async fn configure_shell_path(gobin: &str) -> bool {
4500 let home = std::env::var("HOME").unwrap_or_else(|_| "/root".to_string());
4501
4502 // Export line to add
4503 let export_line = format!("export PATH=\"$PATH:{}\"", gobin);
4504 let marker = "# EnumRust Go binaries PATH";
4505 let full_block = format!("\n{}\n{}\n", marker, export_line);
4506
4507 let shell_configs = vec![
4508 format!("{}/.bashrc", home),
4509 format!("{}/.zshrc", home),
4510 format!("{}/.profile", home),
4511 ];
4512
4513 let mut configured = false;
4514
4515 for config_path in shell_configs {
4516 let path = Path::new(&config_path);
4517
4518 // Skip if file doesn't exist
4519 if !path.exists() {
4520 continue;
4521 }
4522
4523 // Read current content
4524 let content = match fs::read_to_string(path) {
4525 Ok(c) => c,
4526 Err(_) => continue,
4527 };
4528
4529 // Skip if already configured (check for marker or the gobin path)
4530 if content.contains(marker) || content.contains(gobin) {
4531 println!("{}", format!(" ℹ️ PATH already in {}", config_path).dimmed());
4532 continue;
4533 }
4534
4535 // Append the export line
4536 let mut file = match OpenOptions::new().append(true).open(path) {
4537 Ok(f) => f,
4538 Err(_) => continue,
4539 };
4540
4541 if file.write_all(full_block.as_bytes()).is_ok() {
4542 println!("{}", format!(" ✓ Added PATH to {}", config_path).green());
4543 configured = true;
4544 }
4545 }
4546
4547 // Also try to update current session's PATH via /etc/profile.d if we have permissions
4548 let profile_d = "/etc/profile.d/enumrust-go.sh";
4549 if !Path::new(profile_d).exists() {
4550 let profile_content = format!("#!/bin/sh\n{}\n{}\n", marker, export_line);
4551 if fs::write(profile_d, profile_content).is_ok() {
4552 let _ = std::process::Command::new("chmod")
4553 .args(["+x", profile_d])
4554 .output();

Callers 1

install_all_toolsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected