-
Notifications
You must be signed in to change notification settings - Fork 192
/
auto_update.sh
75 lines (68 loc) · 3.28 KB
/
auto_update.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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
idleleo_dir="/etc/idleleo"
nginx_dir="/etc/nginx"
xray_conf_dir="${idleleo_conf_dir}/xray"
xray_conf="${xray_conf_dir}/config.json"
log_dir="${idleleo_dir}/logs"
log_file="${log_dir}/auto_update.log"
running_file="${log_dir}/auto_update.running"
xray_qr_config_file="${idleleo_dir}/info/vless_qr.json"
get_versions_all=$(curl -s https://www.idleleo.com/api/xray_shell_versions)
info_extraction_all=$(jq -rc . ${xray_qr_config_file})
[[ ! -d "${log_dir}" ]] && mkdir -p ${log_dir}
if [[ -f "${running_file}" ]]; then
echo "上个自动更新程序仍在运行! 检查于: $(date '+%Y-%m-%d %H:%M') 建议手动排错!" >>${log_file}
exit 1
else
touch ${running_file}
fi
[[ -f "${log_file}" ]] && rm -rf ${log_file}
echo "更新时间: $(date '+%Y-%m-%d %H:%M')" >${log_file}
check_online_version() {
echo ${get_versions_all} | jq -rc ".$1"
[[ 0 -ne $? ]] && echo "在线版本检测失败, 请稍后再试!" >>${log_file} && exit 1
}
info_extraction() {
echo ${info_extraction_all} | jq -r ".$1"
}
shell_online_version="$(check_online_version shell_online_version)"
xray_online_version="$(check_online_version xray_tested_version)"
nginx_online_version="$(check_online_version nginx_online_version)"
openssl_online_version="$(check_online_version openssl_online_version)"
jemalloc_online_version="$(check_online_version jemalloc_tested_version)"
if [[ -f ${xray_qr_config_file} ]]; then
if [[ $(info_extraction shell_version) == null ]] || [[ $(info_extraction shell_version) != ${shell_online_version} ]]; then
bash idleleo -u auto_update
[[ 0 -ne $? ]] && echo "脚本 更新失败!" >>${log_file} && exit 1
echo "脚本 更新成功!" >>${log_file}
add_shell_version=$(jq -r ". += {\"shell_version\": \"${shell_online_version}\"}" ${xray_qr_config_file})
echo "${add_shell_version}" | jq . >${xray_qr_config_file}
else
echo "脚本 最新版!" >>${log_file}
fi
if [[ $(info_extraction nginx_version) == null ]] || [[ ! -f "${nginx_dir}/sbin/nginx" ]]; then
echo "Nginx 未安装!"
elif [[ ${nginx_online_version} != $(info_extraction nginx_version) ]] || [[ ${openssl_online_version} != $(info_extraction openssl_version) ]] || [[ ${jemalloc_online_version} != $(info_extraction jemalloc_version) ]]; then
bash idleleo -n auto_update
[[ 0 -ne $? ]] && echo "Nginx 更新失败!" >>${log_file} && exit 1
echo "Nginx 更新成功!" >>${log_file}
else
echo "Nginx 最新版!" >>${log_file}
fi
if [[ -f ${xray_qr_config_file} ]] && [[ -f ${xray_conf} ]] && [[ -f /usr/local/bin/xray ]]; then
if [[ $(info_extraction xray_version) == null ]]; then
echo "Xray 版本未知 无法自动更新" >>${log_file}
elif [[ ${xray_online_version} != $(info_extraction xray_version) ]]; then
bash idleleo -x auto_update
[[ 0 -ne $? ]] && echo "Xray 更新失败!" >>${log_file} && exit 1
echo "Xray 更新成功!" >>${log_file}
elif [[ ${xray_online_version} == $(info_extraction xray_version) ]]; then
echo "Xray 最新版!" >>${log_file}
fi
else
echo "Xray 未安装!" >>${log_file}
fi
fi
rm -rf ${running_file}