#!/bin/bash # tin machine status - Show machine environment status 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" # Show machine environment status show_machine_status() { local service_env="$1" # Parse service-environment local parsed_output if ! parsed_output=$(parse_machine_name "$service_env" 2>/dev/null); then error_with_prefix "Machine Status" "Invalid machine environment format: '$service_env'" echo "Expected: - (e.g., gazette-prod, bsky-pds-dev)" >&2 exit 1 fi local service=$(echo "$parsed_output" | sed -n '1p') local environment=$(echo "$parsed_output" | sed -n '2p') echo "Machine Environment Status: $service_env" echo "========================================" echo # Calculate UID and check user exists local service_uid if service_uid=$(calculate_service_uid "$service" "$environment" 2>/dev/null); then echo "Service: $service" echo "Environment: $environment" echo "UID: $service_uid" if getent passwd "$service_uid" >/dev/null 2>&1; then local username=$(getent passwd "$service_uid" | cut -d: -f1) echo "User: $username ✅" else echo "User: missing ❌" echo "Create with: tin machine create $service $environment" return 1 fi else error_with_prefix "Machine Status" "Cannot calculate UID for $service_env" return 1 fi # Check NFS mount local mount_point="/mnt/$service-$environment" echo "Mount: $mount_point" if mountpoint -q "$mount_point" 2>/dev/null; then echo " Status: mounted ✅" echo " Usage: $(df -h "$mount_point" | tail -1 | awk '{print $3 "/" $2 " (" $5 " used)"}')" else echo " Status: not mounted ❌" fi # Check Docker access if sudo -u "$service-$environment" docker version >/dev/null 2>&1; then echo "Docker: accessible ✅" else echo "Docker: not accessible ❌" fi echo echo "Environment variables:" if sudo -u "$service-$environment" bash -c 'source ~/.tinsnip-env-loader.sh 2>/dev/null && env | grep ^TIN_' 2>/dev/null; then echo " Environment: loaded ✅" else echo " Environment: not configured ❌" fi } # Main execution if [[ $# -eq 0 ]]; then error_with_prefix "Machine Status" "Service-environment required" echo "Usage: tin machine status " >&2 echo "Example: tin machine status gazette-prod" >&2 exit 1 fi service_env="$1" show_machine_status "$service_env"