2018-09-06 09:47:33 -04:00
|
|
|
#!/bin/bash
|
2023-01-13 22:30:29 +00:00
|
|
|
DB_DEFAULT_PWD="hirs_db"
|
2018-09-06 09:47:33 -04:00
|
|
|
|
2019-01-07 15:28:53 -05:00
|
|
|
# Check if we're in a Docker container
|
|
|
|
if [ -f /.dockerenv ]; then
|
|
|
|
DOCKER_CONTAINER=true
|
|
|
|
else
|
|
|
|
DOCKER_CONTAINER=false
|
|
|
|
fi
|
2018-09-06 09:47:33 -04:00
|
|
|
|
|
|
|
echo "Creating HIRS Database..."
|
2019-01-07 15:28:53 -05:00
|
|
|
|
|
|
|
if [ $DOCKER_CONTAINER = true ]; then
|
2023-01-13 22:30:29 +00:00
|
|
|
# If in Docker container, avoid services that invoke the D-Bus
|
|
|
|
if [[ $(pgrep -c -u mysql mysqld) -eq 0 ]]; then
|
|
|
|
echo "running in a container..."
|
2023-01-17 23:33:10 +00:00
|
|
|
/usr/bin/mysql_install_db
|
|
|
|
chown -R mysql:mysql /var/lib/mysql
|
2023-01-13 22:30:29 +00:00
|
|
|
/usr/libexec/mysql-prepare-db-dir > /dev/null 2>&1
|
|
|
|
nohup /usr/bin/mysqld_safe > /dev/null 2>&1 &
|
|
|
|
fi
|
2019-01-07 15:28:53 -05:00
|
|
|
else
|
|
|
|
SQL_SERVICE=`/opt/hirs/scripts/common/get_db_service.sh`
|
2023-01-13 18:38:40 +00:00
|
|
|
systemctl $SQL_SERVICE enable
|
|
|
|
systemctl $SQL_SERVICE start
|
2019-01-07 15:28:53 -05:00
|
|
|
fi
|
2018-09-06 09:47:33 -04:00
|
|
|
|
2023-01-13 22:30:29 +00:00
|
|
|
mysqladmin -u root password $DB_DEFAULT_PWD
|
2023-01-13 18:38:40 +00:00
|
|
|
DB_CREATE_SCRIPT=/opt/hirs/scripts/common/db_create.sql.el7
|
|
|
|
|
2023-01-13 22:30:29 +00:00
|
|
|
mysql -u root --password="$DB_DEFAULT_PWD" < $DB_CREATE_SCRIPT
|