#!/bin/sh set -ev # Create Postgres instance mkdir -p /srv/sigmah/postgres_data chown -R 105432:105432 /srv/sigmah/postgres_data chmod 700 /srv/sigmah/postgres_data lxc-execute -n sigmah-postgres -- initdb -D /var/lib/postgresql # Configure Postgres cp postgres_data/postgresql.conf /srv/sigmah/postgres_data/postgresql.conf cp postgres_data/pg_hba.conf /srv/sigmah/postgres_data/pg_hba.conf # Create database export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') service lxc-sigmah-postgres start envsubst /srv/sigmah/sigmah_conf/persistence.xml cp sigmah_conf/sigmah.properties /srv/sigmah/sigmah_conf/sigmah.properties chown -R 108080:108080 /srv/sigmah/sigmah_conf lxc-execute sigmah -- cat /srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png >/srv/sigmah/sigmah_data/files/logo.png # Populate database lxc-execute sigmah -- cat /srv/sigmah-MinimumDataKit.sql >/tmp/sigmah-MinimumDataKit.sql lxc-execute sigmah -- cat /srv/sigmah-newOrganizationLaunchScript.sql >/tmp/sigmah-newOrganizationLaunchScript.sql export SIGMAH_ADMIN_USER=Admin export SIGMAH_ADMIN_EMAIL=admin@example.com export SIGMAH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') export SIGMAH_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${SIGMAH_ADMIN_PWD}'.encode(), bcrypt.gensalt(prefix=b'2a')).decode())") sed -i "s|§OrganizationName§|Demo organization|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§OrganizationLogoFilename§|logo.png|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§HeadquartersCountryCode§|CZ|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§UserEmail§|${SIGMAH_ADMIN_EMAIL}|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§UserName§|${SIGMAH_ADMIN_USER}|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§UserFirstName§|${SIGMAH_ADMIN_USER}|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|§UserLocale§|en|g" /tmp/sigmah-newOrganizationLaunchScript.sql sed -i "s|\$2a\$10\$pMcTA1p9fefR8U9NoOPei.H0eq/TbbdSF27M0tn9iDWBrA4JHeCDC|${SIGMAH_ADMIN_HASH}|" /tmp/sigmah-newOrganizationLaunchScript.sql cat /tmp/sigmah-MinimumDataKit.sql | lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah" cat /tmp/sigmah-newOrganizationLaunchScript.sql | lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah" rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql # Install config update script cp update-conf.sh /srv/sigmah/update-conf.sh # Stop services required for setup service lxc-sigmah-postgres stop # Register application vmmgr register-app sigmah sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}" # TODO: SQL skripty jako soucast installu?