Skip to content

Commit

Permalink
Command: add/remove a cron for renewal Let's Encrypt certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
tmachyshyn committed May 29, 2024
1 parent ca75d9a commit 9135e7b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions commands/command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function actionHelp() {
printf " export-table-sql Export a single database table into SQL dump\n"
printf " cert-generate Generate a new Let's Encrypt certificate\n"
printf " cert-renew Renew an existing Let's Encrypt certificate\n"
printf " cert-cron-add Add a cronjob for automatic renewal Let's Encrypt certificates\n"
printf " cert-cron-remove Remove a cronjob for automatic renewal Let's Encrypt certificates\n"
printf " apply-domain Apply a domain change\n"
printf " help Information about the commands\n"
}
Expand Down Expand Up @@ -74,6 +76,31 @@ function getActualInstalledMode() {
fi
}

function addCron() {
local search="$1"
local cronLine="$2"

if ! crontab -l > /dev/null 2>&1; then
echo "" | sudo crontab -
fi

local hasCron=$(sudo crontab -l | grep -i "$search")

if [ -z "$hasCron" ]; then
(sudo crontab -l; echo "$cronLine") | sudo crontab -
fi
}

function removeCron() {
local search="$1"

local hasCron=$(sudo crontab -l | grep -i "$search")

if [ -n "$hasCron" ]; then
crontab -l | grep -vi "$search" | sudo crontab -
fi
}

function actionRebuild() {
docker exec --user www-data -i espocrm /bin/bash -c "php command.php rebuild"
}
Expand Down Expand Up @@ -350,6 +377,14 @@ function actionCertRenew() {
printf "Done\n\n"
}

function actionCertCronAdd() {
addCron "command.sh cert-renew" "0 1 * * * $homeDirectory/command.sh cert-renew >> $homeDirectory/data/letsencrypt/renew.log 2>&1"
}

function actionCertCronRemove() {
removeCron "command.sh cert-renew"
}

function actionApplyDomain() {
case "$(getActualInstalledMode)" in
letsencrypt )
Expand Down Expand Up @@ -529,6 +564,14 @@ case "$action" in
actionCertRenew
;;

cert-cron-add )
actionCertCronAdd
;;

cert-cron-remove )
actionCertCronRemove
;;

apply-domain )
actionApplyDomain
;;
Expand Down

0 comments on commit 9135e7b

Please sign in to comment.