|
| 1 | +#!/bin/bash |
| 2 | +#--------------------------------------------------------- |
| 3 | +# Relink local certificates found to link to specific files |
| 4 | +#--------------------------------------------------------- |
| 5 | + |
| 6 | +source /etc/lsb-release |
| 7 | + |
| 8 | +export RED='\033[0;31m' |
| 9 | +export GREEN='\033[0;32m' |
| 10 | +export BLUE='\033[0;34m' |
| 11 | +export YELLOW='\033[0;33m' |
| 12 | + |
| 13 | + |
| 14 | +echo "***** $0 *****" |
| 15 | + |
| 16 | +if [ "x$2" == "x" ]; then |
| 17 | + echo "Relink local certificates found into /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt to link to specific cert files" |
| 18 | + echo |
| 19 | + echo "Usage: $0 root_of_cert_to_link_to regex_of_files_to_replace test|confirm" |
| 20 | + echo "Example: $0 /etc/apache2/all.with.dolicloud.com xxx.dolicloud.com test|confirm" |
| 21 | + echo |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +if [ "x$3" != "xtest" -a "x$3" != "xconfirm" ]; then |
| 26 | + echo "Parameter 3 must be test|confirm" |
| 27 | + exit 2 |
| 28 | +fi |
| 29 | + |
| 30 | +# possibility to change the ssl certificates name |
| 31 | +export webSSLCertificateCRT=`grep '^websslcertificatecrt=' /etc/sellyoursaas.conf | cut -d '=' -f 2` |
| 32 | +if [[ "x$webSSLCertificateCRT" == "x" ]]; then |
| 33 | + export webSSLCertificateCRT=with.sellyoursaas.com.crt |
| 34 | +fi |
| 35 | +export webSSLCertificateKEY=`grep '^websslcertificatekey=' /etc/sellyoursaas.conf | cut -d '=' -f 2` |
| 36 | +if [[ "x$webSSLCertificateKEY" == "x" ]]; then |
| 37 | + export webSSLCertificateKEY=with.sellyoursaas.com.key |
| 38 | +fi |
| 39 | +export webSSLCertificateIntermediate=`grep '^websslcertificateintermediate=' /etc/sellyoursaas.conf | cut -d '=' -f 2` |
| 40 | +if [[ "x$webSSLCertificateIntermediate" == "x" ]]; then |
| 41 | + export webSSLCertificateIntermediate=with.sellyoursaas.com-intermediate.crt |
| 42 | +fi |
| 43 | +export domainmyaccount=`grep '^domain=' /etc/sellyoursaas.conf | cut -d '=' -f 2` |
| 44 | + |
| 45 | +export urlwhenoffline=$1 |
| 46 | +if [[ $urlwhenoffline != http* ]]; then |
| 47 | + export urlwhenoffline="https://myaccount.$domainmyaccount/$1" |
| 48 | +fi |
| 49 | + |
| 50 | + |
| 51 | +export scriptdir=$(dirname $(realpath ${0})) |
| 52 | + |
| 53 | +echo "Search local cert files to relink with: ls /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/*.key | grep $2" |
| 54 | +for fic in `ls /home/admin/wwwroot/dolibarr_documents/sellyoursaas_local/crt/*.key | grep $2` |
| 55 | +do |
| 56 | + newfic="${fic%.key}" |
| 57 | + echo "* Process file $newfic..." |
| 58 | + echo "ln -fs $1.key $newfic.key" |
| 59 | + echo "ln -fs $1.crt $newfic.crt" |
| 60 | + echo "ln -fs $1-intermediate.crt $newfic-intermediate.crt" |
| 61 | + if [ "x$3" == "xconfirm" ]; then |
| 62 | + ln -fs $1.key $newfic.key |
| 63 | + ln -fs $1.crt $newfic.crt |
| 64 | + ln -fs $1-intermediate.crt $newfic-intermediate.crt |
| 65 | + else |
| 66 | + echo "Test mode: nothing done" |
| 67 | + fi |
| 68 | +done |
| 69 | + |
| 70 | +echo "Finished." |
0 commit comments