41 lines
1.2 KiB
Bash
41 lines
1.2 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Automate mysql secure installation for debian-based systems
|
||
|
# https://gist.github.com/coderua/5592d95970038944d099
|
||
|
|
||
|
. bin/variables.sh
|
||
|
. bin/functions.sh
|
||
|
|
||
|
install_pkg mariadb-server
|
||
|
echo -e "${ORANGE}${BOLD}Generate and store the password somewhere safe${RESET}"
|
||
|
echo -e "${PURPLE}${BOLD}Enter the MariaDB root password : ${RESET}"
|
||
|
read -s DB_ROOT_PASSWORD
|
||
|
echo
|
||
|
install_pkg expect
|
||
|
secure_mysql=$(expect -c "
|
||
|
set timeout 3
|
||
|
spawn mysql_secure_installation
|
||
|
expect \"Enter current password for root (enter for none):\"
|
||
|
send \"\r\"
|
||
|
expect \"Switch to unix_socket authentication \\[Y/n\\]\"
|
||
|
send \"n\r\"
|
||
|
expect \"Change the root password? \\[Y/n\\]\"
|
||
|
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}"
|
||
|
|
||
|
echo -e "${PURPLE}MariaDB is installed and secure${RESET}"
|