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

52 lines
2.4 KiB
Bash
Executable File

#!/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 <createdb.sql | lxc-attach -u 5432 -g 5432 sigmah-postgres -- psql
# Configure Sigmah
mkdir -p /srv/sigmah/sigmah_conf /srv/sigmah/sigmah_data/files /srv/sigmah/sigmah_data/archives
chown -R 108080:108080 /srv/sigmah/sigmah_data
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
lxchelper extract sigmah /srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/sigmah_data/files/logo.png
# Populate database
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())")
lxc-execute sigmah -- cat /srv/sigmah-MinimumDataKit.sql | lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
lxc-execute sigmah -- cat /srv/sigmah-newOrganizationLaunchScript.sql | \
sed -e "s|§OrganizationName§|Demo organization|g" \
-e "s|§OrganizationLogoFilename§|logo.png|g" \
-e "s|§HeadquartersCountryCode§|CZ|g" \
-e "s|§UserEmail§|${SIGMAH_ADMIN_EMAIL}|g" \
-e "s|§UserName§|${SIGMAH_ADMIN_USER}|g" \
-e "s|§UserFirstName§|${SIGMAH_ADMIN_USER}|g" \
-e "s|§UserLocale§|en|g" \
-e "s|\$2a\$10\$pMcTA1p9fefR8U9NoOPei.H0eq/TbbdSF27M0tn9iDWBrA4JHeCDC|${SIGMAH_ADMIN_HASH}|" \
| lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
# 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}"