Skip to content

Commit bb22546

Browse files
committed
backport acme and haproxy from master
1 parent 229fd9e commit bb22546

17 files changed

Lines changed: 824 additions & 4 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# Copyright (C) 2016 Toke Høiland-Jørgensen
3+
#
4+
# This is free software, licensed under the GNU General Public License v3 or
5+
# later.
6+
#
7+
8+
include $(TOPDIR)/rules.mk
9+
10+
PKG_NAME:=acme-acmesh
11+
PKG_VERSION:=3.0.1
12+
PKG_RELEASE:=$(AUTORELEASE)
13+
14+
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
15+
PKG_SOURCE_URL:=https://codeload.github.com/acmesh-official/acme.sh/tar.gz/$(PKG_VERSION)?
16+
PKG_HASH:=6212cc0c2bca99a7dd6cbb4236b4c7dd5d1113dab0841e66dae4d307d902a8e6
17+
PKG_BUILD_DIR:=$(BUILD_DIR)/acme.sh-$(PKG_VERSION)
18+
19+
PKG_MAINTAINER:=Toke Høiland-Jørgensen <toke@toke.dk>
20+
PKG_LICENSE:=GPL-3.0-only
21+
PKG_LICENSE_FILES:=LICENSE.md
22+
23+
include $(INCLUDE_DIR)/package.mk
24+
25+
define Package/acme-acmesh
26+
SECTION:=net
27+
CATEGORY:=Network
28+
DEPENDS:=+acme-common +wget-ssl +ca-bundle +openssl-util +socat
29+
TITLE:=ACME client acme.sh wrapper script
30+
URL:=https://acme.sh
31+
PKGARCH:=all
32+
PROVIDES:=acme-client
33+
endef
34+
35+
define Package/acme-acmesh/description
36+
A client for issuing ACME (e.g, Letsencrypt) certificates.
37+
endef
38+
39+
define Build/Configure
40+
endef
41+
42+
define Build/Compile
43+
endef
44+
45+
define Package/acme-acmesh/install
46+
$(INSTALL_DIR) $(1)/usr/lib/acme/client
47+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/acme.sh $(1)/usr/lib/acme/client
48+
$(INSTALL_BIN) ./files/hook.sh $(1)/usr/lib/acme/hook
49+
endef
50+
51+
define Package/acme-acmesh-dnsapi
52+
SECTION:=net
53+
CATEGORY:=Network
54+
DEPENDS:=+acme
55+
TITLE:=DNS API integration for ACME (Letsencrypt) client
56+
PKGARCH:=all
57+
endef
58+
59+
define Package/acme-acmesh-dnsapi/description
60+
This package provides DNS API integration for ACME (Letsencrypt) client.
61+
endef
62+
63+
define Package/acme-acmesh-dnsapi/install
64+
$(INSTALL_DIR) $(1)/usr/lib/acme/client/dnsapi
65+
$(INSTALL_DATA) $(PKG_BUILD_DIR)/dnsapi/*.sh $(1)/usr/lib/acme/client/dnsapi
66+
endef
67+
68+
$(eval $(call BuildPackage,acme-acmesh))
69+
$(eval $(call BuildPackage,acme-acmesh-dnsapi))
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/sh
2+
set -u
3+
ACME=/usr/lib/acme/client/acme.sh
4+
LOG_TAG=acme-acmesh
5+
# webroot option deprecated, use the hardcoded value directly in the next major version
6+
WEBROOT=${webroot:-/var/run/acme/challenge}
7+
8+
# shellcheck source=net/acme/files/functions.sh
9+
. /usr/lib/acme/functions.sh
10+
11+
# Needed by acme.sh
12+
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
13+
export NO_TIMESTAMP=1
14+
15+
cmd="$1"
16+
17+
case $cmd in
18+
get)
19+
set --
20+
[ "$debug" = 1 ] && set -- "$@" --debug
21+
22+
case $keylength in
23+
ec-*)
24+
domain_dir="$state_dir/${main_domain}_ecc"
25+
set -- "$@" --ecc
26+
;;
27+
*)
28+
domain_dir="$state_dir/$main_domain"
29+
;;
30+
esac
31+
32+
log info "Running ACME for $main_domain"
33+
34+
if [ -e "$domain_dir" ]; then
35+
if [ "$staging" = 0 ] && grep -q "acme-staging" "$domain_dir/$main_domain.conf"; then
36+
mv "$domain_dir" "$domain_dir.staging"
37+
log info "Certificates are previously issued from a staging server, but staging option is diabled, moved to $domain_dir.staging."
38+
staging_moved=1
39+
else
40+
set -- "$@" --renew --home "$state_dir" -d "$main_domain"
41+
log info "$*"
42+
trap 'ACTION=renewed-failed hotplug-call acme;exit 1' INT
43+
"$ACME" "$@"
44+
status=$?
45+
trap - INT
46+
47+
case $status in
48+
0) ;; # renewed ok, handled by acme.sh hook, ignore.
49+
2) ;; # renew skipped, ignore.
50+
*)
51+
ACTION=renew-failed hotplug-call acme
52+
;;
53+
esac
54+
return 0
55+
fi
56+
fi
57+
58+
for d in $domains; do
59+
set -- "$@" -d "$d"
60+
done
61+
set -- "$@" --keylength "$keylength" --accountemail "$account_email"
62+
63+
if [ "$acme_server" ]; then
64+
set -- "$@" --server "$acme_server"
65+
# default to letsencrypt because the upstream default may change
66+
elif [ "$staging" = 1 ]; then
67+
set -- "$@" --server letsencrypt_test
68+
else
69+
set -- "$@" --server letsencrypt
70+
fi
71+
72+
if [ "$days" ]; then
73+
set -- "$@" --days "$days"
74+
fi
75+
76+
if [ "$dns" ]; then
77+
set -- "$@" --dns "$dns"
78+
if [ "$dalias" ]; then
79+
set -- "$@" --domain-alias "$dalias"
80+
if [ "$calias" ]; then
81+
log err "Both domain and challenge aliases are defined. Ignoring the challenge alias."
82+
fi
83+
elif [ "$calias" ]; then
84+
set -- "$@" --challenge-alias "$calias"
85+
fi
86+
elif [ "$standalone" = 1 ]; then
87+
set -- "$@" --standalone --listen-v6
88+
else
89+
mkdir -p "$WEBROOT"
90+
set -- "$@" --webroot "$WEBROOT"
91+
fi
92+
93+
set -- "$@" --issue --home "$state_dir"
94+
95+
log info "$*"
96+
trap 'ACTION=issue-failed hotplug-call acme;exit 1' INT
97+
"$ACME" "$@" \
98+
--pre-hook 'ACTION=prepare hotplug-call acme' \
99+
--renew-hook 'ACTION=renewed hotplug-call acme'
100+
status=$?
101+
trap - INT
102+
103+
case $status in
104+
0)
105+
ln -s "$domain_dir/$main_domain.cer" /etc/ssl/acme
106+
ln -s "$domain_dir/$main_domain.key" /etc/ssl/acme
107+
ln -s "$domain_dir/fullchain.cer" "/etc/ssl/acme/$main_domain.fullchain.cer"
108+
ln -s "$domain_dir/ca.cer" "/etc/ssl/acme/$main_domain.chain.cer"
109+
ACTION=issued hotplug-call acme
110+
;;
111+
*)
112+
if [ "$staging_moved" = 1 ]; then
113+
mv "$domain_dir.staging" "$domain_dir"
114+
log err "Staging certificate restored"
115+
elif [ -d "$domain_dir" ]; then
116+
failed_dir="$domain_dir.failed-$(date +%s)"
117+
mv "$domain_dir" "$failed_dir"
118+
log err "State moved to $failed_dir"
119+
fi
120+
ACTION=issue-failed hotplug-call acme
121+
return 0
122+
;;
123+
esac
124+
;;
125+
esac
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Copyright (C) 2016 Toke Høiland-Jørgensen
3+
#
4+
# This is free software, licensed under the GNU General Public License v3 or
5+
# later.
6+
#
7+
8+
include $(TOPDIR)/rules.mk
9+
10+
PKG_NAME:=acme-common
11+
PKG_VERSION:=1.0.0
12+
13+
PKG_MAINTAINER:=Toke Høiland-Jørgensen <toke@toke.dk>
14+
PKG_LICENSE:=GPL-3.0-only
15+
PKG_LICENSE_FILES:=LICENSE.md
16+
17+
include $(INCLUDE_DIR)/package.mk
18+
19+
define Package/acme-common
20+
SECTION:=net
21+
CATEGORY:=Network
22+
TITLE:=ACME client wrapper common files
23+
PKGARCH:=all
24+
endef
25+
26+
define Package/acme-common/description
27+
ACME client wrapper common files.
28+
endef
29+
30+
define Package/acme-common/conffiles
31+
/etc/config/acme
32+
/etc/acme
33+
/etc/ssl/acme
34+
endef
35+
36+
define Package/acme-common/install
37+
$(INSTALL_DIR) $(1)/etc/acme
38+
$(INSTALL_DIR) $(1)/etc/config
39+
$(INSTALL_CONF) ./files/acme.config $(1)/etc/config/acme
40+
$(INSTALL_DIR) $(1)/usr/bin
41+
$(INSTALL_BIN) ./files/acme.sh $(1)/usr/bin/acme
42+
$(INSTALL_DIR) $(1)/usr/lib/acme
43+
$(INSTALL_DATA) ./files/functions.sh $(1)/usr/lib/acme
44+
$(INSTALL_DIR) $(1)/etc/init.d
45+
$(INSTALL_BIN) ./files/acme.init $(1)/etc/init.d/acme
46+
$(INSTALL_DIR) $(1)/etc/uci-defaults
47+
$(INSTALL_DATA) ./files/acme.uci-defaults $(1)/etc/uci-defaults/acme
48+
endef
49+
50+
define Package/acme/postinst
51+
#!/bin/sh
52+
grep -q '/usr/bin/acme' /etc/crontabs/root 2>/dev/null && exit 0
53+
echo "0 0 * * * /usr/bin/acme get" >> /etc/crontabs/root
54+
endef
55+
56+
define Package/acme-common/prerm
57+
#!/bin/sh
58+
sed -i '\|/usr/bin/acme|d' /etc/crontabs/root
59+
endef
60+
61+
define Build/Configure
62+
endef
63+
64+
define Build/Compile
65+
endef
66+
67+
$(eval $(call BuildPackage,acme-common))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
config acme
2+
option state_dir '/etc/acme'
3+
option account_email 'email@example.org'
4+
option debug 0
5+
6+
config cert 'example_wildcard'
7+
option enabled 0
8+
option use_staging 1
9+
list domains example.org
10+
list domains sub.example.org
11+
list domains *.sub.example.org
12+
option dns "dns_freedns"
13+
list credentials 'FREEDNS_User="ssladmin@example.org"'
14+
list credentials 'FREEDNS_Password="1234"'
15+
option calias "example.com"
16+
option dalias "dalias.example.com"
17+
18+
config cert 'example'
19+
option enabled 0
20+
option use_staging 1
21+
list domains example.org
22+
list domains sub.example.org
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
START=80
4+
USE_PROCD=1
5+
6+
service_triggers() {
7+
procd_add_config_trigger config.change acme \
8+
/usr/bin/acme get
9+
}

0 commit comments

Comments
 (0)