Merge branch 'dev' into patch-2

This commit is contained in:
Sofia
2026-01-15 03:00:25 +08:00
committed by GitHub
24 changed files with 1248 additions and 893 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
meta_v=v1.19.17 meta_v=v1.19.17
singboxr_v=1.13.0-alpha.27 singboxr_v=1.13.0-alpha.27
versionsh=1.9.4beta1.1 versionsh=1.9.4beta2
GeoIP_v=20251205 GeoIP_v=20251205

View File

@@ -1,16 +1,93 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (C) Juewuy # Copyright (C) Juewuy
# ================================= table format tools =================================
# >>>>>>>>>>>>>>
# set the total width of the menu
# (adjusting this number will automatically change the entire menu, including the separator lines)
# note: The number represents the number of columns that appear when the "||" appears on the right
TABLE_WIDTH=60
# define two extra-long template strings in advance
# (the length should be greater than the expected TABLE_WIDTH)
FULL_EQ="===================================================================================================="
FULL_DASH="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
# function to print content lines
# (using cursor jump)
content_line() {
echo -e " ${1}\033[${TABLE_WIDTH}G||"
}
# function to print sub content lines
# for printing accompanying instructions
sub_content_line() {
echo -e " ${1}\033[${TABLE_WIDTH}G||"
content_line
}
# increase the spacing between the front
# and back forms to improve readability
double_line_break() {
printf "\n\n"
}
# function to print separators
# (using string slicing)
# parameter $1: pass in "=" or "-"
separator_line() {
local separator_type="$1"
local output_line=""
local len=$((TABLE_WIDTH - 1))
if [ "$separator_type" == "=" ]; then
output_line="${FULL_EQ:0:$len}"
else
output_line="${FULL_DASH:0:$len}"
fi
echo "${output_line}||"
}
# <<<<<<<<<<<<<<
# ================================= table format tools =================================
# =============================== display prompt message ===============================
# >>>>>>>>>>>>>>
abort_install() {
double_line_break
separator_line "="
content_line "安装已取消"
separator_line "="
double_line_break
exit 1
}
invalid_input_retry() {
double_line_break
separator_line "="
content_line "\033[31m输入错误\033[0m"
content_line "\033[31m请重新设置\033[0m"
separator_line "="
sleep 1
}
# <<<<<<<<<<<<<<
# =============================== display prompt message ===============================
[ -z "$url" ] && url="https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@dev" [ -z "$url" ] && url="https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@dev"
type bash &>/dev/null && shtype=bash || shtype=sh type bash &>/dev/null && shtype=bash || shtype=sh
[ -n "$(echo -e | grep e)" ] && echo=echo || echo='echo -e'
echo "***********************************************"
echo "** 欢迎使用 **"
echo "** ShellCrash **"
echo "** by Juewuy **"
echo "***********************************************"
# Check available capacity error_down() {
content_line "\033[33m请参考\033[0m"
content_line "\033[33mgithub.com/juewuy/ShellCrash/blob/master/README_CN.md\033[0m"
content_line "\033[33m或使用其他安装源重新安装\033[0m"
}
# check available capacity
dir_avail() { dir_avail() {
df -h >/dev/null 2>&1 && h="$2" df -h >/dev/null 2>&1 && h="$2"
df -P $h "${1:-.}" 2>/dev/null | awk 'NR==2 {print $4}' df -P $h "${1:-.}" 2>/dev/null | awk 'NR==2 {print $4}'
@@ -31,8 +108,18 @@ webget() {
if curl --version >/dev/null 2>&1; then if curl --version >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-s' || progress='-#' [ "$3" = "echooff" ] && progress='-s' || progress='-#'
[ -z "$4" ] && redirect='-L' || redirect='' [ -z "$4" ] && redirect='-L' || redirect=''
result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2) result=$(curl -w %{http_code} --connect-timeout 5 "$progress" "$redirect" -ko "$1" "$2")
[ -n "$(echo $result | grep -e ^2)" ] && result="200"
# === original version ===
# [ -n "$(echo $result | grep -e ^2)" ] && result="200"
# === fixed version ===
# strictly match the 200 status code to avoid 204 (empty content)
# or 202 being mistakenly interpreted as success
if [ "$result" = "200" ]; then
result="200"
fi
else else
if wget --version >/dev/null 2>&1; then if wget --version >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress' [ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
@@ -42,33 +129,26 @@ webget() {
fi fi
[ "$3" = "echoon" ] && progress='' [ "$3" = "echoon" ] && progress=''
[ "$3" = "echooff" ] && progress='-q' [ "$3" = "echooff" ] && progress='-q'
wget $progress $redirect $certificate $timeout -O $1 $2 wget "$progress" "$redirect" "$certificate" "$timeout" -O "$1" "$2"
[ $? -eq 0 ] && result="200" [ $? -eq 0 ] && result="200"
fi fi
} }
error_down() {
$echo "请参考 \033[32mhttps://github.com/juewuy/ShellCrash/blob/master/README_CN.md"
$echo "\033[33m使用其他安装源重新安装\033[0m"
}
# 安装及初始化 # 安装及初始化
set_alias() { set_alias() {
while true; do while true; do
echo "-----------------------------------------------" double_line_break
$echo "\033[36m请选择一个别名或使用自定义别名\033[0m" separator_line "="
echo "-----------------------------------------------" content_line "\033[36m请选择一个别名\033[0m"
$echo " 1 【\033[32mcrash\033[0m" content_line "\033[36m或直接输入自定义别名\033[0m"
$echo " 2 【\033[32m sc \033[0m】" separator_line "-"
$echo " 3 【\033[32m mm \033[0m】" content_line "1) 【\033[32mcrash\033[0m】"
$echo " 0 退出安装" content_line "2) 【\033[32m sc \033[0m】"
echo "-----------------------------------------------" content_line "3) 【\033[32m mm \033[0m】"
read -p "请输入相应数字或自定义别名 > " res content_line "E) 退出安装"
separator_line "="
read -p "请输入相应数字/自定义别名> " res
case "$res" in case "$res" in
0)
echo "安装已取消"
exit 1
;;
1) 1)
my_alias=crash my_alias=crash
;; ;;
@@ -78,41 +158,62 @@ set_alias() {
3) 3)
my_alias=mm my_alias=mm
;; ;;
"E" | "e")
abort_install
;;
*) *)
my_alias=$res my_alias=$res
;; ;;
esac esac
cmd=$(ckcmd "$my_alias" | grep 'menu.sh') cmd=$(ckcmd "$my_alias" | grep 'menu.sh')
ckcmd "$my_alias" && [ -z "$cmd" ] && { ckcmd "$my_alias" && [ -z "$cmd" ] && {
$echo "\033[33m此别名和当前系统内置命令/别名冲突,请换一个!\033[0m" double_line_break
separator_line "="
content_line "该别名【\033[32m$my_alias\033[0m】和当前系统内置命令别名\033[33m冲突\033[0m请更换"
separator_line "="
sleep 1 sleep 1
continue continue
} }
break break 1
done done
} }
gettar() { gettar() {
webget /tmp/ShellCrash.tar.gz "$url/ShellCrash.tar.gz" webget /tmp/ShellCrash.tar.gz "$url/ShellCrash.tar.gz" >/dev/null 2>&1
if [ "$result" != "200" ]; then if [ "$result" != "200" ]; then
$echo "\033[33m文件下载失败!\033[0m" content_line "\033[31m下载失败!\033[0m"
error_down error_down
separator_line "="
double_line_break
exit 1 exit 1
else else
$CRASHDIR/start.sh stop 2>/dev/null content_line "下载成功"
"$CRASHDIR"/start.sh stop 2>/dev/null
# 解压 # 解压
echo "-----------------------------------------------" content_line "开始解压文件......"
echo "开始解压文件!" mkdir -p "$CRASHDIR" >/dev/null
mkdir -p $CRASHDIR >/dev/null tar -zxf '/tmp/ShellCrash.tar.gz' -C "$CRASHDIR"/ || tar -zxf '/tmp/ShellCrash.tar.gz' --no-same-owner -C "$CRASHDIR"/
tar -zxf '/tmp/ShellCrash.tar.gz' -C $CRASHDIR/ || tar -zxf '/tmp/ShellCrash.tar.gz' --no-same-owner -C $CRASHDIR/ if [ -s "$CRASHDIR"/init.sh ]; then
if [ -s $CRASHDIR/init.sh ]; then content_line "解压成功"
separator_line "="
set_alias set_alias
. $CRASHDIR/init.sh >/dev/null . $CRASHDIR/init.sh >/dev/null
[ "$?" != 0 ] && $echo "\033[33m初始化失败请尝试本地安装\033[0m" && exit 1 if [ $? != 0 ]; then
content_line "\033[31m初始化失败请尝试本地安装\033[0m"
separator_line "="
double_line_break
exit 1
fi
else else
rm -rf /tmp/ShellCrash.tar.gz rm -rf /tmp/ShellCrash.tar.gz
$echo "\033[33m文件解压失败!\033[0m" content_line "\033[31m解压失败!\033[0m"
error_down error_down
separator_line "="
double_line_break
exit 1 exit 1
fi fi
fi fi
@@ -120,62 +221,162 @@ gettar() {
set_usb_dir() { set_usb_dir() {
while true; do while true; do
$echo "请选择安装目录" double_line_break
du -hL /mnt | awk '{print " "NR" "$2" "$1}' separator_line "="
read -p "请输入相应数字 > " num content_line "请选择安装目录:"
dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) separator_line "-"
if [ -z "$dir" ]; then
$echo "\033[31m输入错误请重新设置\033[0m" # original version
continue # du -hL /mnt | awk '{print " "NR" "$2" "$1}'
fi du -hL /mnt |
break 1 awk '{print NR") "$2" (已用空间:"$1""}' |
while IFS= read -r line; do
content_line "$line"
done
content_line "0) 返回上级菜单"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in
0)
return 1
;;
*)
dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p)
if [ -z "$dir" ]; then
invalid_input_retry
continue
fi
return 0
;;
esac
done done
} }
set_asus_dir() { set_asus_dir() {
while true; do while true; do
echo -e "请选择U盘目录" double_line_break
du -hL /tmp/mnt | awk -F/ 'NF<=4' | awk '{print " "NR" "$2" "$1}' separator_line "="
read -p "请输入相应数字 > " num content_line "请选择U盘目录"
dir=$(du -hL /tmp/mnt | awk -F/ 'NF<=4' | awk '{print $2}' | sed -n "$num"p) separator_line "-"
if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ]; then
echo -e "\033[31m未找到下载大师自启文件$dir/asusware.arm/etc/init.d/S50downloadmaster请检查设置\033[0m" # original version
continue # du -hL /tmp/mnt | awk -F/ 'NF<=4' | awk '{print " "NR" "$2" "$1}'
fi du -hL /tmp/mnt |
break 1 awk -F/ 'NF<=4 {print NR") "$2" (已用空间:"$1""}' |
while IFS= read -r line; do
content_line "$line"
done
content_line "0) 返回上级菜单"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in
0)
return 1
;;
*)
dir=$(du -hL /tmp/mnt | awk -F/ 'NF<=4' | awk '{print $2}' | sed -n "$num"p)
if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ]; then
double_line_break
separator_line "="
content_line "\033[33m未找到下载大师自启文件\033[0m"
content_line "\033[33m$dir/asusware.arm/etc/init.d/S50downloadmaster\033[0m"
content_line "\033[33m请检查设置\033[0m"
separator_line "="
continue
fi
return 0
;;
esac
done done
} }
set_cust_dir() { set_cust_dir() {
while true; do while true; do
echo "-----------------------------------------------" double_line_break
echo '可用路径 剩余空间:' separator_line "="
df -h | awk '{print $6,$4}' | sed 1d content_line "\033[33m注意\033[0m"
echo '路径必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' content_line "\033[33m路径必须带 / 的格式\033[0m"
read -p "请输入自定义路径 > " dir content_line "\033[33m写入虚拟内存/tmp/opt/sys...)的文件会在重启后消失!\033[0m"
if [ "$(dir_avail $dir)" = 0 ] || [ -n "$(echo $dir | grep -E 'tmp|opt|sys')" ]; then separator_line "-"
$echo "\033[31m路径错误请重新设置\033[0m" content_line "参考路经:"
continue separator_line "-"
fi
break 1 # original version
# df -h | awk '{print $6,$4}' | sed 1d
df -h |
awk 'NR>1 {
path="";
for(i=6;i<=NF;i++) path=path $i " ";
sub(/ $/, "", path);
print path "|" $4
}' |
while IFS='|' read -r mount_point path_avail; do
if [ -n "$mount_point" ]; then
i=$((i + 1))
printf -v line_content "%-3s %s" "$i)" "$mount_point"
content_line "$line_content"
sub_content_line " (可用空间:$path_avail"
fi
done
content_line "0) 返回上级菜单"
separator_line "="
read -p "请输入自定义路径> " dir
case "$dir" in
0)
return 1
;;
*)
if [ "$(dir_avail "$dir")" = 0 ] || [ -n "$(echo "$dir" | grep -E 'tmp|opt|sys')" ]; then
invalid_input_retry
continue
fi
return 0
;;
esac
done done
} }
setdir() { setdir() {
while true; do while true; do
echo "-----------------------------------------------" double_line_break
$echo "\033[33m注意安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" separator_line "="
content_line "\033[33m注意\033[0m"
content_line "\033[33m安装ShellCrash至少需要预留约 1MB 的磁盘空间\033[0m"
if [ -n "$systype" ]; then if [ -n "$systype" ]; then
[ "$systype" = "Padavan" ] && dir=/etc/storage [ "$systype" = "Padavan" ] && dir=/etc/storage
[ "$systype" = "mi_snapshot" ] && { [ "$systype" = "mi_snapshot" ] && {
$echo "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" content_line "\033[33m检测到当前设备为小米官方系统\033[0m"
[ -d /data ] && $echo " 1 安装到 /data 目录,剩余空间:$(dir_avail /data -h)(支持软固化功能)"
[ -d /userdisk ] && $echo " 2 安装到 /userdisk 目录,剩余空间:$(dir_avail /userdisk -h)(支持软固化功能)" separator_line "-"
[ -d /data/other_vol ] && $echo " 3 安装到 /data/other_vol 目录,剩余空间:$(dir_avail /data/other_vol -h)(支持软固化功能)" content_line "请选择安装位置:"
$echo " 4 安装到自定义目录(不推荐,不明勿用!)" separator_line "-"
$echo " 0 退出安装"
echo "-----------------------------------------------" if [ -d /data ]; then
read -p "请输入相应数字 > " num content_line "1) 安装到 /data 目录"
sub_content_line "剩余空间:$(dir_avail /data -h)(支持软固化功能)"
fi
if [ -d /userdisk ]; then
content_line "2) 安装到 /userdisk 目录"
sub_content_line "剩余空间:$(dir_avail /userdisk -h)(支持软固化功能)"
fi
if [ -d /data/other_vol ]; then
content_line "3) 安装到 /data/other_vol 目录"
sub_content_line "剩余空间:$(dir_avail /data/other_vol -h)(支持软固化功能)"
fi
content_line "4) 安装到自定义目录"
sub_content_line "(不推荐,不明勿用!)"
content_line "E) 退出安装"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in case "$num" in
1) 1)
dir=/data dir=/data
@@ -188,51 +389,104 @@ setdir() {
;; ;;
4) 4)
set_cust_dir set_cust_dir
ret=$?
[ "$ret" -eq 1 ] && continue
;;
"E" | "e")
abort_install
;; ;;
*) *)
exit 1 invalid_input_retry
continue
;; ;;
esac esac
} }
[ "$systype" = "asusrouter" ] && { [ "$systype" = "asusrouter" ] && {
$echo "\033[33m检测到当前设备为华硕固件请选择安装方式\033[0m"
$echo " 1 基于USB设备安装(限23年9月之前固件须插入\033[31m任意\033[0mUSB设备)" content_line "\033[33m检测到当前设备为华硕固件\033[0m"
$echo " 2 基于自启脚本安装(仅支持梅林及部分非koolshare官改固件)" separator_line "-"
$echo " 3 基于U盘+下载大师安装(支持所有固件限ARM设备须插入U盘或移动硬盘)" content_line "请选择安装方式:"
$echo " 0 退出安装" separator_line "-"
echo "-----------------------------------------------"
read -p "请输入相应数字 > " num content_line "1) 基于USB设备安装"
sub_content_line "限23年9月之前固件须插入任意USB设备"
content_line "2) 基于自启脚本安装"
sub_content_line "仅支持梅林及部分非koolshare官改固件"
content_line "3) 基于U盘 + 下载大师安装"
sub_content_line "支持所有固件限ARM设备须插入U盘或移动硬盘"
content_line "E) 退出安装"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in case "$num" in
1) 1)
read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res double_line_break
[ "$res" = "1" ] && set_usb_dir || dir=/jffs separator_line "="
content_line "请选择脚本安装位置:"
separator_line "-"
content_line "1) USB存储"
content_line "2) 系统闪存"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in
1)
set_usb_dir
;;
*)
dir=/jffs
;;
esac
usb_status=1 usb_status=1
;; ;;
2) 2)
$echo "如无法正常开机启动请重新使用USB方式安装" double_line_break
separator_line "="
content_line "如无法正常开机启动请重新使用USB方式安装"
separator_line "="
sleep 2 sleep 2
dir=/jffs dir=/jffs
;; ;;
3) 3)
echo -e "请先在路由器网页后台安装下载大师并启用,之后选择外置存储所在目录!" double_line_break
separator_line "="
content_line "请先在路由器网页后台安装下载大师并启用,"
content_line "之后选择外置存储所在目录!"
separator_line "="
sleep 2 sleep 2
set_asus_dir set_asus_dir
ret=$?
[ "$ret" -eq 1 ] && continue
;;
"E" | "e")
abort_install
;; ;;
*) *)
exit 1 invalid_input_retry
continue
;; ;;
esac esac
} }
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
else else
$echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" separator_line "-"
$echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" content_line "请选择安装目录:"
$echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" separator_line "-"
$echo " 4 在\033[32m外置存储\033[0m中安装" content_line "1) \033[32m/etc目录\033[0m 适合root用户"
$echo " 5 手动设置安装目录" content_line "2) \033[32m/usr/share目录\033[0m 适合Linux系统"
$echo " 0 退出安装" content_line "3) \033[32m当前用户目录\033[0m 适合非root用户"
echo "----------------------------------------------" content_line "4) \033[32m外置存储\033[0m"
read -p "请输入相应数字 > " num content_line "5) 手动设置"
content_line "E) 退出安装"
separator_line "="
read -p "请输入相应数字> " num
# 设置目录 # 设置目录
case "$num" in case "$num" in
1) 1)
@@ -247,87 +501,173 @@ setdir() {
;; ;;
4) 4)
set_usb_dir set_usb_dir
ret=$?
[ "$ret" -eq 1 ] && continue
;; ;;
5) 5)
set_cust_dir set_cust_dir
ret=$?
[ "$ret" -eq 1 ] && continue
;;
"E" | "e")
abort_install
;; ;;
*) *)
echo "安装已取消" invalid_input_retry
exit 1 continue
;; ;;
esac esac
fi fi
if [ ! -w $dir ]; then if [ ! -w "$dir" ]; then
$echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" double_line_break
sleep 1 separator_line "="
content_line "\033[31m没有$dir目录写入权限\033[0m"
content_line "\033[31m请重新设置\033[0m"
separator_line "="
sleep 2
else else
$echo "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)" while true; do
read -p "确认安装?(1/0) > " res double_line_break
if [ "$res" = "1" ]; then separator_line "="
CRASHDIR=$dir/ShellCrash content_line "目标目录:\033[32m$dir\033[0m"
break content_line "可用空间:$(dir_avail $dir -h)"
fi separator_line "-"
content_line "1) 确认安装"
content_line "E) 退出安装"
content_line "0) 返回上级菜单"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in
0)
break 1
;;
1)
CRASHDIR="${dir}/ShellCrash"
break 2
;;
"E" | "e")
abort_install
;;
*)
invalid_input_retry
continue
;;
esac
done
fi fi
done done
} }
install() { install() {
echo "-----------------------------------------------" double_line_break
echo "开始从服务器获取安装文件!" separator_line "="
echo "-----------------------------------------------" content_line "下载安装文件......"
gettar gettar
echo "-----------------------------------------------" double_line_break
echo "ShellCrash 已经安装成功!" separator_line "="
[ "$profile" = "~/.bashrc" ] && echo "请执行【. ~/.bashrc > /dev/null】命令以更新环境变量" content_line "ShellCrash 已经安装成功"
[ -n "$(ls -l /bin/sh | grep -oE 'zsh')" ] && echo "请执行【. ~/.zshrc > /dev/null】命令以更新环境变量" [ "$profile" = "~/.bashrc" ] && content_line "请执行【. ~/.bashrc > /dev/null】命令以更新环境变量"
echo "-----------------------------------------------" [ -n "$(ls -l /bin/sh | grep -oE 'zsh')" ] && content_line "请执行【. ~/.zshrc > /dev/null】命令以更新环境变量"
$echo "\033[33m输入\033[30;47m $my_alias \033[0;33m命令即可管理\033[0m" content_line "输入\033[32m $my_alias \033[0m命令即可管理"
echo "-----------------------------------------------" separator_line "="
double_line_break
} }
setversion() { setversion() {
echo "-----------------------------------------------" while true; do
$echo "\033[33m请选择想要安装的版本\033[0m" double_line_break
$echo " 1 \033[32m公测版(推荐)\033[0m" separator_line "="
$echo " 2 \033[36m稳定版\033[0m" content_line "请选择安装版本:"
$echo " 3 \033[31m开发版\033[0m" separator_line "-"
echo "-----------------------------------------------" content_line "1) \033[32m公测版推荐\033[0m"
read -p "请输入相应数字 > " num content_line "2) \033[36m稳定版\033[0m"
case "$num" in content_line "3) \033[31m开发版\033[0m"
2) content_line "E) 退出安装"
url=$(echo $url | sed 's/master/stable/') separator_line "="
;; read -p "请输入相应数字> " num
3) case "$num" in
url=$(echo $url | sed 's/master/dev/') 1)
;; break 1
*) ;; ;;
esac 2)
url=$(echo "$url" | sed 's/master/stable/')
break 1
;;
3)
url=$(echo "$url" | sed 's/master/dev/')
break 1
;;
"E" | "e")
abort_install
;;
*)
invalid_input_retry
continue
;;
esac
done
} }
# =============================== the script start here ================================
# clean screen
printf "\033[H\033[2J"
double_line_break
separator_line "="
content_line " 欢迎使用"
content_line " ShellCrash"
content_line
content_line " 支持各种基于 openwrt 的路由器设备"
content_line " 支持Debian、Centos等标准 Linux 系统"
content_line " 如遇问题请加TG群反馈t.me/ShellClash"
content_line
content_line " by Juewuy"
separator_line "="
# 特殊固件识别及标记 # 特殊固件识别及标记
[ -f "/etc/storage/started_script.sh" ] && { [ -f "/etc/storage/started_script.sh" ] && {
systype=Padavan #老毛子固件 systype=Padavan # 老毛子固件
initdir='/etc/storage/started_script.sh' initdir='/etc/storage/started_script.sh'
} }
[ -d "/jffs" ] && { [ -d "/jffs" ] && {
systype=asusrouter #华硕固件 systype=asusrouter # 华硕固件
[ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter' [ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter'
[ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start' [ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start'
} }
[ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备 [ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot # 小米设备
[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 [ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot # NETGEAR设备
# 检查root权限 # 检查root权限
if [ "$USER" != "root" -a -z "$systype" ]; then if [ "$USER" != "root" ] && [ -z "$systype" ]; then
echo "当前用户:$USER" while true; do
$echo "\033[31m请尽量使用root用户不要直接使用sudo命令执行安装!\033[0m" double_line_break
echo "-----------------------------------------------" separator_line "="
read -p "仍要安装?可能会产生未知错误!(1/0) > " res content_line "当前用户 $USER 非 root 用户"
[ "$res" != "1" ] && exit 1 content_line "\033[33m请尽量使用 root 用户不要直接使用sudo命令执行安装\033[0m"
content_line "\033[31m继续安装可能会产生未知错误\033[0m"
separator_line "-"
content_line "1) 继续安装"
content_line "E) 退出安装"
separator_line "="
read -p "请输入相应数字> " num
case "$num" in
1)
break 1
;;
"E" | "e")
abort_install
;;
*)
invalid_input_retry
continue
;;
esac
done
fi fi
if [ -n "$(echo $url | grep master)" ]; then if [ -n "$(echo "$url" | grep master)" ]; then
setversion setversion
fi fi
@@ -337,38 +677,61 @@ webget /tmp/version "$url/version" echooff
rm -rf /tmp/version rm -rf /tmp/version
# 输出 # 输出
$echo "最新版本:\033[32m$versionsh\033[0m" double_line_break
echo "-----------------------------------------------" separator_line "="
$echo "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/ShellClash \033[0m" content_line "最新版本:\033[32m$versionsh\033[0m"
$echo "\033[37m支持各种基于openwrt的路由器设备" separator_line "="
$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m"
if [ -n "$CRASHDIR" ]; then if [ -n "$CRASHDIR" ]; then
echo "-----------------------------------------------" while true; do
$echo "检测到旧的安装目录\033[36m$CRASHDIR\033[0m是否覆盖安装" double_line_break
$echo "\033[32m覆盖安装时不会移除配置文件\033[0m" separator_line "="
read -p "覆盖安装/卸载旧版本?(1/0) > " res content_line "检测到旧版本安装目录:\033[36m$CRASHDIR\033[0m"
case "$res" in content_line "\033[33m注意覆盖安装时不会移除配置文件\033[0m"
1) separator_line "-"
install content_line "1) 覆盖安装"
;; content_line "2) 卸载旧版本"
0) content_line "E) 退出安装"
rm -rf $CRASHDIR separator_line "="
echo "-----------------------------------------------" read -p "请输入相应数字> " num
$echo "\033[31m 旧版本文件已卸载!\033[0m" case "$num" in
setdir 1)
install install
;; break 1
9) ;;
echo "测试模式,变更安装位置" 2)
setdir rm -rf "$CRASHDIR"
install
;; double_line_break
*) separator_line "="
$echo "\033[31m输入错误!已取消安装\033[0m" content_line "\033[31m旧版本文件已卸载\033[0m"
exit 1 separator_line "="
;;
esac setdir
install
break 1
;;
9)
double_line_break
separator_line "="
content_line "测试模式,变更安装位置"
separator_line "="
setdir
install
break 1
;;
"E" | "e")
abort_install
;;
*)
invalid_input_retry
continue
;;
esac
done
else else
setdir setdir
install install

