diff --git a/maria_db.sh b/install_mysql.sh similarity index 70% rename from maria_db.sh rename to install_mysql.sh index 74317407bb52a4719691f6b81d76e2b9ce9bd1ac..48408c1cdc2730123fd24bf94b60b90a82b1a8fd 100755 --- a/maria_db.sh +++ b/install_mysql.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash ### - # Installs and sets up MariaDB. + # Installs and sets up MySQL/MariaDB. ## @@ -15,36 +15,60 @@ function main () { check_is_user root - # Check that expected key exists. - if [[ ${!kwargs[@]} =~ "os" ]] + # Check that expected os key exists. + if [[ ! ${!kwargs[@]} =~ "os" ]] then - # Check os to install for. - if [[ ${kwargs["os"]} == "arch" ]] - then - install_db_arch + echo -e "${text_red}Failed to provide expected OS kwarg. Terminating script.${text_reset}" + exit 1 + fi - elif [[ ${kwargs["os"]} == "ubuntu" ]] - then - install_db_ubuntu + # Check that expected db key exists. + if [[ ! ${!kwargs[@]} =~ "db" ]] + then + echo -e "${text_red}Failed to provide expected database kwarg. Terminating script.${text_reset}" + exit 1 + fi + # Check os to install for. + if [[ ${kwargs["os"]} == "arch" ]] + then + # Handle for Arch Linux. + if [[ ${kwargs["db"]} == "mariadb" ]] + then + install_arch_mariadb else - echo -e "${text_red}Unrecognized OS type. Terminating script.${text_reset}" + echo -e "${text_red}Unrecognized database type. Terminating script.${text_reset}" exit 1 fi - set_config + elif [[ ${kwargs["os"]} == "ubuntu" ]] + then + # Handle for Ubuntu. + if [[ ${kwargs["db"]} == "mysql" ]] + then + install_ubuntu_mysql + + elif [[ ${kwargs["db"]} == "mariadb" ]] + then + install_ubuntu_mariadb + echo -e "${text_red}Unrecognized database type. Terminating script.${text_reset}" + exit 1 + fi else - echo -e "${text_red}Failed to provide OS kwarg. Terminating script.${text_reset}" + echo -e "${text_red}Unrecognized OS type. Terminating script.${text_reset}" exit 1 fi + + set_config + } ### # Installation logic for Arch Linux systems. ## -function install_db_arch () { +function install_arch_mariadb () { # Install MariaDB. pacman -Syu mariadb --noconfirm @@ -61,9 +85,26 @@ function install_db_arch () { ### - # Installation logic for Ubuntu systems. + # MySQL installation logic for Ubuntu systems. + ## +function install_ubuntu_mysql () { + # Install MariaDB. + sudo apt update + sudo apt install mysql-server mysql-client -y + + # Start MariaDB service and set to start on boot. + systemctl enable mariadb.service + systemctl start mariadb.service + + # Proceed with initial configuration. + mysql_secure_installation +} + + +### + # MariaDB installation logic for Ubuntu systems. ## -function install_db_ubuntu() { +function install_ubuntu_mariadb () { # Install MariaDB. sudo apt update sudo apt install mariadb-server -y @@ -79,6 +120,7 @@ function install_db_ubuntu() { ### # Updates config file for first time setup. + # Should apply to all currently handled OS systems and database types. ## function set_config () { # Check that expected config file exists. diff --git a/run.sh b/run.sh index 766b917d2450547da8a1bb407ceb12fe714ade37..3b043e9774f930240ce4191a91147647b223ec52 100755 --- a/run.sh +++ b/run.sh @@ -31,7 +31,7 @@ function main () { read echo -e "${text_blue}Starting MariaDB installation.${text_reset}" - sudo ./maria_db.sh --os arch + sudo ./install_mysql.sh --os arch --db mariadb echo -e "${text_green}MariaDB installation complete.${text_reset}" elif [[ ${user_input} == 2 ]] @@ -52,7 +52,7 @@ function main () { read echo -e "${text_blue}Starting MySQL installation.${text_reset}" - sudo ./mysql_db.sh --os ubuntu + sudo ./install_mysql.sh --os ubuntu --db mysql echo -e "${text_green}MySQL installation complete.${text_reset}" elif [[ ${user_input} == 2 ]] @@ -63,7 +63,7 @@ function main () { read echo -e "${text_blue}Starting MariaDB installation.${text_reset}" - sudo ./maria_db.sh --os ubuntu + sudo ./install_mysql.sh --os ubuntu --db mariadb echo -e "${text_green}MariaDB installation complete.${text_reset}" else