fix(ssh): fix issue with empty argument, add logs, add check for socket

This commit is contained in:
yeti 2025-04-18 09:22:55 +01:00
parent 6ec78f09fd
commit aa6c1d7771

View File

@ -3,15 +3,52 @@
PERSON="$1"
WORKSPACE="$SSH_ORIGINAL_COMMAND"
IMAGE="localhost:5100/analytics-backend-workspace:latest"
TMUX_SESSION="$WORKSPACE|analytics-backend"
DEV_USER="devuser"
XDG_RUNTIME_DIR="/run/user/$(id -u)"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# Log access
log "[SSH] $USER connected with command: $SSH_ORIGINAL_COMMAND" >>/home/infilytics/ssh-router.log
# log "🧩 IMAGE = '$IMAGE'"
# log "🧩 WORKSPACE = '$WORKSPACE'"
# log "🧩 PERSON = '$PERSON'"
# Fallbacks
if [[ -z "${WORKSPACE:-}" ]]; then
WORKSPACE="$PERSON"
log " Defaulted WORKSPACE to $WORKSPACE"
fi
if [[ -z "${TMUX_SESSION:-}" ]]; then
TMUX_SESSION="$WORKSPACE|analytics-backend"
log " Defaulted TMUX_SESSION to $TMUX_SESSION"
fi
if [[ -z "${IMAGE:-}" ]]; then
IMAGE="localhost:5100/analytics-backend-workspace:latest"
log " Defaulted IMAGE to $IMAGE"
fi
TMUX_SESSION="$WORKSPACE|analytics-backend"
# Start podman socket service if it's not running
if [[ ! -S "$XDG_RUNTIME_DIR/podman/podman.sock" ]]; then
log "🔄 Starting Podman socket service for user $USER"
systemctl --user start podman.socket || {
log "❌ Failed to start podman.socket via systemd"
exit 1
}
# Wait briefly for socket to appear
sleep 1
fi
if [[ ! -S "$XDG_RUNTIME_DIR/podman/podman.sock" ]]; then
log "❌ Podman socket still missing after startup attempt"
exit 1
fi
# Check if image exists locally
if ! podman image exists "$IMAGE"; then
@ -73,13 +110,6 @@ get_access_mode_and_session() {
local workspace="$1"
local person="$2"
# If workspace is empty, use person's name
if [[ -z "$workspace" ]]; then
WORKSPACE="$person"
echo "access=rw"
return 0
fi
if [[ ! "$workspace" =~ ^[a-zA-Z0-9._-]+$ ]]; then
log "❌ Invalid container name: $WORKSPACE"
exit 1