aboutsummaryrefslogtreecommitdiffstats
path: root/security/lego/files/lego.sh.sample.in
blob: 92cd2bc50420ca4d43f3d1cecab329bd5cd5a552 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh -e

# Email used for registration and recovery contact.
EMAIL=""

BASEDIR="%%ETCDIR%%"
SSLDIR="%%PREFIX%%/etc/ssl/lego"
DOMAINSFILE="${BASEDIR}/domains.txt"

if [ -z "${EMAIL}" ]; then
	echo "Please set EMAIL to a valid address in ${BASEDIR}/lego.sh"
	exit 1
fi

if [ ! -e "${DOMAINSFILE}" ]; then
	echo "Please create ${DOMAINSFILE} as specified in ${BASEDIR}/lego.sh"
	exit 1
fi

if [ "$1" = "run" ]; then
	command="run"
else
	command="renew --days 30"
fi

run_or_renew() {
	%%PREFIX%%/bin/lego --path "${SSLDIR}" \
		--email="${EMAIL}" \
		$(printf -- "--domains=%s " $line) \
		--http --http.webroot="%%WWWDIR%%" \
		$1
}

while read line <&3; do
	if [ "$command" = "run" ]; then
		run_or_renew "$command"
	else
		output=$(run_or_renew "$command") || (echo "$output" && exit 1)
	fi
done 3<"${DOMAINSFILE}"