HIRS/package/linux/db/db_drop.sh

65 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/bash
2018-09-06 13:47:33 +00:00
2023-10-10 18:29:37 +00:00
DB_SRV_CONF=/etc/my.cnf.d/mariadb-server.cnf
DB_CLIENT_CONF=/etc/my.cnf.d/client.cnf
2023-08-11 13:47:30 +00:00
SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )";)
2023-08-23 20:30:06 +00:00
LOG_FILE=/dev/null
2023-09-18 20:48:29 +00:00
DB_ADMIN_PWD=$1
2023-08-11 13:47:30 +00:00
2023-09-18 20:48:29 +00:00
#source /etc/hirs/aca/aca.properties;
source $SCRIPT_DIR/mysql_util.sh
2023-10-10 18:29:37 +00:00
source /etc/os-release
2023-08-23 20:30:06 +00:00
check_systemd
2023-08-23 20:30:06 +00:00
# Check for sudo or root user, not actually needed but a good idea
if [ "$EUID" -ne 0 ]
then echo "This script requires root. Please run as root"
exit 1
fi
2023-10-10 18:29:37 +00:00
# Setup distro specifc paths and variables
if [ $ID = "ubuntu" ]; then
DB_SRV_CONF="/etc/mysql/mariadb.conf.d/50-server.cnf"
DB_CLIENT_CONF="/etc/mysql/mariadb.conf.d/50-client.cnf"
fi
2023-08-23 20:30:06 +00:00
if [ -d /opt/hirs/scripts/db ]; then
2023-08-11 13:47:30 +00:00
MYSQL_DIR="/opt/hirs/scripts/db"
else
MYSQL_DIR="$SCRIPT_DIR"
fi
2023-08-23 20:30:06 +00:00
echo "dropping hirs_db database"
2023-05-03 16:54:35 +00:00
2024-02-21 18:16:13 +00:00
mysql -u root --password=$DB_ADMIN_PWD -e "FLUSH HOSTS; FLUSH LOGS; FLUSH STATUS; FLUSH PRIVILEGES; FLUSH USER_RESOURCES"
mysql -u root --password=$DB_ADMIN_PWD -e "DROP USER 'hirs_db'@'localhost';"
mysql -u root --password=$DB_ADMIN_PWD -e "DROP DATABASE IF EXISTS hirs_db;"
echo "hirs_db database and hirs_db user removed"
2024-02-23 20:19:02 +00:00
2023-08-23 20:30:06 +00:00
# reset the mysql root if the password was left in the properties fiel
2023-09-18 20:48:29 +00:00
if [ ! -z $DB_ADMIN_PWD ]; then
2023-08-23 20:30:06 +00:00
echo "Resetting mysql root password to empty"
2023-09-18 20:48:29 +00:00
mysql -u root --password=$DB_ADMIN_PWD -e "SET PASSWORD FOR "root@localhost" = PASSWORD('');"
2023-08-28 20:18:08 +00:00
mysql -u "root" -e "FLUSH LOGS;"
2023-08-23 20:30:06 +00:00
else
echo "Note root password was NOT reset"
fi
# Remove key , cert and truststore entries from client.cnf andf mariadb.cnf
2024-03-28 19:26:21 +00:00
echo "Removing hirs tls references from mariadb configuration files"
2023-10-10 18:29:37 +00:00
grep -v "hirs" $DB_SRV_CONF > tmpfile && mv tmpfile $DB_SRV_CONF
2024-03-28 20:39:20 +00:00
# The following arent avialble in Mariadb 10.3
#grep -v "tls_version" $DB_SRV_CONF > tmpfile && mv tmpfile $DB_SRV_CONF
#grep -v "require_secure_transport" $DB_SRV_CONF > tmpfile && mv tmpfile $DB_SRV_CONF
2024-03-28 19:26:21 +00:00
2023-10-10 18:29:37 +00:00
grep -v "hirs" $DB_CLIENT_CONF > tmpfile && mv tmpfile $DB_CLIENT_CONF
2023-08-23 20:30:06 +00:00
2024-03-28 19:26:21 +00:00
2023-08-23 20:30:06 +00:00
echo "restarting mariadb"
2023-08-28 20:18:08 +00:00
mysqld_reboot