diff --git a/Dockers/remote-laravel-container/entrypoint.sh b/Dockers/remote-laravel-container/entrypoint.sh index cd837b9..19945c0 100644 --- a/Dockers/remote-laravel-container/entrypoint.sh +++ b/Dockers/remote-laravel-container/entrypoint.sh @@ -92,6 +92,7 @@ CONFIG_FILE="/etc/teleport.yaml" # Edit the teleport.yaml file to update the nodename sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE" +# Function to add labels to teleport.yaml # Function to add labels to teleport.yaml add_teleport_labels() { if [ -n "$TELEPORT_LABELS" ]; then @@ -103,14 +104,12 @@ add_teleport_labels() { return 1 fi - # Remove any existing labels section - sed -i '/^ labels:/,/^[^[:space:]]/ { /^ labels:/d; /^[^[:space:]]/!d; }' "$CONFIG_FILE" + # Create a backup + cp "$CONFIG_FILE" "$CONFIG_FILE.backup" - # 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_line}a\\ labels:" "$CONFIG_FILE" + # Build the new ssh_service section + NEW_SSH_SECTION="ssh_service:" + NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" labels:" # Parse TELEPORT_LABELS and add each label IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS" @@ -124,7 +123,7 @@ add_teleport_labels() { value=$(echo "$label" | cut -d':' -f2- | xargs) if [ -n "$key" ] && [ -n "$value" ]; then - echo " $key: $value" >> "$CONFIG_FILE" + NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" $key: $value" echo "Added label: $key = $value" else echo "Warning: Invalid label format '$label'. Expected format: key:value" @@ -134,6 +133,36 @@ add_teleport_labels() { fi done + NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" enabled: \"yes\"" + + # Replace the ssh_service section + awk -v new_section="$NEW_SSH_SECTION" ' + BEGIN { + in_ssh_service = 0 + section_replaced = 0 + } + /^ssh_service:/ { + in_ssh_service = 1 + if (!section_replaced) { + print new_section + section_replaced = 1 + } + next + } + in_ssh_service && /^[a-zA-Z_][a-zA-Z0-9_]*:/ { + in_ssh_service = 0 + } + in_ssh_service { + next + } + { + print $0 + } + ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" + + # Replace the original file + mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" + echo "Teleport labels added successfully" else echo "No TELEPORT_LABELS environment variable set, skipping label configuration" diff --git a/Dockers/remote-laravel-container/version b/Dockers/remote-laravel-container/version index 389f774..8a36cd1 100644 --- a/Dockers/remote-laravel-container/version +++ b/Dockers/remote-laravel-container/version @@ -1 +1 @@ -4.0 \ No newline at end of file +4.1 \ No newline at end of file