-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathinstall.sh
More file actions
291 lines (235 loc) · 8.55 KB
/
install.sh
File metadata and controls
291 lines (235 loc) · 8.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
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
283
284
285
286
287
288
289
290
291
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[1;94m'
NC='\033[0m'
BOLD='\033[1m'
CHECK_MARK="[✓]"
CROSS_MARK="[✗]"
INFO_MARK="[i]"
WARNING_MARK="[!]"
log_info() {
echo -e "${BLUE}${INFO_MARK} ${1}${NC}"
}
log_success() {
echo -e "${GREEN}${CHECK_MARK} ${1}${NC}"
}
log_warning() {
echo -e "${YELLOW}${WARNING_MARK} ${1}${NC}"
}
log_error() {
echo -e "${RED}${CROSS_MARK} ${1}${NC}" >&2
}
handle_error() {
log_error "Error occurred at line $1"
exit 1
}
trap 'handle_error $LINENO' ERR
check_root() {
if [ "$(id -u)" -ne 0 ]; then
log_error "This script must be run as root."
exit 1
fi
log_info "Running with root privileges"
}
check_os_version() {
local os_name os_version
log_info "Checking OS compatibility..."
if [ -f /etc/os-release ]; then
os_name=$(grep '^ID=' /etc/os-release | cut -d= -f2)
os_version=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
else
log_error "Unsupported OS or unable to determine OS version."
exit 1
fi
if ! command -v bc &> /dev/null; then
log_info "Installing bc package..."
apt update -qq && apt install -y -qq bc
if [ $? -ne 0 ]; then
log_error "Failed to install bc package."
exit 1
fi
fi
if [[ "$os_name" == "ubuntu" && $(echo "$os_version >= 22" | bc) -eq 1 ]] ||
[[ "$os_name" == "debian" && $(echo "$os_version >= 12" | bc) -eq 1 ]]; then
log_success "OS check passed: $os_name $os_version"
else
log_error "This script is only supported on Ubuntu 22+ or Debian 12+."
exit 1
fi
log_info "Checking CPU for AVX support (required for MongoDB)..."
if grep -q -m1 -o -E 'avx|avx2|avx512' /proc/cpuinfo; then
log_success "CPU supports AVX instruction set."
else
log_error "CPU does not support the required AVX instruction set for MongoDB."
log_info "For systems without AVX support, you can use the 'nodb' version of the panel."
log_info "To install it, please run the following command:"
echo -e "${YELLOW}bash <(curl -sL https://raw.githubusercontent.com/ReturnFI/Blitz/nodb/install.sh)${NC}"
log_error "Installation aborted."
exit 1
fi
}
install_mongodb() {
log_info "Installing MongoDB..."
if command -v mongod &> /dev/null; then
log_success "MongoDB is already installed"
return 0
fi
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
local codename
codename=$(lsb_release -cs)
local repo_line=""
case "$codename" in
"noble" | "jammy")
repo_line="deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu $codename/mongodb-org/8.0 multiverse"
;;
"bookworm" | "trixie")
repo_line="deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main"
;;
*)
log_error "Unsupported OS codename for MongoDB installation: $codename"
exit 1
;;
esac
echo "$repo_line" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list > /dev/null
apt update -qq
apt install -y -qq mongodb-org
systemctl enable mongod
systemctl start mongod
if systemctl is-active --quiet mongod; then
log_success "MongoDB installed and started successfully"
else
log_error "MongoDB installation failed or service not running"
exit 1
fi
}
install_packages() {
local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "bc" "zip" "unzip" "lsof" "gnupg" "lsb-release")
local MISSING_PACKAGES=()
log_info "Checking required packages..."
for package in "${REQUIRED_PACKAGES[@]}"; do
if ! command -v "$package" &> /dev/null && ! dpkg -l | grep -q "^ii.*$package "; then
MISSING_PACKAGES+=("$package")
else
log_success "Package $package is already installed"
fi
done
if [ ${#MISSING_PACKAGES[@]} -ne 0 ]; then
log_info "Installing missing packages: ${MISSING_PACKAGES[*]}"
apt update -qq || { log_error "Failed to update apt repositories"; exit 1; }
apt upgrade -y -qq || { log_warning "Failed to upgrade packages, continuing..."; }
for package in "${MISSING_PACKAGES[@]}"; do
log_info "Installing $package..."
if apt install -y -qq "$package"; then
log_success "Installed $package"
else
log_error "Failed to install $package"
exit 1
fi
done
else
log_success "All required packages are already installed."
fi
install_mongodb
}
download_and_extract_release() {
log_info "Downloading and extracting Blitz panel..."
if [ -d "/etc/hysteria" ]; then
log_warning "Directory /etc/hysteria already exists."
read -p "Do you want to remove it and install again? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf /etc/hysteria
else
log_info "Skipping download. Using existing directory."
return 0
fi
fi
local arch
case $(uname -m) in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
*)
log_error "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
log_info "Detected architecture: $arch"
local zip_name="Blitz-${arch}.zip"
local download_url="https://github.com/ReturnFI/Blitz/releases/latest/download/${zip_name}"
local temp_zip="/tmp/${zip_name}"
log_info "Downloading from ${download_url}..."
if curl -sL -o "$temp_zip" "$download_url"; then
log_success "Download complete."
else
log_error "Failed to download the release asset. Please check the URL and your connection."
exit 1
fi
log_info "Extracting to /etc/hysteria..."
mkdir -p /etc/hysteria
if unzip -q "$temp_zip" -d /etc/hysteria; then
log_success "Extracted successfully."
else
log_error "Failed to extract the archive."
exit 1
fi
rm "$temp_zip"
log_info "Cleaned up temporary file."
local auth_binary="/etc/hysteria/core/scripts/auth/user_auth"
if [ -f "$auth_binary" ]; then
chmod +x "$auth_binary"
log_success "Set execute permission for auth binary."
else
log_warning "Auth binary not found at $auth_binary. The installation might be incomplete."
fi
}
setup_python_env() {
log_info "Setting up Python virtual environment..."
cd /etc/hysteria || { log_error "Failed to change to /etc/hysteria directory"; exit 1; }
if python3 -m venv hysteria2_venv &> /dev/null; then
log_success "Created Python virtual environment"
else
log_error "Failed to create Python virtual environment"
exit 1
fi
source /etc/hysteria/hysteria2_venv/bin/activate || { log_error "Failed to activate virtual environment"; exit 1; }
log_info "Installing Python requirements..."
if pip install -r requirements.txt &> /dev/null; then
log_success "Installed Python requirements"
else
log_error "Failed to install Python requirements"
exit 1
fi
}
add_alias() {
log_info "Adding 'hys2' alias to .bashrc..."
if ! grep -q "alias hys2='source /etc/hysteria/hysteria2_venv/bin/activate && /etc/hysteria/menu.sh'" ~/.bashrc; then
echo "alias hys2='source /etc/hysteria/hysteria2_venv/bin/activate && /etc/hysteria/menu.sh'" >> ~/.bashrc
log_success "Added 'hys2' alias to .bashrc"
else
log_info "Alias 'hys2' already exists in .bashrc"
fi
}
run_menu() {
log_info "Preparing to run menu..."
cd /etc/hysteria || { log_error "Failed to change to /etc/hysteria directory"; exit 1; }
chmod +x menu.sh || { log_error "Failed to make menu.sh executable"; exit 1; }
log_info "Starting menu..."
echo -e "\n${BOLD}${GREEN}======== Launching Blitz Menu ========${NC}\n"
./menu.sh
}
main() {
echo -e "\n${BOLD}${BLUE}======== Blitz Setup Script ========${NC}\n"
check_root
check_os_version
install_packages
download_and_extract_release
setup_python_env
add_alias
source ~/.bashrc &> /dev/null || true
echo -e "\n${YELLOW}Starting Blitz in 3 seconds...${NC}"
sleep 3
run_menu
}
main