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

131 lines
4.3 KiB
Bash
Raw Normal View History

2017-02-02 21:57:24 +01:00
#!/bin/sh
2018-03-22 02:37:55 +01:00
# FusionPBX - Install
# Mark J Crane <markjcrane@fusionpbx.com>
# Copyright (C) 2018
# All Rights Reserved.
2017-03-04 20:53:41 +01: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 18:30:31 +01:00
#remove dehyrdated letsencrypt script
rm /usr/local/sbin/dehydrated
rm -R /usr/src/dehydrated
2018-03-21 18:30:31 +01:00
#rm -R /etc/dehydrated/
#rm -R /usr/src/dns-01-manual
#rm -R /var/www/dehydrated
2018-03-21 18:20:07 +01:00
#request the domain name, email address and wild card domain
2017-02-02 23:31:00 +01:00
read -p 'Domain Name: ' domain_name
read -p 'Email Address: ' email_address
2018-03-22 02:26:05 +01:00
2018-03-21 18:20:07 +01:00
#get and install dehydrated
2024-06-10 15:33:50 +02:00
cd /usr/src && git clone https://github.com/dehydrated-io/dehydrated.git
2018-03-21 18:00:29 +01:00
cd /usr/src/dehydrated
cp dehydrated /usr/local/sbin
mkdir -p /var/www/dehydrated
mkdir -p /etc/dehydrated/certs
2017-02-02 22:34:35 +01:00
2018-07-25 07:41:15 +02:00
#wildcard detection
2020-03-28 00:16:23 +01:00
wildcard_domain=$(echo $domain_name | cut -c1-1)
if [ "$wildcard_domain" = "*" ]; then
wildcard_domain="true"
2018-07-25 07:41:15 +02:00
else
2020-03-28 00:16:23 +01:00
wildcard_domain="false"
2018-07-25 07:41:15 +02:00
fi
2018-03-22 02:30:40 +01:00
#remove the wildcard and period
2020-03-28 00:16:23 +01:00
if [ .$wildcard_domain = ."true" ]; then
2018-03-22 17:10:12 +01:00
domain_name=$(echo "$domain_name" | cut -c3-255)
fi
2018-03-22 02:30:40 +01:00
2018-03-21 18:00:29 +01:00
#manual dns hook
2020-03-28 00:16:23 +01:00
if [ .$wildcard_domain = ."true" ]; then
2018-08-02 20:46:32 +02:00
cd /usr/src
2019-05-30 08:43:48 +02:00
git clone https://github.com/gheja/dns-01-manual.git
2018-08-02 20:46:32 +02:00
cd /usr/src/dns-01-manual/
cp hook.sh /etc/dehydrated/hook.sh
chmod 755 /etc/dehydrated/hook.sh
2018-07-25 07:41:15 +02:00
fi
2018-07-25 07:55:18 +02: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 07:41:15 +02: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 07:41:15 +02:00
#accept the terms
2020-05-12 21:34:00 +02:00
./dehydrated --register --accept-terms --config /etc/dehydrated/config
2018-07-25 07:41:15 +02:00
#set the domain alias
domain_alias=$(echo "$domain_name" | head -n1 | cut -d " " -f1)
2018-07-25 07:55:18 +02:00
#create an alias when using wildcard dns
2020-03-28 00:16:23 +01:00
if [ .$wildcard_domain = ."true" ]; then
2018-07-25 07:55:18 +02:00
echo "*.$domain_name > $domain_name" > /etc/dehydrated/domains.txt
fi
2018-07-25 07:41:15 +02:00
#add the domain name to domains.txt
2020-03-28 00:16:23 +01:00
if [ .$wildcard_domain = ."false" ]; then
2018-07-25 07:41:15 +02:00
echo "$domain_name" > /etc/dehydrated/domains.txt
fi
2017-03-11 20:40:29 +01:00
2018-07-25 07:41:15 +02:00
#request the certificates
2020-03-28 00:16:23 +01: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 18:50:04 +01:00
fi
2020-03-28 00:16:23 +01:00
if [ .$wildcard_domain = ."false" ]; then
./dehydrated --cron --alias $domain_alias --preferred-chain "ISRG Root X1" --algo rsa --config /etc/dehydrated/config --out /etc/dehydrated/certs --challenge http-01
2018-03-21 18:50:04 +01:00
fi
2018-07-25 07:55:18 +02:00
#make sure the nginx ssl directory exists
mkdir -p /etc/nginx/ssl
#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 22:34:35 +01:00
#read the config
2017-02-02 22:34:35 +01:00
/usr/sbin/nginx -t && /usr/sbin/nginx -s reload
2018-07-25 07:41:15 +02:00
#setup freeswitch tls
if [ .$switch_tls = ."true" ]; then
#make sure the freeswitch directory exists
mkdir -p /etc/freeswitch/tls
2018-03-22 08:27:00 +01:00
2018-07-25 07:41:15 +02:00
#make sure the freeswitch certificate directory is empty
rm /etc/freeswitch/tls/*
2018-03-22 17:10:12 +01:00
2018-07-25 07:41:15 +02:00
#combine the certs into all.pem
2018-07-25 07:59:53 +02: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 08:27:00 +01:00
2018-07-25 07:41:15 +02:00
#copy the certificates
2018-07-25 07:59:53 +02: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 08:27:00 +01:00
2018-07-25 07:41:15 +02: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 08:27:00 +01:00
2018-07-25 07:41:15 +02:00
#set the permissions
chown -R www-data:www-data /etc/freeswitch/tls
2018-08-02 20:46:32 +02:00
fi