<commit_before>#!/bin/bash
set -eo pipefail

# local variables
DEFAULT_PWD="<PASSWORD>"
DEFAULT_PWD_COMMENT="******"

# required variables
: ${GLOBAL_SECRET_KEY:=}

# optional variables
# global
: ${GLOBAL_DEFAULT_FROM_EMAIL:=<EMAIL>}
: ${GLOBAL_OWNER_CAN_MANAGE_CUSTOMER:=true}
# system logs
: ${LOGGING_ADMIN_EMAIL:=}
: ${LOGGING_LOG_LEVEL:=INFO}
# user logs
: ${EVENTS_LOGSERVER_HOST:=waldur-logs}
: ${EVENTS_LOGSERVER_PORT:=5959}
: ${EVENTS_LOG_LEVEL:=INFO}
# database
: ${POSTGRESQL_HOST:=waldur-db}
: ${POSTGRESQL_PORT:=5432}
: ${POSTGRESQL_NAME:=waldur}
: ${POSTGRESQL_USER:=waldur}
: ${POSTGRESQL_PASSWORD:=$DEFAULT_PWD}
# queue
: ${REDIS_HOST:=waldur-queue}
: ${REDIS_PORT:=6379}
: ${REDIS_PASSWORD:=$DEFAULT_PWD}
# uwsgi
: ${UWSGI_SOCKET:=":8000"}
# user / group ids
: ${WALDUR_UID:=984}
: ${WALDUR_GID:=984}


echo "INFO: Welcome to Waldur Mastermind!"

if ! id waldur 2> /dev/null > /dev/null; then
  # Create user and group if it does not exist yet
  echo "INFO: Creating user waldur ${WALDUR_UID}:${WALDUR_GID} "
  groupadd -g $WALDUR_GID waldur
  useradd --home /var/lib/waldur --shell /bin/sh --system --uid $WALDUR_UID --gid $WALDUR_GID waldur
fi

if [ -d "/etc/waldur" ]; then
  echo "INFO: Existing configuration directory detected at /etc/waldur"
  echo "INFO: Spawning $@"
  exec /usr/local/bin/tini -- "$@"
else
  echo "INFO: Creating new /etc/waldur folder structure"
  # Copy configuration files
  mkdir -p /etc/waldur/
  cp /etc/waldur-templates/celery.conf /etc/waldur/celery.conf
  cp /etc/waldur-templates/waldur/core.ini /etc/waldur/core.ini
  cp /etc/waldur-templates/uwsgi.ini /etc/waldur/uwsgi.ini

  # Create logging directory
  mkdir -p /var/log/waldur/
  chmod 750 /var/log/waldur/
  chown waldur:waldur /var/log/waldur/

  # Create media assets directory
  mkdir -p /var/lib/waldur/media/
  chmod 750 /var/lib/waldur/
  chown waldur:waldur /var/lib/waldur/

  # Copy SAML2 attributes
  mkdir -p /etc/waldur/saml2/
  cp -r /etc/waldur-templates/saml2/attribute-maps /etc/waldur/saml2/
  cp /etc/waldur-templates/saml2.conf.py.example /etc/waldur/saml2/
fi

if [ -d "/opnd" ]; then
  echo "INFO: Custom configuration directory mount detected as /opnd"
  echo "INFO: NB! Skipping ENV variables processing and using supplied configuration files!"
  echo "INFO: Linking /etc/waldur -> /opnd"
  rm -rf /etc/waldur
  ln -s /opnd /etc/waldur
else

  echo "INFO: Processing required ENV variables..."
  if [ -z "$GLOBAL_SECRET_KEY" ]; then

    echo "ERROR: Environment variable GLOBAL_SECRET_KEY is not defined! Aborting."
    echo "NOTE: "
  cat << EOF

  You can add docker run ENV variable with this random generated key like this:
    -e GLOBAL_SECRET_KEY='$( head -c32 /dev/urandom | base64 )'

  Alternatively you can generate secret_key by running the following command:
    echo \$( head -c32 /dev/urandom | base64 )

  WARNING: Changing secret_key with existing database is not supported!
