pedalboard-scripts/url.sh
2022-03-30 15:33:31 +02:00

32 lines
No EOL
679 B
Bash
Executable file

#!/usr/bin/env bash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
set -e
[[ -z "$1" ]] && printf "${FONT_BOLD}error:${FONT_NORMAL} no endpoint given\n" && exit 1
url="$1"
[[ "$url" != "/"* ]] && url="/$url"
if [[ "$2" ]]; then
index="$2"
[[ "$index" != "/"* ]] && index="/$index"
fi
url="$url$index"
function checkVariable() {
[[ "$1" ]] && return 0
printf "error: variable"
[[ "$2" ]] && printf " \'$2\'"
printf " is not set\n"
exit 1
}
checkVariable "$PBC_PROTOCOL" "PBC_PROTOCOL"
checkVariable "$PBC_HOST" "PBC_HOST"
checkVariable "$PBC_PORT" "PBC_PORT"
url="$PBC_PROTOCOL://$PBC_HOST:$PBC_PORT$url"
printf "$url"