#!/bin/sh

cd /turnenaufzeit/server

echo "export const SYSTEMname = '$SYSTEM_NAME';" > src/env.ts

echo "export const DBuser = '$DB_USER';" >> src/env.ts
echo "export const DBpwd = '$DB_PWD';" >> src/env.ts
echo "export const DBhost = '$DB_HOST';" >> src/env.ts
echo "export const DBport = $DB_PORT;" >> src/env.ts
echo "export const DBsource = '$DB_SOURCE';" >> src/env.ts
echo "export const DBdb = '$DB_DB';" >> src/env.ts

echo "export const MAILhost = '$MAIL_HOST';" >> src/env.ts
echo "export const MAILport = $MAIL_PORT;" >> src/env.ts
echo "export const MAILsecure = $MAIL_SECURE;" >> src/env.ts
echo "export const MAILuser = '$MAIL_USER';" >> src/env.ts
echo "export const MAILpwd = '$MAIL_PWD';" >> src/env.ts
echo "export const MAILaddress = '$MAIL_ADDRESS';" >> src/env.ts
echo "export const MAILname = '$MAIL_NAME';" >> src/env.ts

echo "export const SERVERport = $SERVER_PORT;" >> src/env.ts
echo "export const SERVERlisten = '$SERVER_LISTEN';" >> src/env.ts
echo "export const SERVERhost = '$SERVER_HOST';" >> src/env.ts

echo "export const ADMINmail = '$ADMIN_MAIL';" >> src/env.ts

if [ "$MAIL_HOST" = "" ] || [ "$MAIL_HOST" = "nomail" ]; then
  echo "no mail specified! exiting..."
  exit
fi

exec "$@"