-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·128 lines (111 loc) · 4.59 KB
/
run.sh
File metadata and controls
executable file
·128 lines (111 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# MISP docker startup script
# Xavier Mertens <xavier@rootshell.be>
#
# 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)
#
set -e
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 [ ! -f /var/www/MISP/VERSION.json ]; 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
postconf -e "relayhost = $POSTFIX_RELAY"
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 < /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 Database configuration file"
cd /var/www/MISP/app/Config
cp -a database.default.php database.php
sed -i "s/localhost/$MYSQL_HOST/" database.php
sed -i "s/db\s*login/$MYSQL_DATABASE/" database.php
sed -i "s/8889/3306/" database.php
sed -i "s/db\s*password/$MYSQL_PASSWORD/" database.php
if [ -z "$REDIS_HOST" ]; then
echo "No REDIS_HOST defined. Defaulting to 'redis'"
sed -i "s|'host' => 'localhost',|'host' => 'redis',|" /var/www/MISP/app/Plugin/CakeResque/Config/config.php
else
echo "Changing REDIS hostname to ${REDIS_HOST}"
sed -i "s|'host' => 'localhost',|'host' => '${REDIS_HOST}',|" /var/www/MISP/app/Plugin/CakeResque/Config/config.php
fi
# 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) ..."
sed -i "s|'baseurl' => '',|'baseurl' => '$MISP_BASEURL',|" /var/www/MISP/app/Config/config.php
fi
# 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
cd /
exec "$@"