#!/bin/bash
set -o errexit

[ -z "$1" ] && echo "Please specify a domain name (ex. magento.test)" && exit

DOMAIN=$1

if ! grep -q "$DOMAIN" /etc/hosts; then
    echo "Your system password is needed to add an entry to /etc/hosts..."
    echo "127.0.0.1 ::1 $DOMAIN" | sudo tee -a /etc/hosts
fi

echo "Set https://${DOMAIN}/ to web/secure/base_url and web/secure/base_url"
bin/clinotty bin/magento config:set web/secure/base_url https://"$DOMAIN"/
bin/clinotty bin/magento config:set web/unsecure/base_url https://"$DOMAIN"/

echo "Generating SSL certificate..."
bin/setup-ssl "$DOMAIN"