Files
fusionpbx-install.sh/debian/resources/letsencrypt.sh
T

131 lines
4.3 KiB
Bash
Raw Normal View History

2017-02-02 13:57:24 -07:00
#!/bin/sh
2018-03-21 19:37:55 -06:00
# FusionPBX - Install
# Mark J Crane <markjcrane@fusionpbx.com>
# Copyright (C) 2018
# All Rights Reserved.
2017-03-04 12:53:41 -07:00
#move to script directory so all relative paths work
cd "$(dirname "$0")"
#includes
. ./config.sh
#Add dependencies
apt-get install -y curl
2018-03-21 11:30:31 -06:00
#remove dehyrdated letsencrypt script
rm /usr/local/sbin/dehydrated
rm -R /usr/src/dehydrated
2018-03-21 11:30:31 -06:00
#rm -R /etc/dehydrated/
#rm -R /usr/src/dns-01-manual
#rm -R /var/www/dehydrated
2018-03-21 11:20:07 -06:00
#request the domain name, email address and wild card domain
2017-02-02 15:31:00 -07:00
read -p 'Domain Name: ' domain_name
2017-02-03 10:13:18 -07:00
read -p 'Email Address: ' email_address
2018-03-21 19:26:05 -06:00
2018-03-21 11:20:07 -06:00
#get and install dehydrated
2018-03-21 11:00:29 -06:00
cd /usr/src && git clone https://github.com/lukas2511/dehydrated.git
cd /usr/src/dehydrated
cp dehydrated /usr/local/sbin
mkdir -p /var/www/dehydrated
mkdir -p /etc/dehydrated/certs
2017-02-02 14:34:35 -07:00
2018-07-25 00:41:15 -05:00
#wildcard detection
2020-03-27 19:16:23 -04:00
wildcard_domain=$(echo $domain_name | cut -c1-1)
if [ "$wildcard_domain" = "*" ]; then
wildcard_domain="true"
2018-07-25 00:41:15 -05:00
else
2020-03-27 19:16:23 -04:00
wildcard_domain="false"
2018-07-25 00:41:15 -05:00
fi
2018-03-21 19:30:40 -06:00
#remove the wildcard and period
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."true" ]; then
2018-03-22 10:10:12 -06:00
domain_name=$(echo "$domain_name" | cut -c3-255)
fi
2018-03-21 19:30:40 -06:00
2018-03-21 11:00:29 -06:00
#manual dns hook
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."true" ]; then
2018-08-02 12:46:32 -06:00
cd /usr/src
2019-05-29 23:43:48 -07:00
git clone https://github.com/gheja/dns-01-manual.git
2018-08-02 12:46:32 -06:00
cd /usr/src/dns-01-manual/
cp hook.sh /etc/dehydrated/hook.sh
chmod 755 /etc/dehydrated/hook.sh
2018-07-25 00:41:15 -05:00
fi
2018-07-25 00:55:18 -05:00
#copy config and hook.sh into /etc/dehydrated
cd /usr/src/dehydrated
cp docs/examples/config /etc/dehydrated
#cp docs/examples/hook.sh /etc/dehydrated
2018-07-25 00:41:15 -05:00
#update the dehydrated config
#sed "s#CONTACT_EMAIL=#CONTACT_EMAIL=$email_address" -i /etc/dehydrated/config
sed -i 's/#CONTACT_EMAIL=/CONTACT_EMAIL="'"$email_address"'"/g' /etc/dehydrated/config
sed -i 's/#WELLKNOWN=/WELLKNOWN=/g' /etc/dehydrated/config
2018-07-25 00:41:15 -05:00
#accept the terms
2020-05-12 13:34:00 -06:00
./dehydrated --register --accept-terms --config /etc/dehydrated/config
2018-07-25 00:41:15 -05:00
#set the domain alias
domain_alias=$(echo "$domain_name" | head -n1 | cut -d " " -f1)
2018-07-25 00:55:18 -05:00
#create an alias when using wildcard dns
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."true" ]; then
2018-07-25 00:55:18 -05:00
echo "*.$domain_name > $domain_name" > /etc/dehydrated/domains.txt
fi
2018-07-25 00:41:15 -05:00
#add the domain name to domains.txt
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."false" ]; then
2018-07-25 00:41:15 -05:00
echo "$domain_name" > /etc/dehydrated/domains.txt
fi
2017-03-11 12:40:29 -07:00
2018-07-25 00:41:15 -05:00
#request the certificates
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."true" ]; then
./dehydrated --cron --domain *.$domain_name --preferred-chain "ISRG Root X1" --algo rsa --alias $domain_alias --config /etc/dehydrated/config --out /etc/dehydrated/certs --challenge dns-01 --hook /etc/dehydrated/hook.sh
2018-03-21 11:50:04 -06:00
fi
2020-03-27 19:16:23 -04:00
if [ .$wildcard_domain = ."false" ]; then
./dehydrated --cron --alias $domain_alias --preferred-chain "ISRG Root X1" --algo rsa --config /etc/dehydrated/config --config /etc/dehydrated/config --out /etc/dehydrated/certs --challenge http-01
2018-03-21 11:50:04 -06:00
fi
2018-07-25 00:55:18 -05:00
#make sure the nginx ssl directory exists
mkdir -p /etc/nginx/ssl
2017-02-03 10:13:18 -07:00
#update nginx config
sed "s@ssl_certificate[ \t]*/etc/ssl/certs/nginx.crt;@ssl_certificate /etc/dehydrated/certs/$domain_alias/fullchain.pem;@g" -i /etc/nginx/sites-available/fusionpbx
sed "s@ssl_certificate_key[ \t]*/etc/ssl/private/nginx.key;@ssl_certificate_key /etc/dehydrated/certs/$domain_alias/privkey.pem;@g" -i /etc/nginx/sites-available/fusionpbx
2017-02-02 14:34:35 -07:00
2017-02-03 10:13:18 -07:00
#read the config
2017-02-02 14:34:35 -07:00
/usr/sbin/nginx -t && /usr/sbin/nginx -s reload
2017-02-03 10:13:18 -07:00
2018-07-25 00:41:15 -05:00
#setup freeswitch tls
if [ .$switch_tls = ."true" ]; then
#make sure the freeswitch directory exists
mkdir -p /etc/freeswitch/tls
2018-03-22 01:27:00 -06:00
2018-07-25 00:41:15 -05:00
#make sure the freeswitch certificate directory is empty
rm /etc/freeswitch/tls/*
2018-03-22 10:10:12 -06:00
2018-07-25 00:41:15 -05:00
#combine the certs into all.pem
2018-07-25 00:59:53 -05:00
cat /etc/dehydrated/certs/$domain_alias/fullchain.pem > /etc/freeswitch/tls/all.pem
cat /etc/dehydrated/certs/$domain_alias/privkey.pem >> /etc/freeswitch/tls/all.pem
#cat /etc/dehydrated/certs/$domain_alias/chain.pem >> /etc/freeswitch/tls/all.pem
2018-03-22 01:27:00 -06:00
2018-07-25 00:41:15 -05:00
#copy the certificates
2018-07-25 00:59:53 -05:00
cp /etc/dehydrated/certs/$domain_alias/cert.pem /etc/freeswitch/tls
cp /etc/dehydrated/certs/$domain_alias/chain.pem /etc/freeswitch/tls
cp /etc/dehydrated/certs/$domain_alias/fullchain.pem /etc/freeswitch/tls
cp /etc/dehydrated/certs/$domain_alias/privkey.pem /etc/freeswitch/tls
2018-03-22 01:27:00 -06:00
2018-07-25 00:41:15 -05:00
#add symbolic links
ln -s /etc/freeswitch/tls/all.pem /etc/freeswitch/tls/agent.pem
ln -s /etc/freeswitch/tls/all.pem /etc/freeswitch/tls/tls.pem
ln -s /etc/freeswitch/tls/all.pem /etc/freeswitch/tls/wss.pem
ln -s /etc/freeswitch/tls/all.pem /etc/freeswitch/tls/dtls-srtp.pem
2018-03-22 01:27:00 -06:00
2018-07-25 00:41:15 -05:00
#set the permissions
chown -R www-data:www-data /etc/freeswitch/tls
2018-08-02 12:46:32 -06:00
fi