Skip to content

Commit 92316ec

Browse files
committed
Sync installers: 2025-03-19 15:31
1 parent a14ffd4 commit 92316ec

File tree

1 file changed

+105
-42
lines changed

1 file changed

+105
-42
lines changed

docs/posix

Lines changed: 105 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Contributors : Aoran Zeng <[email protected]>
88
# |
99
# Created On : <2024-10-25>
10-
# Last Modified : <2025-03-07>
10+
# Last Modified : <2025-03-19>
1111
#
1212
# chsrc installer for Linux & macOS
1313
# ---------------------------------------------------------------
@@ -64,6 +64,99 @@ help() {
6464
}
6565

6666

67+
get_arch() {
68+
echo $(uname -m | tr '[:upper:]' '[:lower:]')
69+
}
70+
71+
get_platform() {
72+
echo $(uname -s | awk '{print tolower($0)}')
73+
}
74+
75+
# Linux -> GNU/Linux
76+
# Android -> Android
77+
get_os() {
78+
echo $(uname -o | awk '{print tolower($0)}')
79+
}
80+
81+
82+
set_arch() {
83+
arch=$(get_arch)
84+
85+
case "$arch" in
86+
x86_64) arch="x64" ;;
87+
aarch64|arm64) arch="aarch64" ;;
88+
riscv64) arch="riscv64" ;;
89+
armv7*) arch="armv7" ;;
90+
*)
91+
if [ "$userOpt_lang" = "zh" ]; then
92+
error "不支持的架构: ${arch}"
93+
else
94+
error "Unsupported arch: ${arch}"
95+
fi
96+
;;
97+
esac
98+
}
99+
100+
101+
set_platform() {
102+
platform=$(get_platform)
103+
104+
case "$platform" in
105+
linux)
106+
platform="linux"
107+
whatos=$(get_os)
108+
if [ "$whatos" = "android" ]; then
109+
if [ "$userOpt_lang" = "zh" ]; then
110+
info "抱歉, 暂无预编译二进制文件供安卓使用。请自行编译:"
111+
else
112+
info "Sorry, No precompiled binaries for Android! Please compile it on your own:"
113+
fi
114+
info "$ git clone https://gitee.com/RubyMetric/chsrc.git; cd chsrc; make"
115+
exit 1
116+
fi
117+
;;
118+
darwin) platform="macos" ;;
119+
bsd|dragonfly)
120+
platform="bsd"
121+
if [ "$userOpt_lang" = "zh" ]; then
122+
info "抱歉, 暂无预编译二进制文件供BSD使用。请自行编译:"
123+
else
124+
info "Sorry, No precompiled binaries for BSD! Please compile it on your own:"
125+
fi
126+
info "$ git clone https://gitee.com/RubyMetric/chsrc.git; cd chsrc"
127+
info "$ clang -Iinclude -Ilib src/chsrc-main.c -o chsrc"
128+
exit 1
129+
;;
130+
*)
131+
if [ "$userOpt_lang" = "zh" ]; then
132+
error "不支持的平台: ${platform}"
133+
else
134+
error "Unsupported platform: ${platform}"
135+
fi
136+
;;
137+
esac
138+
}
139+
140+
141+
set_binary_version() {
142+
if [[ ! "$userOpt_version" =~ ^(pre|0\.([1-9])\.([0-9]))$ ]]; then
143+
# version 不符合条件,报错
144+
if [ "$userOpt_lang" = "zh" ]; then
145+
error "不支持的版本: ${userOpt_version},版本号必须为 0.x.y (>=0.1.4) 或 'pre'"
146+
else
147+
error "Unsupported version: ${userOpt_version}. Version number must be 0.x.y (>=0.1.4) or 'pre'"
148+
fi
149+
fi
150+
151+
binary_version="${userOpt_version}"
152+
153+
# version 版本不是 'pre',添加'v'前缀
154+
if [[ "$userOpt_version" =~ ^(0\.([1-9])\.([0-9]))$ ]]; then
155+
binary_version="v${userOpt_version}"
156+
fi
157+
}
158+
159+
67160
#
68161
# 1. 若用户指定了安装目录,则安装至那里
69162
#
@@ -81,13 +174,13 @@ set_install_dir() {
81174

82175
# 检查目录是否存在,如果不存在则创建该目录
83176
if [ ! -d "$userOpt_install_dir" ]; then
84-
# 多种语言输出
177+
85178
if [ "$userOpt_lang" = "zh" ]; then
86179
echo "目录 $userOpt_install_dir 不存在,正在创建..."
87180
else
88181
echo "Directory $userOpt_install_dir does not exist. Creating..."
89182
fi
90-
# 多语言输出
183+
91184
if ! mkdir -p "$userOpt_install_dir"; then
92185
if [ "$userOpt_lang" = "zh" ]; then
93186
echo "创建目录失败,请重试"
@@ -127,60 +220,30 @@ set_install_dir() {
127220

128221

129222
install() {
130-
arch="$(uname -m | tr '[:upper:]' '[:lower:]')"
131223

132-
case "$arch" in
133-
x86_64) arch="x64" ;;
134-
aarch64|arm64) arch="aarch64" ;;
135-
riscv64) arch="riscv64" ;;
136-
armv7*) arch="armv7" ;;
137-
*)
138-
if [ "$userOpt_lang" = "zh" ]; then
139-
error "不支持的架构: ${arch}"
140-
else
141-
error "Unsupported architecture: ${arch}"
142-
fi
143-
;;
144-
esac
224+
set_binary_version
145225

