From 9a7aab63b8b3c7f6e1852123afe8e749a8806d39 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 14:59:37 +0800 Subject: [PATCH 01/13] : not support specifying version. --- tool/install.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tool/install.sh b/tool/install.sh index 963a760..173c47c 100644 --- a/tool/install.sh +++ b/tool/install.sh @@ -100,9 +100,6 @@ while getopts ":hd:" option; do d) install_dir=${OPTARG} ;; - v) - version=${OPTARG} - ;; \?) echo "无效的命令行选项。使用 -h 查看帮助" exit 1 From fad34413890484f817af1853353f1617a7fc4d14 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:03:35 +0800 Subject: [PATCH 02/13] : add logic to judge whether dir exists. --- tool/install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tool/install.sh b/tool/install.sh index 173c47c..5c8ce86 100644 --- a/tool/install.sh +++ b/tool/install.sh @@ -99,6 +99,11 @@ while getopts ":hd:" option; do ;; d) install_dir=${OPTARG} + # 检查路径是否存在,如果不存在则创建该路径 + if [ ! -d "$install_dir" ]; then + echo "目录 $install_dir 不存在,正在创建..." + mkdir -p "$install_dir" || { echo "创建目录失败,请重试"; exit 1; } + fi ;; \?) echo "无效的命令行选项。使用 -h 查看帮助" From 2ec4957d3cff44eb4b87865b423e419ba6a255ff Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:28:49 +0800 Subject: [PATCH 03/13] : add version specify feature. --- tool/install.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) mode change 100644 => 100755 tool/install.sh diff --git a/tool/install.sh b/tool/install.sh old mode 100644 new mode 100755 index 5c8ce86..d78f6bf --- a/tool/install.sh +++ b/tool/install.sh @@ -13,6 +13,7 @@ # --------------------------------------------------------------- install_dir="" +version="pre" path_to_executable="" default_install_path="/usr/local/bin" binary_name="chsrc" @@ -41,6 +42,12 @@ set_install_path() { if [ -n "$install_dir" ]; then # 扩展 ~ 符号 install_dir="${install_dir/#\~/$HOME}" + + # 检查路径是否存在,如果不存在则创建该路径 + if [ ! -d "$install_dir" ]; then + echo "目录 $install_dir 不存在,正在创建..." + mkdir -p "$install_dir" || { echo "创建目录失败,请重试"; exit 1; } + fi elif existing_path=$(command -v "$binary_name" 2>/dev/null); then info "$binary_name 已安装,更新路径: ${existing_path}" install_dir=$(dirname "$existing_path") @@ -74,11 +81,16 @@ install() { *) error "不支持的平台: ${platform}" ;; esac - url="https://gitee.com/RubyMetric/chsrc/releases/download/pre/${binary_name}-${arch}-${platform}" + if [[ ! "$version" =~ ^(pre|0\.1\.([4-9]))$ ]]; then + # version 不符合条件,报错 + error "不支持的版本: ${version},版本号必须在 0.1.4 到 0.1.9 之间或为 'pre'" + fi + + url="https://gitee.com/RubyMetric/chsrc/releases/download/${version}/${binary_name}-${arch}-${platform}" path_to_executable="${install_dir}/${binary_name}" - info "下载 ${binary_name} (${arch} 架构, ${platform} 平台) 到 ${path_to_executable}" + info "下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version}版本) 到 ${path_to_executable}" # 下载文件并设置权限 if curl -sL "$url" -o "$path_to_executable"; then @@ -91,7 +103,7 @@ install() { # main -while getopts ":hd:" option; do +while getopts ":hd:v:" option; do case $option in h) help @@ -99,11 +111,9 @@ while getopts ":hd:" option; do ;; d) install_dir=${OPTARG} - # 检查路径是否存在,如果不存在则创建该路径 - if [ ! -d "$install_dir" ]; then - echo "目录 $install_dir 不存在,正在创建..." - mkdir -p "$install_dir" || { echo "创建目录失败,请重试"; exit 1; } - fi + ;; + v) + version=${OPTARG} ;; \?) echo "无效的命令行选项。使用 -h 查看帮助" From 73b23fc18e279b7ccb7316494416a9ec7c2b03ab Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:29:40 +0800 Subject: [PATCH 04/13] : fix bug, macOS m1 report $arch: arm64. --- tool/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/install.sh b/tool/install.sh index d78f6bf..aeed239 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -67,7 +67,7 @@ install() { case "$arch" in x86_64) arch="x64" ;; - aarch64) arch="aarch64" ;; + aarch64|arm64) arch="aarch64" ;; riscv64) arch="riscv64" ;; armv7*) arch="armv7" ;; *) error "不支持的架构: ${arch}" ;; From 9f3046b4237b6360c377a3caf7ef8b1d46e4335a Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:34:00 +0800 Subject: [PATCH 05/13] : if exit with error, catch the signal, clean up the tmp dir. --- tool/install.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tool/install.sh b/tool/install.sh index aeed239..f309391 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -17,6 +17,7 @@ version="pre" path_to_executable="" default_install_path="/usr/local/bin" binary_name="chsrc" +temp_install_dir="" # 用于存储临时安装目录 info() { echo "[INFO] $*" @@ -37,7 +38,6 @@ help() { echo } - set_install_path() { if [ -n "$install_dir" ]; then # 扩展 ~ 符号 @@ -47,6 +47,7 @@ set_install_path() { if [ ! -d "$install_dir" ]; then echo "目录 $install_dir 不存在,正在创建..." mkdir -p "$install_dir" || { echo "创建目录失败,请重试"; exit 1; } + temp_install_dir="$install_dir" # 记录临时安装目录 fi elif existing_path=$(command -v "$binary_name" 2>/dev/null); then info "$binary_name 已安装,更新路径: ${existing_path}" @@ -61,7 +62,6 @@ set_install_path() { fi } - install() { arch="$(uname -m | tr '[:upper:]' '[:lower:]')" @@ -92,7 +92,6 @@ install() { info "下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version}版本) 到 ${path_to_executable}" - # 下载文件并设置权限 if curl -sL "$url" -o "$path_to_executable"; then chmod +x "$path_to_executable" info "🎉 安装完成,路径: $path_to_executable" @@ -101,6 +100,16 @@ install() { fi } +# 清理函数 +cleanup() { + if [ -n "$temp_install_dir" ] && [ -d "$temp_install_dir" ]; then + echo "清理创建的目录: $temp_install_dir" + rm -rf "$temp_install_dir" + fi +} + +# 设置 trap 以捕获退出信号 +trap cleanup EXIT # main while getopts ":hd:v:" option; do @@ -123,4 +132,4 @@ while getopts ":hd:v:" option; do done set_install_path -install +install \ No newline at end of file From 3f0e7fa78d52cf5066e34efb5ff46ebf9160944d Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:44:56 +0800 Subject: [PATCH 06/13] : add new comments, update help func display. --- tool/install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tool/install.sh b/tool/install.sh index f309391..30ac96e 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -31,10 +31,11 @@ error() { help() { echo "chsrc Installer" echo - echo "使用: install.sh [-h] [-d <安装目录>]" + echo "使用: install.sh [-h] [-d <安装目录>] [-v <版本号>]" echo "选项:" echo "-h 打印此帮助信息" echo "-d 指定安装目录,默认为 /usr/local/bin;如果已安装,则覆盖旧版本" + echo "-v 指定版本号,范围是 0.1.4 到 0.1.9 或 'pre'" echo } From 9db18d2b04e16cdc47f77308df7184f7525b7954 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:51:14 +0800 Subject: [PATCH 07/13] : add readable comments on script func. --- tool/install.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tool/install.sh b/tool/install.sh index 30ac96e..3ff9fdb 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -19,15 +19,18 @@ default_install_path="/usr/local/bin" binary_name="chsrc" temp_install_dir="" # 用于存储临时安装目录 +# 输出相关信息 info() { echo "[INFO] $*" } +# 输出错误到stdout和stderr error() { echo -e "[ERROR] $*" >&2 exit 1 } +# 显示 chsrc 安装程序的帮助信息,包括使用说明和可用选项 help() { echo "chsrc Installer" echo @@ -39,6 +42,7 @@ help() { echo } +# 确定下载路径 set_install_path() { if [ -n "$install_dir" ]; then # 扩展 ~ 符号 @@ -63,6 +67,7 @@ set_install_path() { fi } +# 从Gitee仓库安装 指定架构,操作系统,版本 的chsrc二进制文件 install() { arch="$(uname -m | tr '[:upper:]' '[:lower:]')" @@ -112,7 +117,7 @@ cleanup() { # 设置 trap 以捕获退出信号 trap cleanup EXIT -# main +# 从命令行读取 安装路径与版本号 while getopts ":hd:v:" option; do case $option in h) From e13656eb9b848a3482c26078db127d14858543b1 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 15:51:38 +0800 Subject: [PATCH 08/13] : create a English version script. --- tool/install-en.sh | 130 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 tool/install-en.sh diff --git a/tool/install-en.sh b/tool/install-en.sh new file mode 100755 index 0000000..27175c2 --- /dev/null +++ b/tool/install-en.sh @@ -0,0 +1,130 @@ +# to avoid the operate system not supporting Chinese output, create an english version +install_dir="" +version="pre" +path_to_executable="" +default_install_path="/usr/local/bin" +binary_name="chsrc" +temp_install_dir="" + +# display related info +info() { + echo "[INFO] $*" +} + +# display error message +error() { + echo -e "[ERROR] $*" >&2 + exit 1 +} + +# display help information for the chsrc installer, +# including usage instructions and available options. +help() { + echo "chsrc Installer" + echo + echo "Usage: install.sh [-h] [-d ] [-v ]" + echo "Options:" + echo "-h Display this help information" + echo "-d Specify the installation directory, defaults to /usr/local/bin; overwrites old versions if already installed" + echo "-v Specify the version number, range is from 0.1.4 to 0.1.9 or 'pre'" + echo +} + +# set install path, if use -d specify, check whether it exists. +set_install_path() { + if [ -n "$install_dir" ]; then + # Expand ~ symbol + install_dir="${install_dir/#\~/$HOME}" + + # Check if the path exists; if not, create it + if [ ! -d "$install_dir" ]; then + echo "Directory $install_dir does not exist. Creating..." + mkdir -p "$install_dir" || { echo "Failed to create directory, please retry"; exit 1; } + temp_install_dir="$install_dir" # Record temporary installation directory + fi + elif existing_path=$(command -v "$binary_name" 2>/dev/null); then + info "$binary_name is already installed, updating path: ${existing_path}" + install_dir=$(dirname "$existing_path") + else + # Check default path + if [ -d "$default_install_path" ] && [ -w "$default_install_path" ]; then + install_dir="$default_install_path" + else + error "Default download path /usr/local/bin is not writable. Please run the script with sudo; or specify another path using the -d option." + fi + fi +} + +# install specifying arch, os, version chsrc binary file from Gitee Repository +install() { + arch="$(uname -m | tr '[:upper:]' '[:lower:]')" + + case "$arch" in + x86_64) arch="x64" ;; + aarch64|arm64) arch="aarch64" ;; + riscv64) arch="riscv64" ;; + armv7*) arch="armv7" ;; + *) error "Unsupported architecture: ${arch}" ;; + esac + + platform="$(uname -s | awk '{print tolower($0)}')" + + case "$platform" in + linux) platform="linux" ;; + darwin) platform="macos" ;; + *) error "Unsupported platform: ${platform}" ;; + esac + + if [[ ! "$version" =~ ^(pre|0\.1\.([4-9]))$ ]]; then + # Version does not meet the criteria, report error + error "Unsupported version: ${version}. Version number must be between 0.1.4 and 0.1.9 or 'pre'" + fi + + # generate download url + url="https://gitee.com/RubyMetric/chsrc/releases/download/${version}/${binary_name}-${arch}-${platform}" + + path_to_executable="${install_dir}/${binary_name}" + + info "Downloading ${binary_name} (${arch} architecture, ${platform} platform, version ${version}) to ${path_to_executable}" + + if curl -sL "$url" -o "$path_to_executable"; then + chmod +x "$path_to_executable" + info "🎉 Installation completed, path: $path_to_executable" + else + error "Download failed, please check your network connection and proxy settings: ${url}" + fi +} + +# Cleanup function +cleanup() { + if [ -n "$temp_install_dir" ] && [ -d "$temp_install_dir" ]; then + echo "Cleaning up created directory: $temp_install_dir" + rm -rf "$temp_install_dir" + fi +} + +# Set trap to catch exit signals +trap cleanup EXIT + +# Parser commandline argvs +while getopts ":hd:v:" option; do + case $option in + h) + help + exit 0 + ;; + d) + install_dir=${OPTARG} + ;; + v) + version=${OPTARG} + ;; + \?) + echo "Invalid command line option. Use -h for help" + exit 1 + ;; + esac +done + +set_install_path +install \ No newline at end of file From 5c1524f08699772866a3ed490ce54c0a65603b02 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 16:05:44 +0800 Subject: [PATCH 09/13] : create a readme file to describe files feature. --- tool/readme.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tool/readme.txt diff --git a/tool/readme.txt b/tool/readme.txt new file mode 100644 index 0000000..9d2cc07 --- /dev/null +++ b/tool/readme.txt @@ -0,0 +1,63 @@ +########################################################################### +# Chsrc 相关工具 +# 脚本工具 +########################################################################### + +************ +1. 概述 +************ + +此文件夹包含许多与安装 Chsrc 二进制文件相关的脚本工具,您可以使用这些工具指定目录路径和发布版本。 + +******** +2. 文件 +******** + +install.sh Bash 安装工具(中文版)。 +install-en.sh Bash 安装工具(英文版)。 +install.ps1 Powershell 安装工具。 +reademe.txt 此文件 + +******************* +3. 安装 +******************* + +步骤1:输入“sudo chmod u+x ./install.sh”以使脚本可执行。 + +步骤2:输入“./install.sh [-h] [-d ] [-v ]”指定安装路径和发布版本。 + +步骤3:如果出现错误,请检查您的网络连接并确保您可以访问Gitee。 + + + +##################################################################### +# Chsrc realated tools +# Scripts Tools +# English Version +##################################################################### + +************ +1. Overview +************ + +This folder contains many script tools realated to install Chsrc binary file, +you can use the tools to specify directory path and release version. + +******** +2. Files +******** + +install.sh Bash install tool(Chinese Version). +install-en.sh Bash install tool(English Version). +install.ps1 Powershell install tool. +reademe.txt This file + +******************* +3. Install +******************* + +Step 1: Type "sudo chmod u+x ./install.sh" to make scrpit executable. + +Step 2: Type "./install.sh [-h] [-d ] [-v ]" to specify install path and release version. + +Step 3: If an error occurs, please check your internet connection and ensure that you can access Gitee. \ No newline at end of file From 2d0e198aa443261753448b06b84706f7cfc7ffe7 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 20:21:39 +0800 Subject: [PATCH 10/13] : add new feature '-l' to select language. --- tool/install.sh | 136 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 113 insertions(+), 23 deletions(-) diff --git a/tool/install.sh b/tool/install.sh index 3ff9fdb..ae3e08d 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -18,6 +18,8 @@ path_to_executable="" default_install_path="/usr/local/bin" binary_name="chsrc" temp_install_dir="" # 用于存储临时安装目录 +helpflag=0 +lan="zh" # 输出相关信息 info() { @@ -32,14 +34,27 @@ error() { # 显示 chsrc 安装程序的帮助信息,包括使用说明和可用选项 help() { - echo "chsrc Installer" - echo - echo "使用: install.sh [-h] [-d <安装目录>] [-v <版本号>]" - echo "选项:" - echo "-h 打印此帮助信息" - echo "-d 指定安装目录,默认为 /usr/local/bin;如果已安装,则覆盖旧版本" - echo "-v 指定版本号,范围是 0.1.4 到 0.1.9 或 'pre'" - echo + if [ "$lan" = "zh" ]; then + echo "chsrc-installer: 在任何类Unix操作系统上安装 chsrc" + echo + echo "使用: install.sh [选项]" + echo "选项:" + echo " -h 打印此帮助信息" + echo " -d 指定安装目录,默认为 /usr/local/bin;若已安装,则覆盖旧版本" + echo " -v 指定 chsrc 版本" + echo " -l 指定脚本语言,支持 zh 和 en " + echo + else + echo "chsrc-installer: Install chsrc on any Unix-like OS" + echo + echo "Usage: install.sh [options]" + echo "Options:" + echo " -h Print this help information" + echo " -d Specify installation directory, default is /usr/local/bin; will overwrite if already installed" + echo " -v Specify chsrc version" + echo " -l Specify script language, supports zh and en" + echo + fi } # 确定下载路径 @@ -50,19 +65,46 @@ set_install_path() { # 检查路径是否存在,如果不存在则创建该路径 if [ ! -d "$install_dir" ]; then - echo "目录 $install_dir 不存在,正在创建..." - mkdir -p "$install_dir" || { echo "创建目录失败,请重试"; exit 1; } + # 多种语言输出 + if [ "$lan" = "zh" ]; then + echo "目录 $install_dir 不存在,正在创建..." + else + echo "Directory $install_dir does not exist. Creating..." + fi + # 多语言输出 + if ! mkdir -p "$install_dir"; then + if [ "$lan" = "zh" ]; then + echo "创建目录失败,请重试" + else + echo "Failed to create directory, please try again" + fi + exit 1 + fi + temp_install_dir="$install_dir" # 记录临时安装目录 fi + elif existing_path=$(command -v "$binary_name" 2>/dev/null); then - info "$binary_name 已安装,更新路径: ${existing_path}" + + if [ "$lan" = "zh"]; then + info "$binary_name 已安装,更新路径: ${existing_path}" + else + info "$binary_name is already installed, updating path: ${existing_path}" + fi + install_dir=$(dirname "$existing_path") else # 检查默认路径 if [ -d "$default_install_path" ] && [ -w "$default_install_path" ]; then install_dir="$default_install_path" else - error "默认下载路径 /usr/local/bin 不可写,请使用 sudo 命令运行脚本;或通过 -d 参数指定其它路径安装" + + if [ "$lan" = "zh"]; then + error "默认下载路径 /usr/local/bin 不可写,请使用 sudo 命令运行脚本;或通过 -d 参数指定其它路径安装" + else + error "Default download path /usr/local/bin is not writable. Please run the script with sudo; or specify another path using the -d option." + fi + fi fi } @@ -76,7 +118,13 @@ install() { aarch64|arm64) arch="aarch64" ;; riscv64) arch="riscv64" ;; armv7*) arch="armv7" ;; - *) error "不支持的架构: ${arch}" ;; + *) + if [ "$lan" = "zh" ]; then + error "不支持的架构: ${arch}" + else + error "Unsupported architecture: ${arch}" + fi + ;; esac platform="$(uname -s | awk '{print tolower($0)}')" @@ -84,32 +132,62 @@ install() { case "$platform" in linux) platform="linux" ;; darwin) platform="macos" ;; - *) error "不支持的平台: ${platform}" ;; + *) + if [ "$lan" = "zh" ]; then + error "不支持的平台: ${platform}" + else + error "Unsupported platform: ${platform}" + fi + ;; esac if [[ ! "$version" =~ ^(pre|0\.1\.([4-9]))$ ]]; then # version 不符合条件,报错 - error "不支持的版本: ${version},版本号必须在 0.1.4 到 0.1.9 之间或为 'pre'" + if [ "$lan" = "zh" ]; then + error "不支持的版本: ${version},版本号必须在 0.1.4 到 0.1.9 之间或为 'pre'" + else + error "Unsupported version: ${version}. Version number must be between 0.1.4 and 0.1.9 or 'pre'" + fi fi url="https://gitee.com/RubyMetric/chsrc/releases/download/${version}/${binary_name}-${arch}-${platform}" path_to_executable="${install_dir}/${binary_name}" - - info "下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version}版本) 到 ${path_to_executable}" + + if [ "$lan" = "zh" ]; then + info "下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version}版本) 到 ${path_to_executable}" + else + info "Downloading ${binary_name} (${arch} architecture, ${platform} platform, version ${version}) to ${path_to_executable}" + fi if curl -sL "$url" -o "$path_to_executable"; then chmod +x "$path_to_executable" - info "🎉 安装完成,路径: $path_to_executable" + + if [ "$lan" = "zh" ]; then + info "🎉 安装完成,版本: $version,路径: $path_to_executable" + else + info "🎉 Installation completed, path: $path_to_executable" + fi + else - error "下载失败,请检查您的网络连接和代理设置: ${url}" + if [ "$lan" = "zh" ]; then + error "下载失败,请检查您的网络连接和代理设置: ${url}" + else + error "Download failed, please check your network connection and proxy settings: ${url}" + fi + fi } # 清理函数 cleanup() { if [ -n "$temp_install_dir" ] && [ -d "$temp_install_dir" ]; then - echo "清理创建的目录: $temp_install_dir" + + if [ "$lan" = "zh" ]; then + echo "清理创建的目录: $temp_install_dir" + else + echo "Cleaning up created directory: $temp_install_dir" + fi rm -rf "$temp_install_dir" fi } @@ -118,11 +196,10 @@ cleanup() { trap cleanup EXIT # 从命令行读取 安装路径与版本号 -while getopts ":hd:v:" option; do +while getopts ":hd:v:l:" option; do case $option in h) - help - exit 0 + helpflag=1 ;; d) install_dir=${OPTARG} @@ -130,6 +207,9 @@ while getopts ":hd:v:" option; do v) version=${OPTARG} ;; + l) + lan=${OPTARG} + ;; \?) echo "无效的命令行选项。使用 -h 查看帮助" exit 1 @@ -137,5 +217,15 @@ while getopts ":hd:v:" option; do esac done +# 判断语言的类型,不符合直接退出 +if [[ "$lan" != "zh" && "$lan" != "en" ]]; then + error "无效的语言选项: $lan。支持的选项是 zh 和 en" +fi + +if [ "$helpflag" -eq 1 ]; then + help + exit 0; +fi + set_install_path install \ No newline at end of file From 10ec1fce88307b774498719057af2bf0da1da8d1 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 20:24:09 +0800 Subject: [PATCH 11/13] : update readme Files part's description. --- tool/readme.txt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tool/readme.txt b/tool/readme.txt index 9d2cc07..518c25d 100644 --- a/tool/readme.txt +++ b/tool/readme.txt @@ -13,8 +13,7 @@ 2. 文件 ******** -install.sh Bash 安装工具(中文版)。 -install-en.sh Bash 安装工具(英文版)。 +install.sh Bash 安装工具 install.ps1 Powershell 安装工具。 reademe.txt 此文件 @@ -24,7 +23,7 @@ reademe.txt 此文件 步骤1:输入“sudo chmod u+x ./install.sh”以使脚本可执行。 -步骤2:输入“./install.sh [-h] [-d ] [-v ]”指定安装路径和发布版本。 +步骤2:输入“./install.sh [-h] [-d ] [-v ] [-l ]”指定安装路径,发布版本和脚本语言。 步骤3:如果出现错误,请检查您的网络连接并确保您可以访问Gitee。 @@ -47,9 +46,7 @@ you can use the tools to specify directory path and release version. 2. Files ******** -install.sh Bash install tool(Chinese Version). -install-en.sh Bash install tool(English Version). -install.ps1 Powershell install tool. +install.sh Bash install tool. reademe.txt This file ******************* @@ -58,6 +55,6 @@ reademe.txt This file Step 1: Type "sudo chmod u+x ./install.sh" to make scrpit executable. -Step 2: Type "./install.sh [-h] [-d ] [-v ]" to specify install path and release version. +Step 2: Type "./install.sh [-h] [-d ] [-v ] [-l ]" to specify install path and release version also language. Step 3: If an error occurs, please check your internet connection and ensure that you can access Gitee. \ No newline at end of file From 754058837e71ed2105dcc604b99dfce96959a1a0 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 20:24:33 +0800 Subject: [PATCH 12/13] : delete en version script. --- tool/install-en.sh | 130 --------------------------------------------- 1 file changed, 130 deletions(-) delete mode 100755 tool/install-en.sh diff --git a/tool/install-en.sh b/tool/install-en.sh deleted file mode 100755 index 27175c2..0000000 --- a/tool/install-en.sh +++ /dev/null @@ -1,130 +0,0 @@ -# to avoid the operate system not supporting Chinese output, create an english version -install_dir="" -version="pre" -path_to_executable="" -default_install_path="/usr/local/bin" -binary_name="chsrc" -temp_install_dir="" - -# display related info -info() { - echo "[INFO] $*" -} - -# display error message -error() { - echo -e "[ERROR] $*" >&2 - exit 1 -} - -# display help information for the chsrc installer, -# including usage instructions and available options. -help() { - echo "chsrc Installer" - echo - echo "Usage: install.sh [-h] [-d ] [-v ]" - echo "Options:" - echo "-h Display this help information" - echo "-d Specify the installation directory, defaults to /usr/local/bin; overwrites old versions if already installed" - echo "-v Specify the version number, range is from 0.1.4 to 0.1.9 or 'pre'" - echo -} - -# set install path, if use -d specify, check whether it exists. -set_install_path() { - if [ -n "$install_dir" ]; then - # Expand ~ symbol - install_dir="${install_dir/#\~/$HOME}" - - # Check if the path exists; if not, create it - if [ ! -d "$install_dir" ]; then - echo "Directory $install_dir does not exist. Creating..." - mkdir -p "$install_dir" || { echo "Failed to create directory, please retry"; exit 1; } - temp_install_dir="$install_dir" # Record temporary installation directory - fi - elif existing_path=$(command -v "$binary_name" 2>/dev/null); then - info "$binary_name is already installed, updating path: ${existing_path}" - install_dir=$(dirname "$existing_path") - else - # Check default path - if [ -d "$default_install_path" ] && [ -w "$default_install_path" ]; then - install_dir="$default_install_path" - else - error "Default download path /usr/local/bin is not writable. Please run the script with sudo; or specify another path using the -d option." - fi - fi -} - -# install specifying arch, os, version chsrc binary file from Gitee Repository -install() { - arch="$(uname -m | tr '[:upper:]' '[:lower:]')" - - case "$arch" in - x86_64) arch="x64" ;; - aarch64|arm64) arch="aarch64" ;; - riscv64) arch="riscv64" ;; - armv7*) arch="armv7" ;; - *) error "Unsupported architecture: ${arch}" ;; - esac - - platform="$(uname -s | awk '{print tolower($0)}')" - - case "$platform" in - linux) platform="linux" ;; - darwin) platform="macos" ;; - *) error "Unsupported platform: ${platform}" ;; - esac - - if [[ ! "$version" =~ ^(pre|0\.1\.([4-9]))$ ]]; then - # Version does not meet the criteria, report error - error "Unsupported version: ${version}. Version number must be between 0.1.4 and 0.1.9 or 'pre'" - fi - - # generate download url - url="https://gitee.com/RubyMetric/chsrc/releases/download/${version}/${binary_name}-${arch}-${platform}" - - path_to_executable="${install_dir}/${binary_name}" - - info "Downloading ${binary_name} (${arch} architecture, ${platform} platform, version ${version}) to ${path_to_executable}" - - if curl -sL "$url" -o "$path_to_executable"; then - chmod +x "$path_to_executable" - info "🎉 Installation completed, path: $path_to_executable" - else - error "Download failed, please check your network connection and proxy settings: ${url}" - fi -} - -# Cleanup function -cleanup() { - if [ -n "$temp_install_dir" ] && [ -d "$temp_install_dir" ]; then - echo "Cleaning up created directory: $temp_install_dir" - rm -rf "$temp_install_dir" - fi -} - -# Set trap to catch exit signals -trap cleanup EXIT - -# Parser commandline argvs -while getopts ":hd:v:" option; do - case $option in - h) - help - exit 0 - ;; - d) - install_dir=${OPTARG} - ;; - v) - version=${OPTARG} - ;; - \?) - echo "Invalid command line option. Use -h for help" - exit 1 - ;; - esac -done - -set_install_path -install \ No newline at end of file From 322a3c93d8e6ec1ebb76571df0abb03921353411 Mon Sep 17 00:00:00 2001 From: YiXuan Ding <1328032567@qq.com> Date: Fri, 25 Oct 2024 20:33:02 +0800 Subject: [PATCH 13/13] : if noroot user, install at "$HOME/.local/bin". --- tool/install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tool/install.sh b/tool/install.sh index ae3e08d..a597e27 100755 --- a/tool/install.sh +++ b/tool/install.sh @@ -16,6 +16,7 @@ install_dir="" version="pre" path_to_executable="" default_install_path="/usr/local/bin" +noroot_default_install_path="$HOME/.local/bin" binary_name="chsrc" temp_install_dir="" # 用于存储临时安装目录 helpflag=0 @@ -97,8 +98,9 @@ set_install_path() { # 检查默认路径 if [ -d "$default_install_path" ] && [ -w "$default_install_path" ]; then install_dir="$default_install_path" + else if [ -d "$noroot_default_install_path" ] && [ -w "$noroot_default_install_path" ]; then + install_dir="$noroot_default_install_path" else - if [ "$lan" = "zh"]; then error "默认下载路径 /usr/local/bin 不可写,请使用 sudo 命令运行脚本;或通过 -d 参数指定其它路径安装" else