nginx-basic/setup.sh

58 lines
1.6 KiB
Bash
Raw Normal View History

2019-01-04 22:04:29 -07:00
#!/bin/bash
#######
### Update NGINX configuration '<tags>' with proper values and optionally copy
### to updated directory structure
#######
# text formatting ansi codes
err="\e[1;31m"
ok="\e[1;32m"
warn="\e[93m"
mag="\e[95m"
cyan="\e[96m"
norm="\e[0m"
# set variables
detectedIP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p')
regexIP4="(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
# quick intro for the user
echo -e "\n${mag}This script will customize the provided NGINX template files for your"
echo "environment. You will be prompted for all necessary information. After that,"
echo "default error pages will be copied to your webroot and your NGINX configuration"
echo -e "directory structure will be customized.${norm}\n"
echo -e "${warn}You may accept the default option (listed in brackets) by simply"
echo "pressing ENTER (i.e. no answer)."
echo -e "You may exit this script at any prompt by typing 'X'${norm}\n"
2019-01-04 22:06:05 -07:00
### get local IP address
while true; do
read -p "What is this NGINX machine's primary local IP4 address? (${detectedIP}) " inputIP
case "${inputIP}" in
'')
IP4="${detectedIP}"
break
;;
[Xx]*)
echo -e "\n${cyan}---exiting---\n${norm}"
exit 1
;;
*)
# check IP for validity
if [[ "${inputIP}" =~ ^${regexIP4}$ ]]; then
IP4="${inputIP}"
break
else
echo -e "\n${err}Invalid IP4 format (xxx.xxx.xxx.xxx)${norm}"
fi
;;
esac
done
2019-01-04 22:04:29 -07:00
exit 0