HIRS/package/scripts/common/db_create.sh

32 lines
900 B
Bash
Raw Normal View History

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
# 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..."
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
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
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