Push-Message-Randomizer/entrypoint.sh
2024-10-09 00:59:29 +02:00

14 lines
336 B
Bash

#!/bin/bash
MESSAGE_FILE="/messages.yaml"
OUTPUT_FILE=${OUTPUT_FILE:-"message.txt"}
NUM_MESSAGES=$(yq eval '.messages | length' "$MESSAGE_FILE")
RANDOM_INDEX=$(( RANDOM % NUM_MESSAGES ))
MESSAGE=$(yq eval ".messages[$RANDOM_INDEX]" "$MESSAGE_FILE")
echo "$MESSAGE" > "$OUTPUT_FILE"
echo "Selected message written to $OUTPUT_FILE"