2018-01-24 15:18:55 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2017-10-26 22:50:04 +02:00
|
|
|
|
2018-09-14 09:43:54 +02:00
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
2017-10-26 22:50:04 +02:00
|
|
|
|
2018-01-24 15:18:55 +01:00
|
|
|
# Check prerequisites
|
2018-09-14 09:43:54 +02:00
|
|
|
[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1
|
2017-10-26 22:50:04 +02:00
|
|
|
|
|
|
|
# Create database
|
|
|
|
export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64)
|
2018-09-14 09:43:54 +02:00
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach mariadb -- mysql
|
2017-10-26 22:50:04 +02:00
|
|
|
|
|
|
|
# Configure Ushahidi
|
2018-02-02 20:16:26 +01:00
|
|
|
mkdir -p /srv/ushahidi/conf /srv/ushahidi/data
|
|
|
|
chown 8014:8014 /srv/ushahidi/data
|
2018-01-27 14:35:16 +01:00
|
|
|
envsubst <${SOURCE_DIR}/srv/ushahidi/conf/env >/srv/ushahidi/conf/env
|
2018-02-20 20:57:04 +01:00
|
|
|
cp ${SOURCE_DIR}/srv/ushahidi/conf/config.json /srv/ushahidi/conf/config.json
|
2017-10-26 22:50:04 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-09-14 09:43:54 +02:00
|
|
|
lxc-execute ushahidi -- /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahidi/platform/application/phinx.php
|
2017-10-26 22:50:04 +02:00
|
|
|
|
|
|
|
# Create admin account
|
|
|
|
export USHAHIDI_ADMIN_USER=admin@example.com
|
|
|
|
export USHAHIDI_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-09-14 09:43:54 +02:00
|
|
|
#TODO: python-bcrypt
|
|
|
|
export USHAHIDI_ADMIN_HASH=$(lxc-execute ushahidi -- php -r "echo password_hash('${USHAHIDI_ADMIN_PWD}', PASSWORD_BCRYPT);")
|
|
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach mariadb -- mysql ushahidi
|
2018-09-04 21:42:26 +02:00
|
|
|
vmmgr update-login ushahidi "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"
|
2017-10-26 22:50:04 +02:00
|
|
|
|
2018-09-14 09:43:54 +02:00
|
|
|
# Install service
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi
|
|
|
|
rc-update -u
|
|
|
|
|
2017-10-26 22:50:04 +02:00
|
|
|
# Install cron job
|
2018-01-24 15:18:55 +01:00
|
|
|
cp ${SOURCE_DIR}/etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi
|
2018-07-15 21:55:35 +02:00
|
|
|
|
|
|
|
# Stop services required for build
|
2018-09-14 09:43:54 +02:00
|
|
|
[ ! -z ${STOP_MARIADB} ] && service mariadb stop
|