HIRS/package/scripts/common/db_create.sh

50 lines
1.5 KiB
Bash
Raw Normal View History

2018-09-06 09:47:33 -04:00
#!/bin/bash
2023-01-19 17:13:46 -05:00
#
###############################################
# HIRS DB creation
# Conditions to address
# a. Install is called mutiple times
# b. Another app sets the root password
# c. ACA is updated
# d. ACA is updated after a DB password change
################################################
if [ -z ${HIRS_DB_PWD+x} ]; then
DB_DEFAULT_PWD="hirs_db";
else
DB_DEFAULT_PWD=$HIRS_DB_PWD;
fi
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..."
# Check if mysql is already running, if not initialize
if [[ $(pgrep -c -u mysql mysqld) -eq 0 ]]; then
# Check if running in a container
if [ $DOCKER_CONTAINER = true ]; then
# if in Docker container, avoid services that invoke the D-Bus
echo "ACA is running in a container..."
2023-01-17 23:33:10 +00:00
/usr/bin/mysql_install_db
chown -R mysql:mysql /var/lib/mysql/
chown -R mysql:mysql /var/log/mariadb/
2023-01-13 22:30:29 +00:00
nohup /usr/bin/mysqld_safe > /dev/null 2>&1 &
else
SQL_SERVICE=`/opt/hirs/scripts/common/get_db_service.sh`
systemctl $SQL_SERVICE enable
systemctl $SQL_SERVICE start
fi
fi
2018-09-06 09:47:33 -04:00
2023-01-19 17:13:46 -05:00
# Set intial passwor, ingore result in case its already been set
mysqladmin -u root --silent password $DB_DEFAULT_PWD || true > /dev/null 2>&1
# Create the hirs_db database
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