Files
ShellCrash/scripts/menus/providers.sh
2026-01-31 13:40:16 +08:00

104 lines
3.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Copyright (C) Juewuy
[ -n "$__IS_MODULE_PROVIDERS" ] && return
__IS_MODULE_PROVIDERS=1
if [ "$crashcore" = singboxr ]; then
CORE_TYPE=singbox
else
CORE_TYPE=clash
fi
providers() {
while true; do
# 获取模版名称
if [ -z "$(grep "provider_temp_${CORE_TYPE}" "$CRASHDIR"/configs/ShellCrash.cfg)" ]; then
provider_temp_des=$(sed -n "1 p" "$CRASHDIR"/configs/"${CORE_TYPE}"_providers.list | awk '{print $1}')
else
provider_temp_file=$(grep "provider_temp_${CORE_TYPE}" "$CRASHDIR"/configs/ShellCrash.cfg | awk -F '=' '{print $2}')
provider_temp_des=$(grep "$provider_temp_file" "$CRASHDIR"/configs/"${CORE_TYPE}"_providers.list | awk '{print $1}')
[ -z "$provider_temp_des" ] && provider_temp_des=$provider_temp_file
fi
top_box "1) \033[32m生成\033[0m包含全部提供者的配置文件" \
"2) 选择\033[33m规则模版\033[0m \033[32m$provider_temp_des\033[0m" \
"3) \033[33m清理\033[0mproviders目录文件" \
""
common_back
read -r -p "请输入对应字母或数字> " num
case "$num" in
"" | 0)
break
;;
1)
if [ -s "$CRASHDIR"/configs/providers.cfg ] || [ -s "$CRASHDIR"/configs/providers_uri.cfg ]; then
. "$CRASHDIR/menus/providers_$CORE_TYPE.sh"
gen_providers
else
msg_alert "\033[31m你还未添加链接或本地配置文件请先添加\033[0m"
fi
;;
2)
list=$(cat "$CRASHDIR/configs/${CORE_TYPE}_providers.list" | awk '{print $1}')
comp_box "当前规则模版为:\033[32m$provider_temp_des\033[0m" \
"\033[33m请选择在线模版\033[0m"
list_box "$list"
content_line ""
content_line "a) 使用\033[36m本地模版\033[0m"
content_line ""
common_back
read -r -p "请输入对应字母或数字> " num
case "$num" in
"" | 0) ;;
a)
echo ""
read -r -p "请输入模版的路径(绝对路径)> " dir
if [ -s "$dir" ]; then
provider_temp_file=$dir
if setconfig provider_temp_"$CORE_TYPE" "$provider_temp_file"; then
common_success
else
common_failed
fi
else
msg_alert "\033[31m输入错误找不到对应模版文件\033[0m"
fi
;;
*)
provider_temp_file=$(sed -n "$num p" "$CRASHDIR"/configs/"${CORE_TYPE}"_providers.list 2>/dev/null | awk '{print $2}')
if [ -z "$provider_temp_file" ]; then
errornum
else
if setconfig provider_temp_"$CORE_TYPE" "$provider_temp_file"; then
common_success
else
common_failed
fi
fi
;;
esac
;;
3)
comp_box "\033[33m将清空 $CRASHDIR/providers 目录下所有内容\033[0m" \
"" \
"是否继续?"
btm_box "1) 是" \
"0) 否"
read -r -p "$COMMON_INPUT> " res
if [ "$res" = "1" ]; then
if rm -rf "$CRASHDIR"/providers; then
common_success
else
common_failed
fi
fi
;;
*)
errornum
;;
esac
done
}