nextload/docker-entrypoint.sh

53 lines
983 B
Bash
Raw Normal View History

2024-06-05 20:29:51 +00:00
#!/bin/bash
set -eu
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
2024-06-19 10:08:41 +00:00
urlencode() {
raw="$1"
encoded=""
length=$(echo -n "$raw" | wc -c)
i=0
while [ $i -lt $length ]; do
c=$(echo "$raw" | cut -c $((i + 1)))
case "$c" in
[a-zA-Z0-9.~_-]) encoded="$encoded$c" ;;
*) encoded="$encoded$(printf '%%%02X' "'$c")" ;;
esac
i=$((i + 1))
done
echo "$encoded"
}
2024-06-05 20:29:51 +00:00
file_env "TOKEN"
file_env "MONGODB_PASSWORD"
file_env "PAYLOAD_SECRET"
2024-06-19 10:08:41 +00:00
MONGODB_PASSWORD_ENCODED=$(urlencode "$MONGODB_PASSWORD")
export MONGODB_URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD_ENCODED@$MONGODB_HOST:$MONGODB_PORT"
2024-06-05 20:29:51 +00:00
"$@"