51 lines
2.7 KiB
Bash
Executable File
51 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ev
|
|
|
|
cd $(realpath $(dirname "${0}"))/install
|
|
|
|
# Check prerequisites
|
|
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
|
|
|
|
# Create database
|
|
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
|
|
|
|
# Configure Sigmah
|
|
mkdir -p /srv/sigmah/conf /srv/sigmah/data/files /srv/sigmah/data/archives
|
|
chown -R 8011:8011 /srv/sigmah/data
|
|
envsubst <srv/sigmah/conf/persistence.xml >/srv/sigmah/conf/persistence.xml
|
|
cp srv/sigmah/conf/sigmah.properties /srv/sigmah/conf/sigmah.properties
|
|
cp /var/lib/lxc/sigmah/sigmah/srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/data/files/logo.png
|
|
|
|
# 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)
|
|
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 postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
|
|
cat /tmp/sigmah-newOrganizationLaunchScript.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
|
|
rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql
|
|
|
|
# Install service
|
|
cp etc/init.d/sigmah /etc/init.d/sigmah
|
|
rc-update -u
|
|
|
|
# Install config update script
|
|
cp srv/sigmah/update-conf.sh /srv/sigmah/update-conf.sh
|
|
|
|
# Stop services required for build
|
|
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
|
|
|
|
# Register application
|
|
vmmgr register-app sigmah sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"
|