-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·150 lines (123 loc) · 3.55 KB
/
install.sh
File metadata and controls
executable file
·150 lines (123 loc) · 3.55 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
#!/bin/sh
set -eu
(set -o pipefail 2>/dev/null) && set -o pipefail
REPO="infraspecdev/goperf"
BIN_DIR="${BIN_DIR:-/usr/local/bin}"
VERSION="${VERSION:-latest}"
error() {
echo "Error: $1" >&2
exit 1
}
command -v curl >/dev/null 2>&1 || error "curl is required but not installed."
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin)
OS_NAME="darwin"
;;
linux)
OS_NAME="linux"
;;
mingw* | msys* | cygwin*)
OS_NAME="windows"
;;
*)
error "Unsupported operating system: $OS"
;;
esac
ARCH=$(uname -m)
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64 | arm64) ARCH="arm64" ;;
*) error "Unsupported architecture: $ARCH" ;;
esac
if [ "$OS_NAME" = "darwin" ] && [ "$ARCH" = "amd64" ]; then
error "macOS Intel (amd64) is not supported. Please build from source."
fi
if [ "$OS_NAME" = "windows" ] && [ "$ARCH" = "arm64" ]; then
error "Windows ARM64 is not supported. Please build from source."
fi
BINARY_NAME="goperf-${OS_NAME}-${ARCH}"
EXE_NAME="goperf"
if [ "$OS_NAME" = "windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
EXE_NAME="goperf.exe"
fi
if [ "$VERSION" = "latest" ]; then
BINARY_URL="https://github.com/$REPO/releases/latest/download/$BINARY_NAME"
else
BINARY_URL="https://github.com/$REPO/releases/download/$VERSION/$BINARY_NAME"
fi
if [ "$BIN_DIR" = "/usr/local/bin" ] && [ -d "$BIN_DIR" ] && [ ! -w "$BIN_DIR" ]; then
BIN_DIR="$HOME/.local/bin"
fi
if [ ! -d "$BIN_DIR" ]; then
if ! mkdir -p "$BIN_DIR" 2>/dev/null; then
error "Cannot create directory: $BIN_DIR
Run the following as root, then retry:
mkdir -p $BIN_DIR"
fi
fi
if [ ! -w "$BIN_DIR" ]; then
error "No write permission for: $BIN_DIR
Re-run with a writable directory:
BIN_DIR=~/.local/bin sh install.sh
Or install as root:
sudo sh install.sh"
fi
echo "Installing goperf..."
echo " Platform : $OS_NAME/$ARCH"
echo " Directory: $BIN_DIR"
if [ "$VERSION" = "latest" ]; then
echo " Downloading latest release..."
else
echo " Downloading release $VERSION..."
fi
TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'goperf.XXXXXX')
trap 'rm -rf "$TMP_DIR"' EXIT INT TERM
DOWNLOAD_PATH="$TMP_DIR/$EXE_NAME"
if ! curl -fL \
--connect-timeout 10 \
--retry 2 \
--silent \
--show-error \
-o "$DOWNLOAD_PATH" \
"$BINARY_URL"; then
error "Failed to download binary from:
$BINARY_URL
Possible reasons:
- No internet connection
- GitHub is unavailable
- No release asset for $OS_NAME/$ARCH (version: $VERSION)
Browse releases manually:
https://github.com/$REPO/releases"
fi
[ -s "$DOWNLOAD_PATH" ] || error "Downloaded binary is empty or corrupted."
echo " Download complete 🎉"
if command -v install >/dev/null 2>&1; then
install -m 755 "$DOWNLOAD_PATH" "$BIN_DIR/$EXE_NAME" \
|| error "Failed to install binary to $BIN_DIR/$EXE_NAME"
else
cp "$DOWNLOAD_PATH" "$BIN_DIR/$EXE_NAME" \
|| error "Failed to copy binary to $BIN_DIR/$EXE_NAME"
chmod 755 "$BIN_DIR/$EXE_NAME" \
|| error "Failed to make binary executable in $BIN_DIR/$EXE_NAME"
fi
echo ""
echo "✅ Installed: $BIN_DIR/$EXE_NAME"
RESOLVED=$(command -v "$EXE_NAME" 2>/dev/null || true)
if [ "$RESOLVED" != "$BIN_DIR/$EXE_NAME" ]; then
if [ -z "$RESOLVED" ]; then
echo ""
echo " Note: '$EXE_NAME' was not found in PATH."
echo ""
echo " Add the following to your ~/.bashrc or ~/.zshrc:"
echo ""
echo " export PATH=\"$BIN_DIR:\$PATH\""
echo ""
echo " Then reload your shell:"
echo ""
echo " source ~/.bashrc"
fi
fi
echo ""
echo "Run 'goperf --help' to get started."