Spotter-VM/lxc-apps/ushahidi/install.sh

42 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
set -ev
cd $(realpath $(dirname "${0}"))/install
# Create MariaDB instance
mkdir -p /srv/ushahidi/mariadb_conf /srv/ushahidi/mariadb_data
chown 103306:103306 /srv/ushahidi/mariadb_data
cp mariadb_conf/my.cnf /srv/ushahidi/mariadb_conf/my.cnf
chown -R 100000:100000 /srv/ushahidi/mariadb_conf
lxc-execute ushahidi-mariadb -- mysql_install_db --user=mysql --datadir=/var/lib/mysql --auth-root-authentication-method=socket --skip-test-db
# Create database
export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service ushahidi-mariadb start
envsubst <createdb.sql | lxc-attach ushahidi-mariadb -- mysql
# Configure Ushahidi
mkdir -p /srv/ushahidi/ushahidi_conf /srv/ushahidi/ushahidi_data
chown 108014:108014 /srv/ushahidi/ushahidi_data
envsubst <ushahidi_conf/env >/srv/ushahidi/ushahidi_conf/env
cp ushahidi_conf/config.json /srv/ushahidi/ushahidi_conf/config.json
chown -R 100000:100000 /srv/ushahidi/ushahidi_conf
# 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 | tr -d '+/=')
export USHAHIDI_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${USHAHIDI_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
envsubst <adminpwd.sql | lxc-attach ushahidi-mariadb -- mysql ushahidi
# Install config update script
cp update-conf.sh /srv/ushahidi/update-conf.sh
# Stop services required for setup
service ushahidi-mariadb stop
# Register application
vmmgr register-app ushahidi ush "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"