devuan: merge letsencrypt.sh from debian

This commit is contained in:
Valentin Kleibel 2022-04-04 16:22:24 +02:00
parent 8dbb543d72
commit e7ed1f7398
1 changed files with 97 additions and 50 deletions

View File

@ -1,80 +1,127 @@
#!/bin/sh #!/bin/sh
# FusionPBX - Install
# Mark J Crane <markjcrane@fusionpbx.com>
# Copyright (C) 2018
# All Rights Reserved.
#move to script directory so all relative paths work #move to script directory so all relative paths work
cd "$(dirname "$0")" cd "$(dirname "$0")"
#includes #includes
. ./config.sh . ./config.sh
. ./colors.sh
. ./environment.sh
#request the domain and email #remove dehyrdated letsencrypt script
rm /usr/local/sbin/dehydrated
rm -R /usr/src/dehydrated
#rm -R /etc/dehydrated/
#rm -R /usr/src/dns-01-manual
#rm -R /var/www/dehydrated
#request the domain name, email address and wild card domain
read -p 'Domain Name: ' domain_name read -p 'Domain Name: ' domain_name
read -p 'Email Address: ' email_address read -p 'Email Address: ' email_address
#domain_name=subdomain.domain.com
#email=username@domain.com
#remove previous install #get and install dehydrated
rm -R /opt/letsencrypt cd /usr/src && git clone https://github.com/lukas2511/dehydrated.git
rm -R /etc/letsencrypt cd /usr/src/dehydrated
cp dehydrated /usr/local/sbin
mkdir -p /var/www/dehydrated
mkdir -p /etc/dehydrated/certs
#use php version 5 for arm #wildcard detection
if [ .$cpu_architecture = .'arm' ]; then wildcard_domain=$(echo $domain_name | cut -c1-1)
php_version=5 if [ "$wildcard_domain" = "*" ]; then
wildcard_domain="true"
else
wildcard_domain="false"
fi fi
#enable fusionpbx nginx config #remove the wildcard and period
cp nginx/fusionpbx /etc/nginx/sites-available/fusionpbx if [ .$wildcard_domain = ."true" ]; then
domain_name=$(echo "$domain_name" | cut -c3-255)
#prepare socket name
if [ ."$php_version" = ."5" ]; then
sed -i /etc/nginx/sites-available/fusionpbx -e 's#unix:.*;#unix:/var/run/php5-fpm.sock;#g'
fi fi
if [ ."$php_version" = ."7" ]; then
sed -i /etc/nginx/sites-available/fusionpbx -e 's#unix:.*;#unix:/var/run/php/php7.0-fpm.sock;#g' #manual dns hook
if [ .$wildcard_domain = ."true" ]; then
cd /usr/src
git clone https://github.com/gheja/dns-01-manual.git
cd /usr/src/dns-01-manual/
cp hook.sh /etc/dehydrated/hook.sh
chmod 755 /etc/dehydrated/hook.sh
fi fi
ln -s /etc/nginx/sites-available/fusionpbx /etc/nginx/sites-enabled/fusionpbx
#read the config #copy config and hook.sh into /etc/dehydrated
/usr/sbin/nginx -t && /usr/sbin/nginx -s reload cd /usr/src/dehydrated
cp docs/examples/config /etc/dehydrated
#cp docs/examples/hook.sh /etc/dehydrated
#install letsencrypt #update the dehydrated config
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt #sed "s#CONTACT_EMAIL=#CONTACT_EMAIL=$email_address" -i /etc/dehydrated/config
chmod 755 /opt/letsencrypt/certbot-auto sed -i 's/#CONTACT_EMAIL=/CONTACT_EMAIL="'"$email_address"'"/g' /etc/dehydrated/config
/opt/letsencrypt/./certbot-auto sed -i 's/#WELLKNOWN=/WELLKNOWN=/g' /etc/dehydrated/config
mkdir -p /etc/letsencrypt/configs
mkdir -p /var/www/letsencrypt/
#cd $pwd #accept the terms
#cd "$(dirname "$0")" ./dehydrated --register --accept-terms --config /etc/dehydrated/config
#copy the domain conf #set the domain alias
cp letsencrypt/domain_name.conf /etc/letsencrypt/configs/$domain_name.conf domain_alias=$(echo "$domain_name" | head -n1 | cut -d " " -f1)
#update the domain_name and email_address #create an alias when using wildcard dns
sed "s#{domain_name}#$domain_name#g" -i /etc/letsencrypt/configs/$domain_name.conf if [ .$wildcard_domain = ."true" ]; then
sed "s#{email_address}#$email_address#g" -i /etc/letsencrypt/configs/$domain_name.conf echo "*.$domain_name > $domain_name" > /etc/dehydrated/domains.txt
fi
#letsencrypt #add the domain name to domains.txt
#sed "s@#letsencrypt@location /.well-known/acme-challenge { root /var/www/letsencrypt; }@g" -i /etc/nginx/sites-available/fusionpbx if [ .$wildcard_domain = ."false" ]; then
echo "$domain_name" > /etc/dehydrated/domains.txt
fi
#get the certs from letsencrypt #request the certificates
cd /opt/letsencrypt && ./letsencrypt-auto --config /etc/letsencrypt/configs/$domain_name.conf certonly 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
fi
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
fi
#make sure the nginx ssl directory exists
mkdir -p /etc/nginx/ssl
#update nginx config #update nginx config
sed "s@ssl_certificate /etc/ssl/certs/nginx.crt;@ssl_certificate /etc/letsencrypt/live/$domain_name/fullchain.pem;@g" -i /etc/nginx/sites-available/fusionpbx sed "s@ssl_certificate /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 /etc/ssl/private/nginx.key;@ssl_certificate_key /etc/letsencrypt/live/$domain_name/privkey.pem;@g" -i /etc/nginx/sites-available/fusionpbx sed "s@ssl_certificate_key /etc/ssl/private/nginx.key;@ssl_certificate_key /etc/dehydrated/certs/$domain_alias/privkey.pem;@g" -i /etc/nginx/sites-available/fusionpbx
#read the config #read the config
/usr/sbin/nginx -t && /usr/sbin/nginx -s reload /usr/sbin/nginx -t && /usr/sbin/nginx -s reload
#combine the certs into all.pem #setup freeswitch tls
cat /etc/letsencrypt/live/$domain_name/cert.pem > /etc/letsencrypt/live/$domain_name/all.pem if [ .$switch_tls = ."true" ]; then
cat /etc/letsencrypt/live/$domain_name/privkey.pem >> /etc/letsencrypt/live/$domain_name/all.pem
cat /etc/letsencrypt/live/$domain_name/chain.pem >> /etc/letsencrypt/live/$domain_name/all.pem
#copy the certs to the switch tls directory #make sure the freeswitch directory exists
mkdir -p /etc/freeswitch/tls mkdir -p /etc/freeswitch/tls
cp /etc/letsencrypt/live/$domain_name/*.pem /etc/freeswitch/tls
cp /etc/freeswitch/tls/all.pem /etc/freeswitch/tls/wss.pem #make sure the freeswitch certificate directory is empty
chown -R www-data:www-data /etc/freeswitch rm /etc/freeswitch/tls/*
#combine the certs into all.pem
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
#copy the certificates
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
#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
#set the permissions
chown -R www-data:www-data /etc/freeswitch/tls
fi