Skip to content

Commit 5a8d6d4

Browse files
committed
feat(脚本): 优化安装依赖
1 parent a06f082 commit 5a8d6d4

1 file changed

Lines changed: 45 additions & 28 deletions

File tree

install.sh

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ initVar() {
127127
removeType='yum -y remove'
128128
upgrade="yum -y update"
129129
echoType='echo -e'
130+
# sudoCMD=""
130131

131132
# 核心支持的cpu版本
132133
xrayCoreCPUVendor=""
@@ -1069,7 +1070,13 @@ mkdirTools() {
10691070

10701071
mkdir -p /usr/share/nginx/html/
10711072
}
1072-
1073+
# 检测root
1074+
checkRoot() {
1075+
if [ "$(id -u)" -ne 0 ]; then
1076+
# sudoCMD="sudo"
1077+
echo "检测到非 Root 用户,将使用 sudo 执行命令..."
1078+
fi
1079+
}
10731080
# 安装工具包
10741081
installTools() {
10751082
echoContent skyBlue "\n进度 $1/${totalProgress} : 安装工具"
@@ -1094,17 +1101,17 @@ installTools() {
10941101
${installType} epel-release >/dev/null 2>&1
10951102
fi
10961103

1097-
if ! find /usr/bin /usr/sbin | grep -q -w sudo; then
1104+
if ! sudo --version >/dev/null 2>&1; then
10981105
echoContent green " ---> 安装sudo"
10991106
${installType} sudo >/dev/null 2>&1
11001107
fi
11011108

1102-
if ! find /usr/bin /usr/sbin | grep -q -w wget; then
1109+
if ! wget --help >/dev/null 2>&1; then
11031110
echoContent green " ---> 安装wget"
11041111
${installType} wget >/dev/null 2>&1
11051112
fi
11061113

1107-
if ! find /usr/bin /usr/sbin | grep -q -w netfilter-persistent; then
1114+
if ! command -v netfilter-persistent >/dev/null 2>&1; then
11081115
if [[ "${release}" != "centos" ]]; then
11091116
echoContent green " ---> 安装iptables"
11101117
echo "iptables-persistent iptables-persistent/autosave_v4 boolean true" | sudo debconf-set-selections
@@ -1113,70 +1120,75 @@ installTools() {
11131120
fi
11141121
fi
11151122

1116-
if ! find /usr/bin /usr/sbin | grep -q -w curl; then
1123+
if ! curl --help >/dev/null 2>&1; then
11171124
echoContent green " ---> 安装curl"
11181125
${installType} curl >/dev/null 2>&1
11191126
fi
11201127

1121-
if ! find /usr/bin /usr/sbin | grep -q -w unzip; then
1128+
if ! unzip >/dev/null 2>&1; then
11221129
echoContent green " ---> 安装unzip"
11231130
${installType} unzip >/dev/null 2>&1
11241131
fi
11251132

1126-
if ! find /usr/bin /usr/sbin | grep -q -w socat; then
1133+
if ! socat -h >/dev/null 2>&1; then
11271134
echoContent green " ---> 安装socat"
11281135
${installType} socat >/dev/null 2>&1
11291136
fi
11301137

1131-
if ! find /usr/bin /usr/sbin | grep -q -w tar; then
1138+
if ! tar --help >/dev/null 2>&1; then
11321139
echoContent green " ---> 安装tar"
11331140
${installType} tar >/dev/null 2>&1
11341141
fi
11351142

1136-
if ! find /usr/bin /usr/sbin | grep -q -w cron; then
1143+
if ! crontab -l >/dev/null 2>&1; then
11371144
echoContent green " ---> 安装crontabs"
1138-
if [[ "${release}" == "ubuntu" ]] || [[ "${release}" == "debian" ]]; then
1145+
if [[ "${release}" == "ubuntu" || "${release}" == "debian" ]]; then
11391146
${installType} cron >/dev/null 2>&1
11401147
else
11411148
${installType} crontabs >/dev/null 2>&1
11421149
fi
11431150
fi
1144-
if ! find /usr/bin /usr/sbin | grep -q -w jq; then
1151+
if ! jq --help >/dev/null 2>&1; then
11451152
echoContent green " ---> 安装jq"
11461153
${installType} jq >/dev/null 2>&1
11471154
fi
11481155

1149-
if ! find /usr/bin /usr/sbin | grep -q -w binutils; then
1156+
if ! command -v ld >/dev/null 2>&1; then
11501157
echoContent green " ---> 安装binutils"
11511158
${installType} binutils >/dev/null 2>&1
11521159
fi
11531160

1154-
if ! find /usr/bin /usr/sbin | grep -q -w openssl; then
1161+
if ! openssl help >/dev/null 2>&1; then
11551162
echoContent green " ---> 安装openssl"
11561163
${installType} openssl >/dev/null 2>&1
11571164
fi
11581165

1159-
if ! find /usr/bin /usr/sbin | grep -q -w ping6; then
1166+
if ! ping6 --help >/dev/null 2>&1; then
11601167
echoContent green " ---> 安装ping6"
11611168
${installType} inetutils-ping >/dev/null 2>&1
11621169
fi
11631170

1164-
if ! find /usr/bin /usr/sbin | grep -q -w qrencode; then
1171+
if ! qrencode --help >/dev/null 2>&1; then
11651172
echoContent green " ---> 安装qrencode"
11661173
${installType} qrencode >/dev/null 2>&1
11671174
fi
11681175

1169-
if ! find /usr/bin /usr/sbin | grep -q -w lsb-release; then
1170-
echoContent green " ---> 安装lsb-release"
1171-
${installType} lsb-release >/dev/null 2>&1
1176+
if ! command -v lsb_release >/dev/null 2>&1; then
1177+
if [[ "${release}" == "ubuntu" || "${release}" == "debian" ]]; then
1178+
${installType} lsb-release >/dev/null 2>&1
1179+
elif [[ "${release}" == "centos" ]]; then
1180+
${installType} redhat-lsb-core >/dev/null 2>&1
1181+
else
1182+
${installType} lsb-release >/dev/null 2>&1
1183+
fi
11721184
fi
11731185

1174-
if ! find /usr/bin /usr/sbin | grep -q -w lsof; then
1186+
if ! lsof -h >/dev/null 2>&1; then
11751187
echoContent green " ---> 安装lsof"
11761188
${installType} lsof >/dev/null 2>&1
11771189
fi
11781190

1179-
if ! find /usr/bin /usr/sbin | grep -q -w dig; then
1191+
if ! dig -h >/dev/null 2>&1; then
11801192
echoContent green " ---> 安装dig"
11811193
if echo "${installType}" | grep -qw "apt"; then
11821194
${installType} dnsutils >/dev/null 2>&1
@@ -1191,7 +1203,7 @@ installTools() {
11911203
if echo "${selectCustomInstallType}" | grep -qwE ",7,|,8,|,7,8,"; then
11921204
echoContent green " ---> 检测到无需依赖Nginx的服务,跳过安装"
11931205
else
1194-
if ! find /usr/bin /usr/sbin | grep -q -w nginx; then
1206+
if ! nginx >/dev/null 2>&1; then
11951207
echoContent green " ---> 安装nginx"
11961208
installNginxTools
11971209
else
@@ -1211,24 +1223,29 @@ installTools() {
12111223
fi
12121224
fi
12131225

1214-
if ! find /usr/bin /usr/sbin | grep -q -w semanage; then
1226+
if ! command -v semanage >/dev/null 2>&1; then
12151227
echoContent green " ---> 安装semanage"
12161228
${installType} bash-completion >/dev/null 2>&1
12171229

12181230
if [[ "${centosVersion}" == "7" ]]; then
1219-
policyCoreUtils="policycoreutils-python.x86_64"
1220-
elif [[ "${centosVersion}" == "8" ]]; then
1221-
policyCoreUtils="policycoreutils-python-utils-2.9-9.el8.noarch"
1231+
policyCoreUtils="policycoreutils-python"
1232+
elif [[ "${centosVersion}" == "8" || "${release}" == "ubuntu" || "${release}" == "debian" ]]; then
1233+
policyCoreUtils="policycoreutils-python-utils"
12221234
fi
12231235

12241236
if [[ -n "${policyCoreUtils}" ]]; then
12251237
${installType} ${policyCoreUtils} >/dev/null 2>&1
12261238
fi
12271239
if [[ -n $(which semanage) ]]; then
1228-
semanage port -a -t http_port_t -p tcp 31300
1229-
1240+
if command -v getenforce >/dev/null 2>&1; then
1241+
selinux_status=$(getenforce)
1242+
if [ "$selinux_status" != "Disabled" ]; then
1243+
semanage port -a -t http_port_t -p tcp 31300
1244+
fi
1245+
fi
12301246
fi
12311247
fi
1248+
12321249
if [[ "${selectCustomInstallType}" == "7" ]]; then
12331250
echoContent green " ---> 检测到无需依赖证书的服务,跳过安装"
12341251
else
@@ -9512,7 +9529,7 @@ menu() {
95129529
cd "$HOME" || exit
95139530
echoContent red "\n=============================================================="
95149531
echoContent green "作者:mack-a"
9515-
echoContent green "当前版本:v3.4.36"
9532+
echoContent green "当前版本:v3.4.37"
95169533
echoContent green "Github:https://github.com/mack-a/v2ray-agent"
95179534
echoContent green "描述:八合一共存脚本\c"
95189535
showInstallStatus

0 commit comments

Comments
 (0)