@@ -20,7 +20,7 @@ noroot_default_install_path="$HOME/.local/bin"
20
20
binary_name=" chsrc"
21
21
temp_install_dir=" " # 用于存储临时安装目录
22
22
helpflag=0
23
- lan =" zh"
23
+ lang =" zh"
24
24
25
25
# 输出相关信息
26
26
info () {
@@ -35,7 +35,7 @@ error() {
35
35
36
36
# 显示 chsrc 安装程序的帮助信息,包括使用说明和可用选项
37
37
help () {
38
- if [ " $lan " = " zh" ]; then
38
+ if [ " $lang " = " zh" ]; then
39
39
echo " chsrc-installer: 在任何类Unix操作系统上安装 chsrc"
40
40
echo
41
41
echo " 使用: install.sh [选项]"
@@ -58,7 +58,7 @@ help() {
58
58
fi
59
59
}
60
60
61
- # 确定下载路径
61
+
62
62
set_install_path () {
63
63
if [ -n " $install_dir " ]; then
64
64
# 扩展 ~ 符号
@@ -67,14 +67,14 @@ set_install_path() {
67
67
# 检查路径是否存在,如果不存在则创建该路径
68
68
if [ ! -d " $install_dir " ]; then
69
69
# 多种语言输出
70
- if [ " $lan " = " zh" ]; then
70
+ if [ " $lang " = " zh" ]; then
71
71
echo " 目录 $install_dir 不存在,正在创建..."
72
72
else
73
73
echo " Directory $install_dir does not exist. Creating..."
74
74
fi
75
75
# 多语言输出
76
76
if ! mkdir -p " $install_dir " ; then
77
- if [ " $lan " = " zh" ]; then
77
+ if [ " $lang " = " zh" ]; then
78
78
echo " 创建目录失败,请重试"
79
79
else
80
80
echo " Failed to create directory, please try again"
@@ -87,7 +87,7 @@ set_install_path() {
87
87
88
88
elif existing_path=$( command -v " $binary_name " 2> /dev/null) ; then
89
89
90
- if [ " $lan " = " zh" ]; then
90
+ if [ " $lang " = " zh" ]; then
91
91
info " $binary_name 已安装,更新路径: ${existing_path} "
92
92
else
93
93
info " $binary_name is already installed, updating path: ${existing_path} "
@@ -98,20 +98,19 @@ set_install_path() {
98
98
# 检查默认路径
99
99
if [ -d " $default_install_path " ] && [ -w " $default_install_path " ]; then
100
100
install_dir=" $default_install_path "
101
- else if [ -d " $noroot_default_install_path " ] && [ -w " $noroot_default_install_path " ]; then
101
+ elif [ -d " $noroot_default_install_path " ] && [ -w " $noroot_default_install_path " ]; then
102
102
install_dir=" $noroot_default_install_path "
103
103
else
104
- if [ " $lan " = " zh" ]; then
104
+ if [ " $lang " = " zh" ]; then
105
105
error " 默认下载路径 /usr/local/bin 不可写,请使用 sudo 命令运行脚本;或通过 -d 参数指定其它路径安装"
106
106
else
107
107
error " Default download path /usr/local/bin is not writable. Please run the script with sudo; or specify another path using the -d option."
108
108
fi
109
-
110
109
fi
111
110
fi
112
111
}
113
112
114
- # 从Gitee仓库安装 指定架构,操作系统,版本 的chsrc二进制文件
113
+
115
114
install () {
116
115
arch=" $( uname -m | tr ' [:upper:]' ' [:lower:]' ) "
117
116
@@ -120,8 +119,8 @@ install() {
120
119
aarch64|arm64) arch=" aarch64" ;;
121
120
riscv64) arch=" riscv64" ;;
122
121
armv7* ) arch=" armv7" ;;
123
- * )
124
- if [ " $lan " = " zh" ]; then
122
+ * )
123
+ if [ " $lang " = " zh" ]; then
125
124
error " 不支持的架构: ${arch} "
126
125
else
127
126
error " Unsupported architecture: ${arch} "
@@ -134,9 +133,9 @@ install() {
134
133
case " $platform " in
135
134
linux) platform=" linux" ;;
136
135
darwin) platform=" macos" ;;
137
- * )
138
- if [ " $lan " = " zh" ]; then
139
- error " 不支持的平台: ${platform} "
136
+ * )
137
+ if [ " $lang " = " zh" ]; then
138
+ error " 不支持的平台: ${platform} "
140
139
else
141
140
error " Unsupported platform: ${platform} "
142
141
fi
@@ -145,7 +144,7 @@ install() {
145
144
146
145
if [[ ! " $version " =~ ^(pre| 0\. 1\. ([4-9]))$ ]]; then
147
146
# version 不符合条件,报错
148
- if [ " $lan " = " zh" ]; then
147
+ if [ " $lang " = " zh" ]; then
149
148
error " 不支持的版本: ${version} ,版本号必须在 0.1.4 到 0.1.9 之间或为 'pre'"
150
149
else
151
150
error " Unsupported version: ${version} . Version number must be between 0.1.4 and 0.1.9 or 'pre'"
@@ -155,8 +154,8 @@ install() {
155
154
url=" https://gitee.com/RubyMetric/chsrc/releases/download/${version} /${binary_name} -${arch} -${platform} "
156
155
157
156
path_to_executable=" ${install_dir} /${binary_name} "
158
-
159
- if [ " $lan " = " zh" ]; then
157
+
158
+ if [ " $lang " = " zh" ]; then
160
159
info " 下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version} 版本) 到 ${path_to_executable} "
161
160
else
162
161
info " Downloading ${binary_name} (${arch} architecture, ${platform} platform, version ${version} ) to ${path_to_executable} "
@@ -165,14 +164,14 @@ install() {
165
164
if curl -sL " $url " -o " $path_to_executable " ; then
166
165
chmod +x " $path_to_executable "
167
166
168
- if [ " $lan " = " zh" ]; then
167
+ if [ " $lang " = " zh" ]; then
169
168
info " 🎉 安装完成,版本: $version ,路径: $path_to_executable "
170
169
else
171
170
info " 🎉 Installation completed, path: $path_to_executable "
172
171
fi
173
172
174
173
else
175
- if [ " $lan " = " zh" ]; then
174
+ if [ " $lang " = " zh" ]; then
176
175
error " 下载失败,请检查您的网络连接和代理设置: ${url} "
177
176
else
178
177
error " Download failed, please check your network connection and proxy settings: ${url} "
@@ -185,7 +184,7 @@ install() {
185
184
cleanup () {
186
185
if [ -n " $temp_install_dir " ] && [ -d " $temp_install_dir " ]; then
187
186
188
- if [ " $lan " = " zh" ]; then
187
+ if [ " $lang " = " zh" ]; then
189
188
echo " 清理创建的目录: $temp_install_dir "
190
189
else
191
190
echo " Cleaning up created directory: $temp_install_dir "
@@ -197,6 +196,7 @@ cleanup() {
197
196
# 设置 trap 以捕获退出信号
198
197
trap cleanup EXIT
199
198
199
+
200
200
# 从命令行读取 安装路径与版本号
201
201
while getopts " :hd:v:l:" option; do
202
202
case $option in
@@ -210,7 +210,7 @@ while getopts ":hd:v:l:" option; do
210
210
version=${OPTARG}
211
211
;;
212
212
l)
213
- lan =${OPTARG}
213
+ lang =${OPTARG}
214
214
;;
215
215
\? )
216
216
echo " 无效的命令行选项,请使用 -h 查看帮助"
@@ -220,8 +220,8 @@ while getopts ":hd:v:l:" option; do
220
220
done
221
221
222
222
# 判断语言的类型,不符合直接退出
223
- if [[ " $lan " != " zh" && " $lan " != " en" ]]; then
224
- error " 无效的语言选项: $lan 。支持的选项是 zh 和 en"
223
+ if [[ " $lang " != " zh" && " $lang " != " en" ]]; then
224
+ error " 无效的语言选项: $lang ,支持的选项为 zh 和 en"
225
225
fi
226
226
227
227
if [ " $helpflag " -eq 1 ]; then
@@ -230,4 +230,4 @@ if [ "$helpflag" -eq 1 ]; then
230
230
fi
231
231
232
232
set_install_path
233
- install
233
+ install
0 commit comments