diff --git a/Dockers/remote-laravel-container/entrypoint.sh b/Dockers/remote-laravel-container/entrypoint.sh index 590b3e5..cd837b9 100644 --- a/Dockers/remote-laravel-container/entrypoint.sh +++ b/Dockers/remote-laravel-container/entrypoint.sh @@ -103,15 +103,14 @@ add_teleport_labels() { return 1 fi - # Check if labels section already exists under ssh_service - if grep -q " labels:" "$CONFIG_FILE"; then - echo "Labels section already exists, updating..." - # Remove existing labels section - sed -i '/^ labels:/,/^[^ ]/ { /^ labels:/d; /^[^ ]/!d; }' "$CONFIG_FILE" - fi + # Remove any existing labels section + sed -i '/^ labels:/,/^[^[:space:]]/ { /^ labels:/d; /^[^[:space:]]/!d; }' "$CONFIG_FILE" + + # Find the line number of ssh_service and add labels after it + ssh_line=$(grep -n "^ssh_service:" "$CONFIG_FILE" | cut -d: -f1) # Add labels section after ssh_service - sed -i '/^ssh_service:/a\ labels:' "$CONFIG_FILE" + sed -i "${ssh_line}a\\ labels:" "$CONFIG_FILE" # Parse TELEPORT_LABELS and add each label IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"