106 lines
3.7 KiB
Bash
Executable file
106 lines
3.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source assets/shell/colors
|
|
source assets/config/deps/dependencies
|
|
|
|
### DEPENDENCY CHECK & INSTALLER
|
|
|
|
echo -e "\n${LCY} Dependency and Privilege Check running...${CRS}\n"
|
|
|
|
### PRIVILEGES
|
|
|
|
if (( $(id -u) == 0 )); then
|
|
echo -e "${GRN} Privilege check passed...${CRS}\n"
|
|
|
|
else
|
|
echo -e "${RED} Privilege check failed... Please run script with sudo or as root!${CRS}\n"
|
|
exit 1
|
|
fi
|
|
|
|
### DEPENDENCIES
|
|
|
|
if command -v "$pkgs" >/dev/null 2>&1; then
|
|
echo -e "${GRN} Dependency check passed...${CRS}\n"
|
|
|
|
else
|
|
echo -e "${RED} Dependencies not met.${CRS}\n"
|
|
|
|
while true; do
|
|
echo -e " ${YEL}Do you wish to install via APT?"
|
|
read -p " (Y/n) --> " install
|
|
echo ""
|
|
if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then
|
|
sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV
|
|
echo -e "\n${GRN} Dependencies installed. Proceeding...${CRS}\n"
|
|
break
|
|
|
|
elif [[ "$install" == "n" || "$install" = "N" ]]; then
|
|
echo -e "\n${RED} Missing dependencies... Exiting!${CRS}\n"
|
|
exit 1
|
|
|
|
else
|
|
echo -e "\n${YEL} Invalid response... Try again...\n\n ${GRN}Y ${YEL}= (Yes, install dependencies and continue)\n ${RED}N ${YEL}= (No, don't install dependencies and exit)${CRS}\n "
|
|
fi
|
|
done
|
|
fi
|
|
|
|
### NGINX SETUP & CONFIG
|
|
|
|
###### HOST
|
|
|
|
ip4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
|
|
echo -e " ${YEL}Current hostname : ${LCY}$HOSTNAME${CRS}"
|
|
echo -e " ${YEL}Current ip address : ${LCY}$ip4${CRS}"
|
|
echo -e "\n ${YEL}This information will be used to configure ${LCY}nginx.conf ${YEL}during the next steps.${CRS}"
|
|
read -p " Would you like to change the hostname? (y/N) --> " conf_host_ip
|
|
|
|
# ask for network interface
|
|
# ask to change hostname in /etc/hosts & /etc/hostname
|
|
|
|
###### CERTIFICATION
|
|
|
|
while true; do
|
|
echo -e "\n ${YEL}Configure SSL and create a self signed cetrificate?${CRS}"
|
|
read -p " (Y/n) --> " installSSL
|
|
if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then
|
|
echo -e " ${YEL}Enter path to certificates folder${CRS}"
|
|
read -p " default = /etc/nginx/ssl --> " cert_path
|
|
if ! [ "$cert_path" ]; then
|
|
cert_path=/etc/nginx/ssl
|
|
elif [[ "$cert_path" = "." ]]; then
|
|
cert_path=$PWD
|
|
else
|
|
:
|
|
fi
|
|
echo ""
|
|
echo -e " ${YEL}Enter file name for certificate and key${CRS}"
|
|
read -p " default = $HOSTNAME --> " cert_name
|
|
if ! [ "$cert_name" ]; then
|
|
cert_name=$HOSTNAME
|
|
else
|
|
:
|
|
fi
|
|
echo ""
|
|
#sudo mkdir -p "$cert_path"
|
|
#sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt
|
|
echo -e "\n${GRN} SSL certificate files ${LCY}$cert_name.crt ${GRN}and ${LCY}$cert_name.key ${GRN}created and stored in ${LCY}$cert_path${CRS}\n"
|
|
break
|
|
elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then
|
|
echo -e "\n${RED} No encryption established${CRS}\n"
|
|
break
|
|
else
|
|
echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, leave unencrypted and continue)${CRS}\n "
|
|
fi
|
|
done
|
|
|
|
|
|
### DEV STATUS
|
|
|
|
#sudo cp -R assets/config/nginx/nginx.conf /etc/nginx/sites-enabled/
|
|
## JEFF
|
|
# utilise sed to edit config
|
|
# test nginx config
|
|
# restart nginx
|
|
## JEFF END
|
|
|
|
echo -e "${GRN}\nScript ran through...${CRS}"
|