Browse Source

quickie site function

master
Daniel Martinez 1 year ago
parent
commit
2edd1200fe
  1. 24
      mkbrd.fn

24
mkbrd.fn

@ -1,18 +1,26 @@
#quickie to create a thing where setup is already established
mkbrd () {
[[ $# != 2 ]] || [[ $# != 3 ]] || echo "Usage ${0} <fully-qualified-domain-name> <php, proxy, or static> <if proxy, port>"
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FQDN=${1}
DOMAIN=$(expr match "${FQDN}" '.*\.\(.*\..*\)')
[[ -z ${DOMAIN} ]] && export DOMAIN=${FQDN}
LOCAL_IP=$(curl -sL i.kbrd.co)
TYPE=${2}
knotc zone-begin ${DOMAIN}
knotc zone-set ${DOMAIN} ${SUBDOMAIN} 14400 A ${LOCAL_IP}
knotc zone-set ${DOMAIN} ${FQDN} 14400 A ${LOCAL_IP}
knotc zone-commit ${DOMAIN}
certbot certonly -n -d ${FQDN} --preferred-challenges=dns --manual --manual-auth-hook=${HOME}/git/certbot-knot-hooks/same-server-authenticator-hook.sh --manual-cleanup-hook=${HOME}/git/certbot-knot-hooks/same-server-authenticator-hook.sh --manual-public-logging-ok
certbot certonly -n -d ${FQDN} --preferred-challenges=dns --manual --manual-auth-hook=${DIR}/scripts/same-server-authenticator-hook.sh --manual-cleanup-hook=${DIR}/scripts/same-server-cleanup-hook.sh --manual-public-logging-ok
case ${TYPE} in
php) ;;
php)
cp ${DIR}/templates/nginx_php.conf /etc/nginx/sites-enabled/${DOMAIN}/${FQDN} ;;
proxy)
ADDL_SED="s/FWDPORRT/${3}/";;
static) ;;
*) return 1;;
sed -e "s/IPADDR/${LOCAL_IP}/g" -e "s/ACTUALDOMAIN/${DOMAIN}/g" -e "s/SUBBYDOMAIN/${SUBDOMAIN}/g" ${ADDL_SED} /etc/nginx/template > /etc/nginx/sites-enabled/${FQDN}.conf
nginx -t && systemctl reload nginx
cp ${DIR}/templates/nginx_proxy.conf /etc/nginx/sites-enabled/${DOMAIN}/${FQDN}
export ADDL_SED="true" ;;
static) cp ${DIR}/templates/nginx_static.conf /etc/nginx/sites-enabled/${DOMAIN}/${FQDN} ;;
*) return 1 ;;
esac
sed -i -e "s/IPADDR/${LOCAL_IP}/g" -e "s/ACTUALDOMAIN/${DOMAIN}/g" -e "s/SUBBYDOMAIN/${FQDN}/g" /etc/nginx/sites-enabled/${DOMAIN}/${FQDN}
[[ -n ${ADDL_SED} ]] && sed -i -e "s/FWDPORRT/${3}/" /etc/nginx/sites-enabled/${DOMAIN}/${FQDN}
nginx -t && systemctl reload nginx || return 2
}
Loading…
Cancel
Save