-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·282 lines (247 loc) · 11.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·282 lines (247 loc) · 11.5 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env bash
# install.sh — One-command installer for VPSBench
# https://github.com/linux-system443/vpsbench
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/linux-system443/vpsbench/main/install.sh | bash
#
# Requirements: Linux, bash, root/sudo for system packages.
# Installs VPSBench into /opt/vpsbench and makes 'vpsbench' available globally.
set -euo pipefail
# ── Constants ────────────────────────────────────────────────────────────────
REPO_URL="https://github.com/linux-system443/vpsbench.git"
INSTALL_DIR="/opt/vpsbench"
VENV_DIR="${INSTALL_DIR}/venv"
BIN_LINK="/usr/local/bin/vpsbench"
PYTHON_MIN_MAJOR=3
PYTHON_MIN_MINOR=10
# ── Helpers ──────────────────────────────────────────────────────────────────
info() { printf "\033[1;34m[INFO]\033[0m %s\n" "$*"; }
success() { printf "\033[1;32m[OK]\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m[WARN]\033[0m %s\n" "$*"; }
error() { printf "\033[1;31m[ERROR]\033[0m %s\n" "$*" >&2; }
die() { error "$*"; exit 1; }
# ── Pre-flight checks ───────────────────────────────────────────────────────
check_platform() {
if [[ "$(uname -s)" != "Linux" ]]; then
die "This installer only supports Linux. Detected: $(uname -s)"
fi
}
check_root_or_sudo() {
if [[ "${EUID}" -eq 0 ]]; then
SUDO=""
elif command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
die "Root/sudo required to install system packages. Run as root or install sudo."
fi
}
# ── Detect package manager ──────────────────────────────────────────────────
detect_pkg_manager() {
PKG_MANAGER=""
PKG_UPDATE=""
PKG_INSTALL=""
if command -v apt-get >/dev/null 2>&1; then
PKG_MANAGER="apt"
PKG_UPDATE="apt-get update -qq"
PKG_INSTALL="apt-get install -y -qq"
elif command -v dnf >/dev/null 2>&1; then
PKG_MANAGER="dnf"
PKG_UPDATE="dnf check-update || true" # dnf returns 100 when updates available
PKG_INSTALL="dnf install -y -q"
elif command -v yum >/dev/null 2>&1; then
PKG_MANAGER="yum"
PKG_UPDATE="yum check-update || true"
PKG_INSTALL="yum install -y -q"
elif command -v pacman >/dev/null 2>&1; then
PKG_MANAGER="pacman"
PKG_UPDATE="pacman -Sy --noconfirm"
PKG_INSTALL="pacman -S --noconfirm"
else
die "No supported package manager found (apt, dnf, yum, pacman). Install dependencies manually."
fi
info "Detected package manager: ${PKG_MANAGER}"
}
# ── Map package names per distro ────────────────────────────────────────────
map_package_name() {
local generic_name="$1"
case "${PKG_MANAGER}" in
apt)
case "${generic_name}" in
python3) echo "python3" ;;
python3-pip) echo "python3-pip" ;;
fio) echo "fio" ;;
sysbench) echo "sysbench" ;;
ping) echo "iputils-ping" ;;
git) echo "git" ;;
*) echo "${generic_name}" ;;
esac
;;
dnf|yum)
case "${generic_name}" in
python3) echo "python3" ;;
python3-pip) echo "python3-pip" ;;
fio) echo "fio" ;;
sysbench) echo "sysbench" ;;
ping) echo "iputils" ;;
git) echo "git" ;;
*) echo "${generic_name}" ;;
esac
;;
pacman)
case "${generic_name}" in
python3) echo "python" ;;
python3-pip) echo "python-pip" ;;
fio) echo "fio" ;;
sysbench) echo "sysbench" ;;
ping) echo "iputils" ;;
git) echo "git" ;;
*) echo "${generic_name}" ;;
esac
;;
esac
}
# ── Install system dependencies ─────────────────────────────────────────────
install_system_deps() {
info "Updating package lists..."
${SUDO} bash -c "${PKG_UPDATE}" >/dev/null 2>&1 || warn "Package list update failed (non-fatal, will try installing anyway)"
local packages_to_install=()
local generic_names=("python3" "python3-pip" "fio" "sysbench" "ping" "git")
for generic in "${generic_names[@]}"; do
local pkg
pkg="$(map_package_name "${generic}")"
packages_to_install+=("${pkg}")
done
info "Installing system dependencies: ${packages_to_install[*]}"
${SUDO} bash -c "${PKG_INSTALL} ${packages_to_install[*]}" >/dev/null 2>&1 \
|| die "Failed to install system packages. Please install manually: ${packages_to_install[*]}"
success "System dependencies installed"
}
# ── Verify Python version ──────────────────────────────────────────────────
verify_python() {
# Find python3
local python_cmd=""
for cmd in python3 python; do
if command -v "${cmd}" >/dev/null 2>&1; then
local version_str
version_str=$("${cmd}" --version 2>&1 | awk '{print $2}')
local major minor
major=$(echo "${version_str}" | cut -d. -f1)
minor=$(echo "${version_str}" | cut -d. -f2)
if [[ "${major}" -ge "${PYTHON_MIN_MAJOR}" ]] && [[ "${minor}" -ge "${PYTHON_MIN_MINOR}" ]]; then
python_cmd="${cmd}"
break
fi
fi
done
if [[ -z "${python_cmd}" ]]; then
die "Python ${PYTHON_MIN_MAJOR}.${PYTHON_MIN_MINOR}+ is required. Install Python 3 and try again."
fi
PYTHON="${python_cmd}"
success "Python found: $(${PYTHON} --version 2>&1)"
}
# ── Handle existing installation ───────────────────────────────────────────
handle_existing_install() {
if [[ -d "${INSTALL_DIR}" ]]; then
warn "Existing VPSBench installation detected at ${INSTALL_DIR}"
info "Updating existing installation..."
fi
}
# ── Clone or update repository ──────────────────────────────────────────────
setup_repository() {
if [[ -d "${INSTALL_DIR}/.git" ]]; then
info "Pulling latest changes..."
git -C "${INSTALL_DIR}" pull --ff-only >/dev/null 2>&1 \
|| warn "Could not pull latest changes, using existing code"
else
info "Cloning VPSBench repository..."
rm -rf "${INSTALL_DIR}"
git clone "${REPO_URL}" "${INSTALL_DIR}" >/dev/null 2>&1 \
|| die "Failed to clone VPSBench repository"
fi
success "Repository ready at ${INSTALL_DIR}"
}
# ── Create virtual environment and install ──────────────────────────────────
install_vpsbench() {
info "Creating virtual environment at ${VENV_DIR}..."
${PYTHON} -m venv "${VENV_DIR}" >/dev/null 2>&1 \
|| die "Failed to create virtual environment"
info "Installing VPSBench into virtual environment..."
"${VENV_DIR}/bin/pip" install --upgrade pip >/dev/null 2>&1
"${VENV_DIR}/bin/pip" install "${INSTALL_DIR}" >/dev/null 2>&1 \
|| die "Failed to install VPSBench"
success "VPSBench installed into ${VENV_DIR}"
}
# ── Create global symlink ──────────────────────────────────────────────────
create_global_command() {
local vpsbench_bin="${VENV_DIR}/bin/vpsbench"
if [[ ! -f "${vpsbench_bin}" ]]; then
die "vpsbench binary not found at ${vpsbench_bin}"
fi
info "Creating global command at ${BIN_LINK}..."
ln -sf "${vpsbench_bin}" "${BIN_LINK}" \
|| {
# If symlink fails (permission issue), try with sudo
${SUDO} ln -sf "${vpsbench_bin}" "${BIN_LINK}" 2>/dev/null \
|| die "Failed to create symlink at ${BIN_LINK}. Check permissions."
}
chmod +x "${vpsbench_bin}" 2>/dev/null || ${SUDO} chmod +x "${vpsbench_bin}" 2>/dev/null || true
success "Global command available: vpsbench"
}
# ── Verify installation ────────────────────────────────────────────────────
verify_installation() {
info "Verifying installation..."
if ! command -v vpsbench >/dev/null 2>&1; then
die "vpsbench command not found in PATH after installation"
fi
local version_output
version_output=$(vpsbench --version 2>&1) || die "vpsbench --version failed"
success "Verification passed: ${version_output}"
}
# ── Print summary ───────────────────────────────────────────────────────────
print_summary() {
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
success "VPSBench installed successfully!"
echo ""
info "Installation location: ${INSTALL_DIR}"
info "Virtual environment: ${VENV_DIR}"
info "Global command: ${BIN_LINK}"
echo ""
info "Quick start:"
echo " vpsbench quick"
echo ""
info "Other commands:"
echo " vpsbench # Full benchmark (~15 min)"
echo " vpsbench cpu # CPU only"
echo " vpsbench memory # Memory only"
echo " vpsbench disk # Disk I/O only"
echo " vpsbench network # Network latency"
echo ""
info "Options:"
echo " --profile gaming # Gaming scoring (default)"
echo " --profile general # General scoring"
echo " --json results.json # Save results to JSON"
echo " --config my.yaml # Custom config file"
echo ""
info "Docs: https://github.com/linux-system443/vpsbench"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
}
# ── Main ────────────────────────────────────────────────────────────────────
main() {
echo ""
info "VPSBench Installer — Made by Salib Technologies"
echo ""
check_platform
detect_pkg_manager
check_root_or_sudo
install_system_deps
verify_python
handle_existing_install
setup_repository
install_vpsbench
create_global_command
verify_installation
print_summary
}
main "$@"