Add check whether database exists

Check whether the MISP database exists, if not, create it.
stevengoossensB 2020-02-07 09:39:51 +01:00 committed by GitHub
parent 94c43c62b8
commit b4176674fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -59,8 +59,13 @@ if [ -r /.firstboot.tmp ]; then
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 # 2>&1`
dbExists=`echo 'SHOW DATABASES;' | mysql -u $MYSQL_USER --password="$MYSQL_PASSWORD" -h $MYSQL_HOST -P 3306`
if [[ $dbExists != *$MYSQL_DATABASE* ]]
echo "Database misp doesn't exist, creating database ..."
`echo 'CREATE DATABASE '$MYSQL_DATABASE';' | mysql -u $MYSQL_USER --password="$MYSQL_PASSWORD" -h $MYSQL_HOST -P 3306`
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