-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·376 lines (334 loc) · 10.7 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·376 lines (334 loc) · 10.7 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/usr/bin/env bash
export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script"
exit 1
fi
INFO="\e[0;32m[INFO]\e[0m"
ERROR="\e[0;31m[ERROR]\e[0m"
print_version() {
clear
echo "+------------------------------------------------------------------------+"
echo "| VT-Init for Debian like Linux, Written by Echocolate |"
echo "+------------------------------------------------------------------------+"
echo "| A script to install the required packages on Linux |"
echo "+------------------------------------------------------------------------+"
echo "| Version: 1.0.1 Last Updated: 2026-08-19 |"
echo "+------------------------------------------------------------------------+"
echo "| https://repos.echocolate.xyz |"
echo "+------------------------------------------------------------------------+"
printf "%s %36s%-12s%24s\n" "|" "Your OS: " "$os $MAJOR_VERSION" "|"
echo "+------------------------------------------------------------------------+"
sleep 2
}
detect_os() {
if [ -f /etc/os-release ]; then
source /etc/os-release
case "$ID" in
ubuntu)
os='Ubuntu'
MAJOR_VERSION=$(echo "$VERSION_ID" | cut -d. -f1)
;;
debian)
os='Debian'
MAJOR_VERSION=$(echo "$VERSION_ID" | cut -d. -f1)
;;
*)
os="Unknown"
MAJOR_VERSION="Unknown"
;;
esac
else
os="Unknown"
MAJOR_VERSION="Unknown"
fi
}
check_VT_INIT() {
[ ! -f "${VT_log}/VT_INIT_FLAG" ] && return 0
return 1
}
check_parallel() {
local MemTotal=$(awk '/MemTotal/ {printf( "%d\n", $2 / 1024 )}' /proc/meminfo)
if [ "$MemTotal" -lt 2048 ]; then
JOBS=2
else
JOBS=$(grep 'processor' /proc/cpuinfo | wc -l)
fi
}
safe_make() {
echo -e "${INFO} Start building ..."
if ! make -j"${JOBS}"; then
echo -e "${INFO} Parallel build failed, try serial build."
make clean && make
fi
if [ $? -eq 0 ]; then
make install
return $?
else
echo -e "${ERROR} All build attempts failed."
return 1
fi
}
download() {
local url="$1" file="$2" n=1 max_retries=3
while [ $n -le $max_retries ]; do
if wget -c -nv "$url" -O "$file"; then
return 0
fi
sleep 2
((n++))
done
echo -e "${ERROR} Download $file failed!"
return 1
}
install_packages() {
apt-get update -y
[[ $? -ne 0 ]] && apt-get update --allow-releaseinfo-change -y
apt-get autoremove -y
apt-get -fy install
for packages in \
build-essential \
git autoconf automake libtool m4 make gcc g++ cmake \
pkg-config \
rsync \
clang \
libc6-dev \
bzip2 unzip \
libbz2-dev \
libjpeg-dev \
libpng-dev \
zlib1g \
zlib1g-dev \
curl \
libcurl3-gnutls \
libcurl4-gnutls-dev \
libcurl4-openssl-dev \
libpcre3-dev \
gzip \
openssl libssl-dev \
libexpat1-dev \
libpcre2-dev \
libldap2-dev \
libsasl2-dev \
libzip-dev \
libsodium-dev \
libc-client-dev \
libkrb5-dev \
bison re2c \
libicu-dev \
libxml2-dev \
libsqlite3-dev \
libwebp-dev \
libonig-dev \
libxslt1.1 libxslt1-dev \
libboost-all-dev \
python3 python3-pip \
;
do apt-get --no-install-recommends install -y $packages; done
}
install_dependency() {
cd ${VT_HOME}
check_parallel
echo -e "${INFO} Proc num: $JOBS"
status=0
install_libiconv
if [[ -n "$mhash_ver" ]]; then
install_mhash
fi
if [[ -n "$mcrypt_ver" ]] && [[ -n "$mcrypt_ver" ]]; then
install_libmcrypt
install_mcrypt
fi
install_freetype
if [ $status -eq 0 ]; then
# VPS-Toolkit Init Flag
date -Iseconds > "${VT_log}/VT_INIT_FLAG"
echo -e "${INFO} All dependencies installed successfully."
else
echo -e "${ERROR} Failed to install some dependencies. Check '${VT_log}/init-$(date '+%F').log' for details."
fi
}
install_libiconv() {
cd ${VT_download}
download "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${libiconv_version}.tar.gz" "libiconv.tar.gz"
[ $? -ne 0 ] && {
((status+=1))
return 1
}
cd ${VT_build}
rm -rf libiconv && mkdir libiconv
tar zxf "${VT_download}/libiconv.tar.gz" --strip-components=1 --directory=libiconv
cd libiconv
./configure --enable-static
safe_make
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install libiconv."
} || {
echo -e "${INFO} Install libiconv successfully."
}
}
install_mhash() {
cd ${VT_download}
download "https://downloads.sourceforge.net/project/mhash/mhash/${mhash_version}/mhash-${mhash_version}.tar.bz2" "mhash.tar.bz2"
[ $? -ne 0 ] && {
((status+=1))
return 1
}
cd ${VT_build}
rm -rf mhash && mkdir mhash
tar jxf "${VT_download}/mhash.tar.bz2" --strip-components=1 --directory=mhash
cd mhash
./configure
safe_make
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install mhash."
} || {
echo -e "${INFO} Install mhash successfully."
}
ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ldconfig
}
install_libmcrypt() {
cd ${VT_download}
download "https://downloads.sourceforge.net/project/mcrypt/Libmcrypt/${libmcrypt_verison}/libmcrypt-${libmcrypt_verison}.tar.gz" "libmcrypt.tar.gz"
[ $? -ne 0 ] && {
((status+=1))
return 1
}
cd ${VT_build}
rm -rf libmcrypt && mkdir libmcrypt
tar zxf "${VT_download}/libmcrypt.tar.gz" --strip-components=1 --directory=libmcrypt
cd libmcrypt
if [[ "$ID" == "debian" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 13 ]] || [[ "$ID" == "ubuntu" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 26 ]]; then
./configure CFLAGS="-g -O2 -std=gnu11 -Wno-implicit-function-declaration -Wno-implicit-int -Wno-builtin-declaration-mismatch -include string.h -include stdlib.h -include stdio.h -DHAVE_MEMMOVE=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1"
else
./configure
fi
safe_make
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install Libmcrypt."
} || {
echo -e "${INFO} Install Libmcrypt successfully."
}
ldconfig
if [[ "$ID" == "debian" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 13 ]] || [[ "$ID" == "ubuntu" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 26 ]]; then
apt-get --no-install-recommends install -y libltdl-dev
./configure --enable-ltdl-install --with-system-libltdl
make CFLAGS="-g -O2 -std=gnu11 -Wno-implicit-function-declaration -Wno-implicit-int -Wno-builtin-declaration-mismatch -include string.h -include stdlib.h -include stdio.h"
else
cd libltdl/
./configure --enable-ltdl-install
make
fi
make install
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install Libmcrypt/libltdl."
} || {
echo -e "${INFO} Install Libmcrypt/libltdl successfully."
}
ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ldconfig
}
install_mcrypt() {
cd ${VT_download}
download "https://downloads.sourceforge.net/project/mcrypt/MCrypt/${mcrypt_version}/mcrypt-${mcrypt_version}.tar.gz" "mcrypt.tar.gz"
[ $? -ne 0 ] && {
((status+=1))
return 1
}
cd ${VT_build}
rm -rf mcrypt && mkdir mcrypt
tar zxf "${VT_download}/mcrypt.tar.gz" --strip-components=1 --directory=mcrypt
cd mcrypt
if [[ "$ID" == "debian" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 13 ]] || [[ "$ID" == "ubuntu" && -n "$MAJOR_VERSION" && "$MAJOR_VERSION" -ge 26 ]]; then
./configure CFLAGS="-g -O2 -std=gnu11 -Wno-implicit-function-declaration -Wno-implicit-int -Wno-builtin-declaration-mismatch -include string.h -include stdlib.h -include stdio.h -DHAVE_MEMMOVE=1 -DHAVE_STRING_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STDIO_H=1"
else
./configure
fi
safe_make
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install MCrypt."
} || {
echo -e "${INFO} Install MCrypt successfully."
}
}
install_freetype() {
cd ${VT_download}
download "https://downloads.sourceforge.net/project/freetype/freetype2/${freetype_version}/freetype-${freetype_version}.tar.xz" "freetype.tar.xz"
[ $? -ne 0 ] && {
((status+=1))
return 1
}
cd ${VT_build}
rm -rf freetype && mkdir freetype
tar Jxf "${VT_download}/freetype.tar.xz" --strip-components=1 --directory=freetype
cd freetype
./configure --prefix=/usr/local/freetype --enable-freetype-config
safe_make
[ $? -ne 0 ] && {
((status+=1))
echo -e "${ERROR} Failed to install freetype2."
} || {
echo -e "${INFO} Install freetype2 successfully."
}
cd
\cp /usr/local/freetype/lib/pkgconfig/freetype2.pc /usr/lib/pkgconfig/
echo "/usr/local/freetype/lib" > /etc/ld.so.conf.d/freetype.conf
ldconfig
ln -sf /usr/local/freetype/include/freetype2/* /usr/include/
}
check_kernel() {
echo "=== 共享内存 ==="
echo "shmmax: $(cat /proc/sys/kernel/shmmax)"
echo "shmall: $(cat /proc/sys/kernel/shmall)"
echo -e "\n=== 网络参数 ==="
echo "somaxconn: $(cat /proc/sys/net/core/somaxconn)"
echo "tcp_max_syn_backlog: $(cat /proc/sys/net/ipv4/tcp_max_syn_backlog)"
echo -e "\n=== 文件描述符 ==="
echo "file-max: $(cat /proc/sys/fs/file-max)"
}
init() {
libiconv_version="${libiconv_ver:-1.19}"
mhash_version="${mhash_ver:-0.9.9.9}"
libmcrypt_verison="${libmcrypt_ver:-2.5.8}"
mcrypt_version="${mcrypt_ver:-2.6.8}"
freetype_version="${freetype_ver:-2.14.3}"
detect_os
print_version
echo -e "[Starting time: `date +'%Y-%m-%d %H:%M:%S'`]"
TIME_START=$(date +%s)
install_packages
if ! check_VT_INIT; then
echo -e "${INFO} Install dependency successfully at $(cat ${VT_log}/VT_INIT_FLAG), skipping ..."
else
install_dependency
fi
echo -e "[End time: `date +'%Y-%m-%d %H:%M:%S'`]"
TIME_END=$(date +%s)
echo -e "${INFO} Successfully done! Command takes $((TIME_END-TIME_START)) seconds."
check_kernel
}
VT_HOME="${HOME}/VT-Data"
VT_log="${VT_HOME}/logs"
VT_bk="${VT_HOME}/backup"
VT_download="${VT_HOME}/source"
VT_build="${VT_HOME}/build"
[ ! -d "${VT_HOME}/" ] && mkdir ${VT_HOME}
[ ! -d "${VT_log}/" ] && mkdir ${VT_log}
[ ! -d "${VT_bk}/" ] && mkdir ${VT_bk}
[ ! -d "${VT_download}/" ] && mkdir ${VT_download}
[ ! -d "${VT_build}/" ] && mkdir ${VT_build}
init 2>&1 | tee "${VT_log}/init-$(date '+%F').log"