homelab infrastructure services

Fix ordering issue: auto-assign service numbers for unknown services

+33 -6
+1 -1
install.sh
··· 7 7 REPO_URL="https://tangled.sh/dynamicalsystem.com/tinsnip" 8 8 BRANCH="main" 9 9 INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/opt/dynamicalsystem.tinsnip}" 10 - INSTALLER_VERSION="abdaf40" # Updated automatically on commit 10 + INSTALLER_VERSION="7d4e872" # Updated automatically on commit 11 11 12 12 # Service repository options 13 13 SERVICE_REPO_URL="${SERVICE_REPO_URL:-}"
+32 -5
machine/scripts/lib.sh
··· 39 39 } 40 40 } 41 41 42 + # Find the next available service number from a registry file 43 + find_next_service_number() { 44 + local registry_path="$1" 45 + 46 + if [[ ! -f "$registry_path" ]]; then 47 + echo "1" 48 + return 49 + fi 50 + 51 + # Extract all service numbers from registry, find the highest 52 + local max_num=0 53 + while IFS='=' read -r service_name service_num; do 54 + # Skip comments and empty lines 55 + [[ "$service_name" =~ ^#.*$ ]] || [[ -z "$service_name" ]] && continue 56 + 57 + if [[ "$service_num" =~ ^[0-9]+$ ]] && [[ "$service_num" -gt "$max_num" ]]; then 58 + max_num="$service_num" 59 + fi 60 + done < "$registry_path" 61 + 62 + # Return next available number (max + 1) 63 + echo $((max_num + 1)) 64 + } 65 + 42 66 # Calculate service UID using TNSEP convention 43 67 # T=1 (Docker), N=namespace number, S=service, E=environment, P=0 44 68 calculate_service_uid() { ··· 67 91 if [[ -f "$registry_path" ]]; then 68 92 service_num=$(grep "^${service_name}=" "$registry_path" | cut -d= -f2) 69 93 if [[ -z "$service_num" ]]; then 70 - echo "ERROR: Service '$service_name' not found in registry at $registry_path" >&2 71 - return 1 94 + # Service not in registry - auto-assign next available number 95 + service_num=$(find_next_service_number "$registry_path") 96 + warn_with_prefix "UID Calculation" "Service '$service_name' not in registry, auto-assigning service number $service_num" 72 97 fi 73 98 else 74 - # Fallback to hardcoded values if registry doesn't exist 99 + # Registry doesn't exist - use fallback mapping or auto-assign 75 100 case "$service_name" in 76 101 gazette) service_num=1 ;; 77 102 lldap) service_num=2 ;; 103 + gateway) service_num=3 ;; 78 104 *) 79 - echo "ERROR: Unknown service: $service_name (no registry found at $registry_path)" >&2 80 - return 1 105 + # Auto-assign starting from service number 4 106 + service_num=4 107 + warn_with_prefix "UID Calculation" "No registry found, auto-assigning service number $service_num for '$service_name'" 81 108 ;; 82 109 esac 83 110 fi