EOF

    exit 1

  fi
  echo "INFO: Setting [global] secret_key"
  crudini --set /etc/waldur/core.ini global secret_key $GLOBAL_SECRET_KEY

  echo "INFO: Processing optional ENV variables..."
  echo "INFO: Setting [global] default_from_email = $GLOBAL_DEFAULT_FROM_EMAIL"
  crudini --set /etc/waldur/core.ini global default_from_email $GLOBAL_DEFAULT_FROM_EMAIL
  echo "INFO: Setting [global] owner_can_manage_customer = $GLOBAL_OWNER_CAN_MANAGE_CUSTOMER"
  crudini --set /etc/waldur/core.ini global owner_can_manage_customer $GLOBAL_OWNER_CAN_MANAGE_CUSTOMER

  if [ -n "$LOGGING_ADMIN_EMAIL" ]; then

    echo "INFO: Setting [logging] admin_email = $LOGGING_ADMIN_EMAIL"
    crudini --set /etc/waldur/core.ini logging admin_email $LOGGING_ADMIN_EMAIL

  fi
  echo "INFO: Setting [logging] log_level = $LOGGING_LOG_LEVEL"
  crudini --set /etc/waldur/core.ini logging log_level $LOGGING_LOG_LEVEL

  echo "INFO: Setting [events] logserver_host = $EVENTS_LOGSERVER_HOST"
  crudini --set /etc/waldur/core.ini events logserver_host $EVENTS_LOGSERVER_HOST
  echo "INFO: Setting [events] logserver_port = $EVENTS_LOGSERVER_PORT"
  crudini --set /etc/waldur/core.ini events logserver_port $EVENTS_LOGSERVER_PORT
  echo "INFO: Setting [events] log_level = $EVENTS_LOG_LEVEL"
  crudini --set /etc/waldur/core.ini events log_level $EVENTS_LOG_LEVEL

  echo "INFO: Setting [postgresql] host = $POSTGRESQL_HOST"
  crudini --set /etc/waldur/core.ini postgresql host $POSTGRESQL_HOST
  echo "INFO: Setting [postgresql] port = $POSTGRESQL_PORT"
  crudini --set /etc/waldur/core.ini postgresql port $POSTGRESQL_PORT
  echo "INFO: Setting [postgresql] name = $POSTGRESQL_NAME"
  crudini --set /etc/waldur/core.ini postgresql name $POSTGRESQL_NAME
  echo "INFO: Setting [postgresql] user = $POSTGRESQL_USER"
  crudini --set /etc/waldur/core.ini postgresql user $POSTGRESQL_USER
  if [ "$POSTGRESQL_PASSWORD" == "$DEFAULT_PWD" ]; then

    DEFAULT_PWD_COMMENT="(default: $DEFAULT_PWD)"

  fi
  echo "INFO: Setting [postgresql] password $DEFAULT_PWD_COMMENT"
  crudini --set /etc/waldur/core.ini postgresql password $POSTGRESQL_PASSWORD

  echo "INFO: Setting [redis] host = $REDIS_HOST"
  crudini --set /etc/waldur/core.ini redis host $REDIS_HOST
  echo "INFO: Setting [redis] port = $REDIS_PORT"
  crudini --set /etc/waldur/core.ini redis port $REDIS_PORT
  echo "INFO: Setting [redis] password = $<PASSWORD>"
  crudini --set /etc/waldur/core.ini redis password $REDIS_PASSWORD

  echo "INFO: Setting [uwsgi] socket = $UWSGI_SOCKET"
  crudini --set /etc/waldur/uwsgi.ini uwsgi socket $UWSGI_SOCKET

  echo "INFO: Disabling log files"
  crudini --set /etc/waldur/core.ini logging log_file
  crudini --set /etc/waldur/core.ini events log_file
  crudini --del /etc/waldur/uwsgi.ini uwsgi logto

fi

echo "INFO: Spawning $@"
exec /usr/local/bin/tini -- "$@"
<commit_msg>Create waldur group if it does not exist yet.<commit_after>#!/bin/bash
set -eo pipefail

# local variables
DEFAULT_PWD="<PASSWORD>"
DEFAULT_PWD_COMMENT="******"

