LoMeS/dev_env_setup.sh

139 lines
4.7 KiB
Bash
Raw Normal View History

2025-10-08 17:46:15 +02:00
#!/bin/bash
2025-10-09 17:57:13 +02:00
source assets/shell/colors
source assets/config/deps/dependencies
### DEPENDENCY CHECK & INSTALLER
2025-10-08 17:46:15 +02:00
2025-10-09 20:07:44 +02:00
echo -e "\n ${LCY}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-09 20:07:44 +02:00
echo -e " ${GRN}Privilege check passed...${CRS}\n"
2025-10-08 17:46:15 +02:00
else
2025-10-09 20:07:44 +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-09 20:07:44 +02:00
echo -e " ${GRN}Dependency check passed...${CRS}\n"
2025-10-08 17:46:15 +02:00
else
2025-10-09 20:07:44 +02:00
echo -e " ${RED}Dependencies not met.${CRS}\n"
2025-10-08 17:46:15 +02:00
while true; do
2025-10-09 17:57:13 +02:00
echo -e " ${YEL}Do you wish to install via APT?"
read -p " (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-09 20:07:44 +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-09 20:07:44 +02:00
echo -e "\n ${RED}Missing dependencies... Exiting!${CRS}\n"
2025-10-08 17:46:15 +02:00
exit 1
else
2025-10-09 20:07:44 +02:00
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 "
2025-10-08 17:46:15 +02:00
fi
done
fi
2025-10-08 19:59:38 +02:00
### NGINX SETUP & CONFIG
2025-10-09 17:57:13 +02:00
###### HOST
2025-10-09 20:07:44 +02:00
onif=$(/sbin/ip route get 162.249.72.1 | awk '{print $5}' | cut -d/ -f1)
ip4=$(/sbin/ip -o -4 addr list "$onif" | awk '{print $4}' | cut -d/ -f1)
############################# add interface fail safe
while true; do
echo -e " ${YEL}What network interface will nginx be using?${CRS}"
read -p " current = "$onif" --> " nif
if ! [ "$nif" ]; then
nif="$onif"
break
2025-10-09 20:48:37 +02:00
elif [ ]; then # JEFF check in /sys/class/net/
2025-10-09 20:07:44 +02:00
break
else
echo -e "\n ${LRD}Interface not found... Try again!${CRS}\n"
fi
done
echo -e "\n ${YEL}Current hostname : ${LCY}$HOSTNAME${CRS}"
2025-10-09 17:57:13 +02:00
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}"
2025-10-09 20:07:44 +02:00
while true; do
read -p " Would you like to change the hostname? (y/N) --> " conf_hostname
if [[ "$conf_hostname" = "" || "$conf_hostname" = "n" || "$conf_hostname" = "N" ]]; then
new_hostname=$HOSTNAME
break
elif [[ "$conf_hostname" = "y" || "$conf_hostname" = "Y" ]]; then
read -p " Enter new hostname --> " new_hostname
sudo sed -i.backup "s/$HOSTNAME/$new_hostname/g" assets/test/hosts #/etc/hosts
sudo sed -i.backup "s/$HOSTNAME/$new_hostname/g" assets/test/hostname #/etc/hostname
echo -e "\n ${GRN}Host name changed to ${LCY}$new_hostname${CRS}"
break
else
echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, set new hostname)\n N = (No, leave as is)${CRS}\n "
fi
done
2025-10-09 17:57:13 +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-09 17:57:13 +02:00
echo -e "\n ${YEL}Configure SSL and create a self signed cetrificate?${CRS}"
read -p " (Y/n) --> " installSSL
2025-10-09 20:07:44 +02:00
2025-10-08 17:46:15 +02:00
if [[ "$installSSL" = "" || "$installSSL" = "y" || "$installSSL" = "Y" ]]; then
2025-10-09 15:42:38 +02:00
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 -e " ${YEL}Enter file name for certificate and key${CRS}"
2025-10-09 17:57:13 +02:00
read -p " default = $HOSTNAME --> " cert_name
2025-10-09 15:42:38 +02:00
if ! [ "$cert_name" ]; then
cert_name=$HOSTNAME
else
:
fi
2025-10-08 18:50:02 +02:00
echo ""
2025-10-09 17:57:13 +02:00
#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
2025-10-09 20:07:44 +02:00
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"
2025-10-08 18:44:04 +02:00
break
elif [[ "$installSSL" == "n" || "$installSSL" = "N" ]]; then
2025-10-09 20:07:44 +02:00
echo -e "\n ${RED}Encryption disabled${CRS}\n"
2025-10-08 18:50:02 +02:00
break
2025-10-08 17:46:15 +02:00
else
2025-10-09 20:07:44 +02:00
echo -e "\n ${YEL}Invalid response... Try again...\n\n Y = (Yes, configure SSL certificate and continue)\n N = (No, leave unencrypted and continue)${CRS}\n "
2025-10-08 17:46:15 +02:00
fi
2025-10-09 20:07:44 +02:00
done
###### NGINX CONFIG
2025-10-09 17:57:13 +02:00
### 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
2025-10-09 20:07:44 +02:00
echo -e "\n ${LGN}Script ran through...${CRS}"