-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathdependencies.sh
247 lines (223 loc) · 8.76 KB
/
dependencies.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
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
# shadowsocks-libev dependencies
LIBSODIUM_VERSION="1.0.19"
LIBSODIUM_FILE="libsodium-${LIBSODIUM_VERSION}"
UNCOMPRESS_FOLDER_NAME="libsodium-stable"
LIBSODIUM_VERSION_FILE=~/.deps-ver/libsodium.v
LIBSODIUM_URL="https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz"
MBEDTLS_VERSION="2.28.4"
MBEDTLS_FILE="mbedtls-${MBEDTLS_VERSION}"
MBEDTLS_VERSION_FILE=~/.deps-ver/mbedtls.v
MBEDTLS_URL="https://github.com/ARMmbed/mbedtls/archive/${MBEDTLS_FILE}.tar.gz"
error_detect_deps_of_ubuntu(){
local command=$1
local depend=$2
if [ ! "$(command -v killall)" ]; then
# psmisc contains killall & fuser & pstree commands.
package_install "psmisc" > /dev/null 2>&1
fi
sleep 3
sudo killall -q apt apt-get
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
_echo -e "依赖包${Red}${depend}${suffix}安装失败,请检查. "
echo "Checking the error message and run the script again."
exit 1
fi
}
error_asciidos_deps_of_ubuntu1901(){
local command=$1
local depend=$2
sleep 3
sudo dpkg --configure -a > /dev/null 2>&1
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
if ls -l /var/lib/dpkg/info | grep -qi 'python-sympy'; then
sudo mv -f /var/lib/dpkg/info/python-sympy.* /tmp
sudo apt update > /dev/null 2>&1
fi
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
_echo -e "依赖包${Red}${depend}${suffix}安装失败,请检查. "
echo "Checking the error message and run the script again."
exit 1
fi
fi
}
error_detect_depends(){
local command=$1
local depend=`echo "${command}" | awk '{print $4}'`
_echo -i "开始安装依赖包 ${depend}"
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
if check_sys sysRelease ubuntu || check_sys sysRelease debian; then
if [ $(get_version) == '19.10' ] && [ ${depend} == 'asciidoc' ]; then
error_asciidos_deps_of_ubuntu1901 "${command}" "${depend}"
else
error_detect_deps_of_ubuntu "${command}" "${depend}"
fi
else
_echo -e "依赖包${Red}${depend}${suffix}安装失败,请检查. "
echo "Checking the error message and run the script again."
exit 1
fi
fi
}
install_dependencies(){
local depends=($*)
if check_sys packageManager yum; then
_echo -i "检查EPEL存储库."
if [ ! -f /etc/yum.repos.d/epel.repo ]; then
yum install -y epel-release > /dev/null 2>&1
fi
[ ! -f /etc/yum.repos.d/epel.repo ] && _echo -e "安装EPEL存储库失败,请检查它。" && exit 1
[ ! "$(command -v yum-config-manager)" ] && yum install -y yum-utils > /dev/null 2>&1
if version_ge $(get_version) 8; then
[ x"$(yum repolist epel | grep -w epel | awk '{print $NF}')" != x"enabled" ] && yum-config-manager --enable epel > /dev/null 2>&1
else
[ x"$(yum-config-manager epel | grep -w enabled | awk '{print $3}')" != x"True" ] && yum-config-manager --enable epel > /dev/null 2>&1
fi
_echo -i "EPEL存储库检查完成."
for depend in ${depends[@]}; do
error_detect_depends "yum -y install ${depend}"
done
elif check_sys packageManager apt; then
apt-get -y update
for depend in ${depends[@]}; do
error_detect_depends "apt-get -y install ${depend}"
done
fi
}
install_dependencies_logic(){
if [[ ${SS_VERSION} = "ss-libev" ]] || [[ "${plugin_num}" == "3" ]]; then
if check_sys packageManager yum; then
local depends=(
gettext gcc pcre pcre-devel autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel zlib-devel openssl-devel git qrencode jq
)
elif check_sys packageManager apt; then
local depends=(
gettext gcc build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libssl-dev git qrencode jq xz-utils
)
fi
install_dependencies "${depends[*]}"
fi
if [ ! "$(command -v qrencode)" ] || [ ! "$(command -v jq)" ]; then
local depends=(qrencode jq)
install_dependencies "${depends[*]}"
fi
if [ "${CipherMark}" != "Non-AEAD-2022" ]; then
if check_sys packageManager yum; then
local depends=(chrony)
elif check_sys packageManager apt; then
local depends=(ntpdate)
fi
install_dependencies "${depends[*]}"
fi
}
install_libsodium(){
local installStatus=$1
cd ${CUR_DIR}
pushd ${TEMP_DIR_PATH} > /dev/null 2>&1
_echo -i "下载${LIBSODIUM_FILE}."
download "${LIBSODIUM_FILE}.tar.gz" "${LIBSODIUM_URL}"
_echo -i "解压${LIBSODIUM_FILE}."
tar zxf ${LIBSODIUM_FILE}.tar.gz && cd ${UNCOMPRESS_FOLDER_NAME}
_echo -i "编译安装${LIBSODIUM_FILE}."
./configure --prefix=/usr && make && make install
if [ $? -ne 0 ]; then
_echo -e "${LIBSODIUM_FILE} ${installStatus}失败 !"
install_cleanup
exit 1
fi
popd > /dev/null 2>&1
# wriet version num
if [ ! -d "$(dirname ${LIBSODIUM_VERSION_FILE})" ]; then
mkdir -p $(dirname ${LIBSODIUM_VERSION_FILE})
fi
echo ${LIBSODIUM_VERSION} > ${LIBSODIUM_VERSION_FILE}
_echo -i "${LIBSODIUM_FILE} ${installStatus}成功 !"
}
install_libsodium_logic(){
if [ ! -f ${LIBSODIUM_VERSION_FILE} ]; then
install_libsodium '安装'
else
read currentLibsodiumVer < ${LIBSODIUM_VERSION_FILE}
latestLibsodiumVer=${LIBSODIUM_VERSION}
if check_latest_version ${currentLibsodiumVer} ${latestLibsodiumVer}; then
install_libsodium '更新'
else
_echo -i "${LIBSODIUM_FILE} 已经安装最新版本."
fi
fi
}
install_mbedtls(){
local installStatus=$1
cd ${CUR_DIR}
pushd ${TEMP_DIR_PATH} > /dev/null 2>&1
_echo -i "下载${MBEDTLS_FILE}."
download "${MBEDTLS_FILE}.tar.gz" "${MBEDTLS_URL}"
_echo -i "解压${MBEDTLS_FILE}."
tar zxf ${MBEDTLS_FILE}.tar.gz
mv "mbedtls-${MBEDTLS_FILE}" ${MBEDTLS_FILE}
cd ${MBEDTLS_FILE}
_echo -i "编译安装${MBEDTLS_FILE}."
make SHARED=1 CFLAGS=-fPIC
make DESTDIR=/usr install
if [ $? -ne 0 ]; then
_echo -e "${MBEDTLS_FILE} ${installStatus}失败."
install_cleanup
exit 1
fi
popd > /dev/null 2>&1
# wriet version num
if [ ! -d "$(dirname ${MBEDTLS_VERSION_FILE})" ]; then
mkdir -p $(dirname ${MBEDTLS_VERSION_FILE})
fi
echo ${MBEDTLS_VERSION} > ${MBEDTLS_VERSION_FILE}
_echo -i "${MBEDTLS_FILE} ${installStatus}成功 !"
}
install_mbedtls_logic(){
if [ ! -f ${MBEDTLS_VERSION_FILE} ]; then
install_mbedtls '安装'
else
read currentMbedtlsVer < ${MBEDTLS_VERSION_FILE}
latestMbedtlsVer=${MBEDTLS_VERSION}
if check_latest_version ${currentMbedtlsVer} ${latestMbedtlsVer}; then
install_mbedtls '更新'
else
_echo -i "${MBEDTLS_FILE} 已经安装最新版本."
fi
fi
}
add_more_entropy(){
# Ubuntu series is started by default after installation
# Debian series needs to add configuration to start after installation
# CentOS 6 is installed by default but not started. CentOS 7 is not started by default after installation. CentOS 8 is installed and started by default.
if [ "${SS_VERSION}" != "ss-libev" ]; then return; fi
local KERNEL_VERSION=$(uname -r | cut -d'-' -f1)
if version_ge ${KERNEL_VERSION} 5.6; then return; fi
local ENTROPY_SIZE_BEFORE=$(cat /proc/sys/kernel/random/entropy_avail)
if [[ ${ENTROPY_SIZE_BEFORE} -lt 1000 ]]; then
_echo -i "安装rng-tools之前熵池的熵值为${Green}${ENTROPY_SIZE_BEFORE}${suffix}"
if [[ ! $(command -v rngd) ]]; then
package_install "rng-tools"
fi
if centosversion 6; then
chkconfig --add rngd
chkconfig rngd on
service rngd start > /dev/null 2>&1
elif centosversion 7 || centosversion 8; then
systemctl enable rngd
systemctl start rngd > /dev/null 2>&1
elif check_sys sysRelease debian; then
update-rc.d -f rng-tools defaults
sed -i '/^HRNGDEVICE/'d /etc/default/rng-tools
echo "HRNGDEVICE=/dev/urandom" >> /etc/default/rng-tools
systemctl start rng-tools > /dev/null 2>&1
fi
sleep 5
local ENTROPY_SIZE_BEHIND=$(cat /proc/sys/kernel/random/entropy_avail)
_echo -i "安装rng-tools之后熵池的熵值为${Green}${ENTROPY_SIZE_BEHIND}${suffix}"
else
_echo -i "当前熵池熵值大于或等于1000,未进行更多添加."
fi
}