# required variables
: ${GLOBAL_SECRET_KEY:=}

# optional variables
# global
: ${GLOBAL_DEFAULT_FROM_EMAIL:=<EMAIL>}
: ${GLOBAL_OWNER_CAN_MANAGE_CUSTOMER:=true}
# system logs
: ${LOGGING_ADMIN_EMAIL:=}
: ${LOGGING_LOG_LEVEL:=INFO}
# user logs
: ${EVENTS_LOGSERVER_HOST:=waldur-logs}
: ${EVENTS_LOGSERVER_PORT:=5959}
: ${EVENTS_LOG_LEVEL:=INFO}
# database
: ${POSTGRESQL_HOST:=waldur-db}
: ${POSTGRESQL_PORT:=5432}
: ${POSTGRESQL_NAME:=waldur}
: ${POSTGRESQL_USER:=waldur}
: ${POSTGRESQL_PASSWORD:=$DEFAULT_PWD}
# queue
: ${REDIS_HOST:=waldur-queue}
: ${REDIS_PORT:=6379}
: ${REDIS_PASSWORD:=$DEFAULT_PWD}
# uwsgi
: ${UWSGI_SOCKET:=":8000"}
# user / group ids
: ${WALDUR_UID:=984}
: ${WALDUR_GID:=984}


echo "INFO: Welcome to Waldur Mastermind!"

/usr/bin/getent group waldur 2>&1 > /dev/null || /usr/sbin/groupadd -g $WALDUR_GID waldur

if ! id waldur 2> /dev/null > /dev/null; then
  # Create user and group if it does not exist yet
  echo "INFO: Creating user waldur ${WALDUR_UID}:${WALDUR_GID} "
  useradd --home /var/lib/waldur --shell /bin/sh --system --uid $WALDUR_UID --gid $WALDUR_GID waldur
fi

if [ -d "/etc/waldur" ]; then
  echo "INFO: Existing configuration directory detected at /etc/waldur"
  echo "INFO: Spawning $@"
  exec /usr/local/bin/tini -- "$@"
else
  echo "INFO: Creating new /etc/waldur folder structure"
  # Copy configuration files
  mkdir -p /etc/waldur/
  cp /etc/waldur-templates/celery.conf /etc/waldur/celery.conf
  cp /etc/waldur-templates/waldur/core.ini /etc/waldur/core.ini
  cp /etc/waldur-templates/uwsgi.ini /etc/waldur/uwsgi.ini

  # Create logging directory
  mkdir -p /var/log/waldur/
  chmod 750 /var/log/waldur/
  chown waldur:waldur /var/log/waldur/

  # Create media assets directory
  mkdir -p /var/lib/waldur/media/
  chmod 750 /var/lib/waldur/
  chown waldur:waldur /var/lib/waldur/

  # Copy SAML2 attributes
  mkdir -p /etc/waldur/saml2/
  cp -r /etc/waldur-templates/saml2/attribute-maps /etc/waldur/saml2/
  cp /etc/waldur-templates/saml2.conf.py.example /etc/waldur/saml2/
fi

if [ -d "/opnd" ]; then
  echo "INFO: Custom configuration directory mount detected as /opnd"
  echo "INFO: NB! Skipping ENV variables processing and using supplied configuration files!"
  echo "INFO: Linking /etc/waldur -> /opnd"
  rm -rf /etc/waldur
  ln -s /opnd /etc/waldur
else

  echo "INFO: Processing required ENV variables..."
  if [ -z "$GLOBAL_SECRET_KEY" ]; then

    echo "ERROR: Environment variable GLOBAL_SECRET_KEY is not defined! Aborting."
    echo "NOTE: "
  cat << EOF

  You can add docker run ENV variable with this random generated key like this:
    -e GLOBAL_SECRET_KEY='$( head -c32 /dev/urandom | base64 )'

  Alternatively you can generate secret_key by running the following command:
    echo \$( head -c32 /dev/urandom | base64 )

  WARNING: Changing secret_key with existing database is not supported!
