Original Post - https://unix.stackexchange.com/questions/391731/automating-certbot-for-osx-server-error-in-get-cert-sh-script
=====================================================
Hello Folks and Gurus,
Apologies if i am posting at the wrong place. Please direct me to the right place as I am really new at all of this.
I am currently facing a problem with my Mac OS-X El Capitan machine when running certbot (or basically letsencrypt).
My machine is a mac mini, that is supposedly running an MDM solution with letsencrypt as its SSL certificate. My MDM is working fine, and i just want to automate the renewal of SSL certificate via certbot.
I followed this guide for the entire set-up - Joshua Jung, Medium.com - setting up mac mini OSX as MDM
https://medium.com/@JoshuaAJung/managing-your-mobile-devices-in-the-cloud-using-apples-own-mdm-solution-8a588d9724b6
This is my script file - get-cert.sh
#!/bin/sh
DOMAIN=āmdm.school.domain"
PEM_FOLDER=ā/etc/letsencrypt/live/${DOMAIN}/"
Renew the certificate
sudo certbot renew --quiet # old way, didnāt work.
new way below -
sudo certbot renew ā-cert-name ${DOMAIN} -q
Generate a passphrase
echo starting password
PASS=$(openssl rand -base64 45 | tr -d /=+ | cut -c -30)
echo finish password - looks like no problem.
Transform the pem files into a p12 file
echo start openssl
sudo openssl pkcs12 -export -inkey ā${PEM_FOLDER}privkey.pemā -in ā${PEM_FOLDER}cert.pemā -certfile ā${PEM_FOLDER}fullchain.pemā -out ā${PEM_FOLDER}letsencrypt_sslcert.p12ā -passout pass:$PASS
echo end openssl
Import the p12 file into the keychain
echo start security import
sudo security import ā${PEM_FOLDER}letsencrypt_sslcert.p12ā -f pkcs12 -k /Library/Keychains/System.keychain -P $PASS -T /Applications/Server.app/Contents/ServerRoot/System/Library/CoreServices/ServerManagerDaemon.bundle/Contents/MacOS/servermgrd
echo end security import
I have 2x issues actually.
First, while i can renew the certificate manually, meaning, if i enter āsudo certbot renewā, the certificate gets renewed successfully. However, if I were to run the command through the script, the error occurs stating that thereās an argument error.
-q/āquiet: ignored explicit argument ā\rā.
second, i encounter error with the openssl import, whereby the error shows:
cert.pemening input file /etc/letsencrypt/live/mdm.school.domain cert.pem: No such file or directoryg
i do have a 3rd issue, where the error occur as per below -
letsencrypt_sslcert.p12: no such file or directoryve/mdm.school.domain but i think this error is related to the second one.
I am stumped at the moment. I have the directories all set properly. I have given 0755 or 0777 permission to the required files in the āliveā folder to all the files (.pem and .p12).
when I run = sudo certbot certificates, i got the info that expiry date is set to 89 days later. certificate path and private key path are correct to the location that is stored at - /etc/letsencrypt/live/mdm.school.domain/fullchain.pem and privkey.pem
Having said that, the content of the live folder, as i checked using finder, is essentially a symlink to the archive folder.
I have also ensured that the archive folder access is given 0755 for privileges.
Hope to pick on the brains of the gurus here.
If I canāt automate the process using the script, then how can I proceed with a manual renewal? I canāt seem to get past the process to generate a certificate that is āreadableā for OS-X certificate repository.
Thank You all in advance!