pedalboard-scripts/bypass.sh

35 lines
928 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
[[ ! -f "./config.env" ]] && printf "error: file \'config.env\' does not exist\n" && exit 1
source "./config.env"
url="/bypass"
index="$1"
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 "sending POST request: \'$url\'...${FONT_BOLD}"
[ "$(curl -X POST -s -f -w "\n%{http_code}" "$url" | tail -n1)" -ne 200 ] && printf " error!\n" || printf " done!\n"