Created
May 17, 2020 02:00
-
-
Save tracy-codes/a9f292f840cc2ff331d7f53889eaccb3 to your computer and use it in GitHub Desktop.
This is the shell script to use with Shopify Slate on Ubuntu to get a proper SSL cert setup for your Slate workflow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ssl-check() { | |
f=~/.localhost_ssl; | |
ssl_crt=$f/server.crt | |
ssl_key=$f/server.key | |
b=$(tput bold) | |
c=$(tput sgr0) | |
ips=$(hostname -I) | |
local_ips=($(echo $ips | tr " " "\n")) | |
# local_ip=999.999.999 # (uncomment for testing) | |
domains=( | |
"localhost" | |
"${local_ips[@]}" | |
) | |
if [[ ! -f $ssl_crt ]]; then | |
echo -e "\n🛑 ${b}Couldn't find a Slate SSL certificate:${c}" | |
make_key=true | |
elif [[ ! $(openssl x509 -noout -text -in $ssl_crt | grep $local_ip) ]]; then | |
echo -e "\n🛑 ${b}Your IP Address has changed:${c}" | |
make_key=true | |
else | |
echo -e "\n✅ ${b}Your IP address is still the same.${c}" | |
fi | |
if [[ $make_key == true ]]; then | |
echo -e "Generating a new Slate SSL certificate...\n" | |
count=$(( ${#domains[@]} - 1)) | |
mkcert ${domains[@]} | |
# Create Slate's default certificate directory, if it doesn't exist | |
test ! -d $f && mkdir $f | |
# It appears mkcert bases its filenames off the number of domains passed after the first one. | |
# This script predicts that filename, so it can copy it to Slate's default location. | |
if [[ $count = 0 ]]; then | |
mv ./localhost.pem $ssl_crt | |
mv ./localhost-key.pem $ssl_key | |
else | |
mv ./localhost+$count.pem $ssl_crt | |
mv ./localhost+$count-key.pem $ssl_key | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment