fix: removed the hardcode codex and claude form ssh.sh

This commit is contained in:
robcholz
2026-02-07 17:12:09 -05:00
parent c0c52a5f8c
commit 518ca14fd3
5 changed files with 48 additions and 20 deletions
+2 -2
View File
@@ -81,11 +81,11 @@ fn default_mounts() -> Vec<String> {
let mut mounts = Vec::new();
let codex_host = home.join(".codex");
if codex_host.exists() {
mounts.push("~/.codex:/usr/local/codex:read-write".to_string());
mounts.push("~/.codex:/home/vibecoder/.codex:read-write".to_string());
}
let claude_host = home.join(".claude");
if claude_host.exists() {
mounts.push("~/.claude:/usr/local/claude:read-write".to_string());
mounts.push("~/.claude:/home/vibecoder/.claude:read-write".to_string());
}
mounts
}
+34 -6
View File
@@ -12,8 +12,9 @@ pub fn build_mount_rows(
) -> Result<Vec<tui::MountListRow>, Box<dyn Error + Send + Sync>> {
let mut rows = Vec::new();
rows.extend(default_mounts(cwd)?);
let guest_home = resolve_guest_home(cwd)?;
for spec in &config.box_cfg.mounts {
rows.push(parse_mount_spec(cwd, spec, false)?);
rows.push(parse_mount_spec(cwd, spec, false, &guest_home)?);
}
Ok(rows)
}
@@ -75,6 +76,7 @@ fn parse_mount_spec(
cwd: &Path,
spec: &str,
default_mount: bool,
guest_home: &str,
) -> Result<tui::MountListRow, Box<dyn Error + Send + Sync>> {
let parts: Vec<&str> = spec.split(':').collect();
if parts.len() < 2 || parts.len() > 3 {
@@ -99,11 +101,7 @@ fn parse_mount_spec(
};
let host_display = display_host_spec(cwd, host_part);
let guest_display = if Path::new(guest_part).is_absolute() {
guest_part.to_string()
} else {
format!("/root/{guest_part}")
};
let guest_display = resolve_guest_display(guest_part, guest_home);
Ok(tui::MountListRow {
host: host_display,
guest: guest_display,
@@ -128,6 +126,36 @@ fn display_host_spec(cwd: &Path, host: &str) -> String {
}
}
fn resolve_guest_home(cwd: &Path) -> Result<String, Box<dyn Error + Send + Sync>> {
let instance_dir = cwd.join(session_manager::INSTANCE_DIR_NAME);
if let Ok(Some(user)) = instance::read_instance_ssh_user(&instance_dir) {
return Ok(format!("/home/{user}"));
}
Ok(format!("/home/{}", instance::DEFAULT_SSH_USER))
}
fn resolve_guest_display(guest: &str, guest_home: &str) -> String {
if guest == "~" {
return "~".to_string();
}
if let Some(stripped) = guest.strip_prefix("~/") {
return format!("~/{stripped}");
}
if Path::new(guest).is_absolute() {
if let Ok(stripped) = Path::new(guest).strip_prefix(guest_home) {
if stripped.components().next().is_none() {
"~".to_string()
} else {
format!("~/{}", stripped.display())
}
} else {
guest.to_string()
}
} else {
format!("/root/{guest}")
}
}
fn display_path(path: &Path) -> String {
let Ok(home) = env::var("HOME") else {
return path.display().to_string();
+10 -1
View File
@@ -27,7 +27,7 @@ use crate::{
const SSH_KEY_NAME: &str = "ssh_key";
pub(crate) const SERIAL_LOG_NAME: &str = "serial.log";
const DEFAULT_SSH_USER: &str = "vibecoder";
pub(crate) const DEFAULT_SSH_USER: &str = "vibecoder";
const SSH_CONNECT_RETRIES: usize = 30;
const SSH_CONNECT_DELAY_MS: u64 = 500;
const SSH_SETUP_SCRIPT: &str = include_str!("ssh.sh");
@@ -181,6 +181,15 @@ pub fn read_instance_vm_ip(
Ok(config.and_then(|cfg| cfg.vm_ipv4))
}
pub fn read_instance_ssh_user(
instance_dir: &Path,
) -> Result<Option<String>, Box<dyn std::error::Error>> {
let config = read_instance_config(instance_dir)?;
Ok(config
.map(|cfg| cfg.ssh_user)
.filter(|user| !user.trim().is_empty()))
}
pub fn touch_last_active(instance_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
let mut config = load_or_create_instance_config(instance_dir)?;
let now = OffsetDateTime::now_utc().format(&Rfc3339)?;
-9
View File
@@ -63,19 +63,10 @@ fi
install -d -m 700 -o "$SSH_USER" -g "$SSH_USER" "/home/${SSH_USER}/.ssh"
install -m 600 -o "$SSH_USER" -g "$SSH_USER" "$KEY_PATH" "/home/${SSH_USER}/.ssh/authorized_keys"
# Ensure codex/claude are visible in the user's HOME
USER_HOME="$(getent passwd "$SSH_USER" | cut -d: -f6 2>/dev/null || true)"
if [ -z "$USER_HOME" ]; then
USER_HOME="/home/${SSH_USER}"
fi
install -d -m 755 /usr/local/codex /usr/local/claude
if [ ! -e "${USER_HOME}/.codex" ]; then
ln -s /usr/local/codex "${USER_HOME}/.codex"
fi
if [ ! -e "${USER_HOME}/.claude" ]; then
ln -s /usr/local/claude "${USER_HOME}/.claude"
fi
chown -h "${SSH_USER}:${SSH_USER}" "${USER_HOME}/.codex" "${USER_HOME}/.claude" 2>/dev/null || true
# Vibebox shell commands
install -d -m 755 /etc/profile.d
+2 -2
View File
@@ -2,8 +2,8 @@
cpu_count = 2
ram_mb = 2048
mounts = [
"~/.codex:/usr/local/codex:read-write",
"~/.claude:/usr/local/claude:read-write",
"~/.codex:~/.codex:read-write",
"~/.claude:~/.claude:read-write",
]
[supervisor]