1
1
#! /bin/bash
2
2
3
3
# # Test for the hooks of acme.sh
4
- pre_hook_file=" /tmp/prehook"
5
- pre_hook_command=" touch $pre_hook_file "
6
- post_hook_file=" /tmp/posthook"
7
- post_hook_command=" touch $post_hook_file "
8
4
5
+ default_pre_hook_file=" /tmp/default_prehook"
6
+ default_pre_hook_command=" touch $default_pre_hook_file "
7
+ default_post_hook_file=" /tmp/default_posthook"
8
+ default_post_hook_ommand=" touch $default_post_hook_file "
9
9
10
+ percontainer_pre_hook_file=" /tmp/percontainer_prehook"
11
+ percontainer_pre_hook_command=" touch $percontainer_pre_hook_file "
12
+ percontainer_post_hook_file=" /tmp/percontainer_posthook"
13
+ percontainer_post_hook_command=" touch $percontainer_post_hook_file "
10
14
11
15
if [[ -z $GITHUB_ACTIONS ]]; then
12
16
le_container_name=" $( basename " ${0%/* } " ) _$( date " +%Y-%m-%d_%H.%M.%S" ) "
13
17
else
14
18
le_container_name=" $( basename " ${0%/* } " ) "
15
19
fi
16
- run_le_container " ${1:? } " " $le_container_name " --cli-args " --env ACME_PRE_HOOK=$pre_hook_command " --cli-args " --env ACME_POST_HOOK=$post_hook_command "
20
+ run_le_container " ${1:? } " " $le_container_name " \
21
+ --cli-args " --env ACME_PRE_HOOK=$default_pre_hook_command " \
22
+ --cli-args " --env ACME_POST_HOOK=$default_post_hook_ommand "
17
23
18
24
# Create the $domains array from comma separated domains in TEST_DOMAINS.
19
25
IFS=' ,' read -r -a domains <<< " $TEST_DOMAINS"
@@ -29,43 +35,85 @@ function cleanup {
29
35
}
30
36
trap cleanup EXIT
31
37
32
- # Run an nginx container for ${domains[0]} with LETSENCRYPT_EMAIL set.
33
38
container_email=" contact@${domains[0]} "
34
- run_nginx_container --hosts " ${domains[0]} " --cli-args " --env LETSENCRYPT_EMAIL=${container_email} "
39
+
40
+ # Run an nginx container for ${domains[0]} with LETSENCRYPT_EMAIL set.
41
+ run_nginx_container --hosts " ${domains[0]} " \
42
+ --cli-args " --env LETSENCRYPT_EMAIL=${container_email} "
43
+
44
+ # Run an nginx container for ${domains[1]} with LETSENCRYPT_EMAIL, ACME_PRE_HOOK and ACME_POST_HOOK set.
45
+ run_nginx_container --hosts " ${domains[1]} " \
46
+ --cli-args " --env LETSENCRYPT_EMAIL=${container_email} " \
47
+ --cli-args " --env ACME_PRE_HOOK=$percontainer_pre_hook_command " \
48
+ --cli-args " --env ACME_POST_HOOK=$percontainer_post_hook_command "
35
49
36
50
# Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
37
51
wait_for_symlink " ${domains[0]} " " $le_container_name "
38
52
39
- # #Check if the command is deliverd properly in /etc/acme.sh
53
+ acme_pre_hook_key=" Le_PreHook="
54
+ acme_post_hook_key=" Le_PostHook="
55
+ acme_base64_start=" '__ACME_BASE64__START_"
56
+ acme_base64_end=" __ACME_BASE64__END_'"
57
+
58
+ # Check if the default command is deliverd properly in /etc/acme.sh
40
59
if docker exec " $le_container_name " [[ ! -d " /etc/acme.sh/$container_email " ]]; then
41
60
echo " The /etc/acme.sh/$container_email folder does not exist."
42
61
elif docker exec " $le_container_name " [[ ! -d " /etc/acme.sh/$container_email /${domains[0]} " ]]; then
43
62
echo " The /etc/acme.sh/$container_email /${domains[0]} folder does not exist."
44
63
elif docker exec " $le_container_name " [[ ! -f " /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf" ]]; then
45
64
echo " The /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf file does not exist."
46
65
fi
47
- acme_pre_hook_key=" Le_PreHook="
48
- acme_post_hook_key=" Le_PostHook="
49
- acme_base64_start=" '__ACME_BASE64__START_"
50
- acme_base64_end=" __ACME_BASE64__END_'"
51
- pre_hook_command_base64=$( echo -n " $pre_hook_command " | base64)
52
- post_hook_command_base64=$( echo -n " $post_hook_command " | base64)
53
66
54
- acme_pre_hook=" $( docker exec " $le_container_name " grep " $acme_pre_hook_key " " /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf" ) "
55
- acme_post_hook=" $( docker exec " $le_container_name " grep " $acme_post_hook_key " " /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf" ) "
67
+ default_pre_hook_command_base64=" ${acme_pre_hook_key}${acme_base64_start} $( echo -n " $default_pre_hook_command " | base64) ${acme_base64_end} "
68
+ default_post_hook_command_base64=" ${acme_post_hook_key}${acme_base64_start} $( echo -n " $default_post_hook_ommand " | base64) ${acme_base64_end} "
69
+
70
+ default_acme_pre_hook=" $( docker exec " $le_container_name " grep " $acme_pre_hook_key " " /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf" ) "
71
+ default_acme_post_hook=" $( docker exec " $le_container_name " grep " $acme_post_hook_key " " /etc/acme.sh/$container_email /${domains[0]} /${domains[0]} .conf" ) "
72
+
73
+ if [[ " $default_pre_hook_command_base64 " != " $default_acme_pre_hook " ]]; then
74
+ echo " Default prehook command not saved properly"
75
+ fi
76
+ if [[ " $default_post_hook_command_base64 " != " $default_acme_post_hook " ]]; then
77
+ echo " Default posthook command not saved properly"
78
+ fi
79
+
80
+
81
+ # Check if the default action is performed
82
+ if docker exec " $le_container_name " [[ ! -f " $default_pre_hook_file " ]]; then
83
+ echo " Default prehook action failed"
84
+ fi
85
+ if docker exec " $le_container_name " [[ ! -f " $default_post_hook_file " ]]; then
86
+ echo " Default posthook action failed"
87
+ fi
88
+
89
+ # Wait for a symlink at /etc/nginx/certs/${domains[1]}.crt
90
+ wait_for_symlink " ${domains[1]} " " $le_container_name "
91
+
92
+ # Check if the per-container command is deliverd properly in /etc/acme.sh
93
+ if docker exec " $le_container_name " [[ ! -d " /etc/acme.sh/$container_email /${domains[1]} " ]]; then
94
+ echo " The /etc/acme.sh/$container_email /${domains[1]} folder does not exist."
95
+ elif docker exec " $le_container_name " [[ ! -f " /etc/acme.sh/$container_email /${domains[1]} /${domains[1]} .conf" ]]; then
96
+ echo " The /etc/acme.sh/$container_email /${domains[1]} /${domains[1]} .conf file does not exist."
97
+ fi
98
+
99
+ percontainer_pre_hook_command_base64=" ${acme_pre_hook_key}${acme_base64_start} $( echo -n " $percontainer_pre_hook_command " | base64) ${acme_base64_end} "
100
+ percontainer_post_hook_command_base64=" ${acme_post_hook_key}${acme_base64_start} $( echo -n " $percontainer_post_hook_command " | base64) ${acme_base64_end} "
101
+
102
+ percontainer_acme_pre_hook=" $( docker exec " $le_container_name " grep " $acme_pre_hook_key " " /etc/acme.sh/$container_email /${domains[1]} /${domains[1]} .conf" ) "
103
+ percontainer_acme_post_hook=" $( docker exec " $le_container_name " grep " $acme_post_hook_key " " /etc/acme.sh/$container_email /${domains[1]} /${domains[1]} .conf" ) "
56
104
57
- if [[ " $acme_pre_hook_key$acme_base64_start$pre_hook_command_base64$acme_base64_end " != " $acme_pre_hook " ]]; then
58
- echo " Prehook command not saved properly"
105
+ if [[ " $percontainer_pre_hook_command_base64 " != " $percontainer_acme_pre_hook " ]]; then
106
+ echo " Per-container prehook command not saved properly"
59
107
fi
60
- if [[ " $acme_post_hook_key$acme_base64_start$post_hook_command_base64$acme_base64_end " != " $acme_post_hook " ]]; then
61
- echo " Posthook command not saved properly"
108
+ if [[ " $percontainer_post_hook_command_base64 " != " $percontainer_acme_post_hook " ]]; then
109
+ echo " Per-container posthook command not saved properly"
62
110
fi
63
111
64
112
65
- # # Check if the action ist performed
66
- if docker exec " $le_container_name " [[ ! -f " $pre_hook_file " ]]; then
67
- echo " Prehook action failed"
113
+ # Check if the percontainer action is performed
114
+ if docker exec " $le_container_name " [[ ! -f " $percontainer_pre_hook_file " ]]; then
115
+ echo " Per-container prehook action failed"
68
116
fi
69
- if docker exec " $le_container_name " [[ ! -f " $post_hook_file " ]]; then
70
- echo " Posthook action failed"
117
+ if docker exec " $le_container_name " [[ ! -f " $percontainer_post_hook_file " ]]; then
118
+ echo " Per-container posthook action failed"
71
119
fi
0 commit comments