From 72ea8a9f76cb9d28f3a018475a58d940b561e9c3 Mon Sep 17 00:00:00 2001 From: Qiao Date: Thu, 10 Apr 2025 18:14:33 +0800 Subject: [PATCH] feat(install): enhance installation script functionality (#770) * feat(install): enhance installation script functionality - Add help information display feature - Support custom GitHub proxy URL - Add --no-gh-proxy option to disable GitHub proxy - Optimize error messages and command prompts - Fix typo (Commend -> Command) * docs: update installation script documentation --------- Co-authored-by: evanq Co-authored-by: Sijie.Sun --- README.md | 31 ++++++++++++++++++++- README_CN.md | 31 ++++++++++++++++++++- script/install.sh | 70 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 118 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6007cda4..8485f382 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,36 @@ EasyTier is a simple, safe and decentralized VPN networking solution implemented wget -O /tmp/easytier.sh "https://raw.githubusercontent.com/EasyTier/EasyTier/main/script/install.sh" && bash /tmp/easytier.sh install ``` - You can also uninstall/update Easytier by the command "uninstall" or "update" of this script + The script supports the following commands and options: + + Commands: + - `install`: Install EasyTier + - `uninstall`: Uninstall EasyTier + - `update`: Update EasyTier to the latest version + - `help`: Show help message + + Options: + - `--skip-folder-verify`: Skip folder verification during installation + - `--skip-folder-fix`: Skip automatic folder path fixing + - `--no-gh-proxy`: Disable GitHub proxy + - `--gh-proxy`: Set custom GitHub proxy URL (default: https://ghfast.top/) + + Examples: + ```sh + # Show help + bash /tmp/easytier.sh help + + # Install with options + bash /tmp/easytier.sh install --skip-folder-verify + bash /tmp/easytier.sh install --no-gh-proxy + bash /tmp/easytier.sh install --gh-proxy https://your-proxy.com/ + + # Update EasyTier + bash /tmp/easytier.sh update + + # Uninstall EasyTier + bash /tmp/easytier.sh uninstall + ``` 6. **Install by Homebrew (For MacOS Only)** diff --git a/README_CN.md b/README_CN.md index 57adaf33..24b8edb8 100644 --- a/README_CN.md +++ b/README_CN.md @@ -61,7 +61,36 @@ wget -O /tmp/easytier.sh "https://raw.githubusercontent.com/EasyTier/EasyTier/main/script/install.sh" && bash /tmp/easytier.sh install ``` - 使用本脚本安装的 Easytier 可以使用脚本的 uninstall/update 对其卸载/升级 + 脚本支持以下命令和选项: + + 命令: + - `install`: 安装 EasyTier + - `uninstall`: 卸载 EasyTier + - `update`: 更新 EasyTier 到最新版本 + - `help`: 显示帮助信息 + + 选项: + - `--skip-folder-verify`: 跳过安装过程中的文件夹验证 + - `--skip-folder-fix`: 跳过自动修复文件夹路径 + - `--no-gh-proxy`: 禁用 GitHub 代理 + - `--gh-proxy`: 设置自定义 GitHub 代理 URL (默认值: https://ghfast.top/) + + 示例: + ```sh + # 查看帮助 + bash /tmp/easytier.sh help + + # 安装(带选项) + bash /tmp/easytier.sh install --skip-folder-verify + bash /tmp/easytier.sh install --no-gh-proxy + bash /tmp/easytier.sh install --gh-proxy https://your-proxy.com/ + + # 更新 EasyTier + bash /tmp/easytier.sh update + + # 卸载 EasyTier + bash /tmp/easytier.sh uninstall + ``` 6. **使用 Homebrew 安装 (仅适用于 MacOS)** diff --git a/script/install.sh b/script/install.sh index d14884d3..9bd2bb25 100644 --- a/script/install.sh +++ b/script/install.sh @@ -1,9 +1,50 @@ #!/bin/bash +RED_COLOR='\e[1;31m' +GREEN_COLOR='\e[1;32m' +YELLOW_COLOR='\e[1;33m' +BLUE_COLOR='\e[1;34m' +PINK_COLOR='\e[1;35m' +SHAN='\e[1;33;5m' +RES='\e[0m' + +HELP() { + echo -e "\r\n${GREEN_COLOR}EasyTier Installation Script Help${RES}\r\n" + echo "Usage: ./install.sh [command] [options]" + echo + echo "Commands:" + echo " install Install EasyTier" + echo " uninstall Uninstall EasyTier" + echo " update Update EasyTier to the latest version" + echo " help Show this help message" + echo + echo "Options:" + echo " --skip-folder-verify Skip folder verification during installation" + echo " --skip-folder-fix Skip automatic folder path fixing" + echo " --no-gh-proxy Disable GitHub proxy" + echo " --gh-proxy URL Set custom GitHub proxy URL" + echo + echo "Examples:" + echo " ./install.sh install /opt/easytier" + echo " ./install.sh install --skip-folder-verify" + echo " ./install.sh install --no-gh-proxy" + echo " ./install.sh install --gh-proxy https://your-proxy.com/" + echo " ./install.sh update" + echo " ./install.sh uninstall" +} + +# Show help if no arguments or help command is used +if [ $# -eq 0 ] || [ "$1" = "help" ]; then + HELP + exit 0 +fi + # This script copy from alist , Thank for it! SKIP_FOLDER_VERIFY=false SKIP_FOLDER_FIX=false +NO_GH_PROXY=false +GH_PROXY='https://ghfast.top/' COMMEND=$1 shift @@ -19,6 +60,16 @@ while [[ "$#" -gt 0 ]]; do case $1 in --skip-folder-verify) SKIP_FOLDER_VERIFY=true ;; --skip-folder-fix) SKIP_FOLDER_FIX=true ;; + --no-gh-proxy) NO_GH_PROXY=true ;; + --gh-proxy) + if [ -n "$2" ]; then + GH_PROXY=$2 + shift + else + echo "Error: --gh-proxy requires a URL" + exit 1 + fi + ;; *) echo "Unknown option: $1"; exit 1 ;; esac shift @@ -40,13 +91,6 @@ echo INSTALL PATH : $INSTALL_PATH echo SKIP FOLDER FIX : $SKIP_FOLDER_FIX echo SKIP FOLDER VERIFY : $SKIP_FOLDER_VERIFY -RED_COLOR='\e[1;31m' -GREEN_COLOR='\e[1;32m' -YELLOW_COLOR='\e[1;33m' -BLUE_COLOR='\e[1;34m' -PINK_COLOR='\e[1;35m' -SHAN='\e[1;33;5m' -RES='\e[0m' # clear # check if unzip is installed @@ -109,8 +153,6 @@ fi echo -e "\r\n${GREEN_COLOR}Your platform: ${ARCH} (${platform}) ${RES}\r\n" 1>&2 -GH_PROXY='https://ghfast.top/' - if [ "$(id -u)" != "0" ]; then echo -e "\r\n${RED_COLOR}This script requires run as Root !${RES}\r\n" 1>&2 exit 1 @@ -159,7 +201,11 @@ INSTALL() { # Download echo -e "\r\n${GREEN_COLOR}Downloading EasyTier $LATEST_VERSION ...${RES}" rm -rf /tmp/easytier_tmp_install.zip - curl -L ${GH_PROXY}https://github.com/EasyTier/EasyTier/releases/latest/download/easytier-linux-${ARCH}-${LATEST_VERSION}.zip -o /tmp/easytier_tmp_install.zip $CURL_BAR + BASE_URL="https://github.com/EasyTier/EasyTier/releases/latest/download/easytier-linux-${ARCH}-${LATEST_VERSION}.zip" + DOWNLOAD_URL=$($NO_GH_PROXY && echo "$BASE_URL" || echo "${GH_PROXY}${BASE_URL}") + echo -e "Download URL: ${GREEN_COLOR}${DOWNLOAD_URL}${RES}" + curl -L ${DOWNLOAD_URL} -o /tmp/easytier_tmp_install.zip $CURL_BAR + # Unzip resource echo -e "\r\n${GREEN_COLOR}Unzip resource ...${RES}" unzip -o /tmp/easytier_tmp_install.zip -d $INSTALL_PATH/ @@ -341,9 +387,9 @@ elif [ "$COMMEND" = "install" ]; then echo -e "${RED_COLOR} Install fail, try install by hand${RES}" fi else - echo -e "${RED_COLOR} Error Commend ${RES}\n\r" + echo -e "${RED_COLOR} Error Command ${RES}\n\r" echo " ALLOW:" - echo -e "\n\r${GREEN_COLOR} install, uninstall, update ${RES}" + echo -e "\n\r${GREEN_COLOR} install, uninstall, update, help ${RES}" fi rm -rf /tmp/easytier_tmp_*