#!/bin/bash # tin machine list - List existing machine environments set -euo pipefail # Get tinsnip root and source libraries SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TINSNIP_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" source "$TINSNIP_ROOT/lib/core.sh" source "$TINSNIP_ROOT/lib/uid.sh" # List existing machine environments list_machines() { echo "Machine Environments" echo "===================" echo # Scan for service users in the system echo "Service Environment UID Status" echo "------- ----------- --- ------" local found_any=false local sheet=$(get_sheet) local sheet_num=$(get_sheet_number "$sheet" 2>/dev/null || echo "") if [[ -z "$sheet_num" ]]; then echo "Sheet '$sheet' not registered - cannot scan for machines" return 1 fi # Scan for users matching SMEP pattern for this sheet for service_num in {00..99}; do for env_num in {0..9}; do for port_num in 0; do # Only check base UID (port 0) local smep_uid="${sheet_num}${service_num}${env_num}${port_num}" if getent passwd "$smep_uid" >/dev/null 2>&1; then local username=$(getent passwd "$smep_uid" | cut -d: -f1) # Parse service and environment from username local parsed_output if parsed_output=$(parse_machine_name "$username" 2>/dev/null); then local service_name=$(echo "$parsed_output" | sed -n '1p') local env_name=$(echo "$parsed_output" | sed -n '2p') local status="Active" # Check if mount exists if mountpoint -q "/mnt/$username" 2>/dev/null; then status="Mounted" fi printf "%-24s %-12s %-6s %s\n" "$service_name" "$env_name" "$smep_uid" "$status" found_any=true fi fi done done done if [[ "$found_any" == "false" ]]; then echo "No machine environments found in sheet '$sheet'" echo "" echo "Create one with: tin machine create " fi } # Main execution list_machines