View File

@@ -102,7 +102,7 @@ grep -q 'firewall_mod' "$CRASHDIR/configs/ShellClash.cfg" 2>/dev/null || {
#设置更新地址 #设置更新地址
[ -n "$url" ] && setconfig update_url $url [ -n "$url" ] && setconfig update_url $url
#设置环境变量 #设置环境变量
[ -w /opt/etc/profile ] && profile=/opt/etc/profile [ -w /opt/etc/profile ] && [ "$systype" = "Padavan" ] && profile=/opt/etc/profile
[ -w /jffs/configs/profile.add ] && profile=/jffs/configs/profile.add [ -w /jffs/configs/profile.add ] && profile=/jffs/configs/profile.add
[ -z "$profile" ] && profile=/etc/profile [ -z "$profile" ] && profile=/etc/profile
if [ -n "$profile" ]; then if [ -n "$profile" ]; then

View File

@@ -0,0 +1,11 @@
# ===== 启动完成 =====
START_SERVICE_OK="服务已启动!"
START_WEB_HINT="请使用"
START_WEB_HINT2="管理内置规则"
START_PAC_HINT="其他设备可使用 PAC 配置:"
START_PROXY_HINT="或使用 HTTP / SOCKS5 方式连接:"
# ===== 启动流程 =====
START_NO_CORE_CFG_TRY_GEN="没有找到核心配置文件,尝试生成 providers 配置文件!"
START_NO_CORE_CFG_IMPORT_FIRST="没有找到核心配置文件,请先导入配置文件!"
START_FIREWALL_DONE="已完成防火墙设置!"

View File

@@ -0,0 +1,11 @@
# ===== Startup =====
START_SERVICE_OK="Service started successfully!"
START_WEB_HINT="Please use"
START_WEB_HINT2="manage built-in rules"
START_PAC_HINT="Other devices can connect using PAC configuration:"
START_PROXY_HINT="Or connect using HTTP / SOCKS5:"
# ===== Startup Flow =====
START_NO_CORE_CFG_TRY_GEN="Core configuration not found. Attempting to generate providers configuration!"
START_NO_CORE_CFG_IMPORT_FIRST="Core configuration not found. Please import a configuration first!"
START_FIREWALL_DONE="Firewall configuration completed!"

View File

@@ -3,6 +3,7 @@ setproxy(){
[ -n "$(pidof CrashCore)" ] && { [ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth="" [ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890 [ -z "$mix_port" ] && mix_port=7890
export all_proxy="http://${auth}127.0.0.1:$mix_port" export https_proxy="http://${auth}127.0.0.1:$mix_port"
export http_proxy="http://${auth}127.0.0.1:$mix_port"
} }
} }

View File

@@ -32,7 +32,8 @@ webget(){
result=$(curl $agent -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url") result=$(curl $agent -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url")
fi fi
[ "$result" = "200" ] && return 0 #成功则退出否则重试 [ "$result" = "200" ] && return 0 #成功则退出否则重试
export all_proxy="" export https_proxy=""
export http_proxy=""
result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2") result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2")
[ "$result" = "200" ] [ "$result" = "200" ]
return $? return $?

View File

@@ -20,11 +20,13 @@ web_save() { #最小化保存面板节点选择
} }
done <"$TMPDIR"/web_proxies done <"$TMPDIR"/web_proxies
rm -rf "$TMPDIR"/web_proxies rm -rf "$TMPDIR"/web_proxies
#对比文件,如果有变动且不为空则写入磁盘,否则清除缓存 #对比文件,如果有变动则写入磁盘,否则清除缓存
for file in web_save web_configs; do for file in web_save; do
if [ -s "$TMPDIR"/${file} ]; then if [ -s "$TMPDIR/$file" ]; then
. "$CRASHDIR"/libs/compare.sh && compare "$TMPDIR"/${file} "$CRASHDIR"/configs/${file} . "$CRASHDIR"/libs/compare.sh && compare "$TMPDIR/$file" "$CRASHDIR/configs/$file"
[ "$?" = 0 ] && rm -rf "$TMPDIR"/${file} || mv -f "$TMPDIR"/${file} "$CRASHDIR"/configs/${file} [ "$?" = 0 ] && rm -f "$TMPDIR/$file" || mv -f "$TMPDIR/$file" "$CRASHDIR/configs/$file"
else
rm -f "$CRASHDIR/configs/$file" #空文件时移除旧文件
fi fi
done done
} }

