From 61c08069a0aff679e35f78b987496cbae2251516 Mon Sep 17 00:00:00 2001 From: VetheonGames Date: Fri, 24 May 2024 09:05:15 -0600 Subject: [PATCH] create nginx extension --- extensions/nginx.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 extensions/nginx.sh diff --git a/extensions/nginx.sh b/extensions/nginx.sh new file mode 100644 index 0000000..b6b02da --- /dev/null +++ b/extensions/nginx.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +LOG_FILE="$(dirname "$(dirname "$0")")/setup.log" + +# Log function +log() { + echo "$1" | tee -a "$LOG_FILE" +} + +# Function to prompt for yes/no input +prompt_yes_no() { + while true; do + read -r -p "$1 (y/n): " REPLY + case "$REPLY" in + [Yy]* ) return 0 ;; + [Nn]* ) return 1 ;; + * ) log "Please answer yes or no." ;; + esac + done +} + +# Function to install Nginx +install_nginx() { + log "Installing Nginx..." + if command -v apt &>/dev/null; then + apt update + apt install -y nginx + elif command -v yum &>/dev/null; then + yum install -y epel-release + yum install -y nginx + else + log "Unsupported package manager. Please install Nginx manually." + exit 1 + fi + log "Nginx installed successfully." +} + +# Function to start Nginx service +start_nginx() { + log "Starting Nginx service..." + systemctl start nginx + log "Nginx service started." +} + +# Function to enable Nginx service at boot +enable_nginx_boot() { + if prompt_yes_no "Do you want Nginx to start at boot?"; then + systemctl enable nginx + log "Nginx service enabled to start at boot." + else + log "Nginx service will not start at boot." + fi +} + +# Main script execution +log "Starting Nginx setup..." + +if prompt_yes_no "Do you want to install Nginx?"; then + install_nginx + start_nginx + enable_nginx_boot +fi + +log "Nginx setup complete."