From c149d8bf3a23564a19f5033f9a999a58952d7f20 Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Fri, 1 Dec 2023 10:49:22 +0100 Subject: [PATCH] Customize the shell script a bit more Add a shbang using env Let override directly the url on argument if set Still handle -l and GOSMEE_DEBUG_SERVICE --- gosmee/templates/replay_script.tmpl.bash | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) 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}