146-
platform="$(uname -s | awk '{print tolower($0)}')"
226+
set_arch
147227

148-
case "$platform" in
149-
linux) platform="linux" ;;
150-
darwin) platform="macos" ;;
151-
*)
152-
if [ "$userOpt_lang" = "zh" ]; then
153-
error "不支持的平台: ${platform}"
154-
else
155-
error "Unsupported platform: ${platform}"
156-
fi
157-
;;
158-
esac
228+
set_platform
159229

160-
if [[ ! "$userOpt_version" =~ ^(pre|0\.([1-9])\.([0-9]))$ ]]; then
161-
# version 不符合条件,报错
162-
if [ "$userOpt_lang" = "zh" ]; then
163-
error "不支持的版本: ${userOpt_version},版本号必须为 0.x.y (>=0.1.4) 或 'pre'"
164-
else
165-
error "Unsupported version: ${userOpt_version}. Version number must be 0.x.y (>=0.1.4) or 'pre'"
166-
fi
167-
fi
230+
set_install_dir
168231

169-
url="https://gitee.com/RubyMetric/chsrc/releases/download/${userOpt_version}/${binary_name}-${arch}-${platform}"
232+
url="https://gitee.com/RubyMetric/chsrc/releases/download/${binary_version}/${binary_name}-${arch}-${platform}"
170233

171234
path_to_executable="${userOpt_install_dir}/${binary_name}"
172235

173236
if [ "$userOpt_lang" = "zh" ]; then
174-
info "下载 ${binary_name} (架构: ${arch}, 平台: ${platform}, 版本: ${userOpt_version}) 到 ${path_to_executable}"
237+
info "下载 ${binary_name} (架构: ${arch}, 平台: ${platform}, 版本: ${binary_version}) 到 ${path_to_executable}"
175238
else
176-
info "Downloading ${binary_name} (architecture: ${arch}, platform: ${platform}, version: ${userOpt_version}) to ${path_to_executable}"
239+
info "Downloading ${binary_name} (arch: ${arch}, platform: ${platform}, version: ${binary_version}) to ${path_to_executable}"
177240
fi
178241

179242
if curl -sL "$url" -o "$path_to_executable"; then
180243
chmod +x "$path_to_executable"
181244

182245
if [ "$userOpt_lang" = "zh" ]; then
183-
info "🎉 安装完成,版本$userOpt_version,路径: $path_to_executable"
246+
info "🎉 安装完成,a版本$binary_version,路径: $path_to_executable"
184247
else
185248
info "🎉 Installation completed, path: $path_to_executable"
186249
fi
@@ -195,6 +258,7 @@ install() {
195258
fi
196259
}
197260

261+
198262
cleanup() {
199263
if [ -n "$tmp_created_install_dir" ] && [ -d "$tmp_created_install_dir" ]; then
200264

@@ -241,5 +305,4 @@ if [ "$userOpt_help" -eq 1 ]; then
241305
exit 0;
242306
fi
243307

244-
set_install_dir
245308
install

0 commit comments

Comments
 (0)