Guest User

Untitled

a guest
Feb 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function ssl-check() {
  2. f=~/.localhost_ssl;
  3. ssl_crt=$f/server.crt
  4. ssl_key=$f/server.key
  5. b=$(tput bold)
  6. c=$(tput sgr0)
  7.  
  8. local_ip=$(ipconfig getifaddr $(route get default | grep interface | awk '{print $2}'))
  9. # local_ip=999.999.999 # (uncomment for testing)
  10.  
  11. domains=(
  12. "localhost"
  13. "$local_ip"
  14. )
  15.  
  16. if [[ ! -f $ssl_crt ]]; then
  17. echo -e "\nšŸ›‘ ${b}Couldn't find a Slate SSL certificate:${c}"
  18. make_key=true
  19. elif [[ ! $(openssl x509 -noout -text -in $ssl_crt | grep $local_ip) ]]; then
  20. echo -e "\nšŸ›‘ ${b}Your IP Address has changed:${c}"
  21. make_key=true
  22. else
  23. echo -e "\nāœ… ${b}Your IP address is still the same.${c}"
  24. fi
  25.  
  26. if [[ $make_key == true ]]; then
  27. echo -e "Generating a new Slate SSL certificate...\n"
  28. count=$(( ${#domains[@]} - 1))
  29. mkcert ${domains[@]}
  30.  
  31. # Create Slate's default certificate directory, if it doesn't exist
  32. test ! -d $f && mkdir $f
  33.  
  34. # It appears mkcert bases its filenames off the number of domains passed after the first one.
  35. # This script predicts that filename, so it can copy it to Slate's default location.
  36. if [[ $count = 0 ]]; then
  37. mv ./localhost.pem $ssl_crt
  38. mv ./localhost-key.pem $ssl_key
  39. else
  40. mv ./localhost+$count.pem $ssl_crt
  41. mv ./localhost+$count-key.pem $ssl_key
  42. fi
  43. fi
  44. }
Add Comment
Please, Sign In to add comment