Kaynağa Gözat

Convert between pem and crt if letsencrypt fails

Bob Mottram 8 yıl önce
ebeveyn
işleme
0b8fc22d70
1 değiştirilmiş dosya ile 24 ekleme ve 17 silme
  1. 24
    17
      src/freedombone-utils-web

+ 24
- 17
src/freedombone-utils-web Dosyayı Görüntüle

@@ -156,26 +156,33 @@ function check_certificates {
156 156
         USE_LETSENCRYPT=$2
157 157
     fi
158 158
     if [[ $USE_LETSENCRYPT == 'no' ]]; then
159
-        if [ ! -f /etc/ssl/private/$1.key ]; then
160
-            echo $"Private certificate for $CHECK_HOSTNAME was not created"
159
+        if [ ! -f /etc/ssl/private/${1}.key ]; then
160
+            echo $"Private certificate for ${CHECK_HOSTNAME} was not created"
161 161
             exit 63959
162 162
         fi
163
-        if [ ! -f /etc/ssl/certs/$1.crt ]; then
164
-            echo $"Public certificate for $CHECK_HOSTNAME was not created"
163
+        if [ ! -f /etc/ssl/certs/${1}.crt ]; then
164
+            echo $"Public certificate for ${CHECK_HOSTNAME} was not created"
165 165
             exit 7679
166 166
         fi
167
+
168
+        if grep -q "${1}.pem" /etc/nginx/sites-available/${1}; then
169
+            sed -i "s|${1}.pem|${1}.crt|g" /etc/nginx/sites-available/${1}
170
+        fi
167 171
     else
168 172
         if [ ! -f /etc/letsencrypt/live/${1}/privkey.pem ]; then
169
-            echo $"Private certificate for $CHECK_HOSTNAME was not created"
173
+            echo $"Private certificate for ${CHECK_HOSTNAME} was not created"
170 174
             exit 6282
171 175
         fi
172 176
         if [ ! -f /etc/letsencrypt/live/${1}/fullchain.pem ]; then
173
-            echo $"Public certificate for $CHECK_HOSTNAME was not created"
177
+            echo $"Public certificate for ${CHECK_HOSTNAME} was not created"
174 178
             exit 5328
175 179
         fi
180
+        if grep -q "${1}.crt" /etc/nginx/sites-available/${1}; then
181
+            sed -i "s|${1}.crt|${1}.pem|g" /etc/nginx/sites-available/${1}
182
+        fi
176 183
     fi
177
-    if [ ! -f /etc/ssl/certs/$1.dhparam ]; then
178
-        echo $"Diffie–Hellman parameters for $CHECK_HOSTNAME were not created"
184
+    if [ ! -f /etc/ssl/certs/${1}.dhparam ]; then
185
+        echo $"Diffie–Hellman parameters for ${CHECK_HOSTNAME} were not created"
179 186
         exit 5989
180 187
     fi
181 188
 }
@@ -190,26 +197,26 @@ function create_site_certificate {
190 197
     fi
191 198
 
192 199
     if [[ $ONION_ONLY == "no" ]]; then
193
-        if [ ! -f /etc/ssl/certs/$SITE_DOMAIN_NAME.dhparam ]; then
200
+        if [ ! -f /etc/ssl/certs/${SITE_DOMAIN_NAME}.dhparam ]; then
194 201
             if [[ $LETSENCRYPT_ENABLED != "yes" ]]; then
195
-                ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
202
+                ${PROJECT_NAME}-addcert -h ${SITE_DOMAIN_NAME} --dhkey ${DH_KEYLENGTH}
196 203
                 function_check check_certificates
197
-                check_certificates $SITE_DOMAIN_NAME
204
+                check_certificates ${SITE_DOMAIN_NAME}
198 205
             else
199
-                ${PROJECT_NAME}-addcert -e $SITE_DOMAIN_NAME -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH --email $MY_EMAIL_ADDRESS
206
+                ${PROJECT_NAME}-addcert -e ${SITE_DOMAIN_NAME} -s ${LETSENCRYPT_SERVER} --dhkey ${DH_KEYLENGTH} --email ${MY_EMAIL_ADDRESS}
200 207
                 if [ ! "$?" = "0" ]; then
201
-                    if [[ $NO_SELF_SIGNED == 'no' ]]; then
202
-                        echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME, so try making a self-signed cert"
203
-                        ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
208
+                    if [[ ${NO_SELF_SIGNED} == 'no' ]]; then
209
+                        echo $"Lets Encrypt failed for ${SITE_DOMAIN_NAME}, so try making a self-signed cert"
210
+                        ${PROJECT_NAME}-addcert -h ${SITE_DOMAIN_NAME} --dhkey ${DH_KEYLENGTH}
204 211
                         function_check check_certificates
205
-                        check_certificates $SITE_DOMAIN_NAME
212
+                        check_certificates ${SITE_DOMAIN_NAME}
206 213
                     else
207 214
                         echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME"
208 215
                         exit 682529
209 216
                     fi
210 217
                 else
211 218
                     function_check check_certificates
212
-                    check_certificates $SITE_DOMAIN_NAME 'yes'
219
+                    check_certificates ${SITE_DOMAIN_NAME} 'yes'
213 220
                 fi
214 221
             fi
215 222
         fi