From 6e0b7faf253161ce1b50c52963ab27e355deadff Mon Sep 17 00:00:00 2001 From: Yang2635 Date: Tue, 17 Jan 2023 23:30:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=B8=E5=85=B3=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=89=A7=E8=A1=8C=EF=BC=8C=E7=A7=BB=E9=99=A4CPU?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E8=B4=9F=E8=BD=BD=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Check_FRPC.sh | 175 +++++++++++++++++++++++--------------------------- 1 file changed, 80 insertions(+), 95 deletions(-) diff --git a/Check_FRPC.sh b/Check_FRPC.sh index 1875e95..4eb926c 100644 --- a/Check_FRPC.sh +++ b/Check_FRPC.sh @@ -6,146 +6,131 @@ MODDIR="$(dirname $(readlink -f "$0"))" . ${MODDIR}/files/status.conf . ${MODDIR}/functions.sh Busybox_file="${MODDIR}/files/bin/busybox_${F_ARCH}" +frpc_bin="frpc-${F_ARCH}" +DATADIR="${DATADIR}" if [ -z "$(cat ${MODDIR}/module.prop)" ]; then cp -af "${MODDIR}/files/module.prop.bak" "${MODDIR}/module.prop" fi running_start() { - local frpc_admin_port running_num - { - network_iface_check - battery_electricity_check - } + local _frpc_admin_port _running_num + battery_electricity_check if [ "$?" -ne 0 ]; then return fi - if [ -f "${DATADIR}/frpc/frpc.ini" ]; then - sed -i "/^FILE_STATUS=/c FILE_STATUS=$(stat -c %Y ${DATADIR}/frpc/frpc.ini)" "${MODDIR}/files/status.conf" - sh ${MODDIR}/Run_FRPC.sh verify - if [ "$?" -eq 0 ]; then - sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确!" "${MODDIR}/files/status.conf" - sh ${MODDIR}/Run_FRPC.sh start - sleep 5 - if [ -n "$(frpc_running_check frpc-${F_ARCH})" ]; then - sed -i -e "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC正在运行中!" \ - -e "/^RELOAD_NUM=/c RELOAD_NUM=0" "${MODDIR}/files/status.conf" - frpc_admin_port=$(get_parameters admin_port "${DATADIR}/frpc/frpc.ini") - if [ "${frpc_admin_port}" -ge 1 ] && [ "${frpc_admin_port}" -le 65535 ]; then - running_num=$(sh ${MODDIR}/Run_FRPC.sh status) - sleep 1 - sed -i "/^RUNNING_NUM=/c RUNNING_NUM=${running_num}" "${MODDIR}/files/status.conf" - elif [ -z "${frpc_admin_port}" ]; then - sed -i "/^RUNNING_NUM=/c RUNNING_NUM=未定义端口!" "${MODDIR}/files/status.conf" - else - sed -i "/^RUNNING_NUM=/c RUNNING_NUM=端口定义可能错误!" "${MODDIR}/files/status.conf" - fi - else - sed -i "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC启动失败!" "${MODDIR}/files/status.conf" - fi - else - sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测错误,请自查配置文件!" \ - -e "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC未运行!" "${MODDIR}/files/status.conf" - fi - else + + if [ ! -f "${DATADIR}/frpc/frpc.ini" ]; then sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=Android\/frpc目录下未找到frpc\.ini文件!" \ -e "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC未运行!" "${MODDIR}/files/status.conf" + return 8 + fi + + sed -i "/^FILE_STATUS=/c FILE_STATUS=$(stat -c %Y ${DATADIR}/frpc/frpc.ini)" "${MODDIR}/files/status.conf" + + sh ${MODDIR}/Run_FRPC.sh verify + if [ "$?" -eq 0 ]; then + sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确!" "${MODDIR}/files/status.conf" + else + sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测错误,请自查配置文件!" \ + -e "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC未运行!" "${MODDIR}/files/status.conf" + return 9 + fi + + sh ${MODDIR}/Run_FRPC.sh start + sleep 5 + if [ -n "$(get_frpc_running_pid ${frpc_bin})" ]; then + sed -i -e "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC正在运行中!" \ + -e "/^RELOAD_NUM=/c RELOAD_NUM=0" "${MODDIR}/files/status.conf" + _frpc_admin_port=$(get_parameters admin_port "${DATADIR}/frpc/frpc.ini") + else + sed -i "/^RUNNING_STATUS=/c RUNNING_STATUS=FRPC启动失败!" "${MODDIR}/files/status.conf" + return 10 + fi + + if [ "${_frpc_admin_port}" -ge 1 ] && [ "${_frpc_admin_port}" -le 65535 ]; then + _running_num=$(sh ${MODDIR}/Run_FRPC.sh status) + sleep 1 + sed -i "/^RUNNING_NUM=/c RUNNING_NUM=${_running_num}" "${MODDIR}/files/status.conf" + elif [ -z "${_frpc_admin_port}" ]; then + sed -i "/^RUNNING_NUM=/c RUNNING_NUM=未定义端口!" "${MODDIR}/files/status.conf" + return 11 + else + sed -i "/^RUNNING_NUM=/c RUNNING_NUM=端口定义可能错误!" "${MODDIR}/files/status.conf" + return 12 fi } check_reload() { - local frpc_admin_port running_num check_new_file_status - { - network_iface_check - battery_electricity_check - } + local _running_num _check_new_file_status + battery_electricity_check if [ "$?" -ne 0 ]; then return fi - if [ -f ${DATADIR}/frpc/frpc.ini ]; then - check_new_file_status="$(stat -c %Y ${DATADIR}/frpc/frpc.ini)" - if [ "${FILE_STATUS}" != "${check_new_file_status}" ]; then - sh ${MODDIR}/Run_FRPC.sh verify - if [ "$?" -eq 0 ]; then - sh ${MODDIR}/Run_FRPC.sh reload - if [ "$?" -eq 0 ]; then - sleep 5 - running_num=$(sh ${MODDIR}/Run_FRPC.sh status) - sed -i -e "/^RELOAD_NUM=/c RELOAD_NUM=$(($RELOAD_NUM + 1))" -e "/^FILE_STATUS=/c FILE_STATUS=${check_new_file_status}" \ - -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确!" \ - -e "/^RUNNING_NUM=/c RUNNING_NUM=${running_num}" "${MODDIR}/files/status.conf" - else - sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确但重载失败,可能修改的参数需重启生效,请自查配置文件或重启frpc程序!(已保持当前运行状态)" "${MODDIR}/files/status.conf" - fi - else - sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测错误,可能修改的参数需重启生效,请自查配置文件或重启frpc程序!(已保持当前运行状态)" "${MODDIR}/files/status.conf" - fi - fi - else + + if [ ! -f ${DATADIR}/frpc/frpc.ini ]; then sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=Android\/frpc目录下未找到frpc\.ini文件!(已保持当前运行状态)" "${MODDIR}/files/status.conf" + return 13 fi -} -network_iface_check() { - local network_iface_num="$(device_network_iface)" - if [ "${network_iface_num}" -eq 0 ]; then - if [ -n "${frpc_pid_num}" ]; then - { - kill -9 "${frpc_pid_num}" - rm -f "${MODDIR}/files/frpc_run.pid" - } - sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=已自动停止检测!" \ - -e "/^RUNNING_STATUS=/c RUNNING_STATUS=未检测到设备的网络接口,可能设备未开启网络,已停止运行!" \ - -e "/^RUNNING_NUM=/c RUNNING_NUM=已自动停止检测!" "${MODDIR}/files/status.conf" - return 1 - else - sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=未运行!" \ - -e "/^RUNNING_STATUS=/c RUNNING_STATUS=未检测到设备的网络接口,可能设备未开启蜂窝数据或WLAN!" \ - -e "/^RUNNING_NUM=/c RUNNING_NUM=已停止检测!" "${MODDIR}/files/status.conf" - return 1 + _check_new_file_status="$(stat -c %Y ${DATADIR}/frpc/frpc.ini)" + if [ "${FILE_STATUS}" != "${_check_new_file_status}" ]; then + sh ${MODDIR}/Run_FRPC.sh verify + if [ "$?" -ne 0 ]; then + sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测错误,可能修改的参数需重启生效,请自查配置文件或重启frpc程序!(已保持当前运行状态)" "${MODDIR}/files/status.conf" + return 14 fi - elif [ -z "${network_iface_num}" ]; then - sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=未运行!" \ - -e "/^RUNNING_STATUS=/c RUNNING_STATUS=相关文件缺失,可能模块工作于虚拟机或低版本Android设备!" \ - -e "/^RUNNING_NUM=/c RUNNING_NUM=已停止检测!" "${MODDIR}/files/status.conf" - return 1 + + sh ${MODDIR}/Run_FRPC.sh reload + if [ "$?" -ne 0 ]; then + sed -i "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确但重载失败,可能修改的参数需重启生效,请自查配置文件或重启frpc程序!(已保持当前运行状态)" "${MODDIR}/files/status.conf" + return 15 + fi + + sleep 5 + _running_num=$(sh ${MODDIR}/Run_FRPC.sh status) + sed -i -e "/^RELOAD_NUM=/c RELOAD_NUM=$(($RELOAD_NUM + 1))" -e "/^FILE_STATUS=/c FILE_STATUS=${_check_new_file_status}" \ + -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=配置文件检测正确!" \ + -e "/^RUNNING_NUM=/c RUNNING_NUM=${_running_num}" "${MODDIR}/files/status.conf" fi } battery_electricity_check() { if [ "$(battery_electricity)" -lt 20 ] && [ "$(battery_charge)" -eq 0 ]; then - if [ -n "${frpc_pid_num}" ]; then + if [ -n "${_frpc_pid_num}" ]; then { - kill -9 "${frpc_pid_num}" + kill -9 ${_frpc_pid_num} rm -f "${MODDIR}/files/frpc_run.pid" } sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=已自动停止检测!" \ -e "/^RUNNING_STATUS=/c RUNNING_STATUS=当前电量低于20%且未在充电,自动停止运行!" \ -e "/^RUNNING_NUM=/c RUNNING_NUM=已自动停止检测!" "${MODDIR}/files/status.conf" - return 2 + return 6 else sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=未运行!" \ -e "/^RUNNING_STATUS=/c RUNNING_STATUS=当前电量低于20%且未在充电,终止运行!" \ -e "/^RUNNING_NUM=/c RUNNING_NUM=已停止检测!" "${MODDIR}/files/status.conf" - return 2 + return 7 fi fi + return 0 } main() { - local frpc_cpu_usage frpc_vmrss - local frpc_pid_num="$(frpc_running_check frpc-${F_ARCH})" + local _frpc_vmrss + local _frpc_pid_num="$(get_frpc_running_pid ${frpc_bin})" + #local _device_network_iface_number="$(device_network_iface_number)" if [ ! -f "${MODDIR}/disable" ]; then - if [ -z "${frpc_pid_num}" ]; then + if [ -z "${_frpc_pid_num}" ]; then running_start - elif [ -n "${frpc_pid_num}" ]; then + elif [ -n "${_frpc_pid_num}" ]; then check_reload fi else - if [ -n "${frpc_pid_num}" ]; then + if [ -n "${_frpc_pid_num}" ]; then { - kill -9 "${frpc_pid_num}" + kill -9 ${_frpc_pid_num} rm -f "${MODDIR}/files/frpc_run.pid" } sed -i -e "/^CHECK_FILE_STATUS=/c CHECK_FILE_STATUS=已手动停止检测!" \ @@ -153,14 +138,14 @@ main() { -e "/^RUNNING_NUM=/c RUNNING_NUM=已手动停止检测!" "${MODDIR}/files/status.conf" fi fi - frpc_cpu_usage="$(frpc_cpu_usage_check frpc-${F_ARCH})" - frpc_vmrss="$(frpc_vmrss_check frpc-${F_ARCH})" + + _frpc_vmrss="$(frpc_vmrss_check ${frpc_bin})" sleep 1 . ${MODDIR}/files/status.conf if [ ! -f ${MODDIR}/update ]; then - sed -i "/^description=/c description=使用Magisk挂载运行通用FRPC程序。[状态:${RUNNING_STATUS};CPU占用(AVG):${frpc_cpu_usage:-NuLL};物理内存占用:${frpc_vmrss:-NuLL}],[配置文件状态:${CHECK_FILE_STATUS};穿透服务数(仅参考):${RUNNING_NUM},自动重载配置文件 ${RELOAD_NUM} 次]" "${MODDIR}/module.prop" + sed -i "/^description=/c description=使用Magisk挂载运行通用FRPC程序。[状态:${RUNNING_STATUS};物理内存占用:${_frpc_vmrss:-NuLL}],[配置文件状态:${CHECK_FILE_STATUS};穿透服务数(仅参考):${RUNNING_NUM},自动重载配置文件 ${RELOAD_NUM} 次]" "${MODDIR}/module.prop" else - sed -i "/^description=/c description=使用Magisk挂载运行通用FRPC程序。[状态:${RUNNING_STATUS},CPU占用(AVG):${frpc_cpu_usage:-NuLL};物理内存占用:${frpc_vmrss:-NuLL}],[配置文件状态:${CHECK_FILE_STATUS};穿透服务数(仅参考):${RUNNING_NUM},自动重载配置文件 ${RELOAD_NUM} 次](模块新设定将在设备重启后生效!)" "${MODDIR}/module.prop" + sed -i "/^description=/c description=使用Magisk挂载运行通用FRPC程序。[状态:${RUNNING_STATUS},物理内存占用:${_frpc_vmrss:-NuLL}],[配置文件状态:${CHECK_FILE_STATUS};穿透服务数(仅参考):${RUNNING_NUM},自动重载配置文件 ${RELOAD_NUM} 次](模块新设定将在设备重启后生效!)" "${MODDIR}/module.prop" fi }