~继续优化代码

~bot_tg.sh施工中
This commit is contained in:
juewuy
2025-12-26 17:35:45 +08:00
parent 0b3beca6a9
commit 1f477a5934
12 changed files with 233 additions and 181 deletions

View File

@@ -1,11 +1,25 @@
#!/bin/sh
# Copyright (C) Juewuy
allow_autostart(){
[ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ] && /etc/init.d/shellcrash enable
ckcmd systemctl && systemctl enable shellcrash.service >/dev/null 2>&1
grep -q 's6' /proc/1/comm && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
rc-status -r >/dev/null 2>&1 && rc-update add shellcrash default >/dev/null 2>&1
rm -rf "$CRASHDIR"/.dis_startup
}
disable_autostart(){
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash >/dev/null 2>&1 && cd - >/dev/null
ckcmd systemctl && systemctl disable shellcrash.service >/dev/null 2>&1
grep -q 's6' /proc/1/comm && rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
rc-status -r >/dev/null 2>&1 && rc-update del shellcrash default >/dev/null 2>&1
touch "$CRASHDIR"/.dis_startup
}
setboot() { #启动设置菜单
[ -z "$start_old" ] && start_old=未开启
[ -z "$start_delay" -o "$start_delay" = 0 ] && delay=未设置 || delay=${start_delay}
[ "$autostart" = "enable" ] && auto_set="\033[33m禁止" || auto_set="\033[32m允许"
[ "${BINDIR}" = "${CRASHDIR}" ] && mini_clash=未开启 || mini_clash=已开启
[ -z "$start_delay" -o "$start_delay" = 0 ] && delay=未设置 || delay="${start_delay}"
check_autostart && auto_set="\033[33m禁止" || auto_set="\033[32m允许"
[ "${BINDIR}" = "$CRASHDIR" ] && mini_clash=未开启 || mini_clash=已开启
[ -z "$network_check" ] && network_check=已开启
echo "-----------------------------------------------"
echo -e "\033[30;47m欢迎使用启动设置菜单\033[0m"
@@ -14,7 +28,7 @@ setboot() { #启动设置菜单
echo -e " 2 使用保守模式: \033[36m$start_old\033[0m ————基于定时任务(每分钟检测)"
echo -e " 3 设置自启延时: \033[36m$delay\033[0m ————用于解决自启后服务受限"
echo -e " 4 启用小闪存模式: \033[36m$mini_clash\033[0m ————用于闪存空间不足的设备"
[ "${BINDIR}" != "${CRASHDIR}" ] && echo -e " 5 设置小闪存目录: \033[36m${BINDIR}\033[0m"
[ "${BINDIR}" != "$CRASHDIR" ] && echo -e " 5 设置小闪存目录: \033[36m${BINDIR}\033[0m"
echo -e " 6 自启网络检查: \033[36m$network_check\033[0m ————禁用则跳过自启时网络检查"
echo "-----------------------------------------------"
echo -e " 0 \033[0m返回上级菜单\033[0m"
@@ -23,23 +37,13 @@ setboot() { #启动设置菜单
case "$num" in
0) ;;
1)
if [ "$autostart" = "enable" ]; then
if check_autostart; then
# 禁止自启动:删除各系统的启动项
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash >/dev/null 2>&1 && cd - >/dev/null
ckcmd systemctl && systemctl disable shellcrash.service >/dev/null 2>&1
grep -q 's6' /proc/1/comm && rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
rc-status -r >/dev/null 2>&1 && rc-update del shellcrash default >/dev/null 2>&1
touch ${CRASHDIR}/.dis_startup
autostart=disable
disable_autostart
echo -e "\033[33m已禁止ShellCrash开机启动\033[0m"
elif [ "$autostart" = "disable" ]; then
else
# 允许自启动:配置各系统的启动项
[ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ] && /etc/init.d/shellcrash enable
ckcmd systemctl && systemctl enable shellcrash.service >/dev/null 2>&1
grep -q 's6' /proc/1/comm && touch /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
rc-status -r >/dev/null 2>&1 && rc-update add shellcrash default >/dev/null 2>&1
rm -rf ${CRASHDIR}/.dis_startup
autostart=enable
allow_autostart
echo -e "\033[32m已设置ShellCrash开机启动\033[0m"
fi
setboot
@@ -47,20 +51,17 @@ setboot() { #启动设置菜单
2)
if [ "$start_old" = "未开启" ] >/dev/null 2>&1; then
echo -e "\033[33m改为使用保守模式启动服务\033[0m"
[ -d /etc/rc.d ] && cd /etc/rc.d && rm -rf *shellcrash >/dev/null 2>&1 && cd - >/dev/null
ckcmd systemctl && systemctl disable shellcrash.service >/dev/null 2>&1
grep -q 's6' /proc/1/comm && rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/afstart
rc-status -r >/dev/null 2>&1 && rc-update del shellcrash default >/dev/null 2>&1
disable_autostart
start_old=已开启
setconfig start_old $start_old
${CRASHDIR}/start.sh stop
setconfig start_old "$start_old"
"$CRASHDIR"/start.sh stop
else
if grep -qE 'procd|systemd|s6' /proc/1/comm || rc-status -r >/dev/null 2>&1; then
echo -e "\033[32m改为使用系统守护进程启动服务\033[0m"
${CRASHDIR}/start.sh cronset "ShellCrash初始化"
"$CRASHDIR"/start.sh cronset "ShellCrash初始化"
start_old=未开启
setconfig start_old $start_old
${CRASHDIR}/start.sh stop
setconfig start_old "$start_old"
"$CRASHDIR"/start.sh stop
else
echo -e "\033[31m当前设备不支持以其他模式启动\033[0m"
@@ -87,7 +88,7 @@ setboot() { #启动设置菜单
setboot
;;
4)
dir_size=$(df ${CRASHDIR} | awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' | grep Ava | awk '{print $2}')
dir_size=$(df "$CRASHDIR" | awk '{ for(i=1;i<=NF;i++){ if(NR==1){ arr[i]=$i; }else{ arr[i]=arr[i]" "$i; } } } END{ for(i=1;i<=NF;i++){ print arr[i]; } }' | grep Ava | awk '{print $2}')
if [ "$mini_clash" = "未开启" ]; then
if [ "$dir_size" -gt 20480 ]; then
echo -e "\033[33m您的设备空间充足(>20M),无需开启!\033[0m"
@@ -109,7 +110,7 @@ setboot() { #启动设置菜单
echo -e "\033[33m已经停用小闪存功能\033[0m"
fi
fi
setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env
setconfig BINDIR "$BINDIR" "$CRASHDIR"/configs/command.env
sleep 1
setboot
;;
@@ -151,7 +152,7 @@ setboot() { #启动设置菜单
errornum
;;
esac
setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env
setconfig BINDIR "$BINDIR" "$CRASHDIR"/configs/command.env
setboot
;;
6)
@@ -165,7 +166,7 @@ setboot() { #启动设置菜单
else
network_check=已禁用
fi
setconfig network_check $network_check
setconfig network_check "$network_check"
}
sleep 1
setboot