#/bin/bash

###
# @author dev <dev@areazero.de>
# @version 2021.06.28.01
###

_DOMAIN_=$1

_SSL_DIR_='/etc/ssl/domains'
_SRC_DIR_='/etc/letsencrypt/live/'${_DOMAIN_}
_DST_DIR_=${_SSL_DIR_}/${_DOMAIN_}

if [ -z "${_DOMAIN_}" -o "${_DOMAIN_}" = '--help' ] ; then
  echo 'usage: '$0' <domain_name>'
  exit 0
fi

if [ ! -d "${_SSL_DIR_}" ] ; then
  mkdir -m 2751 "${_SSL_DIR_}" || exit 1
fi

if [ ! -d "${_DST_DIR_}" ] ; then
  mkdir -m 2751 "${_DST_DIR_}" || exit 1
fi

ln -s ${_SRC_DIR_}/cert.pem       ${_DST_DIR_}/domain.crt || exit 1
ln -s ${_SRC_DIR_}/privkey.pem    ${_DST_DIR_}/domain.key || exit 1
ln -s ${_SRC_DIR_}/fullchain.pem  ${_DST_DIR_}/domain.pem || exit 1
ln -s ${_SRC_DIR_}/chain.pem      ${_DST_DIR_}/trusted.pem || exit 1

find "${_DST_DIR_}" || exit 1

echo "done"

