homelab infrastructure services
at main 68 lines 2.4 kB view raw
1#!/bin/bash 2# tin machine list - List existing machine environments 3 4set -euo pipefail 5 6# Get tinsnip root and source libraries 7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8TINSNIP_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" 9source "$TINSNIP_ROOT/lib/core.sh" 10source "$TINSNIP_ROOT/lib/uid.sh" 11 12# List existing machine environments 13list_machines() { 14 echo "Machine Environments" 15 echo "===================" 16 echo 17 18 # Scan for service users in the system 19 echo "Service Environment UID Status" 20 echo "------- ----------- --- ------" 21 22 local found_any=false 23 local sheet=$(get_sheet) 24 local sheet_num=$(get_sheet_number "$sheet" 2>/dev/null || echo "") 25 26 if [[ -z "$sheet_num" ]]; then 27 echo "Sheet '$sheet' not registered - cannot scan for machines" 28 return 1 29 fi 30 31 # Scan for users matching SMEP pattern for this sheet 32 for service_num in {00..99}; do 33 for env_num in {0..9}; do 34 for port_num in 0; do # Only check base UID (port 0) 35 local smep_uid="${sheet_num}${service_num}${env_num}${port_num}" 36 37 if getent passwd "$smep_uid" >/dev/null 2>&1; then 38 local username=$(getent passwd "$smep_uid" | cut -d: -f1) 39 40 # Parse service and environment from username 41 local parsed_output 42 if parsed_output=$(parse_machine_name "$username" 2>/dev/null); then 43 local service_name=$(echo "$parsed_output" | sed -n '1p') 44 local env_name=$(echo "$parsed_output" | sed -n '2p') 45 local status="Active" 46 47 # Check if mount exists 48 if mountpoint -q "/mnt/$username" 2>/dev/null; then 49 status="Mounted" 50 fi 51 52 printf "%-24s %-12s %-6s %s\n" "$service_name" "$env_name" "$smep_uid" "$status" 53 found_any=true 54 fi 55 fi 56 done 57 done 58 done 59 60 if [[ "$found_any" == "false" ]]; then 61 echo "No machine environments found in sheet '$sheet'" 62 echo "" 63 echo "Create one with: tin machine create <service> <environment>" 64 fi 65} 66 67# Main execution 68list_machines