EOF

    exit 1

  fi
  echo "INFO: Setting [global] secret_key"
  crudini --set /etc/waldur/core.ini global secret_key $GLOBAL_SECRET_KEY

  echo "INFO: Processing optional ENV variables..."
  echo "INFO: Setting [global] default_from_email = $GLOBAL_DEFAULT_FROM_EMAIL"
  crudini --set /etc/waldur/core.ini global default_from_email $GLOBAL_DEFAULT_FROM_EMAIL
  echo "INFO: Setting [global] owner_can_manage_customer = $GLOBAL_OWNER_CAN_MANAGE_CUSTOMER"
  crudini --set /etc/waldur/core.ini global owner_can_manage_customer $GLOBAL_OWNER_CAN_MANAGE_CUSTOMER

  if [ -n "$LOGGING_ADMIN_EMAIL" ]; then

    echo "INFO: Setting [logging] admin_email = $LOGGING_ADMIN_EMAIL"
    crudini --set /etc/waldur/core.ini logging admin_email $LOGGING_ADMIN_EMAIL

  fi
  echo "INFO: Setting [logging] log_level = $LOGGING_LOG_LEVEL"
  crudini --set /etc/waldur/core.ini logging log_level $LOGGING_LOG_LEVEL

  echo "INFO: Setting [events] logserver_host = $EVENTS_LOGSERVER_HOST"
  crudini --set /etc/waldur/core.ini events logserver_host $EVENTS_LOGSERVER_HOST
  echo "INFO: Setting [events] logserver_port = $EVENTS_LOGSERVER_PORT"
  crudini --set /etc/waldur/core.ini events logserver_port $EVENTS_LOGSERVER_PORT
  echo "INFO: Setting [events] log_level = $EVENTS_LOG_LEVEL"
  crudini --set /etc/waldur/core.ini events log_level $EVENTS_LOG_LEVEL

  echo "INFO: Setting [postgresql] host = $POSTGRESQL_HOST"
  crudini --set /etc/waldur/core.ini postgresql host $POSTGRESQL_HOST
  echo "INFO: Setting [postgresql] port = $POSTGRESQL_PORT"
  crudini --set /etc/waldur/core.ini postgresql port $POSTGRESQL_PORT
  echo "INFO: Setting [postgresql] name = $POSTGRESQL_NAME"
  crudini --set /etc/waldur/core.ini postgresql name $POSTGRESQL_NAME
  echo "INFO: Setting [postgresql] user = $POSTGRESQL_USER"
  crudini --set /etc/waldur/core.ini postgresql user $POSTGRESQL_USER
  if [ "$POSTGRESQL_PASSWORD" == "$DEFAULT_PWD" ]; then

    DEFAULT_PWD_COMMENT="(default: $DEFAULT_PWD)"

  fi
  echo "INFO: Setting [postgresql] password $DEFAULT_PWD_COMMENT"
  crudini --set /etc/waldur/core.ini postgresql password $POSTGRESQL_PASSWORD

  echo "INFO: Setting [redis] host = $REDIS_HOST"
  crudini --set /etc/waldur/core.ini redis host $REDIS_HOST
  echo "INFO: Setting [redis] port = $REDIS_PORT"
  crudini --set /etc/waldur/core.ini redis port $REDIS_PORT
  echo "INFO: Setting [redis] password = $REDIS_PASSWORD"
  crudini --set /etc/waldur/core.ini redis password $REDIS_PASSWORD

  echo "INFO: Setting [uwsgi] socket = $UWSGI_SOCKET"
  crudini --set /etc/waldur/uwsgi.ini uwsgi socket $UWSGI_SOCKET

  echo "INFO: Disabling log files"
  crudini --set /etc/waldur/core.ini logging log_file
  crudini --set /etc/waldur/core.ini events log_file
  crudini --del /etc/waldur/uwsgi.ini uwsgi logto

fi

echo "INFO: Spawning $@"
exec /usr/local/bin/tini -- "$@"

{'fraction_non_alphanumeric': 0.12212298179319821, 'fraction_numerical': 0.007729302645139127, 'mean_word_length': 4.226660682226212, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055155', 'n_tokens_mistral': 4518, 'n_tokens_neox': 4383, 'n_words': 1057}