From cbc397038729b58a305aab31bc3958758e145c77 Mon Sep 17 00:00:00 2001 From: gaofei Date: Fri, 30 Aug 2024 11:06:59 +0800 Subject: [PATCH 1/5] update --- quick_server.sh | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100755 quick_server.sh diff --git a/quick_server.sh b/quick_server.sh new file mode 100755 index 0000000..f149548 --- /dev/null +++ b/quick_server.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +GREEN='\033[0;32m' +RED='\033[0;31m' +BLUE='\033[0;34m' +YELLOW='\033[0;33m' +UNDERLINE='\033[4m' # 下划线 +NC='\033[0m' # No Color + +if [[ -z $DEPLOY_DOMAIN ]]; then + echo + echo "[${RED}Err${NC}] DEPLOY_DOMAIN is not set" + echo + exit 1 +fi + +function is_valid_domain() { + local str="$1" + + # 使用正则表达式匹配合法域名格式 + if [[ $str =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+$ ]]; then + return 0 # 合法返回0 + else + return 1 # 不合法返回1 + fi +} + +# 验证域名格式是否合法 +echo -e "\n[INFO] Validate DOMAN: ${BLUE}${DEPLOY_DOMAIN}${NC} ..." + +if is_valid_domain "$DEPLOY_DOMAIN"; then + echo -e "[INFO] ${BLUE}${UNDERLINE}$DEPLOY_DOMAIN${NC} is a valid domain.\n" +else + echo -e "[${RED}ERR${NC}] ${BLUE}${UNDERLINE}$DEPLOY_DOMAIN${NC} is not a valid domain. Abort." + exit 1 +fi + +# 设置工作目录 +WORKING_DIR="/root/.local/magic" +if [ ! -d "${WORKING_DIR}" ]; then + mkdir -p "${WORKING_DIR}" +fi + +CADDY_STORAGE="${WORKING_DIR}/caddy" +CERT_DIR="$CADDY_STORAGE/certificates/acme-v02.api.letsencrypt.org-directory/$DEPLOY_DOMAIN" +CRT_FILE="$CERT_DIR/$DEPLOY_DOMAIN.crt" +KEY_FILE="$CERT_DIR/$DEPLOY_DOMAIN.key" +HY_CONFIG_FILE="${WORKING_DIR}/hy-config.yaml" +CADDY_CONFIG_FILE="${WORKING_DIR}/Caddyfile" + +echo -e "[INFO] Download ${GREEN}hysteria${NC} and ${GREEN}caddy${NC} ..." +curl -L -o /usr/local/bin/hysteria https://github.com/xxoommd/ultimate_collection/releases/download/latest/hysteria && + curl -L -o /usr/local/bin/caddy https://github.com/xxoommd/ultimate_collection/releases/download/latest/caddy && + chmod +x /usr/local/bin/hysteria /usr/local/bin/caddy +echo -e "[INFO] Download Done\n" + +# Generating all config files... +echo -e "[INFO] Generate ${GREEN}${CADDY_CONFIG_FILE}${NC} ..." +cat >${CADDY_CONFIG_FILE} <${HY_CONFIG_FILE} </etc/systemd/system/hysteria.service </etc/systemd/system/caddy.service < Date: Fri, 30 Aug 2024 11:11:40 +0800 Subject: [PATCH 2/5] update server --- quick_server.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/quick_server.sh b/quick_server.sh index f149548..e4800a1 100755 --- a/quick_server.sh +++ b/quick_server.sh @@ -14,6 +14,9 @@ if [[ -z $DEPLOY_DOMAIN ]]; then exit 1 fi +caddy_download_url="https://gitee.com/xxoommd/magic/releases/download/v0.1/caddy-linux-amd64" +hysteria_download_url="https://gitee.com/xxoommd/magic/releases/download/v0.1/hysteria-linxu-amd64-avx" + function is_valid_domain() { local str="$1" @@ -49,8 +52,8 @@ HY_CONFIG_FILE="${WORKING_DIR}/hy-config.yaml" CADDY_CONFIG_FILE="${WORKING_DIR}/Caddyfile" echo -e "[INFO] Download ${GREEN}hysteria${NC} and ${GREEN}caddy${NC} ..." -curl -L -o /usr/local/bin/hysteria https://github.com/xxoommd/ultimate_collection/releases/download/latest/hysteria && - curl -L -o /usr/local/bin/caddy https://github.com/xxoommd/ultimate_collection/releases/download/latest/caddy && +curl -L -o /usr/local/bin/hysteria $hysteria_download_url && + curl -L -o /usr/local/bin/caddy $caddy_download_url && chmod +x /usr/local/bin/hysteria /usr/local/bin/caddy echo -e "[INFO] Download Done\n" From 9bda957428564c4eaf2ec8070cff3dfc7782ee25 Mon Sep 17 00:00:00 2001 From: gaofei Date: Fri, 30 Aug 2024 11:12:36 +0800 Subject: [PATCH 3/5] update server --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e2e481..26029cc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ export DEPLOY_DOMAIN=xxx.xxx - Github: ```shell -bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/x/quick_server.sh) +bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/quick_server.sh) ``` - Gitea: From a4f2ef126cc18c67c4629219faf1c44a843c64fd Mon Sep 17 00:00:00 2001 From: gaofei Date: Fri, 30 Aug 2024 11:39:11 +0800 Subject: [PATCH 4/5] update all --- README.md | 2 +- quick_client.sh | 2 +- quick_server.sh | 38 ++++++++++++++++++++++++++++++-------- update_bin.sh | 11 +++++++---- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 26029cc..13c873d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/quick_ser - Gitea: ```shell -bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/quick_server.sh) +DOWNLOAD_SRC=gitee bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/quick_server.sh) ``` #### client diff --git a/quick_client.sh b/quick_client.sh index ff63ac2..9534d35 100755 --- a/quick_client.sh +++ b/quick_client.sh @@ -24,7 +24,7 @@ fi TAG=${TAG:-latest} -github_download_url_prefix="https://gitee.com/xxoommd/magic/releases/download" +github_download_url_prefix="https://github.com/xxoommd/magic/releases/download" gitee_download_url_prefix="https://github.com/xxoommd/ultimate_collection/releases/download" naive_bin_name="" diff --git a/quick_server.sh b/quick_server.sh index e4800a1..4784c09 100755 --- a/quick_server.sh +++ b/quick_server.sh @@ -7,16 +7,15 @@ YELLOW='\033[0;33m' UNDERLINE='\033[4m' # 下划线 NC='\033[0m' # No Color -if [[ -z $DEPLOY_DOMAIN ]]; then - echo - echo "[${RED}Err${NC}] DEPLOY_DOMAIN is not set" - echo +# 仅root用户执行 +if [ "$(id -u)" -eq 0 ]; then + echo "当前用户是 root" +else + echo -e "${RED}[Err]${NC}当前用户不是 root" exit 1 fi -caddy_download_url="https://gitee.com/xxoommd/magic/releases/download/v0.1/caddy-linux-amd64" -hysteria_download_url="https://gitee.com/xxoommd/magic/releases/download/v0.1/hysteria-linxu-amd64-avx" - +# 验证域名格式是否合法 function is_valid_domain() { local str="$1" @@ -28,9 +27,15 @@ function is_valid_domain() { fi } -# 验证域名格式是否合法 echo -e "\n[INFO] Validate DOMAN: ${BLUE}${DEPLOY_DOMAIN}${NC} ..." +if [[ -z $DEPLOY_DOMAIN ]]; then + echo + echo "[${RED}Err${NC}] DEPLOY_DOMAIN is not set" + echo + exit 1 +fi + if is_valid_domain "$DEPLOY_DOMAIN"; then echo -e "[INFO] ${BLUE}${UNDERLINE}$DEPLOY_DOMAIN${NC} is a valid domain.\n" else @@ -38,6 +43,23 @@ else exit 1 fi +TAG=${TAG:-"latest"} + +echo -e "[INFO] Using TAG: ${YELLOW}${TAG}${NC}" + +caddy_download_url="" +hysteria_download_url="" + +if [ "$DOWNLOAD_SRC" = "gitee" ]; then + echo -e "[INFO] Download from ${YELLOW}Gitee${NC} ..." + caddy_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64" + hysteria_download_url="https://gitee.com/xxoommd/magic/releases/download/${TAG}/hysteria-linxu-amd64-avx" +else + echo -e "[INFO] Download from ${YELLOW}Github${NC} ..." + caddy_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/caddy-linux-amd64" + hysteria_download_url="https://github.com/xxoommd/magic/releases/download/${TAG}/hysteria-linxu-amd64-avx" +fi + # 设置工作目录 WORKING_DIR="/root/.local/magic" if [ ! -d "${WORKING_DIR}" ]; then diff --git a/update_bin.sh b/update_bin.sh index 700b649..e891ea8 100755 --- a/update_bin.sh +++ b/update_bin.sh @@ -97,11 +97,14 @@ function update_naive() { chmod +x $BIN_PATH/naive* && ls -lhF $BIN_PATH/naive* } -function update_hysteria() { - curl -s -L -o $BIN_PATH/hysteria-linxu-amd64-avx https://download.hysteria.network/app/latest/hysteria-linux-amd64-avx && - curl -s -L -o $BIN_PATH/hysteria-darwin-amd64-avx https://download.hysteria.network/app/latest/hysteria-darwin-amd64-avx && +function download_hysteria() { + echo "- Downloading hysteria-linxu-amd64-avx ..." && + curl -s -L -o $BIN_PATH/hysteria-linxu-amd64-avx https://download.hysteria.network/app/latest/hysteria-linux-amd64-avx && + echo "- Downloading hysteria-darwin-amd64 ..." && curl -s -L -o $BIN_PATH/hysteria-darwin-amd64 https://download.hysteria.network/app/latest/hysteria-darwin-amd64 && + echo "- Downloading hysteria-darwin-arm64 ..." && curl -s -L -o $BIN_PATH/hysteria-darwin-arm64 https://download.hysteria.network/app/latest/hysteria-darwin-arm64 && + echo "- Downloading hysteria-windows-amd64-avx.exe ..." && curl -s -L -o $BIN_PATH/hysteria-windows-amd64-avx.exe https://download.hysteria.network/app/latest/hysteria-windows-amd64-avx.exe && echo && chmod +x $BIN_PATH/* && ls -lhF $BIN_PATH/hy* @@ -164,7 +167,7 @@ function main() { if [ "$up_hy" = true ]; then echo -e "[INFO] Downloading ${GREEN}hysteria2${NC} ..." - if update_hysteria; then + if download_hysteria; then echo -e "[INFO] Download ${GREEN}hysteria2${NC} success" else echo -e "[Err] Download ${GREEN}hysteria2${NC} fail" From 2d1da1dcc54e96f8cf48b7ec4561103912753760 Mon Sep 17 00:00:00 2001 From: gaofei Date: Fri, 30 Aug 2024 11:40:04 +0800 Subject: [PATCH 5/5] update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 13c873d..2fe6324 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ export DEPLOY_DOMAIN=xxx.xxx bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/quick_server.sh) ``` -- Gitea: +- Gitee: ```shell DOWNLOAD_SRC=gitee bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/quick_server.sh) @@ -30,7 +30,7 @@ DOWNLOAD_SRC=gitee bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/qu TAG=latest bash <(curl -fsSL https://raw.githubusercontent.com/xxoommd/magic/main/quick_client.sh) ``` -- Gitea: +- Gitee: ```shell TAG=latest bash <(curl -fsSL https://gitee.com/xxoommd/magic/raw/main/quick_client.sh)