From 20c5161dc5bc5c0116515c8237431116db02dec3 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 26 Oct 2017 22:50:04 +0200 Subject: [PATCH] Introduce Ushahidi app --- 20-ushahidi.sh | 53 +++++++++++++++++++ ushahidi/etc/cron.d/ushahidi | 4 ++ ushahidi/etc/nginx/sites-available/ushahidi | 23 ++++++++ ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf | 12 +++++ ushahidi/srv/ushahidi/platform/.env | 5 ++ ushahidi/tmp/ushahidi-adminpwd.sql | 1 + ushahidi/tmp/ushahidi-createdb.sql | 2 + 7 files changed, 100 insertions(+) create mode 100755 20-ushahidi.sh create mode 100644 ushahidi/etc/cron.d/ushahidi create mode 100644 ushahidi/etc/nginx/sites-available/ushahidi create mode 100644 ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf create mode 100644 ushahidi/srv/ushahidi/platform/.env create mode 100644 ushahidi/tmp/ushahidi-adminpwd.sql create mode 100644 ushahidi/tmp/ushahidi-createdb.sql diff --git a/20-ushahidi.sh b/20-ushahidi.sh new file mode 100755 index 0000000..101c6a2 --- /dev/null +++ b/20-ushahidi.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +SOURCE_DIR=$(realpath $(dirname "${0}")) + +# Install dependencies for Ushahidi +apt-get -y --no-install-recommends install php7.0-curl php7.0-gd php7.0-fpm php7.0-json php7.0-imap php7.0-mcrypt php7.0-mysql + +# Install Ushahidi +wget https://github.com/ushahidi/platform-release/releases/download/v3.7.1/ushahidi-platform-release-v3.7.1.tar.gz -O /tmp/ushahidi.tar.gz +tar xzf /tmp/ushahidi.tar.gz -C /tmp +mv /tmp/ushahidi-platform-release-v3.7.1/html /srv/ushahidi +rm -f /tmp/ushahidi.tar.gz +rm -rf /tmp/ushahidi-platform-release-v3.7.1 + +# Create database +export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64) +envsubst <${SOURCE_DIR}/ushahidi/tmp/ushahidi-createdb.sql >/tmp/ushahidi-createdb.sql +mysql /srv/ushahidi/platform/.env + +# Populate database +cd /srv/ushahidi/platform +./bin/phinx migrate -c 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=$(php -r "echo password_hash('${USHAHIDI_ADMIN_PWD}', PASSWORD_BCRYPT);") +envsubst <${SOURCE_DIR}/ushahidi/tmp/ushahidi-adminpwd.sql >/tmp/ushahidi-adminpwd.sql +mysql ushahidi /dev/null +*/5 * * * * ushahidi cd /srv/ushahidi/platform && ./bin/ushahidi dataprovider incoming >/dev/null +*/5 * * * * ushahidi cd /srv/ushahidi/platform && ./bin/ushahidi savedsearch >/dev/null +*/5 * * * * ushahidi cd /srv/ushahidi/platform && ./bin/ushahidi notification queue >/dev/null diff --git a/ushahidi/etc/nginx/sites-available/ushahidi b/ushahidi/etc/nginx/sites-available/ushahidi new file mode 100644 index 0000000..69e065f --- /dev/null +++ b/ushahidi/etc/nginx/sites-available/ushahidi @@ -0,0 +1,23 @@ +server { + listen 8002 ssl http2; + listen [::]:8002 ssl http2; + + access_log /var/log/nginx/ushahidi.access.log; + error_log /var/log/nginx/ushahidi.error.log; + + root /srv/ushahidi; + + location /platform { + fastcgi_index index.php; + include fastcgi.conf; + fastcgi_param SCRIPT_FILENAME $document_root/platform/httpdocs/index.php; + fastcgi_split_path_info ^(/platform/)(.*)$; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; + fastcgi_pass unix:/run/php/ushahidi.sock; + } + + location / { + try_files $uri /index.html; + } +} diff --git a/ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf b/ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf new file mode 100644 index 0000000..ada9a4a --- /dev/null +++ b/ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf @@ -0,0 +1,12 @@ +[ushahidi] +user = ushahidi +group = ushahidi + +listen = /run/php/ushahidi.sock +listen.owner = www-data +listen.group = www-data + +pm = ondemand +pm.max_children = 8 + +php_admin_value[open_basedir] = /srv/ushahidi:/tmp diff --git a/ushahidi/srv/ushahidi/platform/.env b/ushahidi/srv/ushahidi/platform/.env new file mode 100644 index 0000000..7ebde13 --- /dev/null +++ b/ushahidi/srv/ushahidi/platform/.env @@ -0,0 +1,5 @@ +DB_HOST=localhost +DB_NAME=ushahidi +DB_USER=ushahidi +DB_PASS=${USHAHIDI_PWD} +DB_TYPE=MySQLi diff --git a/ushahidi/tmp/ushahidi-adminpwd.sql b/ushahidi/tmp/ushahidi-adminpwd.sql new file mode 100644 index 0000000..93dbb71 --- /dev/null +++ b/ushahidi/tmp/ushahidi-adminpwd.sql @@ -0,0 +1 @@ +UPDATE users SET email = '${USHAHIDI_ADMIN_USER}', password = '${USHAHIDI_ADMIN_HASH}', updated = created WHERE realname = 'admin'; diff --git a/ushahidi/tmp/ushahidi-createdb.sql b/ushahidi/tmp/ushahidi-createdb.sql new file mode 100644 index 0000000..fa294ab --- /dev/null +++ b/ushahidi/tmp/ushahidi-createdb.sql @@ -0,0 +1,2 @@ +CREATE DATABASE ushahidi; +GRANT ALL PRIVILEGES ON ushahidi.* To 'ushahidi'@'%' IDENTIFIED BY '${USHAHIDI_PWD}';