fusionpbx-install.sh/freebsd/resources/letsencrypt.sh

126 lines
4.6 KiB
Bash
Raw Normal View History

2018-07-01 16:35:36 +02:00
#!/bin/sh
# FusionPBX - Install
# Mark J Crane <markjcrane@fusionpbx.com>
# Copyright (C) 2018
# All Rights Reserved.
2018-07-01 17:34:40 +02:00
2018-07-01 16:35:36 +02:00
#move to script directory so all relative paths work
cd "$(dirname "$0")"
#includes
. ./config.sh
#remove dehyrdated letsencrypt script
2018-07-04 23:59:45 +02:00
#pkg remove dehydrated
2018-07-01 17:34:40 +02:00
#rm -R /usr/local/etc/dehydrated/
2018-07-01 16:35:36 +02:00
#rm /usr/local/sbin/dehydrated
#rm -R /usr/src/dehydrated
#rm -R /usr/src/dns-01-manual
2018-07-01 17:34:40 +02:00
#rm -R /usr/local/www/dehydrated
2018-07-01 16:35:36 +02:00
#request the domain name, email address and wild card domain
read -p 'Domain Name: ' domain_name
read -p 'Email Address: ' email_address
#get and install dehydrated
2018-07-04 23:59:45 +02:00
pkg install dehydrated
#cd /usr/src && git clone https://github.com/lukas2511/dehydrated.git
#cd /usr/src/dehydrated
#cp dehydrated /usr/local/sbin
#mkdir -p /usr/local/www/dehydrated
#mkdir -p /usr/local/etc/dehydrated/certs
2018-07-01 16:35:36 +02:00
#manual dns hook
cd /usr/src
git clone https://github.com/owhen/dns-01-manual.git
cd /usr/src/dns-01-manual/
2018-07-01 17:34:40 +02:00
cp hook.sh /usr/local/etc/dehydrated/hook.sh
chmod 755 /usr/local/etc/dehydrated/hook.sh
2018-07-01 16:35:36 +02:00
2018-07-01 17:34:40 +02:00
#copy config and hook.sh into /usr/local/etc/dehydrated
2018-07-01 16:35:36 +02:00
cd /usr/src/dehydrated
2018-07-01 17:34:40 +02:00
cp docs/examples/config /usr/local/etc/dehydrated
#cp docs/examples/hook.sh /usr/local/etc/dehydrated
2018-07-01 16:35:36 +02:00
2018-07-01 17:34:40 +02:00
#vim /usr/local/etc/dehydrated/config
#sed "s#CONTACT_EMAIL=#CONTACT_EMAIL=$email_address" -i /usr/local/etc/dehydrated/config
2018-07-01 16:35:36 +02:00
#accept the terms
2018-07-01 17:34:40 +02:00
dehydrated --register --accept-terms --config /usr/local/etc/dehydrated/config
2018-07-01 16:35:36 +02:00
2018-07-21 08:18:39 +02:00
#wildcard detection
wilcard_domain=$(echo $domain_name | cut -c1-1)
if [ "$wilcard_domain" = "*" ]; then
wilcard_domain="true"
else
wilcard_domain="false"
fi
#remove the wildcard and period
if [ .$wilcard_domain = ."true" ]; then
domain_name=$(echo "$domain_name" | cut -c3-255)
fi
#create an alias when using wildcard dns
2018-07-21 22:00:40 +02:00
if [ .$wilcard_domain = ."true" ]; then
echo "*.$domain_name > $domain_name" > /usr/local/etc/dehydrated/domains.txt
fi
#add the domain_name to domains.txt
if [ .$wilcard_domain = ."false" ]; then
echo "$domain_name" > /usr/local/etc/dehydrated/domains.txt
fi
2018-07-21 08:18:39 +02:00
2018-07-01 16:35:36 +02:00
#wildcard domain
2018-07-21 08:18:39 +02:00
if [ .$wilcard_domain = ."true" ]; then
2018-07-01 17:34:40 +02:00
dehydrated --cron --domain *.$domain_name --alias $domain_name --config /usr/local/etc/dehydrated/config --out /usr/local/etc/dehydrated/certs --challenge dns-01 --hook /usr/local/etc/dehydrated/hook.sh
2018-07-01 16:35:36 +02:00
fi
#single domain
2018-07-21 08:18:39 +02:00
if [ .$wilcard_domain = ."false" ]; then
2018-07-21 22:00:40 +02:00
dehydrated --cron --domain $domain_name --config /usr/local/etc/dehydrated/config --out /usr/local/etc/dehydrated/certs --challenge http-01
2018-07-01 16:35:36 +02:00
fi
2018-07-04 23:59:45 +02:00
#remove the old backups
rm /usr/local/etc/nginx/server.crt.backup
rm /usr/local/etc/nginx/server.key.backup
#nginx config - backup the original certificates and copy the news ones for nginx
mv /usr/local/etc/nginx/server.crt /usr/local/etc/nginx/server.crt.backup
mv /usr/local/etc/nginx/server.key /usr/local/etc/nginx/server.key.backup
cp /usr/local/etc/dehydrated/certs/$domain_name/fullchain.pem /usr/local/etc/nginx/server.crt
cp /usr/local/etc/dehydrated/certs/$domain_name/privkey.pem /usr/local/etc/nginx/server.key
2018-07-01 16:35:36 +02:00
#read the config
2018-07-01 17:34:40 +02:00
/usr/local/sbin/nginx -t && /usr/local/sbin/nginx -s reload
2018-07-01 16:35:36 +02:00
2018-07-21 08:18:39 +02:00
#setup freeswitch tls
if [ .$switch_tls = ."true" ]; then
#make sure the freeswitch directory exists
mkdir -p /usr/local/etc/freeswitch/tls
#make sure the freeswitch certificate directory is empty
rm /usr/local/etc/freeswitch/tls/*
#combine the certs into all.pem
cat /usr/local/etc/dehydrated/certs/$domain_name/fullchain.pem > /usr/local/etc/freeswitch/tls/all.pem
cat /usr/local/etc/dehydrated/certs/$domain_name/privkey.pem >> /usr/local/etc/freeswitch/tls/all.pem
#cat /usr/local/etc/dehydrated/certs/$domain_name/chain.pem >> /usr/local/etc/freeswitch/tls/all.pem
#copy the certificates
cp /usr/local/etc/dehydrated/certs/$domain_name/cert.pem /usr/local/etc/freeswitch/tls
cp /usr/local/etc/dehydrated/certs/$domain_name/chain.pem /usr/local/etc/freeswitch/tls
cp /usr/local/etc/dehydrated/certs/$domain_name/fullchain.pem /usr/local/etc/freeswitch/tls
cp /usr/local/etc/dehydrated/certs/$domain_name/privkey.pem /usr/local/etc/freeswitch/tls
#add symbolic links
ln -s /usr/local/etc/freeswitch/tls/all.pem /usr/local/etc/freeswitch/tls/agent.pem
ln -s /usr/local/etc/freeswitch/tls/all.pem /usr/local/etc/freeswitch/tls/tls.pem
ln -s /usr/local/etc/freeswitch/tls/all.pem /usr/local/etc/freeswitch/tls/wss.pem
ln -s /usr/local/etc/freeswitch/tls/all.pem /usr/local/etc/freeswitch/tls/dtls-srtp.pem
#set the permissions
chown -R www:www /usr/local/etc/freeswitch/tls
fi