Skip to content

Commit fddad4d

Browse files
committed
[install] add gitee chevk
1 parent 9ea8dcd commit fddad4d

File tree

1 file changed

+89
-13
lines changed

1 file changed

+89
-13
lines changed

install.sh

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ export RTT_CC=gcc
1919

2020
echo "RTT_ROOT is set to: $RTT_ROOT"
2121

22+
23+
check_if_china_ip() {
24+
# 默认情况下不使用gitee
25+
use_gitee=false
26+
27+
# 尝试通过IP地址判断
28+
ip=$(curl -s https://ifconfig.me/ip)
29+
if [ -n "$ip" ]; then
30+
location=$(curl -s http://www.ip-api.com/json/$ip | grep -o '"country":"China"')
31+
if [ "$location" == '"country":"China"' ]; then
32+
use_gitee=true
33+
echo "Detected China IP. Using gitee."
34+
else
35+
echo "IP location is not in China."
36+
fi
37+
else
38+
echo "Failed to retrieve IP address. Falling back to timezone check."
39+
40+
# 通过时区判断
41+
if [ $(($(date +%z)/100)) -eq 8 ]; then
42+
use_gitee=true
43+
echo "Detected timezone UTC+8. Using gitee."
44+
else
45+
echo "Timezone is not UTC+8."
46+
fi
47+
fi
48+
49+
echo $use_gitee
50+
}
51+
52+
2253
# 检测操作系统类型和发行版
2354
detect_os() {
2455
if command -v uname >/dev/null 2>&1; then
@@ -53,14 +84,27 @@ detect_os() {
5384
echo "Detected Operating System: $OS, Distribution: $DISTRO, Version: $VERSION"
5485
}
5586

56-
# 安装函数
87+
# 修改的安装函数
5788
install_on_ubuntu() {
5889
echo "Installing on Debian/Ubuntu..."
59-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh
60-
chmod 777 install_ubuntu.sh
61-
./install_ubuntu.sh
90+
use_gitee=$(check_if_china_ip)
91+
92+
# 根据检测结果决定是否使用--gitee参数
93+
if [ "$use_gitee" = true ]; then
94+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh
95+
chmod 777 install_ubuntu.sh
96+
echo "Installing on China gitee..."
97+
./install_ubuntu.sh --gitee
98+
else
99+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh
100+
chmod 777 install_ubuntu.sh
101+
echo "Installing on no China..."
102+
./install_ubuntu.sh
103+
fi
104+
rm install_ubuntu.sh
62105
}
63106

107+
64108
install_on_fedora() {
65109
echo "Installing on Fedora..."
66110

@@ -76,9 +120,21 @@ install_on_arch() {
76120

77121
install_on_macos() {
78122
echo "Installing on macOS..."
79-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_macos.sh
80-
chmod 777 install_macos.sh
81-
./install_macos.sh
123+
use_gitee=$(check_if_china_ip)
124+
125+
# 根据检测结果决定是否使用--gitee参数
126+
if [ "$use_gitee" = true ]; then
127+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_macos.sh
128+
chmod 777 install_macos.sh
129+
echo "Installing on China gitee..."
130+
./install_macos.sh --gitee
131+
else
132+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_macos.sh
133+
chmod 777 install_macos.sh
134+
echo "Installing on no China..."
135+
./install_macos.sh
136+
fi
137+
rm ./install_macos.sh
82138
}
83139

84140
install_on_wsl() {
@@ -87,16 +143,36 @@ install_on_wsl() {
87143

88144
install_on_windows() {
89145
echo "Installing on Windows using PowerShell..."
90-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1
91-
chmod 777 install_windows.ps1
92-
./install_windows.ps1
146+
use_gitee=$(check_if_china_ip)
147+
148+
# 根据检测结果决定是否使用--gitee参数
149+
if [ "$use_gitee" = true ]; then
150+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1
151+
echo "Installing on China gitee..."
152+
./install_windows.ps1 --gitee
153+
else
154+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_windows.ps1
155+
echo "Installing on no China..."
156+
./install_windows.ps1
157+
fi
158+
rm ./install_windows.ps1
93159
}
94160

95161
install_on_opensuse() {
96162
echo "Installing on openSUSE..."
97-
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_suse.sh
98-
chmod 777 install_suse.sh
99-
./install_suse.sh
163+
use_gitee=$(check_if_china_ip)
164+
if [ "$use_gitee" = true ]; then
165+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_suse.sh
166+
chmod 777 install_suse.sh
167+
echo "Installing on China gitee..."
168+
./install_suse.sh --gitee
169+
else
170+
wget https://raw.githubusercontent.com/RT-Thread/env/master/install_suse.sh
171+
chmod 777 install_suse.sh
172+
echo "Installing on no China..."
173+
./install_suse.sh
174+
fi
175+
rm ./install_suse.sh
100176
}
101177
# 主函数
102178
main() {

0 commit comments

Comments
 (0)