From cf552dbe41d3595981786fd6340cd8e7f7911fff Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 23 Sep 2024 07:41:48 +0200 Subject: [PATCH] Improve all.sh script --- all.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/all.sh b/all.sh index 1a9f3f9..ce4e9a8 100644 --- a/all.sh +++ b/all.sh @@ -1,23 +1,47 @@ #!/bin/sh + +log() { + # Echo the timestamp followed by the original message + echo "[$(date "+%Y-%m-%dT%H:%M:%S%z")][all] - $1" +} +# Function to execute the script execute_script() { script_path="https://elastic.github.io/kibana-demo-data/scripts/$1.sh" - curl "$script_path" | sh & + curl -fsSL "$script_path" | sh } +# Function to search for a string in the array of arguments +search_string_in_args() { + search=$1 + shift + for arg in "$@"; do + if [ "$arg" = "$search" ]; then + return 0 + fi + done + return 1 +} + +# available scripts scripts="custom o11y sample security makelogs" if [ $# -eq 0 ]; then + # execute all scripts + log "Executing all scripts" for script in $scripts; do execute_script "$script" done else + # execute scripts based on arguments for script in $scripts; do + if search_string_in_args "$script" "$@"; then + log "Executing $script" execute_script "$script" fi done fi -wait + log "Finished execution"