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
|
|
|
|
2018-10-26 15:02:11 +02:00
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
2017-12-04 21:08:04 +01:00
|
|
|
|
2018-01-23 21:27:18 +01:00
|
|
|
# Check prerequisites
|
2018-09-14 09:09:46 +02:00
|
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
2017-12-08 09:39:02 +01:00
|
|
|
|
2017-12-04 21:08:04 +01:00
|
|
|
# Create database
|
|
|
|
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
2017-12-04 21:08:04 +01:00
|
|
|
|
|
|
|
# Configure Sigmah
|
2018-01-26 21:25:03 +01:00
|
|
|
mkdir -p /srv/sigmah/conf /srv/sigmah/data/files /srv/sigmah/data/archives
|
2018-01-27 22:36:57 +01:00
|
|
|
chown -R 8011:8011 /srv/sigmah/data
|
2018-10-25 22:22:36 +02:00
|
|
|
envsubst <srv/sigmah/conf/persistence.xml >/srv/sigmah/conf/persistence.xml
|
|
|
|
cp srv/sigmah/conf/sigmah.properties /srv/sigmah/conf/sigmah.properties
|
2018-09-14 09:09:46 +02:00
|
|
|
cp /var/lib/lxc/sigmah/sigmah/srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/data/files/logo.png
|
2017-12-04 21:08:04 +01:00
|
|
|
|
|
|
|
# Populate database
|
|
|
|
wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-MinimumDataKit-2.0.postgresql.sql -O /tmp/sigmah-MinimumDataKit.sql
|
|
|
|
wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-newOrganizationLaunchScript-2.0.postgresql.sql -O /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)
|
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
|
2018-09-14 09:09:46 +02:00
|
|
|
cat /tmp/sigmah-MinimumDataKit.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
|
2018-09-14 18:13:11 +02:00
|
|
|
cat /tmp/sigmah-newOrganizationLaunchScript.sql | lxc-attach 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-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-14 09:09:46 +02:00
|
|
|
# Install service
|
2018-10-25 22:22:36 +02:00
|
|
|
cp etc/init.d/sigmah /etc/init.d/sigmah
|
2018-09-14 09:09:46 +02:00
|
|
|
rc-update -u
|
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2018-10-25 22:22:36 +02:00
|
|
|
cp srv/sigmah/update-conf.sh /srv/sigmah/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-07-15 21:55:35 +02:00
|
|
|
# Stop services required for build
|
2018-09-14 09:09:46 +02:00
|
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
|
|
|
exit 0
|