Spotter-VM/lxc-apps/sigmah/install.sh

56 lines
2.9 KiB
Bash
Raw Normal View History

2018-01-26 21:25:03 +01:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
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
# 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
# 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
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
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
# 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
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 '+/=')
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
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
# Install config update script
2019-10-05 15:34:42 +02:00
cp update-conf.sh /srv/sigmah/update-conf.sh
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
# 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?