Repository navigation
Expand file tree
/
Copy pathsuim
More file actions
executable file
·226 lines (196 loc) · 5.85 KB
/
Copy pathsuim
File metadata and controls
executable file
·226 lines (196 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
SUIM_HOME="$HOME/.suim"
VERSIONS_DIR="$SUIM_HOME/versions"
CURRENT_VERSION_FILE="$SUIM_HOME/current"
GITHUB_PROXY=https://gh.api.99988866.xyz/
mkdir -p "$VERSIONS_DIR"
get_os_arch() {
# 获取操作系统类型
local os=""
case "$(uname -s)" in
Darwin*) os="macos" ;;
Linux*)
if [ -f /etc/os-release ]; then
if grep -q "Ubuntu" /etc/os-release; then
os="ubuntu"
else
os="linux" # 默认 linux
fi
else
os="linux"
fi
;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
*) os="unknown" ;;
esac
# 获取架构
local arch=""
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
arm64|aarch64)
if [ "$os" = "macos" ]; then
arch="arm64"
else
arch="aarch64"
fi
;;
*) arch="unknown" ;;
esac
# 输出格式化的结果
echo "${os}-${arch}"
}
# Get current system info
get_system_info() {
echo "$(get_os_arch)"
}
# Show current version
show_version() {
if [ -f "$CURRENT_VERSION_FILE" ]; then
cat "$CURRENT_VERSION_FILE"
else
echo "No version currently set"
fi
}
# List installed versions
list_versions() {
echo "Installed versions:"
if [ -d "$VERSIONS_DIR" ]; then
ls -1 "$VERSIONS_DIR"
fi
}
# Get available remote versions
list_remote_versions() {
echo "Fetching remote versions..."
curl -s https://api.github.com/repos/MystenLabs/sui/releases |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/' |
grep -E '^(mainnet|testnet|devnet)-' |
sort -u -r
}
# Download and install specified version
install_version() {
local version=$1
shift # Remove version from arguments
local use_proxy=false
local proxy_url="https://ghproxy.net/"
# Check for --with-proxy flag
for arg in "$@"; do
if [ "$arg" = "--with-proxy" ]; then
use_proxy=true
break
fi
done
local system_info=$(get_system_info)
local base_url="https://github.com/MystenLabs/sui/releases/download/${version}/sui-${version}-${system_info}.tgz"
local target_dir="$VERSIONS_DIR/${version}"
local temp_file="/tmp/sui-${version}.tgz"
# Check if already installed
if [ -d "$target_dir" ]; then
echo "Version ${version} is already installed"
return 1
fi
echo "Downloading ${version}..."
# Set download URL based on proxy flag
local download_url="$base_url"
if [ "$use_proxy" = true ]; then
echo "Using ${proxy_url} proxy for faster download..."
download_url="${proxy_url}/${base_url}"
fi
wget --continue --show-progress -O "$temp_file" "$download_url"
if [ $? -eq 0 ]; then
mkdir -p "$target_dir"
tar xzf "$temp_file" -C "$target_dir"
rm "$temp_file"
echo "Installation completed: ${version}"
use_version "${version}"
else
echo "Download failed"
rm -f "$temp_file"
rm -rf "$target_dir"
return 1
fi
}
# Switch to specified version
use_version() {
local version=$1
local version_dir="$VERSIONS_DIR/${version}"
if [ ! -d "$version_dir" ]; then
echo "Version ${version} is not installed"
return 1
fi
echo "$version" > "$CURRENT_VERSION_FILE"
# Update environment variables
export SUI_VERSION_PATH="$VERSIONS_DIR/$(cat $CURRENT_VERSION_FILE)"
export PATH="$SUI_VERSION_PATH:$PATH"
# Reload shell with new environment
echo "Switched to version: ${version}"
echo "Reloading environment variables..."
exec $SHELL -l
}
# Uninstall specified version
uninstall_version() {
local version=$1
local version_dir="$VERSIONS_DIR/${version}"
if [ ! -d "$version_dir" ]; then
echo "Version ${version} is not installed"
return 1
fi
rm -rf "$version_dir"
echo "Deleted version: ${version}"
# Clear current version if it's the one being uninstalled
if [ "$(cat "$CURRENT_VERSION_FILE" 2>/dev/null)" = "$version" ]; then
rm -f "$CURRENT_VERSION_FILE"
fi
}
# Main command handler
case "$1" in
"list")
list_versions
;;
"version")
show_version
;;
"versions")
list_remote_versions
;;
"install")
shift # Remove 'install' from arguments
if [ -z "$1" ]; then
echo "Please specify version to install"
echo "Usage: suim install <version> [--with-proxy]"
exit 1
fi
install_version "$@" # Pass all remaining arguments
;;
"use")
if [ -z "$2" ]; then
cat $CURRENT_VERSION_FILE
sui --version
exit 1
fi
use_version "$2"
;;
"uninstall")
if [ -z "$2" ]; then
echo "Please specify version to uninstall"
exit 1
fi
uninstall_version "$2"
;;
*)
latest_testnet=`suim versions |grep -m1 testnet`
latest_mainnet=`suim versions |grep -m1 mainnet`
echo "Usage:"
echo " suim list # List installed versions"
echo " suim version # Show current version"
echo " suim versions # List available remote versions"
echo " suim install <version> [--with-proxy] # Install specified version with optional proxy"
echo " suim use <version> # Switch to specified version"
echo " suim uninstall <version> # Uninstall specified version"
echo "Example:"
echo "suim install ${latest_testnet} --with-proxy"
echo "suim install ${latest_mainnet} "
echo "suim versions | grep -m1 devnet"
exit 1
;;
esac