41 lines
1.5 KiB
Bash
Executable File
41 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
|
|
|
|
# Check prerequisites
|
|
[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1
|
|
|
|
# Create database
|
|
export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64)
|
|
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach mariadb -- mysql
|
|
|
|
# Configure Ushahidi
|
|
mkdir -p /srv/ushahidi/conf /srv/ushahidi/data
|
|
chown 8014:8014 /srv/ushahidi/data
|
|
envsubst <${SOURCE_DIR}/srv/ushahidi/conf/env >/srv/ushahidi/conf/env
|
|
cp ${SOURCE_DIR}/srv/ushahidi/conf/config.json /srv/ushahidi/conf/config.json
|
|
|
|
# Populate database
|
|
lxc-execute ushahidi -- /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahidi/platform/application/phinx.php
|
|
|
|
# Create admin account
|
|
export USHAHIDI_ADMIN_USER=admin@example.com
|
|
export USHAHIDI_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
export USHAHIDI_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${USHAHIDI_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
|
|
envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach mariadb -- mysql ushahidi
|
|
vmmgr update-login ushahidi "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"
|
|
|
|
# Install cron job
|
|
cp ${SOURCE_DIR}/etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi
|
|
|
|
# Install service
|
|
cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi
|
|
rc-update -u
|
|
|
|
# Install config update script
|
|
cp ${SOURCE_DIR}/srv/ushahidi/update-conf.sh /srv/ushahidi/update-conf.sh
|
|
|
|
# Stop services required for build
|
|
[ ! -z ${STOP_MARIADB} ] && service mariadb stop
|