From 022b78a4e3c7fade58b0ca1aeb3436fbcacf56b7 Mon Sep 17 00:00:00 2001 From: sofia <253282481+sofia-riese@users.noreply.github.com> Date: Sat, 24 Jan 2026 00:02:35 +0800 Subject: [PATCH] feat(menu.sh): redesign static text menu --- scripts/lang/chs/menu.lang | 20 +- scripts/lang/en/menu.lang | 1 - scripts/menu.sh | 586 +++++++++++++++++++++---------------- scripts/menus/1_start.sh | 1 + scripts/start.sh | 4 +- 5 files changed, 349 insertions(+), 263 deletions(-) diff --git a/scripts/lang/chs/menu.lang b/scripts/lang/chs/menu.lang index b84c71e2..f1ccbc57 100644 --- a/scripts/lang/chs/menu.lang +++ b/scripts/lang/chs/menu.lang @@ -1,8 +1,7 @@ # ===== 通用提示 ===== MENU_ERR_INPUT="请输入正确的字母或数字!" -MENU_RESTART_NOTICE="检测到已变更的内容,请重启服务!" -MENU_RESTART_ASK="是否现在重启服务?(1/0) > " +MENU_RESTART_NOTICE="检测到配置变更,是否立即重启服务以应用新配置:" MENU_PORT_CONFLICT_TITLE="检测到端口被以下进程占用!内核可能无法正常启动!" MENU_PORT_CONFLICT_HINT="请修改默认端口配置!" @@ -14,10 +13,10 @@ MENU_CORE_REMOVED="内核文件已移除,请认真检查后重新上传!" MENU_CFG_LOADED_OK="配置文件加载完成!" MENU_OVERRIDE_WARN="你已经禁用了配置文件覆写功能,这会导致大量脚本功能无法使用!" -MENU_OVERRIDE_ASK="是否取消禁用?" +MENU_OVERRIDE_ASK="是否取消禁用:" # ===== 欢迎与状态 ===== -MENU_WELCOME="欢迎使用ShellCrash!" +MENU_WELCOME="欢迎使用ShellCrash" MENU_VERSION_LABEL="版本:" MENU_RUN_ON="正在运行" @@ -39,10 +38,10 @@ MENU_TG_CHANNEL="TG频道:" # ===== /tmp 文件检测 ===== MENU_TMP_CORE_FOUND="发现可用的内核文件:" -MENU_TMP_CORE_ASK="是否加载(会停止当前服务)?" +MENU_TMP_CORE_ASK="是否立即加载该内核(会停止当前服务):" MENU_TMP_CFG_FOUND="发现内核配置文件:" -MENU_TMP_CFG_ASK="是否加载为配置文件?(1/0) > " +MENU_TMP_CFG_ASK="是否立即加载为配置文件:" MENU_MAIN_1="启动/重启服务" MENU_MAIN_2="功能设置" @@ -55,14 +54,15 @@ MENU_MAIN_8="工具与优化" MENU_MAIN_9="更新与支持" MENU_MAIN_0="退出脚本" -MENU_MAIN_PROMPT="请输入对应数字 > " +MENU_MAIN_PROMPT="请输入对应数字> " # ===== 服务操作 ===== MENU_SERVICE_STOPPED="服务已停止!" # ===== 测试 / 调试 ===== -MENU_TEST_RUNNING="正在测试运行!如发现错误请截图后前往咨询" -MENU_TEST_DONE_OK="测试完成!没有发现问题,请重新启动服务~" +MENU_TEST_RUNNING_1="正在测试运行!" +MENU_TEST_RUNNING_2="如发现错误请截图后前往咨询:" +MENU_TEST_DONE_OK="测试完成!没有发现问题,请重新启动服务~" MENU_TEST_DONE_FAIL="测试完成!" MENU_TEST_LOG_HINT="完整执行记录请查看:" @@ -82,4 +82,4 @@ MENU_CLI_BOOT_INIT="开机初始化" MENU_HELP_ONLINE="在线求助:" MENU_HELP_BLOG="官方博客:" -MENU_HELP_GITHUB="发布页面:" \ No newline at end of file +MENU_HELP_GITHUB="发布页面:" diff --git a/scripts/lang/en/menu.lang b/scripts/lang/en/menu.lang index 9e3abcbf..5f4fdf60 100644 --- a/scripts/lang/en/menu.lang +++ b/scripts/lang/en/menu.lang @@ -2,7 +2,6 @@ MENU_ERR_INPUT="Please enter a valid letter or number!" MENU_RESTART_NOTICE="Changes have been detected. Please restart the service!" -MENU_RESTART_ASK="Restart the service now? (1/0) > " MENU_PORT_CONFLICT_TITLE="The port is occupied by the following process. The core may fail to start!" MENU_PORT_CONFLICT_HINT="Please modify the default port configuration!" diff --git a/scripts/menu.sh b/scripts/menu.sh index a04db994..63c0c63a 100644 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -2,9 +2,10 @@ # Copyright (C) Juewuy CRASHDIR=$( - cd $(dirname $0) - pwd + cd $(dirname $0) + pwd ) + CFG_PATH="$CRASHDIR"/configs/ShellCrash.cfg # 加载执行目录,失败则初始化 @@ -30,238 +31,309 @@ load_lang common load_lang menu errornum() { - line_break - separator_line "=" - content_line "\033[31m$MENU_ERR_INPUT\033[0m" - separator_line "=" + line_break + separator_line "=" + content_line "\033[31m$MENU_ERR_INPUT\033[0m" + separator_line "=" } checkrestart() { - echo "-----------------------------------------------" - echo -e "\033[32m$MENU_RESTART_NOTICE\033[0m" - echo "-----------------------------------------------" - read -p "$MENU_RESTART_ASK" res - [ "$res" = 1 ] && start_service + line_break + separator_line "=" + content_line "\033[32m$MENU_RESTART_NOTICE\033[0m" + separator_line "=" + content_line "1) 立即重启" + content_line "0) 暂不重启" + separator_line "=" + read -r -p "$COMMON_INPUT> " res + if [ "$res" = 1 ]; then + start_service + fi } -checkport() { #检查端口冲突 - for portx in $dns_port $mix_port $redir_port $((redir_port + 1)) $db_port; do - if [ -n "$(netstat -ntul 2>&1 | grep ":$portx ")" ]; then - echo "-----------------------------------------------" - echo -e "【$portx】: $MENU_PORT_CONFLICT_TITLE" - echo -e "\033[0m$(netstat -ntul | grep ":$portx" | head -n 1)\033[0m" - echo "-----------------------------------------------" - echo -e "\033[36m$MENU_PORT_CONFLICT_HINT\033[0m" - . "$CRASHDIR"/menus/2_settings.sh && set_adv_config - . "$CRASHDIR"/libs/get_config.sh - checkport - fi - done +# 检查端口冲突 +checkport() { + while true; do + # Before each round of checks begins, execute netstat only once and cache the results + # Avoid calling the system command once for each port + current_listening=$(netstat -ntul 2>&1) + + conflict_found=0 + + for portx in $dns_port $mix_port $redir_port $((redir_port + 1)) $db_port; do + # Use `grep` to search within the cached variables instead of re-running `netstat` + conflict_line=$(echo "$current_listening" | grep ":$portx ") + + if [ -n "$conflict_line" ]; then + line_break + separator_line "=" + content_line "【$portx】:$MENU_PORT_CONFLICT_TITLE" + content_line "\033[0m$(echo "$conflict_line" | head -n 1)\033[0m" + content_line "\033[36m$MENU_PORT_CONFLICT_HINT\033[0m" + separator_line "=" + + . "$CRASHDIR"/menus/2_settings.sh && set_adv_config + . "$CRASHDIR"/libs/get_config.sh + + # Mark conflict and exit the for loop, triggering the while loop to restart the check + # This replaces the original recursive call to `checkport` + conflict_found=1 + break + fi + done + + # If no conflicts are found after the entire for loop completes, + # the while loop exits and the function terminates. + if [ "$conflict_found" -eq 0 ]; then + break + fi + done } -ckstatus() { #脚本启动前检查 - #检查脚本配置文件 - if [ -f "$CFG_PATH" ]; then - [ -n "$(awk 'a[$0]++' "$CFG_PATH")" ] && awk '!a[$0]++' "$CFG_PATH" >"$CFG_PATH" - else - . "$CRASHDIR"/init.sh >/dev/null 2>&1 - fi - versionsh=$(cat "$CRASHDIR"/version) - [ -n "$versionsh" ] && versionsh_l=$versionsh - [ -z "$redir_mod" ] && redir_mod="$MENU_PURE_MOD" - #获取本机host地址 - [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') - [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) - [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) - [ -z "$host" ] && host='$MENU_IP_DF' - #dashboard目录位置 - if [ -f /www/clash/index.html ]; then - dbdir=/www/clash - hostdir=/clash - else - dbdir="$CRASHDIR"/ui - hostdir=":$db_port/ui" - fi +# 脚本启动前检查 +ckstatus() { + # 检查脚本配置文件 + if [ -f "$CFG_PATH" ]; then + [ -n "$(awk 'a[$0]++' "$CFG_PATH")" ] && awk '!a[$0]++' "$CFG_PATH" >"$CFG_PATH" + else + . "$CRASHDIR"/init.sh >/dev/null 2>&1 + fi - if check_autostart; then - auto="\033[32m$MENU_AUTOSTART_ON\033[0m" - else - auto="\033[31m$MENU_AUTOSTART_OFF\033[0m" - fi + versionsh=$(cat "$CRASHDIR"/version) + [ -n "$versionsh" ] && versionsh_l=$versionsh + [ -z "$redir_mod" ] && redir_mod="$MENU_PURE_MOD" - PID=$(pidof CrashCore | awk '{print $NF}') - if [ -n "$PID" ]; then - run="\033[32m$MENU_RUN_ON($redir_mod$MENU_MOD)\033[0m" - running_status - elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ]; then - run="\033[32m$MENU_RUN_SET($redir_mod$MENU_MOD)\033[0m" - else - run="\033[31m$MENU_RUN_OFF($redir_mod$MENU_MOD)\033[0m" - #检测系统端口占用 - checkport - fi - corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/') - #[ "$firewall_area" = 5 ] && corename='转发' - [ -f "$TMPDIR"/debug.log -o -f "$CRASHDIR"/debug.log -a -n "$PID" ] && auto="\033[33m$MENU_AUTOSTART_DEBUG\033[0m" - #输出状态 - echo "-----------------------------------------------" - echo -e "\033[30;46m$MENU_WELCOME\033[0m\t\t$MENU_VERSION_LABEL$versionsh_l" - echo -e "$corename$run\t$auto" + # 获取本机host地址 + [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') + [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) + [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) + [ -z "$host" ] && host='$MENU_IP_DF' - if [ -n "$PID" ]; then - echo -e "$MENU_MEM_USED\033[44m$VmRSS\033[0m\t\t$MENU_RUNNING_TIME\033[46;30m$day\033[44;37m$time\033[0m" - fi + # dashboard目录位置 + if [ -f /www/clash/index.html ]; then + dbdir=/www/clash + hostdir=/clash + else + dbdir="$CRASHDIR"/ui + hostdir=":$db_port/ui" + fi - echo -e "$MENU_TG_CHANNEL\033[36;4mhttps://t.me/ShellClash\033[0m" - echo "-----------------------------------------------" - #检查新手引导 - if [ -z "$userguide" ]; then - . "$CRASHDIR"/menus/userguide.sh && userguide - setconfig userguide 1 - fi - #检查执行权限 - [ ! -x "$CRASHDIR"/start.sh ] && chmod +x "$CRASHDIR"/start.sh - #检查/tmp内核文件 - for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -Ev ".*(zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box|meta.*'); do - echo -e "$MENU_TMP_CORE_FOUND \033[36m/tmp/$file\033[0m " - read -p "$MENU_TMP_CORE_ASK(1/0) > " res - [ "$res" = 1 ] && { - zip_type=$(echo "$file" | grep -oE 'tar.gz$|upx$|gz$') - . "$CRASHDIR"/menus/9_upgrade.sh && setcoretype - . "$CRASHDIR"/libs/core_tools.sh && core_check "/tmp/$file" - if [ "$?" = 0 ]; then - echo -e "\033[32m$MENU_CORE_LOADED_OK\033[0m " - switch_core - else - echo -e "\033[33m$MENU_CORE_LOADED_BAD033[0m" - rm -rf /tmp/"$file" - echo -e "\033[33m$MENU_CORE_REMOVED\033[0m" - fi - sleep 1 - } - echo "-----------------------------------------------" - done - #检查/tmp配置文件 - for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -iE 'config.yaml$|config.yml$|config.json$'); do - tmp_file=/tmp/$file - echo -e "$MENU_TMP_CFG_FOUND \033[36m/tmp/$file\033[0m " - read -p "$MENU_TMP_CFG_ASK(1/0) > " res - [ "$res" = 1 ] && { - if [ -n "$(echo /tmp/$file | grep -iE '.json$')" ]; then - mv -f /tmp/$file "$CRASHDIR"/jsons/config.json - else - mv -f /tmp/$file "$CRASHDIR"/yamls/config.yaml - fi - echo -e "\033[32m$MENU_CFG_LOADED_OK\033[0m " - sleep 1 - } - done - #检查禁用配置覆写 - [ "$disoverride" = "1" ] && { - echo -e "\033[33m$MENU_OVERRIDE_WARN\033[0m " - read -p "$MENU_OVERRIDE_ASK(1/0) > " res - [ "$res" = 1 ] && unset disoverride && setconfig disoverride - echo "-----------------------------------------------" - } + if check_autostart; then + auto="\033[32m$MENU_AUTOSTART_ON\033[0m" + else + auto="\033[31m$MENU_AUTOSTART_OFF\033[0m" + fi + + PID=$(pidof CrashCore | awk '{print $NF}') + if [ -n "$PID" ]; then + run="\033[32m$MENU_RUN_ON($redir_mod$MENU_MOD)\033[0m" + running_status + elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ]; then + run="\033[32m$MENU_RUN_SET($redir_mod$MENU_MOD)\033[0m" + else + run="\033[31m$MENU_RUN_OFF($redir_mod$MENU_MOD)\033[0m" + # 检测系统端口占用 + checkport + fi + corename=$(echo $crashcore | sed 's/singboxr/SingBoxR/' | sed 's/singbox/SingBox/' | sed 's/clash/Clash/' | sed 's/meta/Mihomo/') + # [ "$firewall_area" = 5 ] && corename='转发' + [ -f "$TMPDIR"/debug.log -o -f "$CRASHDIR"/debug.log -a -n "$PID" ] && auto="\033[33m$MENU_AUTOSTART_DEBUG\033[0m" + + # 检查新手引导 + if [ -z "$userguide" ]; then + . "$CRASHDIR"/menus/userguide.sh && userguide + setconfig userguide 1 + fi + + # 检查执行权限 + [ ! -x "$CRASHDIR"/start.sh ] && chmod +x "$CRASHDIR"/start.sh + + line_break + separator_line "=" + content_line " $MENU_WELCOME" + content_line "" + content_line "$(printf "%$((${TABLE_WIDTH:-60} - 1))s" "$MENU_VERSION_LABEL$versionsh_l")" + content_line " $MENU_TG_CHANNEL\033[36;4mhttps://t.me/ShellClash\033[0m" + separator_line "=" + content_line "$corename$run\t $auto" + if [ -n "$PID" ]; then + content_line "$MENU_MEM_USED\033[44m$VmRSS\033[0m\t\t $MENU_RUNNING_TIME\033[46;30m$day\033[44;37m$time\033[0m" + fi + separator_line "=" + + # 检查/tmp内核文件 + for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -Ev ".*(zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box|meta.*'); do + line_break + separator_line "=" + content_line "$MENU_TMP_CORE_FOUND \033[36m/tmp/$file\033[0m" + content_line "$MENU_TMP_CORE_ASK" + separator_line "=" + content_line "1) 立即加载" + content_line "0) 暂不加载" + separator_line "=" + read -r -p "$COMMON_INPUT> " res + [ "$res" = 1 ] && { + line_break + separator_line "=" + zip_type=$(echo "$file" | grep -oE 'tar.gz$|upx$|gz$') + . "$CRASHDIR"/menus/9_upgrade.sh && setcoretype + . "$CRASHDIR"/libs/core_tools.sh && core_check "/tmp/$file" + if [ "$?" = 0 ]; then + content_line "\033[32m$MENU_CORE_LOADED_OK\033[0m" + separator_line "=" + switch_core + else + content_line "\033[33m$MENU_CORE_LOADED_BAD\033[0m" + rm -rf /tmp/"$file" + content_line "\033[33m$MENU_CORE_REMOVED\033[0m" + fi + separator_line "=" + sleep 1 + } + done + + # 检查/tmp配置文件 + for file in $(ls /tmp | grep -v [/$] | grep -v ' ' | grep -iE 'config.yaml$|config.yml$|config.json$'); do + tmp_file=/tmp/$file + line_break + separator_line "=" + content_line "$MENU_TMP_CFG_FOUND \033[36m/tmp/$file\033[0m" + content_line "$MENU_TMP_CFG_ASK" + separator_line "=" + content_line "1) 立即加载" + content_line "0) 暂不加载" + separator_line "=" + read -p "$COMMON_INPUT> " res + [ "$res" = 1 ] && { + if [ -n "$(echo /tmp/$file | grep -iE '.json$')" ]; then + mv -f /tmp/$file "$CRASHDIR"/jsons/config.json + else + mv -f /tmp/$file "$CRASHDIR"/yamls/config.yaml + fi + line_break + separator_line "=" + content_line "\033[32m$MENU_CFG_LOADED_OK\033[0m " + separator_line "=" + sleep 1 + } + done + + # 检查禁用配置覆写 + [ "$disoverride" = "1" ] && { + line_break + separator_line "=" + content_line "\033[33m$MENU_OVERRIDE_WARN\033[0m" + content_line "$MENU_OVERRIDE_ASK" + separator_line "=" + content_line "1) 是" + content_line "0) 否" + separator_line "=" + read -p "$COMMON_INPUT> " res + [ "$res" = 1 ] && unset disoverride && setconfig disoverride + } } main_menu() { - while true; do - ckstatus + while true; do + ckstatus - echo -e " 1 \033[32m$MENU_MAIN_1\033[0m" - echo -e " 2 \033[36m$MENU_MAIN_2\033[0m" - echo -e " 3 \033[31m$MENU_MAIN_3\033[0m" - echo -e " 4 \033[33m$MENU_MAIN_4\033[0m" - echo -e " 5 \033[32m$MENU_MAIN_5\033[0m" - echo -e " 6 \033[36m$MENU_MAIN_6\033[0m" - echo -e " 7 \033[33m$MENU_MAIN_7\033[0m" - echo -e " 8 $MENU_MAIN_8" - echo -e " 9 \033[32m$MENU_MAIN_9\033[0m" - echo "-----------------------------------------------" - echo -e " 0 $MENU_MAIN_0" + content_line "1) \033[32m$MENU_MAIN_1\033[0m" + content_line "2) \033[36m$MENU_MAIN_2\033[0m" + content_line "3) \033[31m$MENU_MAIN_3\033[0m" + content_line "4) \033[33m$MENU_MAIN_4\033[0m" + content_line "5) \033[32m$MENU_MAIN_5\033[0m" + content_line "6) \033[36m$MENU_MAIN_6\033[0m" + content_line "7) \033[33m$MENU_MAIN_7\033[0m" + content_line "8) $MENU_MAIN_8" + content_line "9) \033[32m$MENU_MAIN_9\033[0m" + content_line "0) $MENU_MAIN_0" + separator_line "=" + read -r -p "$MENU_MAIN_PROMPT" num - read -p "$MENU_MAIN_PROMPT" num - - case "$num" in - "" | 0) - exit - ;; - 1) - start_service - exit - ;; - 2) - checkcfg=$(cat "$CFG_PATH") - . "$CRASHDIR"/menus/2_settings.sh && settings - if [ -n "$PID" ]; then - checkcfg_new=$(cat "$CFG_PATH") - [ "$checkcfg" != "$checkcfg_new" ] && checkrestart - fi - ;; - 3) - [ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop - "$CRASHDIR"/start.sh stop - sleep 1 - echo "-----------------------------------------------" - echo -e "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m" - ;; - 4) - . "$CRASHDIR"/menus/4_setboot.sh && setboot - ;; - 5) - . "$CRASHDIR"/menus/5_task.sh && task_menu - ;; - 6) - . "$CRASHDIR"/menus/6_core_config.sh && set_core_config - ;; - 7) - GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg - touch "$GT_CFG_PATH" - checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH") - . "$CRASHDIR"/menus/7_gateway.sh && gateway - if [ -n "$PID" ]; then - checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH") - [ "$checkcfg" != "$checkcfg_new" ] && checkrestart - fi - ;; - 8) - . "$CRASHDIR"/menus/8_tools.sh && tools - ;; - 9) - checkcfg=$(cat "$CFG_PATH") - . "$CRASHDIR"/menus/9_upgrade.sh && upgrade - if [ -n "$PID" ]; then - checkcfg_new=$(cat "$CFG_PATH") - [ "$checkcfg" != "$checkcfg_new" ] && checkrestart - fi - ;; - *) - errornum - sleep 1 - ;; - esac - done + case "$num" in + "" | 0) + line_break + exit 0 + ;; + 1) + start_service + exit + line_break + ;; + 2) + checkcfg=$(cat "$CFG_PATH") + . "$CRASHDIR"/menus/2_settings.sh && settings + if [ -n "$PID" ]; then + checkcfg_new=$(cat "$CFG_PATH") + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi + ;; + 3) + [ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop + "$CRASHDIR"/start.sh stop + sleep 1 + line_break + separator_line "=" + content_line "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m" + separator_line "=" + sleep 1 + ;; + 4) + . "$CRASHDIR"/menus/4_setboot.sh && setboot + ;; + 5) + . "$CRASHDIR"/menus/5_task.sh && task_menu + ;; + 6) + . "$CRASHDIR"/menus/6_core_config.sh && set_core_config + ;; + 7) + GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg + touch "$GT_CFG_PATH" + checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH") + . "$CRASHDIR"/menus/7_gateway.sh && gateway + if [ -n "$PID" ]; then + checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH") + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi + ;; + 8) + . "$CRASHDIR"/menus/8_tools.sh && tools + ;; + 9) + checkcfg=$(cat "$CFG_PATH") + . "$CRASHDIR"/menus/9_upgrade.sh && upgrade + if [ -n "$PID" ]; then + checkcfg_new=$(cat "$CFG_PATH") + [ "$checkcfg" != "$checkcfg_new" ] && checkrestart + fi + ;; + *) + errornum + sleep 1 + ;; + esac + done } case "$1" in "") - main_menu - ;; + main_menu + ;; -l) - main_menu - ;; + main_menu + ;; -t) - shtype=sh + shtype=sh [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash - "$shtype" -x "$CRASHDIR"/menu.sh -l - ;; + "$shtype" -x "$CRASHDIR"/menu.sh -l + ;; -s) - "$CRASHDIR"/start.sh "$2" "$3" "$4" "$5" "$6" - ;; + "$CRASHDIR"/start.sh "$2" "$3" "$4" "$5" "$6" + ;; -i) - . "$CRASHDIR"/init.sh 2>/dev/null - ;; + . "$CRASHDIR"/init.sh 2>/dev/null + ;; -st) shtype=sh ckcmd bash && shtype=bash @@ -270,48 +342,62 @@ case "$1" in start_legacy "$COMMAND" 'shellcrash' "$shtype" -x "$CRASHDIR"/starts/afstart.sh "$CRASHDIR"/start.sh stop - ;; + ;; -d) - shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash - echo -e "$MENU_TEST_RUNNING\033[32;4mt.me/ShellClash\033[0m" - "$shtype" "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh_bug.log - "$shtype" -x "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh.log - echo ----------------------------------------- - cat "$TMPDIR"/debug_sh_bug.log | grep 'start\.sh' >"$TMPDIR"/sh_bug - if [ -s "$TMPDIR"/sh_bug ]; then - while read line; do - echo -e "$MENU_ERROR_FOUND\033[33;4m$line\033[0m" - grep -A 1 -B 3 "$line" "$TMPDIR"/debug_sh.log - echo ----------------------------------------- - done <"$TMPDIR"/sh_bug - rm -rf "$TMPDIR"/sh_bug - echo -e "\033[32m$MENU_TEST_DONE_FAIL\033[0m$MENU_TEST_LOG_HINT\033[36m$TMPDIR/debug_sh.log\033[0m" - else - echo -e "\033[32m$MENU_TEST_DONE_OK\033[0m" - rm -rf "$TMPDIR"/debug_sh.log - fi - "$CRASHDIR"/start.sh stop - ;; + shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash + line_break + separator_line "=" + content_line "$MENU_TEST_RUNNING_1" + content_line "$MENU_TEST_RUNNING_2\033[36;4mhttps://t.me/ShellClash\033[0m" + separator_line "=" + "$shtype" "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh_bug.log + "$shtype" -x "$CRASHDIR"/start.sh debug >/dev/null 2>"$TMPDIR"/debug_sh.log + line_break + cat "$TMPDIR"/debug_sh_bug.log | grep 'start\.sh' >"$TMPDIR"/sh_bug + if [ -s "$TMPDIR"/sh_bug ]; then + echo "===========================================================" + while read line; do + echo -e "$MENU_ERROR_FOUND\033[33;4m$line\033[0m" + grep -A 1 -B 3 "$line" "$TMPDIR"/debug_sh.log + echo "===========================================================" + done <"$TMPDIR"/sh_bug + rm -rf "$TMPDIR"/sh_bug + line_break + separator_line "=" + content_line "\033[32m$MENU_TEST_DONE_FAIL\033[0m" + content_line "$MENU_TEST_LOG_HINT\033[36m$TMPDIR/debug_sh.log\033[0m" + separator_line "=" + else + rm -rf "$TMPDIR"/debug_sh.log + separator_line "=" + content_line "\033[32m$MENU_TEST_DONE_OK\033[0m" + separator_line "=" + line_break + fi + "$CRASHDIR"/start.sh stop + ;; -u) - . "$CRASHDIR"/menus/uninstall.sh && uninstall - ;; + . "$CRASHDIR"/menus/uninstall.sh && uninstall + ;; *) - echo ----------------------------------------- - echo "$MENU_WELCOME" - echo ----------------------------------------- - echo " -t $MENU_CLI_TEST" - echo " -h $MENU_CLI_HELP" - echo " -u $MENU_CLI_UNINSTALL" - echo " -i $MENU_CLI_INIT" - echo " -d $MENU_CLI_DEBUG" - echo ----------------------------------------- - echo " crash -s start $MENU_CLI_START" - echo " crash -s stop $MENU_CLI_STOP" - echo " $CRASHDIR/start.sh init $MENU_CLI_BOOT_INIT" - echo ----------------------------------------- - echo "$MENU_HELP_ONLINE t.me/ShellClash" - echo "$MENU_HELP_BLOG juewuy.github.io" - echo "$MENU_HELP_GITHUB github.com/juewuy/ShellCrash" - echo ----------------------------------------- - ;; + line_break + separator_line "=" + content_line "$MENU_WELCOME" + separator_line "=" + content_line "-t $MENU_CLI_TEST" + content_line "-h $MENU_CLI_HELP" + content_line "-u $MENU_CLI_UNINSTALL" + content_line "-i $MENU_CLI_INIT" + content_line "-d $MENU_CLI_DEBUG" + separator_line "-" + content_line "crash -s start $MENU_CLI_START" + content_line "crash -s stop $MENU_CLI_STOP" + content_line "$CRASHDIR/start.sh init $MENU_CLI_BOOT_INIT" + separator_line "-" + content_line "$MENU_HELP_ONLINE\033[36mhttps://t.me/ShellClash\033[0m" + content_line "$MENU_HELP_BLOG\033[36mhttps://juewuy.github.io\033[0m" + content_line "$MENU_HELP_GITHUB\033[36mhttps://github.com/juewuy/ShellCrash\033[0m" + separator_line "=" + line_break + ;; esac diff --git a/scripts/menus/1_start.sh b/scripts/menus/1_start.sh index e52241be..7548dd4e 100644 --- a/scripts/menus/1_start.sh +++ b/scripts/menus/1_start.sh @@ -19,6 +19,7 @@ startover() { fi separator_line "=" line_break + sleep 1 return 0 } diff --git a/scripts/start.sh b/scripts/start.sh index e9ee6403..3dc8bd16 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -28,7 +28,7 @@ stop_firewall(){ start_l(){ bfstart && { . "$CRASHDIR"/starts/start_legacy.sh - start_legacy "$COMMAND" 'shellcrash' + start_legacy "$COMMAND" 'shellcrash' } && afstart & } @@ -65,7 +65,7 @@ start) fi ;; stop) - logger ShellCrash服务即将关闭…… + logger ShellCrash服务即将关闭...... [ -n "$(pidof CrashCore)" ] && web_save #保存面板配置 #删除守护进程&面板配置自动保存 cronset '保守模式守护进程'