diff --git a/update-setup.sh b/update-setup.sh index 1ecfc80..2b93715 100755 --- a/update-setup.sh +++ b/update-setup.sh @@ -623,85 +623,69 @@ list_services() { return 1 fi - # Show a warning if we're not creating a backup for this operation echo -e "${BLUE}Checking services in $COMPOSE_FILE...${NC}" echo -e "${CYAN}SERVICE\t\tAUTH STATUS${NC}" echo -e "${CYAN}-------\t\t-----------${NC}" local service_count=0 - # Use yq if available for more reliable parsing - if command -v yq &> /dev/null; then - # Get all services from the docker-compose.yml file - local services=$(yq e '.services | keys | .[]' "$COMPOSE_FILE" 2>/dev/null) + # Get all router names from the labels + # This pattern is specific to how your docker-compose.yml format works + local router_lines=$(grep -n "traefik.http.routers" "$COMPOSE_FILE") + + # Process each router line to get service names + while IFS= read -r line; do + local line_num=$(echo "$line" | cut -d: -f1) + local router_config=$(echo "$line" | cut -d: -f2-) - for service in $services; do + # Extract service name from router definition + if [[ "$router_config" =~ traefik\.http\.routers\.([^.]+) ]]; then + local service="${BASH_REMATCH[1]}" + # Skip infrastructure containers if [[ "$service" == "redis" || "$service" == "authelia" || "$service" == "traefik" || "$service" == "tailscale" || "$service" == "watchtower" || "$service" == "autoheal" || "$service" == "middlewares" ]]; then continue fi - # Check if this service has Traefik router configured - local has_router=$(yq e ".services.$service.labels[] | select(contains(\"traefik.http.routers.$service\"))" "$COMPOSE_FILE" 2>/dev/null) - if [ -n "$has_router" ]; then - local status=$(get_auth_status "$service") - - # Format the output with padding - printf "${BOLD}%-20s${NC}" "$service" - - case "$status" in - "enabled") - echo -e "${GREEN}Enabled${NC}" - service_count=$((service_count + 1)) - ;; - "disabled") - echo -e "${YELLOW}Disabled${NC}" - service_count=$((service_count + 1)) - ;; - *) - echo -e "${RED}Unknown${NC}" - ;; - esac - fi - done - else - # Fallback to using grep for parsing (less reliable) - # First identify all container names - local services=$(grep "container_name:" "$COMPOSE_FILE" | awk '{print $3}') - - for service in $services; do - # Skip infrastructure containers - if [[ "$service" == "redis" || "$service" == "authelia" || "$service" == "traefik" || "$service" == "tailscale" || "$service" == "watchtower" || "$service" == "autoheal" || "$service" == "middlewares" ]]; then + # Skip duplicate entries - only handle each service once + if [[ "$processed_services" == *"$service"* ]]; then continue fi + processed_services="$processed_services $service" - # Look specifically for router configuration for this service - if grep -q "traefik.http.routers.$service" "$COMPOSE_FILE"; then - local status=$(get_auth_status "$service") - - printf "${BOLD}%-20s${NC}" "$service" - - case "$status" in - "enabled") - echo -e "${GREEN}Enabled${NC}" - service_count=$((service_count + 1)) - ;; - "disabled") - echo -e "${YELLOW}Disabled${NC}" - service_count=$((service_count + 1)) - ;; - *) - echo -e "${RED}Unknown${NC}" - ;; - esac + # Find if this router has a middlewares configuration, with or without authelia + local status="unknown" + # Look for middlewares for this service + if grep -q "traefik.http.routers.$service.middlewares=.*authelia-auth" "$COMPOSE_FILE"; then + status="enabled" + elif grep -q "traefik.http.routers.$service.middlewares=" "$COMPOSE_FILE"; then + # Has middlewares but no authelia-auth + if ! grep -q "traefik.http.routers.$service.middlewares=.*authelia-auth" "$COMPOSE_FILE"; then + status="disabled" + fi fi - done - fi + + printf "${BOLD}%-20s${NC}" "$service" + + case "$status" in + "enabled") + echo -e "${GREEN}Enabled${NC}" + service_count=$((service_count + 1)) + ;; + "disabled") + echo -e "${YELLOW}Disabled${NC}" + service_count=$((service_count + 1)) + ;; + *) + echo -e "${RED}Unknown${NC}" + ;; + esac + fi + done <<< "$router_lines" if [ $service_count -eq 0 ]; then echo -e "${YELLOW}No services found with authentication status.${NC}" - echo -e "${YELLOW}This could indicate that no services are configured with Traefik routers,${NC}" - echo -e "${YELLOW}or that the compose file has an unexpected structure.${NC}" + echo -e "${YELLOW}This could indicate an issue with detecting middlewares in your docker-compose.yml.${NC}" fi }