Introduce Ushahidi app

This commit is contained in:
Disassembler 2017-10-26 22:50:04 +02:00
parent 4fedd99752
commit 20c5161dc5
7 changed files with 100 additions and 0 deletions

53
20-ushahidi.sh Executable file
View File

@ -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 </tmp/ushahidi-createdb.sql
# Configure Ushahidi
envsubst <${SOURCE_DIR}/ushahidi/srv/ushahidi/platform/.env >/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 </tmp/ushahidi-adminpwd.sql
rm -f /tmp/ushahidi-adminpwd.sql
# Create OS user
adduser --system --group --home /srv/ushahidi --shell /bin/false ushahidi
chown -R ushahidi:www-data /srv/ushahidi/
# Create PHP and nginx app definition
cp ${SOURCE_DIR}/ushahidi/etc/php/7.0/fpm/pool.d/ushahidi.conf /etc/php/7.0/fpm/pool.d/ushahidi.conf
cp ${SOURCE_DIR}/ushahidi/etc/nginx/sites-available/ushahidi /etc/nginx/sites-available/ushahidi
ln -s /etc/nginx/sites-available/ushahidi /etc/nginx/sites-enabled/ushahidi
# Restart services
systemctl restart php7.0-fpm
systemctl restart nginx
# Install cron job
cp ${SOURCE_DIR}/ushahidi/etc/cron.d/ushahidi /etc/cron.d/ushahidi
# Add portal application definition
${SOURCE_DIR}/basic/portal-app-manager.py ushahidi "https://{host}:8002/" "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"
${SOURCE_DIR}/basic/portal-app-manager.py ushahidi-mobile

View File

@ -0,0 +1,4 @@
*/5 * * * * ushahidi cd /srv/ushahidi/platform && ./bin/ushahidi dataprovider outgoing >/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

View File

@ -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;
}
}

View File

@ -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

View File

@ -0,0 +1,5 @@
DB_HOST=localhost
DB_NAME=ushahidi
DB_USER=ushahidi
DB_PASS=${USHAHIDI_PWD}
DB_TYPE=MySQLi

View File

@ -0,0 +1 @@
UPDATE users SET email = '${USHAHIDI_ADMIN_USER}', password = '${USHAHIDI_ADMIN_HASH}', updated = created WHERE realname = 'admin';

View File

@ -0,0 +1,2 @@
CREATE DATABASE ushahidi;
GRANT ALL PRIVILEGES ON ushahidi.* To 'ushahidi'@'%' IDENTIFIED BY '${USHAHIDI_PWD}';