|
|
@@ -59,12 +59,53 @@ bool ensure_acme_client(const std::string& email, std::string& err) {
|
|
|
log_info("installing acme.sh home=" + acme_home());
|
|
|
const std::string mail =
|
|
|
email.empty() ? "noreply@localhost" : email;
|
|
|
- // Official installer; install into software/acme.
|
|
|
- const std::string cmd =
|
|
|
- "curl -fsSL https://get.acme.sh | sh -s email=" + mail +
|
|
|
- " --home \"" + acme_home() + "\" --nocron";
|
|
|
- if (run_cmd(cmd, true) != 0 || !path_exists(acme_bin())) {
|
|
|
- err = "安装 acme.sh 失败,请检查网络与 curl";
|
|
|
+
|
|
|
+ // Prefer China mirrors (get.acme.sh / GitHub is often very slow).
|
|
|
+ // See: https://github.com/acmesh-official/acme.sh/wiki/Install-in-China
|
|
|
+ const std::string src_dir =
|
|
|
+ join_path(software_root(), ".build/acme.sh-src");
|
|
|
+ remove_path(src_dir);
|
|
|
+ ensure_dir(join_path(software_root(), ".build"));
|
|
|
+
|
|
|
+ bool got_src = false;
|
|
|
+ const char* git_mirrors[] = {
|
|
|
+ "https://gitee.com/neilpang/acme.sh.git",
|
|
|
+ "https://gitee.com/acmesh-official/acme.sh.git",
|
|
|
+ "https://github.com/acmesh-official/acme.sh.git",
|
|
|
+ };
|
|
|
+ for (const char* url : git_mirrors) {
|
|
|
+ log_info(std::string("acme.sh clone ") + url);
|
|
|
+ const std::string cmd =
|
|
|
+ "git clone --depth 1 \"" + std::string(url) + "\" \"" + src_dir +
|
|
|
+ "\"";
|
|
|
+ if (run_cmd(cmd, true) == 0 &&
|
|
|
+ path_exists(join_path(src_dir, "acme.sh"))) {
|
|
|
+ got_src = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ remove_path(src_dir);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!got_src) {
|
|
|
+ // Last resort: official installer (may be slow outside China mirrors).
|
|
|
+ log_info("acme.sh fallback: get.acme.sh");
|
|
|
+ const std::string cmd =
|
|
|
+ "curl -fsSL --connect-timeout 15 --max-time 180 "
|
|
|
+ "https://get.acme.sh | sh -s email=" +
|
|
|
+ mail + " --home \"" + acme_home() + "\" --nocron";
|
|
|
+ if (run_cmd(cmd, true) != 0 || !path_exists(acme_bin())) {
|
|
|
+ err = "安装 acme.sh 失败,请检查网络(建议可访问 gitee.com)";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ log_info("acme.sh installed");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ const std::string install =
|
|
|
+ "cd \"" + src_dir + "\" && ./acme.sh --install -m \"" + mail +
|
|
|
+ "\" --home \"" + acme_home() + "\" --nocron";
|
|
|
+ if (run_cmd(install, true) != 0 || !path_exists(acme_bin())) {
|
|
|
+ err = "安装 acme.sh 失败";
|
|
|
return false;
|
|
|
}
|
|
|
log_info("acme.sh installed");
|