53 lines
983 B
Bash
Executable File
53 lines
983 B
Bash
Executable File
#!/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"
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
file_env "TOKEN"
|
|
file_env "MONGODB_PASSWORD"
|
|
file_env "PAYLOAD_SECRET"
|
|
|
|
MONGODB_PASSWORD_ENCODED=$(urlencode "$MONGODB_PASSWORD")
|
|
|
|
export MONGODB_URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD_ENCODED@$MONGODB_HOST:$MONGODB_PORT"
|
|
|
|
"$@"
|