updated certbot section to verify files
This commit is contained in:
		
							parent
							
								
									e61d62b972
								
							
						
					
					
						commit
						cc940635a8
					
				
							
								
								
									
										45
									
								
								setup.sh
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								setup.sh
									
									
									
									
									
								
							| @ -25,6 +25,7 @@ unset KeyPath | |||||||
| unset CAChainPath | unset CAChainPath | ||||||
| unset DHPath | unset DHPath | ||||||
| 
 | 
 | ||||||
|  | certbotFiles=(cert.pem chain.pem fullchain.pem privkey.pem) | ||||||
| detectedIP=$(ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p') | 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])" | 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])" | ||||||
| regexHostname="(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])" | regexHostname="(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])" | ||||||
| @ -103,11 +104,47 @@ if [ "${useCertbot}" -eq 1 ]; then | |||||||
|                 ;; |                 ;; | ||||||
|             *) |             *) | ||||||
|                 # check hostname for validity |                 # check hostname for validity | ||||||
|                 if [[ "${inputCertbotDomain}" =~ ^${regexHostname}$ ]]; then |                 if [[ ! "${inputCertbotDomain}" =~ ^${regexHostname}$ ]]; then | ||||||
|                     CertbotDomain="${inputCertbotDomain}" |  | ||||||
|                     break |  | ||||||
|                 else |  | ||||||
|                     echo -e "\n${err}Invalid hostname${norm}" |                     echo -e "\n${err}Invalid hostname${norm}" | ||||||
|  |                 else | ||||||
|  |                     # check if Certbot files exist in path implied from hostname | ||||||
|  |                     echo -e "\n${cyan}Verifying Certbot files..." | ||||||
|  |                     echo -e "(/etc/letsencrypt/live/${inputCertbotDomain}/...)${norm}" | ||||||
|  |                     certbotBadFile=() | ||||||
|  |                     for certbotFile in "${certbotFiles[@]}"; do | ||||||
|  |                         if [ -f "/etc/letsencrypt/live/${inputCertbotDomain}/$certbotFile" ]; then | ||||||
|  |                             echo -e "File: ${certbotFile} -- ${ok}OK${norm}" | ||||||
|  |                         else | ||||||
|  |                             echo -e "File: ${certbotFile} -- ${err}X${norm}" | ||||||
|  |                             certbotBadFile+=("${certbotFile}") | ||||||
|  |                         fi | ||||||
|  |                     done | ||||||
|  |                     if [ -z "${certbotBadFile}" ]; then | ||||||
|  |                         echo -e "${cyan}Certbot files seem intact${norm}" | ||||||
|  |                         CertbotDomain="${inputCertbotDomain}" | ||||||
|  |                         break | ||||||
|  |                     else | ||||||
|  |                         echo -e "\n${err}The following files are missing from ${inputCertbotDomain}:" | ||||||
|  |                         echo -e "${warn}${certbotBadFile[@]}${norm}" | ||||||
|  |                         echo -e "${err}These files are all required for proper SSL operation of NGINX using Certbot.${norm}\n" | ||||||
|  |                         while true; do | ||||||
|  |                             read -p "Do you want to use these settings anyways? " yn | ||||||
|  |                             case "${yn}" in | ||||||
|  |                                     [Yy]*) | ||||||
|  |                                         CertbotDomain="${inputCertbotDomain}" | ||||||
|  |                                         break | ||||||
|  |                                         ;; | ||||||
|  |                                     [Nn]*) | ||||||
|  |                                         break | ||||||
|  |                                         ;; | ||||||
|  |                                     *) | ||||||
|  |                                         ;; | ||||||
|  |                             esac | ||||||
|  |                         done | ||||||
|  |                     fi | ||||||
|  |                     if [ -n "${CertbotDomain}" ]; then | ||||||
|  |                         break | ||||||
|  |                     fi | ||||||
|                 fi |                 fi | ||||||
|                 ;; |                 ;; | ||||||
|         esac |         esac | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user