pedalboard-scripts/url.sh

38 lines
801 B
Bash
Raw Normal View History

2022-03-25 15:16:17 +01:00
#!/usr/bin/env bash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
2022-03-25 16:18:43 +01:00
set -e
2022-03-25 15:16:17 +01:00
2022-03-25 16:18:43 +01:00
[[ -z "$1" ]] && printf "error: no endpoint given\n" && exit 1
url="$1"
[[ "$url" != "/"* ]] && url="/$url"
. "$(dirname $(realpath $0))/config.env"
index="$2"
2022-03-25 15:16:17 +01:00
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"
fi
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"
2022-03-25 16:18:43 +01:00
printf "$url"