SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 906 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. set -e
  3.  
  4. POSTGRES_DB_HOST=${POSTGRES_DB_HOST:-$POSTGRES_PORT_5432_TCP_ADDR}
  5. POSTGRES_DB_PORT=${POSTGRES_DB_PORT:-$POSTGRES_PORT_5432_TCP_PORT}
  6. POSTGRES_DB_PORT=${POSTGRES_DB_PORT:-5432}
  7. POSTGRES_USER=${POSTGRES_USER:-dspace}
  8. POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-dspace}
  9. POSTGRES_SCHEMA=${POSTGRES_SCHEMA:-dspace}
  10. POSTGRES_ADMIN_USER=${POSTGRES_ADMIN_USER:-postgres}
  11. POSTGRES_ADMIN_PASSWORD=${POSTGRES_ADMIN_PASSWORD}
  12.  
  13. if [ -z $POSTGRES_DB_HOST -a -z $POSTGRES_DB_PORT ]; then
  14.   echo "Please create a postgres container and link it to this one:"
  15.   echo "> docker run -d --name dspace_db postgres"
  16.   echo "> docker run --link dspace_db:postgres -p 8080:8080 unixelias/docker-dspace setup-postgres"
  17.   exit 1
  18. fi
  19.  
  20. DSPACE_CFG=/dspace/config/local.cfg
  21. if [ -n $POSTGRES_ADMIN_PASSWORD ]; then
  22.   export PGPASSWORD=$POSTGRES_ADMIN_PASSWORD
  23. fi
  24.  
  25. # Create database if not exists
  26. SCHEMA_EXISTS=$(psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -U "$POSTGRES_ADMIN_USER" -lqt | cut -d \| -f 1 | grep -qw "$POSTGRES_SCHEMA";echo $?)
  27. if [ $SCHEMA_EXISTS -eq 1 ]; then
  28.   psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -d postgres -U "$POSTGRES_ADMIN_USER" -c "CREATE DATABASE $POSTGRES_SCHEMA;" 2>&1 > /dev/null
  29.   echo "Database '${POSTGRES_SCHEMA}' created"
  30. fi
  31.  
  32. # Install extension pgcrypto
  33. EXTENSION_EXISTS=$(psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -U "$POSTGRES_ADMIN_USER" -d dspace -c "SELECT extname FROM  pg_extension" | cut -d \| -f 3 | grep "pgcrypto" 2>&1 > /dev/null;echo $?)
  34. if [ "$EXTENSION_EXISTS" -eq 1 ]; then
  35.   psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -d dspace -U "$POSTGRES_ADMIN_USER" -c "CREATE EXTENSION pgcrypto;" 2>&1 > /dev/null
  36.   echo "Extension 'pgcrypto' installed on '${POSTGRES_SCHEMA}' database"
  37. fi
  38.  
  39. # Create user
  40. USER_EXISTS=$(psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -d postgres -U "$POSTGRES_ADMIN_USER" -c "SELECT 1 FROM pg_roles WHERE rolname='${POSTGRES_USER}';" | grep "1" 2>&1 > /dev/null; echo $?)
  41. if [ $USER_EXISTS -eq 1 ]; then
  42.   psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -d postgres -U "$POSTGRES_ADMIN_USER" -c "CREATE USER $POSTGRES_USER WITH LOGIN PASSWORD '$POSTGRES_PASSWORD';" 2>&1 > /dev/null
  43.   psql -h "$POSTGRES_DB_HOST" -p "$POSTGRES_DB_PORT" -d postgres -U "$POSTGRES_ADMIN_USER" -c "GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_SCHEMA to $POSTGRES_USER;" 2>&1 > /dev/null
  44.   echo "User '${POSTGRES_USER}' created"
  45. fi
  46.  
  47. # Configure database in dspace.cfg
  48. sed -i "s#db.url = jdbc:postgresql://postgres:5432/dspace#db.url = jdbc:postgresql://${POSTGRES_DB_HOST}:${POSTGRES_DB_PORT}/${POSTGRES_SCHEMA}#" ${DSPACE_CFG}
  49. sed -i "s#db.username = dspace#db.username = ${POSTGRES_USER}#" ${DSPACE_CFG}
  50. sed -i "s#db.password = dspace#db.password = ${POSTGRES_PASSWORD}#" ${DSPACE_CFG}
  51. echo "Dspace configuration changed"
  52.  
  53. # Create DSpace administrator
  54. # TODO - Marcelo custom - Não criar um administrador automaticamente
  55. #dspace create-administrator -e ${ADMIN_EMAIL:-admin@mail.com} -f ${ADMIN_FIRSTNAME:-DSpace} -l ${ADMIN_LASTNAME:-Admin} -p ${ADMIN_PASSWD:-admin123} -c ${ADMIN_LANGUAGE:-en}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top