refactor(set_core_config): replace recursion with while loop

This commit is contained in:
Sofia
2026-01-11 17:09:11 +08:00
committed by GitHub
parent 55b8266dfd
commit 56d8bbadc2

View File

@@ -1029,8 +1029,9 @@ set_core_config_link(){ #直接导入配置
fi
}
#配置文件主界面
set_core_config(){
# 配置文件主界面
set_core_config() {
while true; do
[ -z "$rule_link" ] && rule_link=1
[ -z "$server_link" ] && server_link=1
echo "$crashcore" | grep -q 'singbox' && config_path="$JSONSDIR"/config.json || config_path="$YAMLSDIR"/config.yaml
@@ -1038,7 +1039,7 @@ set_core_config(){
echo -e "\033[30;47m ShellCrash配置文件管理\033[0m"
echo "-----------------------------------------------"
echo -e " 1 在线\033[32m生成配置文件\033[0m(基于Subconverter订阅转换)"
if [ -f "$CRASHDIR"/v2b_api.sh ];then
if [ -f "$CRASHDIR"/v2b_api.sh ]; then
echo -e " 2 登录\033[33m获取订阅(推荐!)\033[0m"
else
echo -e " 2 在线\033[33m获取配置文件\033[0m(基于订阅提供者)"
@@ -1054,10 +1055,11 @@ set_core_config(){
[ "$inuserguide" = 1 ] || echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
"" | 0)
break
;;
1)
if [ -n "$Url" ];then
if [ -n "$Url" ]; then
echo "-----------------------------------------------"
echo -e "\033[33m检测到已记录的链接内容\033[0m"
echo -e "\033[4;32m$Url\033[0m"
@@ -1072,22 +1074,19 @@ set_core_config(){
fi
fi
gen_core_config_link
set_core_config
;;
2)
if [ -f "$CRASHDIR"/v2b_api.sh ];then
if [ -f "$CRASHDIR"/v2b_api.sh ]; then
. "$CRASHDIR"/v2b_api.sh
set_core_config
else
set_core_config_link
fi
set_core_config
;;
3)
if [ "$crashcore" = meta -o "$crashcore" = clashpre ];then
if [ "$crashcore" = meta -o "$crashcore" = clashpre ]; then
coretype=clash
setproviders
elif [ "$crashcore" = singboxr ];then
elif [ "$crashcore" = singboxr ]; then
coretype=singbox
setproviders
else
@@ -1095,33 +1094,31 @@ set_core_config(){
sleep 1
checkupdate && setcore
fi
set_core_config
;;
4)
echo "-----------------------------------------------"
echo -e "\033[33m请将本地配置文件上传到/tmp目录并重命名为config.yaml或者config.json\033[0m"
echo -e "\033[32m之后重新运行本脚本即可自动弹出导入提示\033[0m"
sleep 2
exit
;;
5)
. "$CRASHDIR"/menus/5_task.sh && task_menu
set_core_config
break
;;
6)
checkcfg=$(cat $CFG_PATH)
override
if [ -n "$PID" ];then
if [ -n "$PID" ]; then
checkcfg_new=$(cat $CFG_PATH)
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart
fi
set_core_config
;;
7)
if [ -z "$Url" -a -z "$Https" ];then
if [ -z "$Url" -a -z "$Https" ]; then
echo "-----------------------------------------------"
echo -e "\033[31m没有找到你的配置文件/订阅链接!请先输入链接!\033[0m"
sleep 1
set_core_config
else
echo "-----------------------------------------------"
echo -e "\033[33m当前系统记录的链接为\033[0m"
@@ -1130,29 +1127,28 @@ set_core_config(){
read -p "确认更新配置文件?[1/0] > " res
if [ "$res" = '1' ]; then
jump_core_config
else
set_core_config
break
fi
fi
;;
8)
if [ ! -f ${config_path}.bak ];then
if [ ! -f ${config_path}.bak ]; then
echo "-----------------------------------------------"
echo -e "\033[31m没有找到配置文件的备份\033[0m"
set_core_config
else
echo "-----------------------------------------------"
echo -e 备份文件共有"\033[32m`wc -l < ${config_path}.bak`\033[0m"行内容,当前文件共有"\033[32m`wc -l < ${config_path}`\033[0m"行内容
echo -e 备份文件共有"\033[32m$(wc -l <${config_path}.bak)\033[0m"行内容,当前文件共有"\033[32m$(wc -l <${config_path})\033[0m"行内容
read -p "确认还原配置文件?此操作不可逆![1/0] > " res
if [ "$res" = '1' ]; then
mv ${config_path}.bak ${config_path}
echo "----------------------------------------------"
echo -e "\033[32m配置文件已还原请手动重启服务\033[0m"
sleep 1
break
else
echo "-----------------------------------------------"
echo -e "\033[31m操作已取消返回上级菜单\033[0m"
set_core_config
sleep 1
fi
fi
;;
@@ -1183,10 +1179,12 @@ set_core_config(){
;;
esac
[ "$num" -le 3 ] && setconfig user_agent "$user_agent"
set_core_config
;;
*)
errornum
sleep 1
break
;;
esac
done
}