View File

@@ -159,88 +159,82 @@ ckstatus() { #脚本启动前检查
} }
main_menu() { main_menu() {
ckstatus while true; do
ckstatus
echo -e " 1 \033[32m$MENU_MAIN_1\033[0m" echo -e " 1 \033[32m$MENU_MAIN_1\033[0m"
echo -e " 2 \033[36m$MENU_MAIN_2\033[0m" echo -e " 2 \033[36m$MENU_MAIN_2\033[0m"
echo -e " 3 \033[31m$MENU_MAIN_3\033[0m" echo -e " 3 \033[31m$MENU_MAIN_3\033[0m"
echo -e " 4 \033[33m$MENU_MAIN_4\033[0m" echo -e " 4 \033[33m$MENU_MAIN_4\033[0m"
echo -e " 5 \033[32m$MENU_MAIN_5\033[0m" echo -e " 5 \033[32m$MENU_MAIN_5\033[0m"
echo -e " 6 \033[36m$MENU_MAIN_6\033[0m" echo -e " 6 \033[36m$MENU_MAIN_6\033[0m"
echo -e " 7 \033[33m$MENU_MAIN_7\033[0m" echo -e " 7 \033[33m$MENU_MAIN_7\033[0m"
echo -e " 8 $MENU_MAIN_8" echo -e " 8 $MENU_MAIN_8"
echo -e " 9 \033[32m$MENU_MAIN_9\033[0m" echo -e " 9 \033[32m$MENU_MAIN_9\033[0m"
echo "-----------------------------------------------"
echo -e " 0 $MENU_MAIN_0"
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
main_menu
;;
3)
[ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop
"$CRASHDIR"/start.sh stop
sleep 1
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m" echo -e " 0 $MENU_MAIN_0"
main_menu
;; read -p "$MENU_MAIN_PROMPT" num
4)
. "$CRASHDIR"/menus/4_setboot.sh && setboot case "$num" in
main_menu "" | 0)
;; exit
5) ;;
. "$CRASHDIR"/menus/5_task.sh && task_menu 1)
main_menu start_service
;; exit
6) ;;
. "$CRASHDIR"/menus/6_core_config.sh && set_core_config 2)
main_menu checkcfg=$(cat "$CFG_PATH")
;; . "$CRASHDIR"/menus/2_settings.sh && settings
7) if [ -n "$PID" ]; then
GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg checkcfg_new=$(cat "$CFG_PATH")
touch "$GT_CFG_PATH" [ "$checkcfg" != "$checkcfg_new" ] && checkrestart
checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH") fi
. "$CRASHDIR"/menus/7_gateway.sh && gateway ;;
if [ -n "$PID" ]; then 3)
checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH") [ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_stop
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart "$CRASHDIR"/start.sh stop
fi sleep 1
main_menu echo "-----------------------------------------------"
;; echo -e "\033[31m$corename$MENU_SERVICE_STOPPED\033[0m"
8) ;;
. "$CRASHDIR"/menus/8_tools.sh && tools 4)
main_menu . "$CRASHDIR"/menus/4_setboot.sh && setboot
;; ;;
9) 5)
checkcfg=$(cat "$CFG_PATH") . "$CRASHDIR"/menus/5_task.sh && task_menu
. "$CRASHDIR"/menus/9_upgrade.sh && upgrade ;;
if [ -n "$PID" ]; then 6)
checkcfg_new=$(cat "$CFG_PATH") . "$CRASHDIR"/menus/6_core_config.sh && set_core_config
[ "$checkcfg" != "$checkcfg_new" ] && checkrestart ;;
fi 7)
main_menu GT_CFG_PATH="$CRASHDIR"/configs/gateway.cfg
;; touch "$GT_CFG_PATH"
*) checkcfg=$(cat "$CFG_PATH" "$GT_CFG_PATH")
errornum . "$CRASHDIR"/menus/7_gateway.sh && gateway
exit if [ -n "$PID" ]; then
;; checkcfg_new=$(cat "$CFG_PATH" "$GT_CFG_PATH")
esac [ "$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 case "$1" in

View File

@@ -3,49 +3,65 @@
[ -n "$__IS_MODULE_1_START_LOADED" ] && return [ -n "$__IS_MODULE_1_START_LOADED" ] && return
__IS_MODULE_1_START_LOADED=1 __IS_MODULE_1_START_LOADED=1
load_lang 1_start
#启动相关 # ===== 启动完成提示 =====
startover() { startover() {
echo -ne " \r" echo -ne " \r"
echo -e "\033[32m服务已启动!\033[0m" echo -e "\033[32m$START_SERVICE_OK\033[0m"
echo -e "请使用 \033[4;36mhttp://$host$hostdir\033[0m 管理内置规则" echo -e "$START_WEB_HINT \033[4;36mhttp://$host$hostdir\033[0m $START_WEB_HINT2"
if [ "$redir_mod" = "纯净模式" ]; then if [ "$redir_mod" = "纯净模式" ]; then
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "其他设备可以使用PAC配置连接\033[4;32mhttp://$host:$db_port/ui/pac\033[0m" echo -e "$START_PAC_HINT \033[4;32mhttp://$host:$db_port/ui/pac\033[0m"
echo -e "或者使用HTTP/SOCK5方式连接IP{\033[36m$host\033[0m}Port{\033[36m$mix_port\033[0m}" echo -e "$START_PROXY_HINT IP{\033[36m$host\033[0m} Port{\033[36m$mix_port\033[0m}"
fi fi
return 0 return 0
} }
# ===== 启动核心 =====
start_core() { start_core() {
if echo "$crashcore" | grep -q 'singbox'; then if echo "$crashcore" | grep -q 'singbox'; then
core_config="$CRASHDIR"/jsons/config.json core_config="$CRASHDIR/jsons/config.json"
else else
core_config="$CRASHDIR"/yamls/config.yaml core_config="$CRASHDIR/yamls/config.yaml"
fi fi
echo "-----------------------------------------------" echo "-----------------------------------------------"
if [ ! -s $core_config -a -s "$CRASHDIR"/configs/providers.cfg ]; then
echo -e "\033[33m没有找到${crashcore}配置文件尝试生成providers配置文件\033[0m" if [ ! -s "$core_config" ] && [ -s "$CRASHDIR/configs/providers.cfg" ]; then
echo -e "\033[33m$START_NO_CORE_CFG_TRY_GEN\033[0m"
[ "$crashcore" = singboxr ] && coretype=singbox [ "$crashcore" = singboxr ] && coretype=singbox
[ "$crashcore" = meta -o "$crashcore" = clashpre ] && coretype=clash [ "$crashcore" = meta -o "$crashcore" = clashpre ] && coretype=clash
. "$CRASHDIR"/menus/6_core_config.sh && gen_${coretype}_providers
elif [ -s $core_config -o -n "$Url" -o -n "$Https" ]; then . "$CRASHDIR/menus/6_core_config.sh" && gen_${coretype}_providers
"$CRASHDIR"/start.sh start
#设置循环检测以判定服务启动是否成功 elif [ -s "$core_config" ] || [ -n "$Url" ] || [ -n "$Https" ]; then
. "$CRASHDIR"/libs/start_wait.sh "$CRASHDIR/start.sh" start
[ -n "$test" -o -n "$(pidof CrashCore)" ] && {
#启动TG机器人 # 循环检测服务启动状态
[ "$bot_tg_service" = ON ] && . "$CRASHDIR"/menus/bot_tg_service.sh && bot_tg_start . "$CRASHDIR/libs/start_wait.sh"
startover
} [ -n "$test" ] || pidof CrashCore >/dev/null && {
# 启动 TG 机器人
if [ "$bot_tg_service" = ON ]; then
. "$CRASHDIR/menus/bot_tg_service.sh" && bot_tg_start
fi
startover
}
else else
echo -e "\033[31m没有找到${crashcore}配置文件,请先导入配置文件!\033[0m" echo -e "\033[31m$START_NO_CORE_CFG_IMPORT_FIRST\033[0m"
. "$CRASHDIR"/menus/6_core_config.sh && set_core_config . "$CRASHDIR/menus/6_core_config.sh" && set_core_config
fi fi
} }
# ===== 启动服务入口 =====
start_service() { start_service() {
if [ "$firewall_area" = 5 ]; then if [ "$firewall_area" = 5 ]; then
"$CRASHDIR"/start.sh start "$CRASHDIR/start.sh" start
echo -e "\033[32m已完成防火墙设置!\033[0m" echo -e "\033[32m$START_FIREWALL_DONE\033[0m"
else else
start_core start_core
fi fi

View File

@@ -372,13 +372,13 @@ EOF
} }
} }
if [ -z "$(grep "provider_temp_${coretype}" "$CRASHDIR"/configs/ShellCrash.cfg)" ];then if [ -z "$(grep "provider_temp_${coretype}" "$CRASHDIR"/configs/ShellCrash.cfg)" ];then
provider_temp_file="$TMPDIR/$(sed -n "1 p" "$CRASHDIR"/configs/${coretype}_providers.list | awk '{print $2}')" provider_temp_file="$(sed -n "1 p" "$CRASHDIR"/configs/${coretype}_providers.list | awk '{print $2}')"
else else
provider_temp_file=$(grep "provider_temp_${coretype}" "$CRASHDIR"/configs/ShellCrash.cfg | awk -F '=' '{print $2}') provider_temp_file=$(grep "provider_temp_${coretype}" "$CRASHDIR"/configs/ShellCrash.cfg | awk -F '=' '{print $2}')
fi fi
echo "-----------------------------------------------" echo "-----------------------------------------------"
if [ -s "$provider_temp_file" ];then if [ -s "$TMPDIR/$provider_temp_file" ];then
ln -sf "$provider_temp_file" "$TMPDIR"/provider_temp_file ln -sf "$TMPDIR/$provider_temp_file" "$TMPDIR"/provider_temp_file
else else
echo -e "\033[33m正在获取在线模版\033[0m" echo -e "\033[33m正在获取在线模版\033[0m"
get_bin "$TMPDIR"/provider_temp_file "rules/${coretype}_providers/$provider_temp_file" get_bin "$TMPDIR"/provider_temp_file "rules/${coretype}_providers/$provider_temp_file"
@@ -416,7 +416,7 @@ EOF
cut -c 1- "$TMPDIR"/providers/providers.yaml "$TMPDIR"/providers/proxy-groups.yaml "$TMPDIR"/providers/rules.yaml > "$TMPDIR"/config.yaml cut -c 1- "$TMPDIR"/providers/providers.yaml "$TMPDIR"/providers/proxy-groups.yaml "$TMPDIR"/providers/rules.yaml > "$TMPDIR"/config.yaml
rm -rf "$TMPDIR"/providers rm -rf "$TMPDIR"/providers
#调用内核测试 #调用内核测试
. "$CRASHDIR"/libs/core_tools.sh && core_find && "$TMPDIR"/CrashCore -t -d "$BINDIR" -f "$TMPDIR"/config.yaml . "$CRASHDIR"/starts/check_core.sh && check_core && "$TMPDIR"/CrashCore -t -d "$BINDIR" -f "$TMPDIR"/config.yaml
if [ "$?" = 0 ];then if [ "$?" = 0 ];then
echo -e "\033[32m配置文件生成成功\033[0m" echo -e "\033[32m配置文件生成成功\033[0m"
mkdir -p "$CRASHDIR"/yamls mkdir -p "$CRASHDIR"/yamls
@@ -518,7 +518,7 @@ EOF
cat "$TMPDIR"/provider_temp_file | sed "s/{providers_tags}/$providers_tags/g" > "$TMPDIR"/providers/outbounds.json cat "$TMPDIR"/provider_temp_file | sed "s/{providers_tags}/$providers_tags/g" > "$TMPDIR"/providers/outbounds.json
rm -rf "$TMPDIR"/provider_temp_file rm -rf "$TMPDIR"/provider_temp_file
#调用内核测试 #调用内核测试
. "$CRASHDIR"/libs/core_tools.sh && core_find && "$TMPDIR"/CrashCore merge "$TMPDIR"/config.json -C "$TMPDIR"/providers . "$CRASHDIR"/starts/check_core.sh && check_core && "$TMPDIR"/CrashCore merge "$TMPDIR"/config.json -C "$TMPDIR"/providers
if [ "$?" = 0 ];then if [ "$?" = 0 ];then
echo -e "\033[32m配置文件生成成功如果启动超时建议更新里手动安装Singbox-srs数据库常用包\033[0m" echo -e "\033[32m配置文件生成成功如果启动超时建议更新里手动安装Singbox-srs数据库常用包\033[0m"
mkdir -p "$CRASHDIR"/jsons mkdir -p "$CRASHDIR"/jsons

