Spotter-VM/ushahidi/install.sh

41 lines
1.4 KiB
Bash
Raw Normal View History

2018-01-24 15:18:55 +01:00
#!/bin/sh
set -e
2017-10-26 22:50:04 +02:00
2018-10-26 15:02:11 +02:00
cd $(realpath $(dirname "${0}"))/install
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-10-25 22:22:36 +02:00
envsubst <createdb.sql | lxc-attach mariadb -- mysql
2017-10-26 22:50:04 +02:00
# Configure Ushahidi
mkdir -p /srv/ushahidi/conf /srv/ushahidi/data
chown 8014:8014 /srv/ushahidi/data
2018-10-25 22:22:36 +02:00
envsubst <srv/ushahidi/conf/env >/srv/ushahidi/conf/env
cp 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)
export USHAHIDI_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${USHAHIDI_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
2018-10-25 22:22:36 +02:00
envsubst <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
# Install cron job
2018-10-25 22:22:36 +02:00
cp etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi
2018-09-14 09:43:54 +02:00
# Install service
2018-10-25 22:22:36 +02:00
cp etc/init.d/ushahidi /etc/init.d/ushahidi
2018-09-14 09:43:54 +02:00
rc-update -u
# Install config update script
2018-10-25 22:22:36 +02:00
cp srv/ushahidi/update-conf.sh /srv/ushahidi/update-conf.sh
# Stop services required for build
2018-09-14 09:43:54 +02:00
[ ! -z ${STOP_MARIADB} ] && service mariadb stop