comparison etc/periodic/weekly/800.local-certbot-post-deploy @ 387:9921352225a9

Weekly periodic script to execute an action when any of given files are readable. Intended to trigger host-level actions after certbot actions in jails.
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 23 Feb 2023 09:08:20 +0100
parents
children
comparison
equal deleted inserted replaced
386:84d2735fe7f6 387:9921352225a9
1 #!/bin/sh
2 # -*- indent-tabs-mode: nil; -*-
3 #
4 # @(#)@@SIMPLEVERSIONTAG@@
5 #
6 # Weekly script to indirectly trigger post deploy actions
7 #
8 # Must be executed **after** 500.certbot.
9 # Otherwise an extra week of delay is encountered.
10 #
11
12 # If there is a global system configuration file, suck it in.
13 if [ -r /etc/defaults/periodic.conf ]
14 then
15 . /etc/defaults/periodic.conf
16 source_periodic_confs
17 fi
18
19 : ${weekly_local_certbot_post_deploy_enable:=NO}
20 : ${weekly_local_certbot_post_deploy_files:=}
21 # e.g. "service nginx onestatus"
22 : ${weekly_local_certbot_post_deploy_condition:=}
23 # e.g. "service nginx reload"
24 : ${weekly_local_certbot_post_deploy_action:=}
25 : ${weekly_local_certbot_post_deploy_files_remove:=YES}
26
27 case "${weekly_local_certbot_post_deploy_enable}" in
28 [Yy][Ee][Ss])
29 echo
30 echo "Testing for newly renewed Let's Encrypt certificates"
31
32 rc=0
33
34 _do_action=""
35 _remove_files=""
36
37 for _f in ${weekly_local_certbot_post_deploy_files}; do
38 if [ -r "${_f}" ]; then
39 _do_action="yes"
40 case "${weekly_local_certbot_post_deploy_files_remove}" in
41 [Yy][Ee][Ss])
42 _remove_files="${_remove_files} ${_f}"
43 ;;
44 esac
45 fi
46 done
47
48 if [ "${_do_action}" = "yes" ]; then
49 if [ -z "${weekly_local_certbot_post_deploy_action}" ]; then
50 echo "ERROR: no deploy action defined" 1>&2
51 exit 2
52 fi
53
54 echo "Deploying newly renewed Let's Encrypt certificates"
55 if [ -n "${weekly_local_certbot_post_deploy_condition}" ]; then
56 if ${weekly_local_certbot_post_deploy_condition} ; then
57 ${weekly_local_certbot_post_deploy_action}
58 rc=$?
59 else
60 rc=1
61 fi
62 else
63 ${weekly_local_certbot_post_deploy_action}
64 rc=$?
65 fi
66
67 # Remove trigger files if configured to do so
68 if [ ${rc} -eq 0 ]; then
69 echo "Removing trigger files..."
70 for _rf in ${_remove_files}; do
71 rm -fv "${_rf}"
72 done
73 fi
74 else
75 echo "No newly renewed Let's Encrypt certificates found"
76 fi
77 ;;
78
79 *)
80 rc=0
81 ;;
82 esac
83
84 exit ${rc}