2018-01-26 21:25:03 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-12-04 21:08:04 +01:00
|
|
|
|
2019-10-05 15:34:42 +02:00
|
|
|
# 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
|
2017-12-08 09:39:02 +01:00
|
|
|
|
2017-12-04 21:08:04 +01:00
|
|
|
# Create database
|
2019-06-05 18:55:15 +02:00
|
|
|
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-11-30 22:11:38 +01:00
|
|
|
service lxc-sigmah-postgres start
|
2019-10-05 15:34:42 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sigmah-postgres -- psql
|
2017-12-04 21:08:04 +01:00
|
|
|
|
|
|
|
# Configure Sigmah
|
2019-10-05 15:34:42 +02:00
|
|
|
mkdir -p /srv/sigmah/sigmah_conf /srv/sigmah/sigmah_data/files /srv/sigmah/sigmah_data/archives
|
2019-10-14 07:59:06 +02:00
|
|
|
chown -R 108080:108080 /srv/sigmah/sigmah_data
|
2019-10-05 15:34:42 +02:00
|
|
|
envsubst <sigmah_conf/persistence.xml >/srv/sigmah/sigmah_conf/persistence.xml
|
|
|
|
cp sigmah_conf/sigmah.properties /srv/sigmah/sigmah_conf/sigmah.properties
|
2019-10-14 07:59:06 +02:00
|
|
|
chown -R 108080:108080 /srv/sigmah/sigmah_conf
|
2019-10-05 15:34:42 +02:00
|
|
|
lxc-execute sigmah -- cat /srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png >/srv/sigmah/sigmah_data/files/logo.png
|
2017-12-04 21:08:04 +01:00
|
|
|
|
|
|
|
# Populate database
|
2019-10-05 15:34:42 +02:00
|
|
|
lxc-execute sigmah -- cat /srv/sigmah-MinimumDataKit.sql >/tmp/sigmah-MinimumDataKit.sql
|
|
|
|
lxc-execute sigmah -- cat /srv/sigmah-newOrganizationLaunchScript.sql >/tmp/sigmah-newOrganizationLaunchScript.sql
|
2017-12-04 21:08:04 +01:00
|
|
|
export SIGMAH_ADMIN_USER=Admin
|
|
|
|
export SIGMAH_ADMIN_EMAIL=admin@example.com
|
2019-06-05 18:55:15 +02:00
|
|
|
export SIGMAH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2018-09-16 17:19:13 +02:00
|
|
|
export SIGMAH_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${SIGMAH_ADMIN_PWD}'.encode(), bcrypt.gensalt(prefix=b'2a')).decode())")
|
2017-12-04 21:08:04 +01:00
|
|
|
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
|
2019-10-05 15:34:42 +02:00
|
|
|
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"
|
2018-01-26 21:25:03 +01:00
|
|
|
rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2019-10-05 15:34:42 +02:00
|
|
|
cp update-conf.sh /srv/sigmah/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2019-10-05 15:34:42 +02:00
|
|
|
# Stop services required for setup
|
2019-11-30 22:11:38 +01:00
|
|
|
service lxc-sigmah-postgres stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2019-02-26 21:12:41 +01:00
|
|
|
vmmgr register-app sigmah sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"
|
2019-10-05 15:34:42 +02:00
|
|
|
|
|
|
|
# TODO: SQL skripty jako soucast installu?
|