From 2eea89309c82953e8cbf44b507b74c11e75b324a Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Sat, 12 Nov 2022 19:12:12 -0500
Subject: [PATCH] Add postgress handling

---
 run.sh                    | 13 +++++++
 src/install_postgresql.sh | 80 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100755 src/install_postgresql.sh

diff --git a/run.sh b/run.sh
index c3d1261..4719fde 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 0000000..8dd7015
--- /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
-- 
GitLab