LoMeS/dev_env_setup.sh

82 lines
2.8 KiB
Bash
Raw Normal View History

2025-10-08 17:46:15 +02:00
#!/bin/bash
2025-10-09 07:56:08 +02:00
source assets/shell/shell_colors
2025-10-08 17:46:15 +02:00
### DEPENDENCY CHECK & INSTALLER
pkgs="openssl nginx"
2025-10-08 18:44:04 +02:00
echo -e "\n${CYN} Dependency and Privilege Check running...${CRS}\n"
2025-10-08 17:46:15 +02:00
2025-10-08 19:59:38 +02:00
### PRIVILEGES
2025-10-08 17:46:15 +02:00
if (( $(id -u) == 0 )); then
2025-10-08 18:44:04 +02:00
echo -e "${GRN} Privilege check passed...${CRS}\n"
2025-10-08 17:46:15 +02:00
else
2025-10-08 18:44:04 +02:00
echo -e "${RED} Privilege check failed... Please run script with sudo or as root!${CRS}\n"
2025-10-08 17:46:15 +02:00
exit 1
fi
2025-10-08 19:59:38 +02:00
### DEPENDENCIES
2025-10-08 17:46:15 +02:00
if command -v "$pkgs" >/dev/null 2>&1; then
2025-10-08 18:44:04 +02:00
echo -e "${GRN} Dependency check passed...${CRS}\n"
2025-10-08 17:46:15 +02:00
else
2025-10-08 18:44:04 +02:00
echo -e "${YEL} Dependencies not met.${CRS}\n"
2025-10-08 17:46:15 +02:00
while true; do
2025-10-08 18:44:04 +02:00
read -p " Do you wish to install via APT? (Y/n) : " install
2025-10-08 18:50:02 +02:00
echo ""
2025-10-08 17:46:15 +02:00
if [[ "$install" = "" || "$install" = "y" || "$install" = "Y" ]]; then
sudo apt update && sudo apt install --install-suggests -y $pkgs --simulate ## DEV
2025-10-08 18:50:02 +02:00
echo -e "\n${GRN} Dependencies installed. Proceeding...${CRS}\n"
2025-10-08 17:46:15 +02:00
break
elif [[ "$install" == "n" || "$install" = "N" ]]; then
2025-10-08 18:44:04 +02:00
echo -e "\n${RED} Missing dependencies... Exiting!${CRS}\n"
2025-10-08 17:46:15 +02:00
exit 1
else
2025-10-08 18:44:04 +02:00
echo -e "\n${YEL} Invalid response... Try again...\n\n Y = (Yes, install dependencies and continue)\n N = (No, don't install dependencies and exit)${CRS}\n "
2025-10-08 17:46:15 +02:00
fi
done
fi
2025-10-08 19:59:38 +02:00
### NGINX SETUP & CONFIG
###### DOMAIN & IP
# ask for network interface & get IP
# get hostname from /etc/hostname
# ask to change hostname in /etc/hosts & /etc/hostname
2025-10-08 17:46:15 +02:00
2025-10-08 19:59:38 +02:00
###### CERTIFICATION
2025-10-08 18:44:04 +02:00
2025-10-08 17:46:15 +02:00
while true; do
2025-10-08 19:59:38 +02:00
read -p " Configure SSL and create a self signed cetrificate? (Y/n) : " installSSL
2025-10-08 17:46:15 +02:00
if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then
2025-10-08 18:44:04 +02:00
read -p " Enter path to certificates folder (Will be created if not present) : " cert_path
2025-10-08 18:50:02 +02:00
echo ""
2025-10-08 18:44:04 +02:00
read -p " Enter file name for certificates (Without file ending) : " cert_name
2025-10-08 18:50:02 +02:00
echo ""
2025-10-08 17:46:15 +02:00
sudo mkdir -p "$cert_path"
2025-10-08 18:44:04 +02:00
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "$cert_path"/"$cert_name".key -out "$cert_path"/"$cert_name".crt
2025-10-08 19:59:38 +02:00
#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
2025-10-08 18:44:04 +02:00
echo -e "\n${GRN} Nginx configured${CRS}\n"
break
elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then
2025-10-08 20:54:53 +02:00
echo -e "\n${RED} Nginx configuration kept default${CRS}\n"
2025-10-08 18:50:02 +02:00
break
2025-10-08 17:46:15 +02:00
else
2025-10-08 18:44:04 +02:00
echo -e "\n${YEL} Invalid response... Try again...\n\nY = (Yes, configure SSL certificate and continue)\nN = (No, don't configure SSL certificate and continue)${CRS}\n "
2025-10-08 17:46:15 +02:00
fi
done
2025-10-08 18:44:04 +02:00
### DEV STATUS
2025-10-08 17:46:15 +02:00
2025-10-08 18:44:04 +02:00
echo -e "${GRN}\nScript ran through...${CRS}"