7070 printf " \nRunning in Standard Mode...\n"
7171fi
7272
73- if [ ${LE_MODE} == " true" ]; then
73+ if [[ ${LE_MODE} == " true" ] ]; then
7474 # Check to see whether LE certificate has changed
7575 printf " \nInspecting current SSL certificate...\n"
76- if md5sum -c ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5 & > /dev/null; then
76+ if md5sum -c " ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5" & > /dev/null; then
7777 # MD5 remains unchanged, exit the script
7878 printf " \nCertificate is unchanged, no update is necessary.\n"
7979 exit 0
@@ -84,7 +84,7 @@ if [ ${LE_MODE} == "true" ]; then
8484fi
8585
8686# Verify required files exist
87- if [ ! -f " ${PRIV_KEY} " ] || [ ! -f " ${CHAIN_FILE} " ]; then
87+ if [[ ! -f ${PRIV_KEY} ]] || [[ ! -f ${CHAIN_FILE} ] ]; then
8888 printf " \nMissing one or more required files. Check your settings.\n"
8989 exit 1
9090else
@@ -99,24 +99,24 @@ P12_TEMP=$(mktemp)
9999
100100# Stop the UniFi Controller
101101printf " \nStopping UniFi Controller...\n"
102- service ${UNIFI_SERVICE} stop
102+ service " ${UNIFI_SERVICE} " stop
103103
104- if [ ${LE_MODE} == " true" ]; then
104+ if [[ ${LE_MODE} == " true" ] ]; then
105105
106106 # Write a new MD5 checksum based on the updated certificate
107107 printf " \nUpdating certificate MD5 checksum...\n"
108108
109- md5sum ${PRIV_KEY} > ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5
109+ md5sum " ${PRIV_KEY} " > " ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5"
110110
111111fi
112112
113113# Create double-safe keystore backup
114- if [ -s " ${KEYSTORE} .orig" ]; then
114+ if [[ -s " ${KEYSTORE} .orig" ] ]; then
115115 printf " \nBackup of original keystore exists!\n"
116116 printf " \nCreating non-destructive backup as keystore.bak...\n"
117- cp ${KEYSTORE} ${KEYSTORE} .bak
117+ cp " ${KEYSTORE} " " ${KEYSTORE} .bak"
118118else
119- cp ${KEYSTORE} ${KEYSTORE} .orig
119+ cp " ${KEYSTORE} " " ${KEYSTORE} .orig"
120120 printf " \nNo original keystore backup found.\n"
121121 printf " \nCreating backup as keystore.orig...\n"
122122fi
125125printf " \nExporting SSL certificate and key data into temporary PKCS12 file...\n"
126126
127127# If there is a signed crt we should include this in the export
128- if [ -f " ${SIGNED_CRT} " ]; then
128+ if [[ -f ${SIGNED_CRT} ] ]; then
129129 openssl pkcs12 -export \
130- -in ${CHAIN_FILE} \
131- -in ${SIGNED_CRT} \
132- -inkey ${PRIV_KEY} \
133- -out ${P12_TEMP} -passout pass:${PASSWORD} \
134- -name ${ALIAS}
130+ -in " ${CHAIN_FILE} " \
131+ -in " ${SIGNED_CRT} " \
132+ -inkey " ${PRIV_KEY} " \
133+ -out " ${P12_TEMP} " -passout pass:" ${PASSWORD} " \
134+ -name " ${ALIAS} "
135135else
136136 openssl pkcs12 -export \
137- -in ${CHAIN_FILE} \
138- -inkey ${PRIV_KEY} \
139- -out ${P12_TEMP} -passout pass:${PASSWORD} \
140- -name ${ALIAS}
137+ -in " ${CHAIN_FILE} " \
138+ -inkey " ${PRIV_KEY} " \
139+ -out " ${P12_TEMP} " -passout pass:" ${PASSWORD} " \
140+ -name " ${ALIAS} "
141141fi
142142
143143# Delete the previous certificate data from keystore to avoid "already exists" message
144144printf " \nRemoving previous certificate data from UniFi keystore...\n"
145- keytool -delete -alias ${ALIAS} -keystore ${KEYSTORE} -deststorepass ${PASSWORD}
145+ keytool -delete -alias " ${ALIAS} " -keystore " ${KEYSTORE} " -deststorepass " ${PASSWORD} "
146146
147147# Import the temp PKCS12 file into the UniFi keystore
148148printf " \nImporting SSL certificate into UniFi keystore...\n"
149149keytool -importkeystore \
150- -srckeystore ${P12_TEMP} -srcstoretype PKCS12 \
151- -srcstorepass ${PASSWORD} \
152- -destkeystore ${KEYSTORE} \
153- -deststorepass ${PASSWORD} \
154- -destkeypass ${PASSWORD} \
155- -alias ${ALIAS} -trustcacerts
150+ -srckeystore " ${P12_TEMP} " -srcstoretype PKCS12 \
151+ -srcstorepass " ${PASSWORD} " \
152+ -destkeystore " ${KEYSTORE} " \
153+ -deststorepass " ${PASSWORD} " \
154+ -destkeypass " ${PASSWORD} " \
155+ -alias " ${ALIAS} " -trustcacerts
156156
157157# Clean up temp files
158158printf " \nRemoving temporary files...\n"
159- rm -f ${P12_TEMP}
159+ rm -f " ${P12_TEMP} "
160160
161161# Restart the UniFi Controller to pick up the updated keystore
162162printf " \nRestarting UniFi Controller to apply new Let's Encrypt SSL certificate...\n"
163- service ${UNIFI_SERVICE} start
163+ service " ${UNIFI_SERVICE} " start
164164
165165# That's all, folks!
166166printf " \nDone!\n"
0 commit comments