diff --git a/maria_db.sh b/maria_db.sh index 21ec9d9d2491c1d4988411c60d5ddef710362f0a..74317407bb52a4719691f6b81d76e2b9ce9bd1ac 100755 --- a/maria_db.sh +++ b/maria_db.sh @@ -15,23 +15,36 @@ function main () { check_is_user root - echo "Starting MariaDB install for Arch Linux." - echo -e "To continue, press ${text_cyan}enter${text_reset}. Otherwise, hit ${text_cyan}ctrl+c${text_reset} to cancel." - read + # Check that expected key exists. + if [[ ${!kwargs[@]} =~ "os" ]] + then + # Check os to install for. + if [[ ${kwargs["os"]} == "arch" ]] + then + install_db_arch - echo -e "${text_blue}Starting MariaDB installation.${text_reset}" + elif [[ ${kwargs["os"]} == "ubuntu" ]] + then + install_db_ubuntu + + else + echo -e "${text_red}Unrecognized OS type. Terminating script.${text_reset}" + exit 1 + fi - install_db - set_config + set_config - echo -e "${text_green}MariaDB installation complete.${text_reset}" + else + echo -e "${text_red}Failed to provide OS kwarg. Terminating script.${text_reset}" + exit 1 + fi } ### - # Core installation logic. + # Installation logic for Arch Linux systems. ## -function install_db () { +function install_db_arch () { # Install MariaDB. pacman -Syu mariadb --noconfirm @@ -47,6 +60,23 @@ function install_db () { } +### + # Installation logic for Ubuntu systems. + ## +function install_db_ubuntu() { + # Install MariaDB. + sudo apt update + sudo apt install mariadb-server -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 +} + + ### # Updates config file for first time setup. ## @@ -135,7 +165,7 @@ function set_config () { else # Config values found. - echo -e "${text_orange}Config appears to already be setSkipping config first time setup.${text_reset}" + echo -e "${text_orange}Config appears to already be set. Skipping config first time setup.${text_reset}" fi } diff --git a/run.sh b/run.sh index 132132b81caeac1bb261c38308dd95c38f00d3c0..766b917d2450547da8a1bb407ceb12fe714ade37 100755 --- a/run.sh +++ b/run.sh @@ -12,11 +12,68 @@ # Script entry point. ## function main () { - echo "Starting Script." + echo "" + echo "Please enter OS type:" + echo -e " ${text_cyan}1${text_reset}) Arch Linux" + echo -e " ${text_cyan}2${text_reset}) Ubuntu" + echo -e " ${text_cyan}3${text_reset}) Other" + echo "" + read user_input - sudo ./maria_db.sh + # Handle user input. + if [[ ${user_input} == 1 ]] + then + # Handle for Arch Linux. - echo "Terminating Script." + # Handle for MariaDB install. + echo "Starting MariaDB install for Arch Linux." + echo -e "To continue, press ${text_cyan}enter${text_reset}. Otherwise, hit ${text_cyan}ctrl+c${text_reset} to cancel." + read + + echo -e "${text_blue}Starting MariaDB installation.${text_reset}" + sudo ./maria_db.sh --os arch + echo -e "${text_green}MariaDB installation complete.${text_reset}" + + elif [[ ${user_input} == 2 ]] + then + # Handle for Ubuntu. + echo "Choose a DB type to install:" + echo -e " ${text_cyan}1${text_reset}) MySQL" + echo -e " ${text_cyan}2${text_reset}) MariaDB" + echo "" + read user_input + + # Handle user input. + if [[ ${user_input} == 1 ]] + then + # Handle for MySQL install. + echo "Starting MySQL install for Ubuntu." + echo -e "To continue, press ${text_cyan}enter${text_reset}. Otherwise, hit ${text_cyan}ctrl+c${text_reset} to cancel." + read + + echo -e "${text_blue}Starting MySQL installation.${text_reset}" + sudo ./mysql_db.sh --os ubuntu + echo -e "${text_green}MySQL installation complete.${text_reset}" + + elif [[ ${user_input} == 2 ]] + then + # Handle for MariaDB install. + echo "Starting MariaDB install for Ubuntu." + echo -e "To continue, press ${text_cyan}enter${text_reset}. Otherwise, hit ${text_cyan}ctrl+c${text_reset} to cancel." + read + + echo -e "${text_blue}Starting MariaDB installation.${text_reset}" + sudo ./maria_db.sh --os ubuntu + echo -e "${text_green}MariaDB installation complete.${text_reset}" + + else + echo -e "${text_orange}Unknown option entered.${text_reset}" + fi + + else + # Handle for all other OS types. + echo -e "${text_orange}Other OS types are currently unsupported.${text_reset}" + fi }