#!/ffp/bin/sh

SCRIPT=$(readlink -f $0)
File=`dirname $SCRIPT`"/genssl.data"
PATH="/ffp/sbin:/usr/sbin:/sbin:/ffp/bin:/usr/bin:/bin"

clear
echo -e "\e[93m\t\tWelcome at Mr Dini's auto cert creator using acme.sh!\e[0m"
echo -e "\n\nIf You don't know, how to use it, please check:\nhttps://prohardver.hu/tema/mr_dini_lokalblogja/hsz_3-3.html"

function genkey {
/ffp/root/.acme.sh/acme.sh --issue -d $Domain --apache
mkdir /ffp/apache/certs/ >/dev/null 2>&1
/ffp/root/.acme.sh/acme.sh --installcert -d $Domain --certpath /ffp/apache/certs/$Domain.cert --keypath /ffp/apache/certs/$Domain.key --capath /ffp/apache/certs/$Domain.ca --fullchainpath /ffp/apache/certs/$Domain.chain
}

# checking if there is a new user/config

if [ -f $File ]; then
   Domain=$(cat $File | sed 's/domain=//')
   genkey
else
   echo -e "\n\nPlease type Your domain/hostname!"
   read Domain
   echo -e "\n\nOkay, saving to file..."
   echo "domain="$Domain > $File
   sed -i "s/asd/$Domain/g" /ffp/apache/conf/httpd.conf
   genkey
fi

