Skip to content

Commit

Permalink
Optimization Function
Browse files Browse the repository at this point in the history
  • Loading branch information
hello-yunshu committed Dec 27, 2021
1 parent 9d2d62a commit bf4a310
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 39 deletions.
6 changes: 3 additions & 3 deletions auto_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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
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})
Expand All @@ -51,7 +51,7 @@ if [[ -f ${xray_qr_config_file} ]]; then
if [[ $(info_extraction nginx_version) == null ]] || [[ ! -f "/etc/nginx/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
bash idleleo -n auto_update
[[ 0 -ne $? ]] && echo "Nginx 更新失败!" >>${log_file} && exit 1
echo "Nginx 更新成功!" >>${log_file}
else
Expand All @@ -61,7 +61,7 @@ if [[ -f ${xray_qr_config_file} ]]; then
if [[ $(info_extraction xray_version) == null ]]; then
echo "Xray 版本未知 无法自动更新" >>${log_file}
elif [[ ${xray_online_version} != $(info_extraction xray_version) ]]; then
bash idleleo -x
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
Expand Down
105 changes: 69 additions & 36 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ OK="${Green}[OK]${Font}"
Error="${RedW}[错误]${Font}"
Warning="${RedW}[警告]${Font}"

shell_version="1.9.2.0"
shell_version="1.9.2.2"
shell_mode="未安装"
tls_mode="None"
ws_grpc_mode="None"
version_cmp="/tmp/version_cmp.tmp"
idleleo_dir="/etc/idleleo"
idleleo_conf_dir="${idleleo_dir}/conf"
log_dir="${idleleo_dir}/logs"
Expand All @@ -64,6 +63,7 @@ auto_update_file="${idleleo_dir}/auto_update.sh"
ssl_update_file="${idleleo_dir}/ssl_update.sh"
cert_group="nobody"
myemali="my@example.com"
shell_version_tmp="${idleleo_dir}/tmp/shell_version.tmp"
get_versions_all=$(curl -s https://www.idleleo.com/api/xray_shell_versions)
bt_nginx="None"
read_config_status=1
Expand All @@ -74,6 +74,9 @@ random_num=$((RANDOM % 12 + 4))
THREAD=$(($(grep 'processor' /proc/cpuinfo | sort -u | wc -l) + 1))
[[ -f ${xray_qr_config_file} ]] && info_extraction_all=$(jq -rc . ${xray_qr_config_file})

##兼容代码,未来删除
[[ ! -d "${idleleo_dir}/tmp" ]] && mkdir -p ${idleleo_dir}/tmp

source '/etc/os-release'

VERSION=$(echo "${VERSION}" | awk -F "[()]" '{print $2}')
Expand Down Expand Up @@ -778,7 +781,7 @@ xray_update() {
if [[ ${auto_update} != "YES" ]]; then
echo -e "${Warning} ${GreenBG} 检测到存在最新测试版 ${Font}"
echo -e "${Warning} ${GreenBG} 脚本可能未兼容此版本 ${Font}"
echo -e "\n${Warning} ${GreenBG} 是否更新到测试版 [Y/${Red}N${Font}${YellowBG}]? ${Font}"
echo -e "\n${Warning} ${GreenBG} 是否更新到测试版 [Y/${Red}N${Font}${GreenBG}]? ${Font}"
read -r xray_test_fq
else
xray_test_fq=1
Expand All @@ -797,7 +800,7 @@ xray_update() {
systemctl stop xray
wait
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install -f --version v${xray_version}
udge "Xray 升级"
judge "Xray 升级"
;;
esac
else
Expand Down Expand Up @@ -1203,7 +1206,8 @@ port_exist_check() {

acme() {
#暂时解决ca问题
if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone --server letsencrypt -k ec-256 --force --test; then
# if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone --server letsencrypt -k ec-256 --force --test; then
if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone -k ec-256 --force --test; then
echo -e "${OK} ${GreenBG} SSL 证书测试签发成功, 开始正式签发 ${Font}"
rm -rf "$HOME/.acme.sh/${domain}_ecc"
else
Expand All @@ -1212,7 +1216,8 @@ acme() {
exit 1
fi

if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone --server letsencrypt -k ec-256 --force; then
# if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone --server letsencrypt -k ec-256 --force; then
if "$HOME"/.acme.sh/acme.sh --issue -d "${domain}" --standalone -k ec-256 --force; then
echo -e "${OK} ${GreenBG} SSL 证书生成成功 ${Font}"
mkdir -p ${ssl_chainpath}
if "$HOME"/.acme.sh/acme.sh --installcert -d "${domain}" --fullchainpath ${ssl_chainpath}/xray.crt --keypath ${ssl_chainpath}/xray.key --ecc --force; then
Expand Down Expand Up @@ -2385,29 +2390,42 @@ show_error_log() {
}

xray_status_add() {
echo -e "\n${GreenBG} Xray 流量统计需要使用 api ${Font}"
echo -e "${GreenBG} 可能会影响 Xray 性能 ${Font}"
echo -e "${GreenBG} 是否继续 [${Red}Y${Font}${GreenBG}/N]? ${Font}"
read -r xray_status_add_fq
case $xray_status_add_fq in
[nN][oO] | [nN]) ;;
*)
if [[ -f ${xray_conf} ]]; then
if [[ $(jq -r .stats ${xray_conf}) == null ]]; then
if [[ -f ${xray_conf} ]]; then
if [[ $(jq -r .stats ${xray_conf}) != null ]]; then
echo -e "\n${GreenBG} 已配置 Xray 流量统计 ${Font}"
echo -e "${GreenBG} 是否需要关闭此功能 [Y/${Red}N${Font}${GreenBG}]? ${Font}"
read -r xray_status_add_fq
case $xray_status_add_fq in
[yY][eE][sS] | [yY])
service_stop
wget -nc --no-check-certificate https://raw.githubusercontent.com/paniy/Xray_bash_onekey/main/status_config.json -O ${xray_status_conf}
xray_status=$(jq -r ". += $(jq -c . ${xray_status_conf})" ${xray_conf})
judge "设置 Xray 流量统计"
xray_status=$(jq -r "del(.api)|del(.stats)|del(.policy)" ${xray_conf})
judge "关闭 Xray 流量统计"
echo "${xray_status}" | jq . >${xray_conf}
service_start
else
echo -e "${Warning} ${GreenBG} 已设置 Xray 流量统计! ${Font}"
fi
[[ -f ${xray_status_conf} ]] && rm -rf ${xray_status_conf}
;;
*) ;;
esac
else
echo -e "${Warning} ${YellowBG} 请先安装 Xray ! ${Font}"
echo -e "\n${GreenBG} Xray 流量统计需要使用 api ${Font}"
echo -e "${GreenBG} 可能会影响 Xray 性能 ${Font}"
echo -e "${GreenBG} 是否继续 [Y/${Red}N${Font}${GreenBG}]? ${Font}"
read -r xray_status_add_fq
case $xray_status_add_fq in
[yY][eE][sS] | [yY])
service_stop
wget -nc --no-check-certificate https://raw.githubusercontent.com/paniy/Xray_bash_onekey/main/status_config.json -O ${xray_status_conf}
xray_status=$(jq -r ". += $(jq -c . ${xray_status_conf})" ${xray_conf})
judge "设置 Xray 流量统计"
echo "${xray_status}" | jq . >${xray_conf}
service_start
;;
*) ;;
esac
fi
;;
esac
else
echo -e "${Warning} ${YellowBG} 请先安装 Xray ! ${Font}"
fi
}

bbr_boost_sh() {
Expand Down Expand Up @@ -2447,6 +2465,22 @@ uninstall_all() {
*) ;;
esac
fi
echo -e "${GreenBG} 是否删除所有脚本文件 [Y/${Red}N${Font}${GreenBG}]? ${Font}"
read -r remove_all_idleleo_file_fq
case $remove_all_idleleo_file_fq in
[yY][eE][sS] | [yY])
rm -rf ${idleleo_commend_file}
rm -rf ${idleleo_dir}
systemctl daemon-reload
echo -e "${OK} ${GreenBG} 已删除所有文件 ${Font}"
echo -e "${GreenBG} ヾ( ̄▽ ̄) 拜拜~ ${Font}"
exit 0
;;
*)
systemctl daemon-reload
echo -e "${OK} ${GreenBG} 已保留脚本文件 (包含 SSL 证书等) ${Font}"
;;
esac
if [[ -f ${xray_qr_config_file} ]]; then
echo -e "${GreenBG} 是否保留配置文件 [Y/${Red}N${Font}${GreenBG}]? ${Font}"
read -r remove_config_fq
Expand All @@ -2460,8 +2494,6 @@ uninstall_all() {
;;
esac
fi
systemctl daemon-reload
echo -e "${OK} ${GreenBG} 已卸载, SSL 证书文件已保留 ${Font}\n"
}

delete_tls_key_and_crt() {
Expand Down Expand Up @@ -2637,11 +2669,11 @@ install_xray_ws_only() {

update_sh() {
ol_version=${shell_online_version}
echo "${ol_version}" >${version_cmp}
echo "${ol_version}" >${shell_version_tmp}
[[ -z ${ol_version} ]] && echo -e "${Error} ${RedBG} 检测最新版本失败! ${Font}" && return 1
echo "${shell_version}" >>${version_cmp}
newest_version=$(sort -rV ${version_cmp} | head -1)
oldest_version=$(sort -V ${version_cmp} | head -1)
echo "${shell_version}" >>${shell_version_tmp}
newest_version=$(sort -rV ${shell_version_tmp} | head -1)
oldest_version=$(sort -V ${shell_version_tmp} | head -1)
version_difference=$(echo "(${newest_version:0:3}-${oldest_version:0:3})>0" | bc)
if [[ ${shell_version} != ${newest_version} ]]; then
if [[ ${auto_update} != "YES" ]]; then
Expand Down Expand Up @@ -2679,6 +2711,7 @@ check_file_integrity() {
check_system
pkg_install "bc,jq,wget"
[[ ! -d "${idleleo_dir}" ]] && mkdir -p ${idleleo_dir}
[[ ! -d "${idleleo_dir}/tmp" ]] && mkdir -p ${idleleo_dir}/tmp
wget -N --no-check-certificate -P ${idleleo_dir} https://raw.githubusercontent.com/paniy/Xray_bash_onekey/main/install.sh && chmod +x ${idleleo_dir}/install.sh
judge "下载最新脚本"
ln -s ${idleleo_dir}/install.sh ${idleleo_commend_file}
Expand Down Expand Up @@ -2836,9 +2869,9 @@ idleleo_commend() {
##在线运行与本地脚本比对
[[ ! -L ${idleleo_commend_file} ]] && chmod +x ${idleleo_dir}/install.sh && ln -s ${idleleo_dir}/install.sh ${idleleo_commend_file}
old_version=$(grep "shell_version=" ${idleleo_dir}/install.sh | head -1 | awk -F '=|"' '{print $3}')
echo "${old_version}" >${version_cmp}
echo "${shell_version}" >>${version_cmp}
oldest_version=$(sort -V ${version_cmp} | head -1)
echo "${old_version}" >${shell_version_tmp}
echo "${shell_version}" >>${shell_version_tmp}
oldest_version=$(sort -V ${shell_version_tmp} | head -1)
version_difference=$(echo "(${shell_version:0:3}-${oldest_version:0:3})>0" | bc)
if [[ -z ${old_version} ]]; then
wget -N --no-check-certificate -P ${idleleo_dir} https://raw.githubusercontent.com/paniy/Xray_bash_onekey/main/install.sh && chmod +x ${idleleo_dir}/install.sh
Expand Down Expand Up @@ -2870,10 +2903,10 @@ idleleo_commend() {
bash idleleo
else
ol_version=${shell_online_version}
echo "${ol_version}" >${version_cmp}
echo "${ol_version}" >${shell_version_tmp}
[[ -z ${ol_version} ]] && shell_need_update="${Red}[检测失败!]${Font}"
echo "${shell_version}" >>${version_cmp}
newest_version=$(sort -rV ${version_cmp} | head -1)
echo "${shell_version}" >>${shell_version_tmp}
newest_version=$(sort -rV ${shell_version_tmp} | head -1)
if [[ ${shell_version} != ${newest_version} ]]; then
shell_need_update="${Red}[有新版!]${Font}"
else
Expand Down

0 comments on commit bf4a310

Please sign in to comment.