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

55 lines
2.5 KiB
Bash
Raw Normal View History

2018-01-24 15:18:55 +01:00
#!/bin/sh
2018-10-28 16:04:11 +01:00
set -ev
2017-10-26 22:50:04 +02:00
2020-03-24 15:15:26 +01:00
# Volumes
MARIADB_CONF="${VOLUMES_DIR}/ushahidi/mariadb_conf"
MARIADB_DATA="${VOLUMES_DIR}/ushahidi/mariadb_data"
2020-03-24 18:21:52 +01:00
REDIS_CONF="${VOLUMES_DIR}/ushahidi/redis_conf"
REDIS_DATA="${VOLUMES_DIR}/ushahidi/redis_data"
2020-03-24 15:15:26 +01:00
USHAHIDI_CONF="${VOLUMES_DIR}/ushahidi/ushahidi_conf"
USHAHIDI_DATA="${VOLUMES_DIR}/ushahidi/ushahidi_data"
2019-10-05 15:40:27 +02:00
# Create MariaDB instance
2020-03-24 15:15:26 +01:00
install -o 100000 -g 100000 -m 755 -d ${MARIADB_CONF}
install -o 103306 -g 103306 -m 750 -d ${MARIADB_DATA}
install -o 100000 -g 100000 -m 644 mariadb_conf/my.cnf ${MARIADB_CONF}/my.cnf
2020-03-24 18:21:52 +01:00
spoc-container exec ushahidi-mariadb -- mysql_install_db --user=mysql --datadir=/var/lib/mysql --auth-root-authentication-method=socket --skip-test-db
2017-10-26 22:50:04 +02:00
# Create database
2019-06-05 18:55:15 +02:00
export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2020-03-24 15:15:26 +01:00
spoc-container start ushahidi-mariadb
envsubst <createdb.sql | spoc-container exec ushahidi-mariadb -- mysql
# Configure Redis
install -o 100000 -g 106379 -m 750 -d ${REDIS_CONF}
install -o 106379 -g 106379 -m 750 -d ${REDIS_DATA}
install -o 100000 -g 106379 -m 640 redis_conf/redis.conf ${REDIS_CONF}/redis.conf
spoc-container start ushahidi-redis
2017-10-26 22:50:04 +02:00
# Configure Ushahidi
2020-03-24 18:21:52 +01:00
export USHAHIDI_APPKEY=$(head -c 32 /dev/urandom | base64 | tr -d '+/=' | cut -c0-32) # Must be exactly 32 characters
install -o 100000 -g 108080 -m 750 -d ${USHAHIDI_CONF}
2020-03-24 15:15:26 +01:00
install -o 108080 -g 108080 -m 755 -d ${USHAHIDI_DATA}
2020-03-24 18:21:52 +01:00
install -o 108080 -g 108080 -m 755 -d ${USHAHIDI_DATA}/passport
envsubst <ushahidi_conf/env | install -o 100000 -g 108080 -m 640 /dev/stdin ${USHAHIDI_CONF}/env
install -o 100000 -g 108080 -m 644 ushahidi_conf/config.json ${USHAHIDI_CONF}/config.json
spoc-container exec ushahidi -- sh -c 'cd /srv/ushahidi/platform; php artisan passport:keys'
2017-10-26 22:50:04 +02:00
# Populate database
2020-03-24 15:15:26 +01:00
spoc-container exec ushahidi -- sh -c 'cd /srv/ushahidi/platform; php artisan migrate'
2017-10-26 22:50:04 +02:00
# Create admin account
export USHAHIDI_ADMIN_USER="admin@example.com"
2019-06-05 18:55:15 +02:00
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'))")
2020-03-24 15:15:26 +01:00
envsubst <adminpwd.sql | spoc-container exec ushahidi-mariadb -- mysql ushahidi
2019-10-05 15:40:27 +02:00
# Stop services required for setup
2020-03-24 15:15:26 +01:00
spoc-container stop ushahidi-redis
spoc-container stop ushahidi-mariadb
2018-10-28 19:50:35 +01:00
# Register application
2019-02-26 21:12:41 +01:00
vmmgr register-app ushahidi ush "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"
vmmgr register-prop ushahidi email "${USHAHIDI_ADMIN_USER}"
vmmgr register-prop ushahidi gmaps-api-key ""