File diff suppressed because it is too large Load Diff

View File

@@ -181,8 +181,9 @@ set_common_ports() {
} }
set_cust_host_ipv4() { #自定义ipv4透明路由网段 set_cust_host_ipv4() { #自定义ipv4透明路由网段
[ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF" [ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="OFF"
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e "当前默认透明路由的网段为: \033[32m$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'br' | grep -v 'iot' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/br.*$//g' | sed 's/metric.*$//g' | tr '\n' ' ' && echo) \033[0m" echo -e "当前默认透明路由的网段为: \033[32m$host_ipv4 \033[0m"
echo -e "当前已添加的自定义网段为:\033[36m$cust_host_ipv4\033[0m" echo -e "当前已添加的自定义网段为:\033[36m$cust_host_ipv4\033[0m"
echo "-----------------------------------------------" echo "-----------------------------------------------"
echo -e " 1 移除所有自定义网段" echo -e " 1 移除所有自定义网段"

View File

@@ -37,6 +37,7 @@ case "$1" in
start) start)
[ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例 [ -n "$(pidof CrashCore)" ] && $0 stop #禁止多实例
stop_firewall #清理路由策略 stop_firewall #清理路由策略
rm -f "CRASHDIR"/.start_error #移除自启失败标记
#使用不同方式启动服务 #使用不同方式启动服务
if [ "$firewall_area" = "5" ]; then #主旁转发 if [ "$firewall_area" = "5" ]; then #主旁转发
. "$CRASHDIR"/starts/fw_start.sh . "$CRASHDIR"/starts/fw_start.sh

View File

@@ -6,6 +6,9 @@
. "$CRASHDIR"/libs/get_config.sh . "$CRASHDIR"/libs/get_config.sh
[ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && . "$CRASHDIR"/init.sh >/dev/null 2>&1 [ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && . "$CRASHDIR"/init.sh >/dev/null 2>&1
[ ! -f "$TMPDIR" ] && mkdir -p "$TMPDIR" [ ! -f "$TMPDIR" ] && mkdir -p "$TMPDIR"
#当上次启动失败时终止自启动
[ -f "CRASHDIR"/.start_error ] && exit 1
#加载工具 #加载工具
. "$CRASHDIR"/libs/check_cmd.sh . "$CRASHDIR"/libs/check_cmd.sh
. "$CRASHDIR"/libs/check_target.sh . "$CRASHDIR"/libs/check_target.sh
@@ -18,6 +21,7 @@
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod='Redir模式' [ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod='Redir模式'
[ -z "$dns_mod" ] && dns_mod='redir_host' [ -z "$dns_mod" ] && dns_mod='redir_host'
[ -z "$redir_mod" ] && firewall_area='4' [ -z "$redir_mod" ] && firewall_area='4'
routing_mark=$((fwmark + 2))
makehtml() { #生成面板跳转文件 makehtml() { #生成面板跳转文件
cat >"$BINDIR"/ui/index.html <<EOF cat >"$BINDIR"/ui/index.html <<EOF
@@ -69,7 +73,7 @@ EOF
[ "$?" = 0 ] && rm -rf "$TMPDIR"/shellcrash_pac || mv -f "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac [ "$?" = 0 ] && rm -rf "$TMPDIR"/shellcrash_pac || mv -f "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac
} }
routing_mark=$((fwmark + 2))
#检测网络连接 #检测网络连接
[ "$network_check" != "OFF" ] && [ ! -f "$TMPDIR"/crash_start_time ] && ckcmd ping && . "$CRASHDIR"/starts/check_network.sh && check_network [ "$network_check" != "OFF" ] && [ ! -f "$TMPDIR"/crash_start_time ] && ckcmd ping && . "$CRASHDIR"/starts/check_network.sh && check_network
[ ! -d "$BINDIR"/ui ] && mkdir -p "$BINDIR"/ui [ ! -d "$BINDIR"/ui ] && mkdir -p "$BINDIR"/ui
@@ -99,7 +103,7 @@ if echo "$crashcore" | grep -q 'singbox'; then
if [ "$disoverride" != "1" ];then if [ "$disoverride" != "1" ];then
. "$CRASHDIR"/starts/singbox_modify.sh && modify_json . "$CRASHDIR"/starts/singbox_modify.sh && modify_json
else else
ln -sf "$core_config" "$TMPDIR"/config.json ln -sf "$core_config" "$TMPDIR"/configs/config.json
fi fi
else else
. "$CRASHDIR"/starts/clash_check.sh && clash_check . "$CRASHDIR"/starts/clash_check.sh && clash_check

View File

@@ -2,8 +2,8 @@
getlanip() { #获取局域网host地址 getlanip() { #获取局域网host地址
i=1 i=1
while [ "$i" -le "20" ]; do while [ "$i" -le "20" ]; do
host_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'brd' | grep -Ev 'utun|iot|peer|docker|podman|virbr|vnet|ovs|vmbr|veth|vmnic|vboxnet|lxcbr|xenbr|vEthernet' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/[[:space:]]br.*$//g' | sed 's/metric.*$//g') #ipv4局域网网段 host_ipv4=$(ip route show scope link | grep -Ev 'wan|utun|iot|peer|docker|podman|virbr|vnet|ovs|vmbr|veth|vmnic|vboxnet|lxcbr|xenbr|vEthernet' | grep -E ' 1(92|0|72)\.' | awk '{print $1}') #ipv4局域网网段
[ "$ipv6_redir" = "ON" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g') #ipv6公网地址段 [ "$ipv6_redir" = "ON" ] && host_ipv6=$(ip -6 route show | grep 'default' | awk '{print $3}') #ipv6公网地址段
[ -f "$TMPDIR"/ShellCrash.log ] && break [ -f "$TMPDIR"/ShellCrash.log ] && break
[ -n "$host_ipv4" -a "$ipv6_redir" != "ON" ] && break [ -n "$host_ipv4" -a "$ipv6_redir" != "ON" ] && break
[ -n "$host_ipv4" -a -n "$host_ipv6" ] && break [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break

View File

@@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
# Copyright (C) Juewuy # Copyright (C) Juewuy
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
start_ipt_route() { #iptables-route通用工具 start_ipt_route() { #iptables-route通用工具
#$1:iptables/ip6tables $2:所在的表(nat/mangle) $3:所在的链(OUTPUT/PREROUTING) $4:新创建的shellcrash链表 $5:tcp/udp/all #$1:iptables/ip6tables $2:所在的表(nat/mangle) $3:所在的链(OUTPUT/PREROUTING) $4:新创建的shellcrash链表 $5:tcp/udp/all
#区分ipv4/ipv6 #区分ipv4/ipv6
@@ -28,7 +31,10 @@ start_ipt_route() { #iptables-route通用工具
"$1" $w -t "$2" -A "$4" -m owner --gid-owner $gid -j RETURN "$1" $w -t "$2" -A "$4" -m owner --gid-owner $gid -j RETURN
done done
[ "$firewall_area" = 5 ] && "$1" $w -t "$2" -A "$4" -s $bypass_host -j RETURN [ "$firewall_area" = 5 ] && "$1" $w -t "$2" -A "$4" -s $bypass_host -j RETURN
[ -z "$ports" ] && "$1" $w -t "$2" -A "$4" -p tcp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN [ -z "$ports" ] && {
"$1" $w -t "$2" -A "$4" -p tcp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN
"$1" $w -t "$2" -A "$4" -p udp -m multiport --dports "$mix_port,$redir_port,$tproxy_port" -j RETURN
}
#跳过目标保留地址及目标本机网段 #跳过目标保留地址及目标本机网段
for ip in $HOST_IP $RESERVED_IP; do for ip in $HOST_IP $RESERVED_IP; do
"$1" $w -t "$2" -A "$4" -d $ip -j RETURN "$1" $w -t "$2" -A "$4" -d $ip -j RETURN
@@ -130,8 +136,6 @@ start_ipt_dns() { #iptables-dns通用工具
"$1" $w -t nat -I "$2" -p udp --dport 53 -j "$3" "$1" $w -t nat -I "$2" -p udp --dport 53 -j "$3"
} }
start_ipt_wan() { #iptables公网防火墙 start_ipt_wan() { #iptables公网防火墙
ckcmd iptables && iptables -h | grep -q '\-w' && iptable='iptables -w' || iptable=iptables
ckcmd ip6tables && ip6tables -h | grep -q '\-w' && ip6table='ip6tables -w' || ip6table=ip6tables
ipt_wan_accept(){ ipt_wan_accept(){
$iptable -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT $iptable -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT
ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$accept_ports" -j ACCEPT
@@ -141,7 +145,7 @@ start_ipt_wan() { #iptables公网防火墙
ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT ckcmd ip6tables && $ip6table -I INPUT -p "$1" -m multiport --dports "$reject_ports" -j REJECT
} }
#端口拦截 #端口拦截
reject_ports="$mix_port,$db_port,$dns_port" reject_ports="$mix_port,$db_port"
ipt_wan_reject tcp ipt_wan_reject tcp
ipt_wan_reject udp ipt_wan_reject udp
#端口放行 #端口放行

View File

@@ -146,7 +146,7 @@ start_nft_wan() { #nftables公网防火墙
nft add rule inet shellcrash input udp dport $fw_wan_nfports meta mark set 0x67890 accept nft add rule inet shellcrash input udp dport $fw_wan_nfports meta mark set 0x67890 accept
} }
#端口拦截 #端口拦截
reject_ports="{ $mix_port, $db_port, $dns_port }" reject_ports="{ $mix_port, $db_port }"
nft add rule inet shellcrash input ip saddr {$HOST_IP} accept nft add rule inet shellcrash input ip saddr {$HOST_IP} accept
nft add rule inet shellcrash input ip6 saddr {$HOST_IP6} accept nft add rule inet shellcrash input ip6 saddr {$HOST_IP6} accept
nft add rule inet shellcrash input tcp dport $reject_ports reject nft add rule inet shellcrash input tcp dport $reject_ports reject

View File

@@ -55,8 +55,8 @@ ckcmd iptables && {
done done
$iptable -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $iptable -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$iptable -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $iptable -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$iptable -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port,$dns_port" -j REJECT 2>/dev/null $iptable -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
$iptable -D INPUT -p udp -m multiport --dports "$mix_port,$db_port,$dns_port" -j REJECT 2>/dev/null $iptable -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
#清理shellcrash自建表 #清理shellcrash自建表
for text in shellcrash_dns shellcrash shellcrash_out shellcrash_dns_out shellcrash_vm shellcrash_vm_dns; do for text in shellcrash_dns shellcrash shellcrash_out shellcrash_dns_out shellcrash_vm shellcrash_vm_dns; do
$iptable -t nat -F "$text" 2>/dev/null $iptable -t nat -F "$text" 2>/dev/null
@@ -105,8 +105,8 @@ ckcmd ip6tables && {
done done
$ip6table -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $ip6table -D INPUT -p tcp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$ip6table -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null $ip6table -D INPUT -p udp -m multiport --dports "$accept_ports" -j ACCEPT 2>/dev/null
$ip6table -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port,$dns_port" -j REJECT 2>/dev/null $ip6table -D INPUT -p tcp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
$ip6table -D INPUT -p udp -m multiport --dports "$mix_port,$db_port,$dns_port" -j REJECT 2>/dev/null $ip6table -D INPUT -p udp -m multiport --dports "$mix_port,$db_port" -j REJECT 2>/dev/null
#清理shellcrash自建表 #清理shellcrash自建表
for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do for text in shellcrashv6_dns shellcrashv6 shellcrashv6_out; do
$ip6table -t nat -F "$text" 2>/dev/null $ip6table -t nat -F "$text" 2>/dev/null

View File

@@ -7,6 +7,7 @@ else
sleep 2 sleep 2
kill $! >/dev/null 2>&1 kill $! >/dev/null 2>&1
fi fi
error=$(cat $TMPDIR/core_test.log | grep -iEo 'error.*=.*|.*ERROR.*|.*FATAL.*') touch "CRASHDIR"/.start_error #标记启动失败,防止自启
error=$(cat "$TMPDIR"/core_test.log | grep -iEo 'error.*=.*|.*ERROR.*|.*FATAL.*')
logger "服务启动失败!请查看报错信息!详细信息请查看$TMPDIR/core_test.log" 33 logger "服务启动失败!请查看报错信息!详细信息请查看$TMPDIR/core_test.log" 33
logger "$error" 31 logger "$error" 31

View File

@@ -2,16 +2,14 @@
. "$CRASHDIR"/libs/check_cmd.sh . "$CRASHDIR"/libs/check_cmd.sh
start_legacy(){ start_legacy(){
ckcmd nohup && _nohup=nohup
if ckcmd su && grep -q 'shellcrash:x:0:7890' /etc/passwd;then if ckcmd su && grep -q 'shellcrash:x:0:7890' /etc/passwd;then
su shellcrash -c "$1 >/dev/null 2>&1 & echo \$! > /tmp/ShellCrash/$2.pid" su shellcrash -c "$_nohup $1 >/dev/null 2>&1 & echo \$! > /tmp/ShellCrash/$2.pid"
elif ckcmd setsid; then elif ckcmd setsid; then
setsid $1 >/dev/null 2>&1 & $_nohup setsid $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid" echo $! > "/tmp/ShellCrash/$2.pid"
elif ckcmd nohup; then
nohup $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid"
else else
$1 >/dev/null 2>&1 & $_nohup $1 >/dev/null 2>&1 &
echo $! > "/tmp/ShellCrash/$2.pid" echo $! > "/tmp/ShellCrash/$2.pid"
fi fi
} }

View File

@@ -1 +1 @@
1.9.4beta1.1 1.9.4beta2