summaryrefslogtreecommitdiffstats
path: root/net/acme-common/files/acme.uci-defaults
blob: d6aa068ad48e3db6c82b4358c646db7e6aa76bf1 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
. /lib/functions.sh

# Create a symlink to webroot
if [ -d /www/ ] && [ ! -L /www/.well-known/acme-challenge ] && [ ! -d /www/.well-known/acme-challenge/ ]; then
	mkdir -p /www/.well-known/
	ln -s /var/run/acme/challenge/.well-known/acme-challenge /www/.well-known/acme-challenge
fi

# migrate deprecated opts
# shellcheck disable=SC2155
handle_cert() {
	local section="$1"
	local use_staging=$(uci_get acme "$section" use_staging)
	if [ -n "$use_staging" ]; then
		uci_remove acme "$section" use_staging
		local staging=$(uci_get acme "$section" staging)
		if [ -z "$staging" ]; then
			uci_set acme "$section" staging "$use_staging"
		fi
	fi

	local keylength=$(uci_get acme "$section" keylength)
	if [ -n "$keylength" ]; then
		uci_remove acme "$section" keylength
		local key_type=$(uci_get acme "$section" key_type)
		if [ -z "$key_type" ]; then
			case $keylength in
			ec-*) key_type=${keylength/-/} ;;
			*) key_type=rsa$keylength ;;
			esac
			uci_set acme "$section" key_type "$key_type"
		fi
	fi

	local standalone=$(uci_get acme "$section" standalone)
	[ -n "$standalone" ] && uci_remove acme "$section" standalone
	local dns=$(uci_get acme "$section" dns)
	local tls=$(uci_get acme "$section" tls)
	local validation_method=$(uci_get acme "$section" validation_method)
	if [ -z "$validation_method" ]; then
		if [ -n "$dns" ]; then
			validation_method="dns"
		elif [ "$standalone" = 1 ]; then
			validation_method="standalone"
		elif [ "$tls" = 1 ]; then
			validation_method="alpn"
		else
			validation_method="webroot"
		fi
		uci_set acme "$section" validation_method "$validation_method"
	fi

	#uacme migration
	local ACME_URL=$(uci_get acme "$section" acme_uri)
	local ACME_SERVER=$(uci_get acme "$section" acme_server)

	if [ -n "$ACME_URL" ]; then
		if [ -n "$ACME_SERVER" ]; then
			if [ "$ACME_URL" = "$ACME_SERVER" ]; then
				uci_remove acme "$section" acme_uri
			else
				log warn "Both acme_uri and acme_server set in $section, need manual cleanup. client will use acme_server in current state"
			fi
		else
			uci_set acme "$section" acme_server "$ACME_URL"
			uci_remove acme "$section" acme_uri
		fi
	fi
	local ACME_STAGING_URL=$(uci_get acme "$section" acme_staging_url)
	if [ -n "$ACME_STAGING_URL" ]; then
		uci_remove acme "$section" acme_staging_url
	fi
}

config_load acme
config_foreach handle_cert cert
uci_commit

# Migrate '/etc/init.d/acme start' to '/etc/init.d/acme renew'
grep -q '/etc/init.d/acme start' /etc/crontabs/root 2>/dev/null && {
	grep -q '/etc/init.d/acme' /etc/crontabs/root 2>/dev/null || echo "0 0 * * * /etc/init.d/acme renew" >>/etc/crontabs/root
	sed '/0 0 * * * \/etc\/init.d\/acme start/d' /etc/crontabs/root
}

exit 0