Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

SSL certificate script not working in ZSH #1094

Open
driespieters opened this issue Mar 2, 2020 · 1 comment
Open

SSL certificate script not working in ZSH #1094

driespieters opened this issue Mar 2, 2020 · 1 comment

Comments

@driespieters
Copy link
Contributor

The Bash function to create a self signed SSL certificate won't work after switching to ZSH. (Default now on OSX)

https://github.com/Shopify/slate/wiki/4.-Create-a-self-signed-SSL-certificate

Does anyone know how to modify the script to run in ZSH?

Temporary fix: revert the console shell to Bash.
chsh -s /bin/bash
(Also restart terminal)

@sam-mcintire
Copy link

sam-mcintire commented Dec 17, 2020

@driespieters I'm switching to ZSH and having this same issue. I don't know ZSH script, but messed around a bit and it looks as though the comments in Shopify's sample ssl-check script were what was causing the issue. The following code — stripped of comments — is working for me.

function ssl-check() {
    f=~/.localhost_ssl;
    ssl_crt=$f/server.crt
    ssl_key=$f/server.key
    b=$(tput bold)
    c=$(tput sgr0)
    
    local_ip=$(ipconfig getifaddr $(route get default | grep interface | awk '{print $2}'))
    
    domains=(
        "localhost"
        "$local_ip"
    )
    
    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[@]}
    
        test ! -d $f && mkdir $f
    
        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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants