2018-06-20 12:55:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# MISP docker startup script
|
2020-10-21 13:47:56 +02:00
|
|
|
# Xavier Mertens <xavier@rootshell.be>
|
2021-03-09 22:45:11 +01:00
|
|
|
# Steven Goossens <steven@teamg.be>
|
2020-10-21 13:47:56 +02:00
|
|
|
#
|
|
|
|
# 2017/05/17 - Created
|
|
|
|
# 2017/05/31 - Fixed small errors
|
|
|
|
# 2019/10/17 - Use built-in mysql docker DB creation and use std env names (dafal)
|
2021-03-09 22:45:11 +01:00
|
|
|
# 2021/03/09 - Update to work with the install script provided by MISP. Includes https support, Python venv,...
|
2020-10-21 13:47:56 +02:00
|
|
|
#
|
2018-06-20 12:55:34 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-10-21 13:47:56 +02:00
|
|
|
if [ -r /.firstboot.tmp ]; then
|
|
|
|
echo "Container started for the fist time. Setup might time a few minutes. Please wait..."
|
|
|
|
echo "(Details are logged in /tmp/install.log)"
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
# If the user uses a mount point restore our files
|
|
|
|
if [ ! -d /var/www/MISP/app ]; then
|
|
|
|
echo "Restoring MISP files..."
|
|
|
|
cd /var/www/MISP
|
|
|
|
tar xzpf /root/MISP.tgz
|
|
|
|
rm /root/MISP.tgz
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Configuring postfix"
|
|
|
|
if [ -z "$POSTFIX_RELAY_HOST" ]; then
|
|
|
|
echo "POSTFIX_RELAY_HOST is not set, please configure Postfix manually later..."
|
|
|
|
else
|
2020-12-04 22:22:00 +01:00
|
|
|
postconf -e "relayhost = $POSTFIX_RELAY_HOST"
|
2020-10-21 13:47:56 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Fix timezone (adapt to your local zone)
|
|
|
|
if [ -z "$TIMEZONE" ]; then
|
|
|
|
echo "TIMEZONE is not set, please configure the local time zone manually later..."
|
|
|
|
else
|
|
|
|
echo "$TIMEZONE" > /etc/timezone
|
|
|
|
dpkg-reconfigure -f noninteractive tzdata >>/tmp/install.log
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Creating MySQL database"
|
|
|
|
|
|
|
|
# Check MYSQL_HOST
|
|
|
|
if [ -z "$MYSQL_HOST" ]; then
|
|
|
|
echo "MYSQL_HOST is not set. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Waiting for DB to be ready
|
|
|
|
while ! mysqladmin ping -h"$MYSQL_HOST" --silent; do
|
|
|
|
sleep 5
|
|
|
|
echo "Waiting for database to be ready..."
|
|
|
|
done
|
|
|
|
|
|
|
|
# Set MYSQL_PASSWORD
|
|
|
|
if [ -z "$MYSQL_PASSWORD" ]; then
|
|
|
|
echo "MYSQL_PASSWORD is not set, use default value 'misp'"
|
|
|
|
MYSQL_PASSWORD=misp
|
|
|
|
else
|
|
|
|
echo "MYSQL_PASSWORD is set to '$MYSQL_PASSWORD'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ret=`echo 'SHOW TABLES;' | mysql -u $MYSQL_USER --password="$MYSQL_PASSWORD" -h $MYSQL_HOST -P 3306 $MYSQL_DATABASE # 2>&1`
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Connected to database successfully!"
|
|
|
|
found=0
|
|
|
|
for table in $ret; do
|
|
|
|
if [ "$table" == "attributes" ]; then
|
|
|
|
found=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $found -eq 1 ]; then
|
|
|
|
echo "Database misp available"
|
|
|
|
else
|
|
|
|
echo "Database misp empty, creating tables ..."
|
|
|
|
ret=`mysql -u $MYSQL_USER --password="$MYSQL_PASSWORD" $MYSQL_DATABASE -h $MYSQL_HOST -P 3306 2>&1 < /var/www/MISP/INSTALL/MYSQL.sql`
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Imported /var/www/MISP/INSTALL/MYSQL.sql successfully"
|
|
|
|
else
|
|
|
|
echo "ERROR: Importing /var/www/MISP/INSTALL/MYSQL.sql failed:"
|
|
|
|
echo $ret
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "ERROR: Connecting to database failed:"
|
|
|
|
echo $ret
|
|
|
|
fi
|
|
|
|
|
|
|
|
# MISP configuration
|
|
|
|
echo "Creating MISP configuration files"
|
|
|
|
cd /var/www/MISP/app/Config
|
2021-03-09 22:45:11 +01:00
|
|
|
cp -a database.default.php database.php
|
2020-10-21 13:47:56 +02:00
|
|
|
sed -i "s/localhost/$MYSQL_HOST/" database.php
|
|
|
|
sed -i "s/db\s*login/$MYSQL_USER/" database.php
|
|
|
|
sed -i "s/8889/3306/" database.php
|
|
|
|
sed -i "s/db\s*password/$MYSQL_PASSWORD/" database.php
|
|
|
|
|
|
|
|
# Fix the base url
|
|
|
|
if [ -z "$MISP_BASEURL" ]; then
|
|
|
|
echo "No base URL defined, don't forget to define it manually!"
|
|
|
|
else
|
|
|
|
echo "Fixing the MISP base URL ($MISP_BASEURL) ..."
|
2021-03-06 19:10:36 +01:00
|
|
|
sed -i "s@'baseurl'[\t ]*=>[\t ]*'',@'baseurl' => '$MISP_BASEURL',@g" /var/www/MISP/app/Config/config.php
|
2020-10-21 13:47:56 +02:00
|
|
|
fi
|
2021-03-09 22:45:11 +01:00
|
|
|
|
|
|
|
#Redis should not run as a daemon
|
|
|
|
sed -i "s/daemonize yes/daemonize no/g" /etc/redis/redis.conf
|
2020-10-21 13:47:56 +02:00
|
|
|
|
|
|
|
# Display tips
|
|
|
|
cat <<__WELCOME__
|
|
|
|
Congratulations!
|
|
|
|
Your MISP docker has been successfully booted for the first time.
|
|
|
|
Don't forget:
|
|
|
|
- Reconfigure postfix to match your environment
|
|
|
|
- Change the MISP admin email address to $MISP_ADMIN_EMAIL
|
|
|
|
|
|
|
|
__WELCOME__
|
|
|
|
rm -f /.firstboot.tmp
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make MISP live - this isn't ideal, as it means taking an instance
|
|
|
|
# non-live will make it live again if the container restarts. That seems
|
|
|
|
# better than the default which is that MISP is non-live on container restart.
|
|
|
|
# Ideally live/non-live would be persisted in the database.
|
2021-03-09 22:45:11 +01:00
|
|
|
/var/www/MISP/app/Console/cake Admin setSetting "MISP.python_bin" "/var/www/MISP/venv/bin/python"
|
2020-01-09 19:35:55 +01:00
|
|
|
/var/www/MISP/app/Console/cake live 1
|
|
|
|
chown www-data:www-data /var/www/MISP/app/Config/config.php*
|
|
|
|
|
2018-06-20 12:55:34 +02:00
|
|
|
# Start supervisord
|
|
|
|
echo "Starting supervisord"
|
|
|
|
cd /
|
2020-10-21 13:47:56 +02:00
|
|
|
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
|
|
|
|