38 lines
No EOL
801 B
Bash
Executable file
38 lines
No EOL
801 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# author: Daniel Sommer <daniel.sommer@velvettear.de>
|
|
# license: MIT
|
|
|
|
set -e
|
|
|
|
[[ -z "$1" ]] && printf "error: 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"
|
|
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"
|
|
|
|
printf "$url" |