Use SCRIPT_DIR, add sshpass and auto-mount workspaces, update flakes
This commit is contained in:
parent
8534f7efb9
commit
9aa72fade7
8 changed files with 292 additions and 413 deletions
54
bin/qvm-run
54
bin/qvm-run
|
|
@ -95,6 +95,34 @@ register_workspace() {
|
|||
return 1 # Indicate new workspace added
|
||||
}
|
||||
|
||||
#
|
||||
# ensure_workspace_mounted - Mount workspace in VM if not already mounted
|
||||
# Args: $1 - SSH port
|
||||
# $2 - mount tag (e.g., ws_abc123)
|
||||
# $3 - guest path (e.g., /workspace/abc123)
|
||||
# Returns: 0 on success
|
||||
#
|
||||
ensure_workspace_mounted() {
|
||||
local ssh_port="$1"
|
||||
local mount_tag="$2"
|
||||
local guest_path="$3"
|
||||
|
||||
# SSH into VM and mount the workspace
|
||||
# - mkdir creates the mount point if missing
|
||||
# - mount attempts to mount the 9p virtfs
|
||||
# - || true ensures we don't fail if already mounted
|
||||
sshpass -p root ssh -o StrictHostKeyChecking=no \
|
||||
-o UserKnownHostsFile=/dev/null \
|
||||
-o LogLevel=ERROR \
|
||||
-o PubkeyAuthentication=no \
|
||||
-o PasswordAuthentication=yes \
|
||||
-p "$ssh_port" \
|
||||
root@localhost \
|
||||
"mkdir -p '$guest_path' && mount -t 9p -o trans=virtio,version=9p2000.L,msize=104857600 '$mount_tag' '$guest_path' 2>/dev/null || true" >/dev/null 2>&1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# is_workspace_mounted - Check if workspace is actually mounted in VM
|
||||
# Args: $1 - SSH port
|
||||
|
|
@ -106,9 +134,11 @@ is_workspace_mounted() {
|
|||
local guest_path="$2"
|
||||
|
||||
# SSH into VM and check if guest path exists and is a directory
|
||||
if ssh -o StrictHostKeyChecking=no \
|
||||
if sshpass -p root ssh -o StrictHostKeyChecking=no \
|
||||
-o UserKnownHostsFile=/dev/null \
|
||||
-o LogLevel=ERROR \
|
||||
-o PubkeyAuthentication=no \
|
||||
-o PasswordAuthentication=yes \
|
||||
-p "$ssh_port" \
|
||||
root@localhost \
|
||||
"test -d '$guest_path'" 2>/dev/null; then
|
||||
|
|
@ -169,14 +199,22 @@ main() {
|
|||
local ssh_port
|
||||
ssh_port=$(get_ssh_port)
|
||||
|
||||
# Check if workspace is actually mounted in VM
|
||||
# Get mount tag from workspaces.json
|
||||
local mount_tag
|
||||
mount_tag=$(jq -r --arg path "$workspace_path" '.[] | select(.host_path == $path) | .mount_tag' "$QVM_WORKSPACES_FILE")
|
||||
|
||||
# Ensure workspace is mounted (auto-mount if not)
|
||||
log_info "Ensuring workspace is mounted..."
|
||||
ensure_workspace_mounted "$ssh_port" "$mount_tag" "$guest_path"
|
||||
|
||||
# Verify workspace is actually mounted
|
||||
if ! is_workspace_mounted "$ssh_port" "$guest_path"; then
|
||||
log_error "Workspace not mounted in VM"
|
||||
log_error "Failed to mount workspace in VM"
|
||||
echo ""
|
||||
echo "This workspace was just registered but is not mounted in the VM."
|
||||
echo "Workspaces must be mounted at VM start time."
|
||||
echo "The workspace could not be mounted automatically."
|
||||
echo "This may indicate the VM was started before this workspace was registered."
|
||||
echo ""
|
||||
echo "Please restart the VM to mount this workspace:"
|
||||
echo "Please restart the VM to properly configure the workspace:"
|
||||
echo " qvm stop"
|
||||
echo " qvm start"
|
||||
echo ""
|
||||
|
|
@ -185,14 +223,18 @@ main() {
|
|||
fi
|
||||
|
||||
# Build SSH command
|
||||
# - Use sshpass for automated password auth (password: root)
|
||||
# - Use -t if stdin is a TTY (for interactive commands)
|
||||
# - Suppress SSH warnings (ephemeral VM, host keys change)
|
||||
# - cd to guest path and execute command
|
||||
local ssh_cmd=(
|
||||
sshpass -p root
|
||||
ssh
|
||||
-o StrictHostKeyChecking=no
|
||||
-o UserKnownHostsFile=/dev/null
|
||||
-o LogLevel=ERROR
|
||||
-o PubkeyAuthentication=no
|
||||
-o PasswordAuthentication=yes
|
||||
-p "$ssh_port"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue