-
Notifications
You must be signed in to change notification settings - Fork 48
/
launch-binary.sh
57 lines (45 loc) · 1.52 KB
/
launch-binary.sh
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
#!/bin/bash
set -e
REPO="ionet-official/io_launch_binaries"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="io-net-launcher"
BINARY_PATH="$INSTALL_DIR/$BINARY_NAME"
get_local_version() {
if [ -f "$BINARY_PATH" ]; then
version_output="$($BINARY_PATH --version)"
echo "$version_output" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+$'
else
echo "none"
fi
}
get_latest_version() {
curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}
download_binary() {
case "$(uname -sm)" in
"Darwin arm64") FILENAME="io_net_launch_binary_mac" ;;
"Linux x86_64") FILENAME="io_net_launch_binary_linux" ;;
*) echo "Unsupported architecture: $(uname -sm)" >&2; exit 1 ;;
esac
URL="https://github.com/$REPO/releases/download/$1/$FILENAME"
echo "Downloading $FILENAME version $1 from GitHub releases"
if ! curl -sSLf "$URL" -o "$BINARY_PATH"; then
echo "Failed to download or write to $INSTALL_DIR; try with sudo" >&2
exit 1
fi
if ! chmod +x "$BINARY_PATH"; then
echo "Failed to set executable permission on $BINARY_PATH" >&2
exit 1
fi
echo "$BINARY_NAME version $1 is successfully installed"
}
local_version=$(get_local_version)
latest_version=$(get_latest_version)
if [ "$local_version" != "$latest_version" ]; then
echo "Local version ($local_version) is different from the latest version ($latest_version). Updating..."
download_binary "$latest_version"
else
echo
fi
# Execute the binary with the provided flags and options
"$BINARY_PATH" "$@"