Skip to content

Commit c6a0801

Browse files
committed
Fix install.sh to make it runnable
[GitHub #98 #104]
1 parent 15c0ae6 commit c6a0801

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

tool/install.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ noroot_default_install_path="$HOME/.local/bin"
2020
binary_name="chsrc"
2121
temp_install_dir="" # 用于存储临时安装目录
2222
helpflag=0
23-
lan="zh"
23+
lang="zh"
2424

2525
# 输出相关信息
2626
info() {
@@ -35,7 +35,7 @@ error() {
3535

3636
# 显示 chsrc 安装程序的帮助信息,包括使用说明和可用选项
3737
help() {
38-
if [ "$lan" = "zh" ]; then
38+
if [ "$lang" = "zh" ]; then
3939
echo "chsrc-installer: 在任何类Unix操作系统上安装 chsrc"
4040
echo
4141
echo "使用: install.sh [选项]"
@@ -58,7 +58,7 @@ help() {
5858
fi
5959
}
6060

61-
# 确定下载路径
61+
6262
set_install_path() {
6363
if [ -n "$install_dir" ]; then
6464
# 扩展 ~ 符号
@@ -67,14 +67,14 @@ set_install_path() {
6767
# 检查路径是否存在,如果不存在则创建该路径
6868
if [ ! -d "$install_dir" ]; then
6969
# 多种语言输出
70-
if [ "$lan" = "zh" ]; then
70+
if [ "$lang" = "zh" ]; then
7171
echo "目录 $install_dir 不存在,正在创建..."
7272
else
7373
echo "Directory $install_dir does not exist. Creating..."
7474
fi
7575
# 多语言输出
7676
if ! mkdir -p "$install_dir"; then
77-
if [ "$lan" = "zh" ]; then
77+
if [ "$lang" = "zh" ]; then
7878
echo "创建目录失败,请重试"
7979
else
8080
echo "Failed to create directory, please try again"
@@ -87,7 +87,7 @@ set_install_path() {
8787

8888
elif existing_path=$(command -v "$binary_name" 2>/dev/null); then
8989

90-
if [ "$lan" = "zh"]; then
90+
if [ "$lang" = "zh" ]; then
9191
info "$binary_name 已安装,更新路径: ${existing_path}"
9292
else
9393
info "$binary_name is already installed, updating path: ${existing_path}"
@@ -98,20 +98,19 @@ set_install_path() {
9898
# 检查默认路径
9999
if [ -d "$default_install_path" ] && [ -w "$default_install_path" ]; then
100100
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
102102
install_dir="$noroot_default_install_path"
103103
else
104-
if [ "$lan" = "zh"]; then
104+
if [ "$lang" = "zh"]; then
105105
error "默认下载路径 /usr/local/bin 不可写,请使用 sudo 命令运行脚本;或通过 -d 参数指定其它路径安装"
106106
else
107107
error "Default download path /usr/local/bin is not writable. Please run the script with sudo; or specify another path using the -d option."
108108
fi
109-
110109
fi
111110
fi
112111
}
113112

114-
# 从Gitee仓库安装 指定架构,操作系统,版本 的chsrc二进制文件
113+
115114
install() {
116115
arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
117116

@@ -120,8 +119,8 @@ install() {
120119
aarch64|arm64) arch="aarch64" ;;
121120
riscv64) arch="riscv64" ;;
122121
armv7*) arch="armv7" ;;
123-
*)
124-
if [ "$lan" = "zh" ]; then
122+
*)
123+
if [ "$lang" = "zh" ]; then
125124
error "不支持的架构: ${arch}"
126125
else
127126
error "Unsupported architecture: ${arch}"
@@ -134,9 +133,9 @@ install() {
134133
case "$platform" in
135134
linux) platform="linux" ;;
136135
darwin) platform="macos" ;;
137-
*)
138-
if [ "$lan" = "zh" ]; then
139-
error "不支持的平台: ${platform}"
136+
*)
137+
if [ "$lang" = "zh" ]; then
138+
error "不支持的平台: ${platform}"
140139
else
141140
error "Unsupported platform: ${platform}"
142141
fi
@@ -145,7 +144,7 @@ install() {
145144

146145
if [[ ! "$version" =~ ^(pre|0\.1\.([4-9]))$ ]]; then
147146
# version 不符合条件,报错
148-
if [ "$lan" = "zh" ]; then
147+
if [ "$lang" = "zh" ]; then
149148
error "不支持的版本: ${version},版本号必须在 0.1.4 到 0.1.9 之间或为 'pre'"
150149
else
151150
error "Unsupported version: ${version}. Version number must be between 0.1.4 and 0.1.9 or 'pre'"
@@ -155,8 +154,8 @@ install() {
155154
url="https://gitee.com/RubyMetric/chsrc/releases/download/${version}/${binary_name}-${arch}-${platform}"
156155

157156
path_to_executable="${install_dir}/${binary_name}"
158-
159-
if [ "$lan" = "zh" ]; then
157+
158+
if [ "$lang" = "zh" ]; then
160159
info "下载 ${binary_name} (${arch} 架构, ${platform} 平台, ${version}版本) 到 ${path_to_executable}"
161160
else
162161
info "Downloading ${binary_name} (${arch} architecture, ${platform} platform, version ${version}) to ${path_to_executable}"
@@ -165,14 +164,14 @@ install() {
165164
if curl -sL "$url" -o "$path_to_executable"; then
166165
chmod +x "$path_to_executable"
167166

168-
if [ "$lan" = "zh" ]; then
167+
if [ "$lang" = "zh" ]; then
169168
info "🎉 安装完成,版本: $version,路径: $path_to_executable"
170169
else
171170
info "🎉 Installation completed, path: $path_to_executable"
172171
fi
173172

174173
else
175-
if [ "$lan" = "zh" ]; then
174+
if [ "$lang" = "zh" ]; then
176175
error "下载失败,请检查您的网络连接和代理设置: ${url}"
177176
else
178177
error "Download failed, please check your network connection and proxy settings: ${url}"
@@ -185,7 +184,7 @@ install() {
185184
cleanup() {
186185
if [ -n "$temp_install_dir" ] && [ -d "$temp_install_dir" ]; then
187186

188-
if [ "$lan" = "zh" ]; then
187+
if [ "$lang" = "zh" ]; then
189188
echo "清理创建的目录: $temp_install_dir"
190189
else
191190
echo "Cleaning up created directory: $temp_install_dir"
@@ -197,6 +196,7 @@ cleanup() {
197196
# 设置 trap 以捕获退出信号
198197
trap cleanup EXIT
199198

199+
200200
# 从命令行读取 安装路径与版本号
201201
while getopts ":hd:v:l:" option; do
202202
case $option in
@@ -210,7 +210,7 @@ while getopts ":hd:v:l:" option; do
210210
version=${OPTARG}
211211
;;
212212
l)
213-
lan=${OPTARG}
213+
lang=${OPTARG}
214214
;;
215215
\?)
216216
echo "无效的命令行选项,请使用 -h 查看帮助"
@@ -220,8 +220,8 @@ while getopts ":hd:v:l:" option; do
220220
done
221221

222222
# 判断语言的类型,不符合直接退出
223-
if [[ "$lan" != "zh" && "$lan" != "en" ]]; then
224-
error "无效的语言选项: $lan。支持的选项是 zh 和 en"
223+
if [[ "$lang" != "zh" && "$lang" != "en" ]]; then
224+
error "无效的语言选项: $lang,支持的选项为 zh 和 en"
225225
fi
226226

227227
if [ "$helpflag" -eq 1 ]; then
@@ -230,4 +230,4 @@ if [ "$helpflag" -eq 1 ]; then
230230
fi
231231

232232
set_install_path
233-
install
233+
install

0 commit comments

Comments
 (0)