Merge pull request #1141 from sofia-riese/patch-1

refactor(forwhat): replace recursion with while loop
This commit is contained in:
juewuy
2026-01-17 17:27:21 +08:00
committed by GitHub

View File

@@ -4,10 +4,8 @@
[ -n "$__IS_MODULE_USERGUIDE_LOADED" ] && return
__IS_MODULE_USERGUIDE_LOADED=1
#新手引导
userguide(){
. "$CRASHDIR"/libs/check_dir_avail.sh
forwhat(){
forwhat() {
while true; do
echo "-----------------------------------------------"
echo -e "\033[30;46m 欢迎使用ShellCrash新手引导 \033[0m"
echo "-----------------------------------------------"
@@ -18,110 +16,126 @@ userguide(){
echo -e " 2 \033[36mLinux设备仅配置本机代理\033[0m"
[ -f "$CFG_PATH.bak" ] && echo -e " 3 \033[33m还原之前备份的设置\033[0m"
echo "-----------------------------------------------"
read -p "请输入对应数字 > " num
read -pr "请输入对应数字 > " num
case "$num" in
1)
#设置运行模式
"" | 1)
# 设置运行模式
redir_mod="混合模式"
[ -n "$(echo $cputype | grep -E "linux.*mips.*")" ] && {
echo "$cputype" | grep -Eq 'linux.*mips.*' && {
if grep -qE '^TPROXY$' /proc/net/ip_tables_targets || modprobe xt_TPROXY >/dev/null 2>&1; then
redir_mod="Tproxy模式"
else
redir_mod="Redir模式"
fi
}
[ -z "$crashcore" ] && crashcore=meta
setconfig crashcore "$crashcore"
setconfig redir_mod "$redir_mod"
setconfig dns_mod mix
setconfig firewall_area '1'
#默认启用绕过CN-IP
# 默认启用绕过CN-IP
setconfig cn_ip_route ON
#自动识别IPV6
# 自动识别IPV6
[ -n "$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g')" ] && {
setconfig ipv6_redir ON
setconfig ipv6_support ON
setconfig ipv6_dns ON
setconfig cn_ipv6_route ON
}
#设置开机启动
[ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ] && /etc/init.d/shellcrash enable
ckcmd systemctl && [ "$(cat /proc/1/comm)" = "systemd" ] && systemctl enable shellcrash.service > /dev/null 2>&1
# 设置开机启动
if [ -f /etc/rc.common ] && [ "$(cat /proc/1/comm)" = "procd" ]; then
/etc/init.d/shellcrash enable
fi
ckcmd systemctl && [ "$(cat /proc/1/comm)" = "systemd" ] && systemctl enable shellcrash.service >/dev/null 2>&1
rm -rf "$CRASHDIR"/.dis_startup
autostart=enable
#检测IP转发
if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ];then
# 检测IP转发
if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then
echo "-----------------------------------------------"
echo -e "\033[33m检测到你的设备尚未开启ip转发局域网设备将无法正常连接网络是否立即开启\033[0m"
read -p "是否开启?(1/0) > " res
read -pr "是否开启?(1/0) > " res
[ "$res" = 1 ] && {
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
echo 'net.ipv4.ip_forward = 1' >>/etc/sysctl.conf
sysctl -w net.ipv4.ip_forward=1
} && echo "已成功开启ipv4转发如未正常开启请手动重启设备" || echo "开启失败!请自行谷歌查找当前设备的开启方法!"
fi
#禁止docker启用的net.bridge.bridge-nf-call-iptables
sysctl -w net.bridge.bridge-nf-call-iptables=0 > /dev/null 2>&1
sysctl -w net.bridge.bridge-nf-call-ip6tables=0 > /dev/null 2>&1
# 禁止docker启用的net.bridge.bridge-nf-call-iptables
sysctl -w net.bridge.bridge-nf-call-iptables=0 >/dev/null 2>&1
sysctl -w net.bridge.bridge-nf-call-ip6tables=0 >/dev/null 2>&1
break
;;
2)
setconfig redir_mod "Redir模式"
[ -n "$(echo $cputype | grep -E "linux.*mips.*")" ] && setconfig crashcore "clash"
echo "$cputype" | grep -Eq "linux.*mips.*" && setconfig crashcore "clash"
setconfig common_ports "OFF"
setconfig firewall_area '2'
break
;;
3)
mv -f $CFG_PATH.bak $CFG_PATH
mv -f "$CFG_PATH.bak" "$CFG_PATH"
echo -e "\033[32m脚本设置已还原\033[0m"
echo -e "\033[33m请重新启动脚本\033[0m"
exit 0
;;
*)
errornum
forwhat
sleep 1
;;
esac
}
done
}
# 新手引导
userguide() {
. "$CRASHDIR"/libs/check_dir_avail.sh
forwhat
#检测小内存模式
# 检测小内存模式
dir_size=$(dir_avail "$CRASHDIR")
if [ "$dir_size" -lt 10240 ];then
if [ "$dir_size" -lt 10240 ]; then
echo "-----------------------------------------------"
echo -e "\033[33m检测到你的安装目录空间不足10M是否开启小闪存模式\033[0m"
echo -e "\033[0m开启后核心及数据库文件将被下载到内存中这将占用一部分内存空间\033[0m"
echo -e "\033[0m每次开机后首次运行服务时都会自动的重新下载相关文件\033[0m"
echo "-----------------------------------------------"
read -p "是否开启?(1/0) > " res
read -pr "是否开启?(1/0) > " res
[ "$res" = 1 ] && {
BINDIR=/tmp/ShellCrash
setconfig BINDIR /tmp/ShellCrash "$CRASHDIR"/configs/command.env
}
fi
#启用推荐的自动任务配置
# 启用推荐的自动任务配置
. "$CRASHDIR"/menus/5_task.sh && task_recom
#小米设备软固化
if [ "$systype" = "mi_snapshot" ];then
# 小米设备软固化
if [ "$systype" = "mi_snapshot" ]; then
echo "-----------------------------------------------"
echo -e "\033[33m检测到为小米路由设备启用软固化可防止路由升级后丢失SSH\033[0m"
read -p "是否启用软固化功能?(1/0) > " res
read -pr "是否启用软固化功能?(1/0) > " res
[ "$res" = 1 ] && mi_autoSSH
fi
#提示导入订阅或者配置文件
[ ! -s "$CRASHDIR"/yamls/config.yaml -a ! -s "$CRASHDIR"/jsons/config.json ] && {
# 提示导入订阅或者配置文件
if [ ! -s "$CRASHDIR"/yamls/config.yaml ] && [ ! -s "$CRASHDIR"/jsons/config.json ]; then
echo "-----------------------------------------------"
echo -e "\033[32m是否导入配置文件\033[0m(这是运行前的最后一步)"
echo -e "\033[0m你必须拥有一份配置文件才能运行服务\033[0m"
echo "-----------------------------------------------"
read -p "现在开始导入?(1/0) > " res
read -pr "现在开始导入?(1/0) > " res
[ "$res" = 1 ] && inuserguide=1 && {
. "$CRASHDIR"/menus/6_core_config.sh && set_core_config
inuserguide=""
}
}
#回到主界面
fi
# 回到主界面
echo "-----------------------------------------------"
echo -e "\033[36m很好现在只需要执行启动就可以愉快的使用了\033[0m"
echo "-----------------------------------------------"
read -p "立即启动服务?(1/0) > " res
read -pr "立即启动服务?(1/0) > " res
[ "$res" = 1 ] && start_core && sleep 2
return 0
}