Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunheng Liu <121078488+Kookiejarz@users.noreply.github.com>2026-04-17 13:19:45 +0300
committerGitHub <noreply@github.com>2026-04-17 13:19:45 +0300
commite02f78ac68e96066288c5da0c38e293160b23143 (patch)
tree5e27dd3a10c42cb1a8d06e5adf664d23b1ca12b0 /update.sh
parent169b216d7eba1641f46dd8ab4b64dfb8f0a5cc2f (diff)
Fix SSL domain setup on reinstall: reuse existing certs and avoid false success/failure logs (#4004)
* perf: replace /dev/urandom | tr with openssl rand to fix CPU spike * fix: add cron to default package installation and improve SSL certificate handling * Reworked `--installcert` success criteria, cleanup behavior adjusted.
Diffstat (limited to 'update.sh')
-rwxr-xr-xupdate.sh99
1 files changed, 60 insertions, 39 deletions
diff --git a/update.sh b/update.sh
index b9cb3ddc..654b7748 100755
--- a/update.sh
+++ b/update.sh
@@ -109,29 +109,29 @@ install_base() {
echo -e "${green}Updating and install dependency packages...${plain}"
case "${release}" in
ubuntu | debian | armbian)
- apt-get update >/dev/null 2>&1 && apt-get install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
+ apt-get update >/dev/null 2>&1 && apt-get install -y -q cron curl tar tzdata socat openssl >/dev/null 2>&1
;;
fedora | amzn | virtuozzo | rhel | almalinux | rocky | ol)
- dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
+ dnf -y update >/dev/null 2>&1 && dnf install -y -q cronie curl tar tzdata socat openssl >/dev/null 2>&1
;;
centos)
if [[ "${VERSION_ID}" =~ ^7 ]]; then
- yum -y update >/dev/null 2>&1 && yum install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
+ yum -y update >/dev/null 2>&1 && yum install -y -q cronie curl tar tzdata socat openssl >/dev/null 2>&1
else
- dnf -y update >/dev/null 2>&1 && dnf install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
+ dnf -y update >/dev/null 2>&1 && dnf install -y -q cronie curl tar tzdata socat openssl >/dev/null 2>&1
fi
;;
arch | manjaro | parch)
- pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm curl tar tzdata socat openssl >/dev/null 2>&1
+ pacman -Syu >/dev/null 2>&1 && pacman -Syu --noconfirm cronie curl tar tzdata socat openssl >/dev/null 2>&1
;;
opensuse-tumbleweed | opensuse-leap)
- zypper refresh >/dev/null 2>&1 && zypper -q install -y curl tar timezone socat openssl >/dev/null 2>&1
+ zypper refresh >/dev/null 2>&1 && zypper -q install -y cron curl tar timezone socat openssl >/dev/null 2>&1
;;
alpine)
- apk update >/dev/null 2>&1 && apk add curl tar tzdata socat openssl>/dev/null 2>&1
+ apk update >/dev/null 2>&1 && apk add dcron curl tar tzdata socat openssl>/dev/null 2>&1
;;
*)
- apt-get update >/dev/null 2>&1 && apt install -y -q curl tar tzdata socat openssl >/dev/null 2>&1
+ apt-get update >/dev/null 2>&1 && apt install -y -q cron curl tar tzdata socat openssl >/dev/null 2>&1
;;
esac
}
@@ -402,15 +402,15 @@ ssl_cert_issue() {
break
done
echo -e "${green}Your domain is: ${domain}, checking it...${plain}"
-
- # check if there already exists a certificate
- local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
- if [ "${currentCert}" == "${domain}" ]; then
- local certInfo=$(~/.acme.sh/acme.sh --list)
- echo -e "${red}System already has certificates for this domain. Cannot issue again.${plain}"
- echo -e "${yellow}Current certificate details:${plain}"
- echo "$certInfo"
- return 1
+ SSL_ISSUED_DOMAIN="${domain}"
+
+ # detect existing certificate and reuse it if present
+ local cert_exists=0
+ if ~/.acme.sh/acme.sh --list 2>/dev/null | awk '{print $1}' | grep -Fxq "${domain}"; then
+ cert_exists=1
+ local certInfo=$(~/.acme.sh/acme.sh --list 2>/dev/null | grep -F "${domain}")
+ echo -e "${yellow}Existing certificate found for ${domain}, will reuse it.${plain}"
+ [[ -n "${certInfo}" ]] && echo "$certInfo"
else
echo -e "${green}Your domain is ready for issuing certificates now...${plain}"
fi
@@ -437,16 +437,20 @@ ssl_cert_issue() {
echo -e "${yellow}Stopping panel temporarily...${plain}"
systemctl stop x-ui 2>/dev/null || rc-service x-ui stop 2>/dev/null
- # issue the certificate
- ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt --force
- ~/.acme.sh/acme.sh --issue -d ${domain} --listen-v6 --standalone --httpport ${WebPort} --force
- if [ $? -ne 0 ]; then
- echo -e "${red}Issuing certificate failed, please check logs.${plain}"
- rm -rf ~/.acme.sh/${domain}
- systemctl start x-ui 2>/dev/null || rc-service x-ui start 2>/dev/null
- return 1
+ if [[ ${cert_exists} -eq 0 ]]; then
+ # issue the certificate
+ ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt --force
+ ~/.acme.sh/acme.sh --issue -d ${domain} --listen-v6 --standalone --httpport ${WebPort} --force
+ if [ $? -ne 0 ]; then
+ echo -e "${red}Issuing certificate failed, please check logs.${plain}"
+ rm -rf ~/.acme.sh/${domain}
+ systemctl start x-ui 2>/dev/null || rc-service x-ui start 2>/dev/null
+ return 1
+ else
+ echo -e "${green}Issuing certificate succeeded, installing certificates...${plain}"
+ fi
else
- echo -e "${green}Issuing certificate succeeded, installing certificates...${plain}"
+ echo -e "${green}Using existing certificate, installing certificates...${plain}"
fi
# Setup reload command
@@ -476,17 +480,27 @@ ssl_cert_issue() {
fi
# install the certificate
- ~/.acme.sh/acme.sh --installcert -d ${domain} \
+ local installOutput=""
+ installOutput=$(~/.acme.sh/acme.sh --installcert -d ${domain} \
--key-file /root/cert/${domain}/privkey.pem \
- --fullchain-file /root/cert/${domain}/fullchain.pem --reloadcmd "${reloadCmd}"
+ --fullchain-file /root/cert/${domain}/fullchain.pem --reloadcmd "${reloadCmd}" 2>&1)
+ local installRc=$?
+ echo "${installOutput}"
- if [ $? -ne 0 ]; then
+ local installWroteFiles=0
+ if echo "${installOutput}" | grep -q "Installing key to:" && echo "${installOutput}" | grep -q "Installing full chain to:"; then
+ installWroteFiles=1
+ fi
+
+ if [[ -f "/root/cert/${domain}/privkey.pem" && -f "/root/cert/${domain}/fullchain.pem" && ( ${installRc} -eq 0 || ${installWroteFiles} -eq 1 ) ]]; then
+ echo -e "${green}Installing certificate succeeded, enabling auto renew...${plain}"
+ else
echo -e "${red}Installing certificate failed, exiting.${plain}"
- rm -rf ~/.acme.sh/${domain}
+ if [[ ${cert_exists} -eq 0 ]]; then
+ rm -rf ~/.acme.sh/${domain}
+ fi
systemctl start x-ui 2>/dev/null || rc-service x-ui start 2>/dev/null
return 1
- else
- echo -e "${green}Installing certificate succeeded, enabling auto renew...${plain}"
fi
# enable auto-renew
@@ -556,14 +570,21 @@ prompt_and_setup_ssl() {
1)
# User chose Let's Encrypt domain option
echo -e "${green}Using Let's Encrypt for domain certificate...${plain}"
- ssl_cert_issue
- # Extract the domain that was used from the certificate
- local cert_domain=$(~/.acme.sh/acme.sh --list 2>/dev/null | tail -1 | awk '{print $1}')
- if [[ -n "${cert_domain}" ]]; then
- SSL_HOST="${cert_domain}"
- echo -e "${green}✓ SSL certificate configured successfully with domain: ${cert_domain}${plain}"
+ if ssl_cert_issue; then
+ local cert_domain="${SSL_ISSUED_DOMAIN}"
+ if [[ -z "${cert_domain}" ]]; then
+ cert_domain=$(~/.acme.sh/acme.sh --list 2>/dev/null | tail -1 | awk '{print $1}')
+ fi
+
+ if [[ -n "${cert_domain}" ]]; then
+ SSL_HOST="${cert_domain}"
+ echo -e "${green}✓ SSL certificate configured successfully with domain: ${cert_domain}${plain}"
+ else
+ echo -e "${yellow}SSL setup may have completed, but domain extraction failed${plain}"
+ SSL_HOST="${server_ip}"
+ fi
else
- echo -e "${yellow}SSL setup may have completed, but domain extraction failed${plain}"
+ echo -e "${red}SSL certificate setup failed for domain mode.${plain}"
SSL_HOST="${server_ip}"
fi
;;