From 80b47e2f43bc2060bed848af0a048185373bc4c6 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 23 Feb 2024 16:21:55 +0100 Subject: [PATCH] mysql_secure_installation correction 4 --- install.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 50d51ad..084bfeb 100644 --- a/install.sh +++ b/install.sh @@ -98,13 +98,31 @@ if [[ "$answer" == "y" ]]; then echo -e "${PURPLE}${BOLD}Enter the MariaDB root password : ${RESET}" read -s db_root_password echo - mariadb -e "UPDATE mysql.user SET Password = PASSWORD('${db_root_password}') WHERE User = 'root'" - mariadb -e "DROP USER ''@'localhost'" - mariadb -e "DROP USER ''@'$(hostname)'" - mariadb -e "DROP DATABASE test" - mariadb -e "FLUSH PRIVILEGES" - # https://fedingo.com/how-to-automate-mysql_secure_installation-script/ - # to replace mysql_secure_installation + apt -y install expect + SECURE_MYSQL=$(expect -c " + set timeout 3 + spawn mysql_secure_installation + expect \"Enter current password for root (enter for none):\" + send \"\r\" + expect \"root password?\" + send \"y\r\" + expect \"New password:\" + send \"$db_root_password\r\" + expect \"Re-enter new password:\" + send \"$db_root_password\r\" + expect \"Remove anonymous users?\" + send \"y\r\" + expect \"Disallow root login remotely?\" + send \"y\r\" + expect \"Remove test database and access to it?\" + send \"y\r\" + expect \"Reload privilege tables now?\" + send \"y\r\" + expect eof + ") + echo "${SECURE_MYSQL}" + apt -y purge expect + # https://gist.github.com/coderua/5592d95970038944d099 fi echo -e "${PURPLE}${BOLD}Setup Directus database ? (y/n) ${RESET}"