Skip to content

Commit

Permalink
Merge pull request #3 from alexzhangs/develop
Browse files Browse the repository at this point in the history
enhancement: docker-entrypoint.sh: check acme.sh account registration status before to register account.
  • Loading branch information
alexzhangs authored May 13, 2024
2 parents 7403d21 + 8f1a581 commit 2a47def
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
46 changes: 46 additions & 0 deletions build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

#? Description:
#? Build the Docker image and run the container for testing.
#?
#? Usage:
#? build-and-run.sh
#?
#? Options:
#? None
#?
#? Environment:
#? The following environment variables are used by this script:
#?
#? - XSH_AWS_CFN_VPN_DOMAIN
#?
#? Required, default is unset.
#? The domain name for the V2Ray service.
#?
#? - Namecom_Username
#?
#? Required, default is unset.
#? The username for the Name.com API.
#?
#? - Namecom_Token
#?
#? Required, default is unset.
#? The token for the Name.com API.
#?

set -e -o pipefail

declare tag
tag=dev-$(date +%Y%m%d-%H%M%S)
docker build -t "alexzhangs/shadowsocks-libev-v2ray:$tag" .

declare MGR_PORT=6001 SS_PORTS=8381-8385 ENCRYPT=aes-256-cfb DOMAIN=$XSH_AWS_CFN_VPN_DOMAIN
declare DNS=dns_namecom DNS_ENV="Namecom_Username=$Namecom_Username,Namecom_Token=$Namecom_Token"

docker run -e V2RAY=1 -e DOMAIN="$DOMAIN" \
-e DNS="$DNS" -e DNS_ENV="$DNS_ENV" \
--restart=always -d -p $MGR_PORT:$MGR_PORT/UDP -p $SS_PORTS:$SS_PORTS -p $SS_PORTS:$SS_PORTS/UDP\
--name "ss-manager-v2ray-$tag" "alexzhangs/shadowsocks-libev-v2ray:$tag" \
ss-manager --manager-address 0.0.0.0:$MGR_PORT \
--executable /usr/local/bin/ss-server -m "$ENCRYPT" -s 0.0.0.0 -u \
--plugin v2ray-plugin --plugin-opts "server;tls;host=$DOMAIN"
27 changes: 22 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
#? For the required <name> and <value>, please refer to:
#? * https://github.com/acmesh-official/acme.sh/wiki/dnsapi
#?
#? File:
#? The following files are created by this script:
#?
#? - ~/.acme-account-done
#?
#? This file is created after the account registration with acme.sh.
#? The account registration is skipped if this file exists.
#?
#? - ~/.acme-cert-done
#?
#? This file is created after the certificate is issued for the domain with acme.sh.
#? The certificate issuance is skipped if this file exists.
#?

# exit on any error
set -e -o pipefail
Expand All @@ -69,17 +82,21 @@ function issue-tls-cert () {
exit 255
fi

declare done_file=~/.issue-tls-cert-done
declare acme_account_done_file=~/.acme-account-done
declare acme_cert_done_file=~/.acme-cert-done

if [[ -f $done_file ]]; then
if [[ -f $acme_cert_done_file ]]; then
echo "INFO: TLS certificate has been issued for the domain $DOMAIN."
return
fi

acme.sh --version

# Register an account with acme.sh
acme.sh --register-account -m "acme@$DOMAIN"
# Register an account with acme.sh if not done
if [[ ! -f $acme_account_done_file ]]; then
acme.sh --register-account -m "acme@$DOMAIN"
touch "$acme_account_done_file"
fi

declare -a acme_common_opts=(--force-color --domain "$DOMAIN")
declare -a acme_issue_opts=("${acme_common_opts[@]}" --renew-hook reboot --dns)
Expand Down Expand Up @@ -122,7 +139,7 @@ function issue-tls-cert () {
ln -s "${DOMAIN}_ecc" "/root/.acme.sh/${DOMAIN}"

# Create the cert done file
touch "$done_file"
touch "$acme_cert_done_file"
}

function main () {
Expand Down

0 comments on commit 2a47def

Please sign in to comment.