diff --git a/run.sh b/run.sh index c3d1261531d1baafb36e3ebcaa0f3fc2a9c8d4c9..4719fde1bf881714451b51ee3180bce197601f03 100755 --- a/run.sh +++ b/run.sh @@ -98,6 +98,19 @@ function main () { sudo ./install_mysql.sh --os ubuntu --db mariadb echo -e "${text_green}MariaDB setup & installation complete.${text_reset}" + elif [[ ${user_input} == 3 ]] + then + # Handle for PostgreSQL install. + echo -e "${text_blue}Installing PostgreSQL for Ubuntu Linux.${text_reset}" + echo -e "${text_blue}Sudo is required for installing/updating system files.${text_reset}" + echo -e "${text_blue}This may ask for your system password.${text_reset}" + echo -e "${text_blue}To continue, press ${text_cyan}enter${text_blue}. Otherwise, hit ${text_cyan}ctrl+c${text_blue} to cancel.${text_reset}" + read + + echo -e "${text_blue}Starting PostgreSQL installation.${text_reset}" + sudo ./install_postgresql.sh --os ubuntu + echo -e "${text_green}PostgreSQL setup & installation complete.${text_reset}" + else # Unhandled type. echo -e "${text_orange}Unknown option entered.${text_reset}" diff --git a/src/install_postgresql.sh b/src/install_postgresql.sh new file mode 100755 index 0000000000000000000000000000000000000000..8dd7015bcbd7dd4cca0e4283c7381a581f9886b2 --- /dev/null +++ b/src/install_postgresql.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +### + # Install and set up for MySQL/MariaDB. + ## + + +# Import utils script. +. $(dirname ${0})/utils.sh + + +# Stop on error. +set -e + + +### + # Script entry point. + # Checks that expected args were provided, to indicate what database type is being installed to what OS. + # Then calls the corresponding function to actually execute logic. + ## +function main () { + + check_is_user root + + # Check that expected os key exists. + if [[ ! ${!kwargs[@]} =~ "os" ]] + then + echo -e "${text_red}Failed to provide expected OS kwarg. Terminating script.${text_reset}" + exit 1 + fi + + # Check os to install for. + if [[ ${kwargs["os"]} == "arch" ]] + then + # Handle for Arch Linux. + install_arch_postgres + + elif [[ ${kwargs["os"]} == "ubuntu" ]] + then + # Handle for Ubuntu. + install_ubuntu_postgres + + else + echo -e "${text_red}Unrecognized OS type. Terminating script.${text_reset}" + exit 1 + fi + +} + + +### + # Installation logic for Arch Linux systems. + ## +function install_arch_postgres () { + + # Install PostgreSQL. + sudo pacman -Syu postgresql --noconfirm > /dev/null + + # Run initial configuration. + sudo -u postgres initdb --locale=en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data + + # Start PostgreSQL service and set to start on boot. + sudo systemctl start postgresql.service > /dev/null + sudo systemctl enable postgresql.service > /dev/null + +} + + +### + # Installation logic for Ubuntu Linux systems. + ## +function install_ubuntu_postgres () { + + # Install PostgreSQL. + sudo apt-get update > /dev/null 2>&1 + sudo apt install postgresql postgresql-contrib -y + +} + + +main