-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
230 lines (212 loc) · 9.65 KB
/
install.sh
File metadata and controls
230 lines (212 loc) · 9.65 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
#!/bin/env bash
cd $HOME
export red="\033[31m"
export green="\033[32m"
export yellow="\033[33m"
export blue="\033[34m"
export purple="\033[35m"
export cyan="\033[36m"
export white="\033[37m"
export background="\033[0m"
if [ "$(uname -o)" = "Android" ]; then
echo "看来你是大聪明 加Q群获取帮助吧 1022982073"
exit 1
fi
if ! [ "$(uname)" == "Linux" ];then
echo -e ${red}请使用linux!${background}
exit 0
fi
if [ "$(id -u)" != "0" ]; then
echo -e ${red} 请使用root用户!${background}
exit 0
fi
function Dependency(){
InstallDependency(){
echo -e ${green}正在安装必要依赖 dialog${background}
if [ $(command -v apt) ];then
apt install -y dialog curl
elif [ $(command -v dnf) ];then
dnf install -y dialog curl
elif [ $(command -v yum) ];then
yum install -y dialog curl
elif [ $(command -v pacman) ];then
pacman -S --noconfirm --needed dialog curl
fi
}
if [ -x "$(command -v whiptail)" ];then
dialog_whiptail=whiptail
elif [ -x "$(command -v dialog)" ];then
dialog_whiptail=dialog
else
dialog_whiptail=dialog
InstallDependency
fi
if [ ! -x "$(command -v curl)" ];then
InstallDependency
fi
}
function SystemCheck(){
if grep -q -E -i Arch /etc/issue && [ -x /usr/bin/pacman ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Kernel /etc/issue && [ -x /usr/bin/dnf ];then
echo -e ${red}暂时放弃对centos的支持${background}
exit
elif grep -q -E -i Kernel /etc/issue && [ -x /usr/bin/yum ];then
echo -e ${red}暂时放弃对centos的支持${background}
exit
elif grep -q -E -i Ubuntu /etc/issue && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Debian /etc/issue && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Kali /etc/issue && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Alpine /etc/os-release && [ -x /sbin/apk ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Arch /etc/os-release && [ -x /usr/bin/pacman ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i CentOS /etc/os-release && [ -x /usr/bin/dnf ];then
echo -e ${red}暂时放弃对centos的支持${background}
exit
elif grep -q -E -i CentOS /etc/os-release && [ -x /usr/bin/yum ];then
echo -e ${red}暂时放弃对centos的支持${background}
exit
elif grep -q -E -i Ubuntu /etc/os-release && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Debian /etc/os-release && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
elif grep -q -E -i Kali /etc/os-release && [ -x /usr/bin/apt ];then
echo -e ${green}系统校验通过${background}
else
echo -e ${red}不受支持的系统${background}
echo -e ${red}程序终止!! 脚本停止运行${background}
exit
fi
}
function Script_Install(){
echo -e ${green}正在获取版本信息${background}
if [ -z "${GitMirror}" ];then
URL="https://ipinfo.io"
Address=$(curl -sL ${URL} | sed -n 's/.*"country": "\(.*\)",.*/\1/p')
if [ "${Address}" = "CN" ]
then
GitMirror="gitee.com"
URL="https://gitee.com/Misaka21011/Yunzai-Bot-Shell/raw/master/version"
else
GitMirror="github.com"
URL="https://raw.githubusercontent.com/misaka20002/Bot-Install-Shell/master/version"
fi
fi
version_date=$(curl -sL ${URL})
version="$(echo "${version_date}" | grep 'version:' | awk '{print $2}')"
date="$(echo "${version_date}" | grep 'date:' | awk '{print $2}')"
echo -e ${cyan}获取成功${background}
echo
echo -e ${white}=========================${background}
echo -e ${red}" "呆毛版 ${yellow}BOT ${green}Install ${cyan}Script ${background}
echo -e " "————" "————" "————" "————" "
echo -e ${green}" "版本:" "v${version} ${cyan}\(date: ${date}\) ${background}
echo -e ${green}" "作者:" "${cyan}小呆毛" "\(Misaka21011\) ${background}
echo -e ${green}" "镜像:" "${cyan}${GitMirror}${background}
echo -e ${white}=========================${background}
echo
echo -e ${white}=========================${background}
echo -e ${green}请选择安装途径${background}
echo -e ${green}1${cyan}\) Gitee${background}
echo -e ${green}2${cyan}\) Github${background}
echo -e ${white}=========================${background}
echo -en ${green}请选择: ${background};read Choice
case ${Choice} in
1)
URL="https://gitee.com/Misaka21011/Yunzai-Bot-Shell/raw/master/Manage/Main.sh"
;;
2)
URL="https://raw.githubusercontent.com/misaka20002/Bot-Install-Shell/master/Manage/Main.sh"
;;
*)
echo -e ${red}输入错误${background}
exit
;;
esac
while true; do
echo -e "${yellow} - ${cyan}正在下载安装...${background}"
# 记录 HTTP 状态码并下载
HTTP_CODE=$(curl -sL -w "%{http_code}" -o xdm_temp "${URL}")
CURL_RET=$?
# 尝试捕获 help 页面内容
HELP_OUTPUT=$(bash xdm_temp help 2>&1)
HELP_RET=$?
# 需要验证下载的文档的正确性,用于修复垃圾 gitee 下载到空文件或拦截页面
if [ ${CURL_RET} -eq 0 ] && [ "${HTTP_CODE}" = "200" ] && [ -s xdm_temp ] && grep -q "function mainbak" xdm_temp && [ ${HELP_RET} -eq 0 ] && echo "${HELP_OUTPUT}" | grep -q "呆毛版"; then
echo "${HELP_OUTPUT}"
mv -f xdm_temp /usr/local/bin/xdm
chmod +x /usr/local/bin/xdm
echo
if ! /usr/local/bin/xdm help >/dev/null 2>&1; then
echo -e "${yellow} - ${red}执行异常,无法正常运行直接命令${background}"
echo -e "${yellow} - ${cyan}正在尝试解决shebang问题${background}"
old_xdm_bash='#!/bin/env bash'
new_xdm_bash=$(command -v bash)
if [ -n "${new_xdm_bash}" ]; then
sed -i "s|${old_xdm_bash}|#!${new_xdm_bash}|g" /usr/local/bin/xdm
# 再次测试
if /usr/local/bin/xdm help >/dev/null 2>&1; then
echo -e "${yellow} - ${green}shebang修复成功${background}"
break
else
echo -e "${yellow} - ${red}修复失败,请手动检查脚本${background}"
echo -e "${yellow} - ${cyan}脚本位置: /usr/local/bin/xdm${background}"
exit 1
fi
else
echo -e "${yellow} - ${red}无法找到bash路径,修复失败${background}"
exit 1
fi
else
break
fi
else
rm -f xdm_temp
echo -e "${yellow} - ${red}下载失败,或文件校验未通过!(HTTP状态码: ${HTTP_CODE},Curl返回码: ${CURL_RET})${background}"
echo -e "${white}=========================${background}"
echo -e "${green}请选择备用下载方式:${background}"
echo -e "${cyan}1) 切换为 Github 原生下载${background}"
echo -e "${cyan}2) 切换为 Github 代理下载 (ghfast.top)${background}"
echo -e "${cyan}3) 切换为 Gitee 原生下载${background}"
echo -e "${cyan}4) 重试当前线路${background}"
echo -e "${red}0) 退出安装${background}"
echo -en "${green}请选择: ${background}"; read retry_choice
case ${retry_choice} in
1) URL="https://raw.githubusercontent.com/misaka20002/Bot-Install-Shell/master/Manage/Main.sh" ;;
2) URL="https://ghfast.top/https://raw.githubusercontent.com/misaka20002/Bot-Install-Shell/master/Manage/Main.sh" ;;
3) URL="https://gitee.com/Misaka21011/Yunzai-Bot-Shell/raw/master/Manage/Main.sh" ;;
4) continue ;;
0) exit 1 ;;
*) echo -e "${red}输入错误,重试当前 URL${background}" ;;
esac
fi
done
echo -e "${yellow} - ${green}安装成功${background}"
echo -e "${yellow} - ${cyan}请使用 ${green}xdm ${cyan}命令 打开脚本${background}"
}
echo -e ${white}"====="${green}呆毛版-Script${white}"====="${background}
echo -e ${cyan}呆毛版 Script ${green}是完全可信的。${background}
echo -e ${cyan}呆毛版 Script ${yellow}不会执行任何恶意命令${background}
echo -e ${cyan}呆毛版 Script ${yellow}不会执行任何恶意命令${background}
echo -e ${cyan}呆毛版 Script ${yellow}不会执行任何恶意命令${background}
echo -e ${cyan}如果您同意安装 请输入 ${green}同意安装${background}
echo -e ${cyan}注意:同意安装即同意本项目的用户协议${background}
echo -e ${cyan}用户协议链接: ${background}
echo -e ${cyan}https://gitee.com/Misaka21011/Yunzai-Bot-Shell/blob/master/Manage/用户协议.txt ${background}
echo -e ${white}"=========================="${background}
echo -en ${green}请输入:${background};read yn
if [ "${yn}" == "同意安装" ]
then
echo -e ${green}2秒后开始安装${background}
sleep 1s
SystemCheck
Dependency
echo
Script_Install
else
echo -e ${red}程序终止!! 脚本停止运行${background}
fi