Spotter-VM/sigmah.sh

56 lines
3.0 KiB
Bash
Raw Normal View History

2018-01-26 21:25:03 +01:00
#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/sigmah
# Check prerequisites
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
2018-02-03 15:17:11 +01:00
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
2018-01-26 21:58:29 +01:00
docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh
2018-01-26 21:25:03 +01:00
# Build Docker container
docker build -t sigmah ${SOURCE_DIR}
2017-12-08 09:39:02 +01:00
# Create database
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64)
2018-01-26 21:25:03 +01:00
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
# 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-01-26 21:25:03 +01:00
envsubst <${SOURCE_DIR}/srv/sigmah/conf/persistence.xml >/srv/sigmah/conf/persistence.xml
cp ${SOURCE_DIR}/srv/sigmah/conf/sigmah.properties /srv/sigmah/conf/sigmah.properties
docker run --rm -v /srv/sigmah/data:/srv/sigmah/data sigmah cp /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)
2018-01-26 21:25:03 +01:00
apk --no-cache add apache2-utils
export SIGMAH_ADMIN_HASH=$(htpasswd -bnBC 10 "" ${SIGMAH_ADMIN_PWD} | tr -d ':\n' | sed 's/$2y/$2a/')
apk --no-cache del apache2-utils
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-01-26 21:25:03 +01:00
cat /tmp/sigmah-MinimumDataKit.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah
cat /tmp/sigmah-newOrganizationLaunchScript.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah
rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql
2018-01-26 21:25:03 +01:00
# Create Sigmah service
cp ${SOURCE_DIR}/etc/init.d/sigmah /etc/init.d/sigmah
rc-update add sigmah boot
service sigmah start
2018-01-26 21:25:03 +01:00
# Create nginx app definition
cp ${SOURCE_DIR}/etc/nginx/conf.d/sigmah.conf /etc/nginx/conf.d/sigmah.conf
service nginx reload
# Add portal application definition
2018-01-27 22:36:57 +01:00
portal-app-manager sigmah "https://{host}:8411/sigmah/" "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"