From 50b4ecf44bd727a5db4daa7f4d75ca962a87a6cb Mon Sep 17 00:00:00 2001 From: velvettear Date: Wed, 30 Mar 2022 15:33:31 +0200 Subject: [PATCH] updated scripts --- config.env | 10 +++++----- toggle-jack-capture.sh => toggle-systemd.sh | 4 ++-- url.sh | 16 +++++----------- 3 files changed, 12 insertions(+), 18 deletions(-) rename toggle-jack-capture.sh => toggle-systemd.sh (86%) diff --git a/config.env b/config.env index ea00ea3..3db7441 100644 --- a/config.env +++ b/config.env @@ -1,8 +1,8 @@ export TERM=xterm -FONT_BOLD=$(tput bold) -FONT_NORMAL=$(tput sgr0) +export FONT_BOLD=$(tput bold) +export FONT_NORMAL=$(tput sgr0) -PBC_PROTOCOL="http" -PBC_HOST="192.168.1.24" -PBC_PORT="3000" \ No newline at end of file +export PBC_PROTOCOL="http" +export PBC_HOST="192.168.1.24" +export PBC_PORT="3000" \ No newline at end of file diff --git a/toggle-jack-capture.sh b/toggle-systemd.sh similarity index 86% rename from toggle-jack-capture.sh rename to toggle-systemd.sh index 49eb571..7dfb51f 100755 --- a/toggle-jack-capture.sh +++ b/toggle-systemd.sh @@ -9,7 +9,7 @@ dir="$(dirname $(realpath "$0"))" . "$dir/config.env" -url="$(""$dir"/url.sh" "/systemd/jack-capture")" +url="$(""$dir"/url.sh" "/systemd" "$1")" printf "> sending POST request to \'$url\'...${FONT_BOLD}" -[ "$(curl -X POST -s -f -w "\n%{http_code}" "$url" -d "state=toggle" | tail -n1)" -ne 200 ] && printf " error!\n" || printf " done!\n" \ No newline at end of file +[ "$(curl -X POST -s -f -w "\n%{http_code}" "$url" -d "state=toggle" | tail -n1)" -ne 200 ] && printf " error!\n" || printf " done!\n" diff --git a/url.sh b/url.sh index 9d5612c..ae39051 100755 --- a/url.sh +++ b/url.sh @@ -5,21 +5,15 @@ set -e -[[ -z "$1" ]] && printf "error: no endpoint given\n" && exit 1 +[[ -z "$1" ]] && printf "${FONT_BOLD}error:${FONT_NORMAL} no endpoint given\n" && exit 1 url="$1" [[ "$url" != "/"* ]] && url="/$url" -. "$(dirname $(realpath $0))/config.env" - -index="$2" -if [[ "$index" ]] && [ "$index" -eq "$index" ] 2> /dev/null; then - if [ "$index" -lt 0 ]; then - index=0 - elif [ "$index" -gt 7 ]; then - index=7 - fi - url="$url/$index" +if [[ "$2" ]]; then + index="$2" + [[ "$index" != "/"* ]] && index="/$index" fi +url="$url$index" function checkVariable() { [[ "$1" ]] && return 0