diff --git a/gosmee/templates/replay_script.tmpl.bash b/gosmee/templates/replay_script.tmpl.bash index e070b78..8813b45 100755 --- a/gosmee/templates/replay_script.tmpl.bash +++ b/gosmee/templates/replay_script.tmpl.bash @@ -1,14 +1,20 @@ -#!/bin/bash -# +#!/usr/bin/env bash +# Copyright 2023 Chmouel Boudjnah # Replay script with headers and JSON payload to the target controller. # -# You can switch the targetURL to another one with the -l switch, which defaults -# to http://localhost:8080. +# You can switch the targetURL with the first command line argument and you can +# the -l switch, which defaults to http://localhost:8080. +# Same goes for the variable GOSMEE_DEBUG_SERVICE. # -# You can customze this target with the env variable: GOSMEE_DEBUG_SERVICE -set -euxf +set -euxfo pipefail cd $(dirname $(readlink -f $0)) -targetURL="{{ .TargetURL }}" -[[ ${1:-""} == -l ]] && targetURL=${GOSMEE_DEBUG_SERVICE:-"http://localhost:8080"} +if [[ ${1:-""} == -l ]]; then + targetURL="http://localhost:8080" +elif [[ -n ${1:-""} ]]; then + targetURL=${1} +elif [[ -n ${GOSMEE_DEBUG_SERVICE:-""} ]]; then + targetURL=${GOSMEE_DEBUG_SERVICE} +fi + curl -sSi -H "Content-Type: {{ .ContentType }}" {{ .Headers }} -X POST -d @./{{ .FileBase }}.json ${targetURL}