70
70
printf " \nRunning in Standard Mode...\n"
71
71
fi
72
72
73
- if [ ${LE_MODE} == " true" ]; then
73
+ if [[ ${LE_MODE} == " true" ] ]; then
74
74
# Check to see whether LE certificate has changed
75
75
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
77
77
# MD5 remains unchanged, exit the script
78
78
printf " \nCertificate is unchanged, no update is necessary.\n"
79
79
exit 0
@@ -84,7 +84,7 @@ if [ ${LE_MODE} == "true" ]; then
84
84
fi
85
85
86
86
# Verify required files exist
87
- if [ ! -f " ${PRIV_KEY} " ] || [ ! -f " ${CHAIN_FILE} " ]; then
87
+ if [[ ! -f ${PRIV_KEY} ]] || [[ ! -f ${CHAIN_FILE} ] ]; then
88
88
printf " \nMissing one or more required files. Check your settings.\n"
89
89
exit 1
90
90
else
@@ -99,24 +99,24 @@ P12_TEMP=$(mktemp)
99
99
100
100
# Stop the UniFi Controller
101
101
printf " \nStopping UniFi Controller...\n"
102
- service ${UNIFI_SERVICE} stop
102
+ service " ${UNIFI_SERVICE} " stop
103
103
104
- if [ ${LE_MODE} == " true" ]; then
104
+ if [[ ${LE_MODE} == " true" ] ]; then
105
105
106
106
# Write a new MD5 checksum based on the updated certificate
107
107
printf " \nUpdating certificate MD5 checksum...\n"
108
108
109
- md5sum ${PRIV_KEY} > ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5
109
+ md5sum " ${PRIV_KEY} " > " ${LE_LIVE_DIR} /${UNIFI_HOSTNAME} /privkey.pem.md5"
110
110
111
111
fi
112
112
113
113
# Create double-safe keystore backup
114
- if [ -s " ${KEYSTORE} .orig" ]; then
114
+ if [[ -s " ${KEYSTORE} .orig" ] ]; then
115
115
printf " \nBackup of original keystore exists!\n"
116
116
printf " \nCreating non-destructive backup as keystore.bak...\n"
117
- cp ${KEYSTORE} ${KEYSTORE} .bak
117
+ cp " ${KEYSTORE} " " ${KEYSTORE} .bak"
118
118
else
119
- cp ${KEYSTORE} ${KEYSTORE} .orig
119
+ cp " ${KEYSTORE} " " ${KEYSTORE} .orig"
120
120
printf " \nNo original keystore backup found.\n"
121
121
printf " \nCreating backup as keystore.orig...\n"
122
122
fi
125
125
printf " \nExporting SSL certificate and key data into temporary PKCS12 file...\n"
126
126
127
127
# 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
129
129
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} "
135
135
else
136
136
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} "
141
141
fi
142
142
143
143
# Delete the previous certificate data from keystore to avoid "already exists" message
144
144
printf " \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} "
146
146
147
147
# Import the temp PKCS12 file into the UniFi keystore
148
148
printf " \nImporting SSL certificate into UniFi keystore...\n"
149
149
keytool -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
156
156
157
157
# Clean up temp files
158
158
printf " \nRemoving temporary files...\n"
159
- rm -f ${P12_TEMP}
159
+ rm -f " ${P12_TEMP} "
160
160
161
161
# Restart the UniFi Controller to pick up the updated keystore
162
162
printf " \nRestarting UniFi Controller to apply new Let's Encrypt SSL certificate...\n"
163
- service ${UNIFI_SERVICE} start
163
+ service " ${UNIFI_SERVICE} " start
164
164
165
165
# That's all, folks!
166
166
printf " \nDone!\n"
0 commit comments