Skip to content

Instantly share code, notes, and snippets.

@B-Galati
Last active December 4, 2020 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save B-Galati/eb1f58de5235a9abe4277eaf946fb85a to your computer and use it in GitHub Desktop.
Save B-Galati/eb1f58de5235a9abe4277eaf946fb85a to your computer and use it in GitHub Desktop.
A script to automatically install mkcert locally if not installed globally
#!/usr/bin/env bash
#
# A lot of inspiration comes directly from symfony cli installer
set -euo pipefail
ROOT_PATH=$(
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd
)
cd "${ROOT_PATH}"
source z-utils.sh
if [[ ${machine} != 'amd64' ]]; then
output_error "Only amd64 machine is supported. Your machine is '${machine}'."
exit 1
fi
platform="${kernel}-${machine}"
version=1.4.1
url="https://github.com/FiloSottile/mkcert/releases/download/v${version}/mkcert-v${version}-${platform}"
checksum="e116543bfabb4d88010dda8a551a5d01abbdf9b4f2c949c044b862365038f632"
if [[ ${kernel} == 'darwin' ]]; then
checksum="9c3dbf27e780f5a9bb893426c0e89dcbb3e9bab1ac4db7eef45ad94a7b5f79f1"
fi
if [[ "${1:-}" == "--force" || "${1:-}" == "-f" ]]; then
output_info "Force installation"
elif [[ -f mkcert ]]; then
output_info "mkcert is already installed"
exit 0
fi
output_info "Downloading version mkcert v${version} from ${url}";
case ${downloader} in
"curl")
curl -SL "${url}" -o mkcert
;;
"wget")
wget -q --show-progress "${url}" -O mkcert
;;
esac
if ! (echo "${checksum} mkcert" | sha256sum -c); then
output_error "/!\ mkcert checksum validation failed. Removing downloaded binary."
rm mkcert
exit 1
fi
chmod +x mkcert
output_success "mkcert v${version} from ${url} installed to '${ROOT_PATH}/mkcert'!"
#!/usr/bin/env bash
# Taken from Symfony installer
function output {
style_start=""
style_end=""
if [ "${2:-}" != "" ]; then
case $2 in
"success")
style_start="\033[0;32m"
style_end="\033[0m"
;;
"error")
style_start="\033[31;31m"
style_end="\033[0m"
;;
"info"|"warning")
style_start="\033[33m"
style_end="\033[39m"
;;
"heading")
style_start="\033[1;33m"
style_end="\033[22;39m"
;;
esac
fi
builtin echo -e "${style_start}${1}${style_end}"
}
function output_success {
output "${1}" 'success'
}
function output_heading {
output "${1}" 'heading'
}
function output_info {
output "${1}" 'info'
}
function output_warning {
output "${1}" 'warning'
}
function output_error {
output "${1}" 'error'
}
# Check that cURL or wget is installed.
downloader=""
command -v curl >/dev/null 2>&1
if [ $? == 0 ]; then
downloader="curl"
else
command -v wget >/dev/null 2>&1
if [ $? == 0 ]; then
downloader="wget"
else
output_error "cURL or wget is required for installation."
exit 1
fi
fi
kernel=`uname -s`
case ${kernel} in
"Linux"|"linux")
kernel="linux"
;;
"Darwin"|"darwin")
kernel="darwin"
;;
*)
output_error "OS '${kernel}' not supported"
exit 1
;;
esac
machine=`uname -m`
if [[ ${machine} == "i386" ]]; then
machine="386"
else
machine="amd64"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment