diff --git a/install.sh b/install.sh index a0e4756..f11652c 100644 --- a/install.sh +++ b/install.sh @@ -2,9 +2,9 @@ # Copyright (C) Juewuy [ -z "$url" ] && url="https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master" -type bash &>/dev/null && shtype=bash || shtype=sh -echo='echo -e' -[ -n "$(echo -e|grep e)" ] && { +type bash &>/dev/null && shtype=bash || shtype=sh +echo='echo -e' +[ -n "$(echo -e | grep e)" ] && { echo "\033[31m不支持dash环境安装!请先输入bash命令后再运行安装命令!\033[0m" exit } @@ -15,23 +15,23 @@ echo "** ShellCrash **" echo "** by Juewuy **" echo "***********************************************" #内置工具 -dir_avail(){ - df $2 $1 |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 -E 'Ava|可用' |awk '{print $2}' +dir_avail() { + df $2 $1 | 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 -E 'Ava|可用' | awk '{print $2}' } -setconfig(){ +setconfig() { configpath=$CRASHDIR/configs/ShellCrash.cfg - [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -n "$(grep ${1} $configpath)" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >>$configpath } -webget(){ +webget() { #参数【$1】代表下载目录,【$2】代表在线地址 #参数【$3】代表输出显示,【$4】不启用重定向 - if curl --version > /dev/null 2>&1;then + if curl --version >/dev/null 2>&1; then [ "$3" = "echooff" ] && progress='-s' || progress='-#' [ -z "$4" ] && redirect='-L' || redirect='' result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2) [ -n "$(echo $result | grep -e ^2)" ] && result="200" 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' [ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect='' certificate='--no-check-certificate' @@ -39,18 +39,18 @@ webget(){ fi [ "$3" = "echoon" ] && progress='' [ "$3" = "echooff" ] && progress='-q' - wget $progress $redirect $certificate $timeout -O $1 $2 + wget $progress $redirect $certificate $timeout -O $1 $2 [ $? -eq 0 ] && result="200" fi } -error_down(){ +error_down() { $echo "请参考 \033[32mhttps://github.com/juewuy/ShellCrash/blob/master/README_CN.md" - $echo "\033[33m使用其他安装源重新安装!\033[0m" + $echo "\033[33m使用其他安装源重新安装!\033[0m" } #安装及初始化 -gettar(){ +gettar() { webget /tmp/ShellCrash.tar.gz "$url/bin/ShellCrash.tar.gz" - if [ "$result" != "200" ];then + if [ "$result" != "200" ]; then $echo "\033[33m文件下载失败!\033[0m" error_down exit 1 @@ -59,159 +59,161 @@ gettar(){ #解压 echo ----------------------------------------------- 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/ - if [ -s $CRASHDIR/init.sh ];then + if [ -s $CRASHDIR/init.sh ]; then . $CRASHDIR/init.sh >/dev/null || $echo "\033[33m初始化失败,请尝试本地安装!\033[0m" else rm -rf /tmp/ShellCrash.tar.gz $echo "\033[33m文件解压失败!\033[0m" error_down exit 1 - fi + fi fi } -setdir(){ - set_usb_dir(){ +setdir() { + set_usb_dir() { $echo "请选择安装目录" du -hL /mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) - if [ -z "$dir" ];then + if [ -z "$dir" ]; then $echo "\033[31m输入错误!请重新设置!\033[0m" set_usb_dir fi } - set_asus_dir(){ + set_asus_dir() { echo -e "请选择U盘目录" du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num dir=$(du -hL /tmp/mnt | awk '{print $2}' | sed -n "$num"p) - if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ];then + if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ]; then echo -e "\033[31m未找到下载大师自启文件:$dir/asusware.arm/etc/init.d/S50downloadmaster,请检查设置!\033[0m" set_asus_dir fi } - set_cust_dir(){ + set_cust_dir() { echo ----------------------------------------------- echo '可用路径 剩余空间:' - df -h | awk '{print $6,$4}'| sed 1d + df -h | awk '{print $6,$4}' | sed 1d echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' read -p "请输入自定义路径 > " dir - if [ "$(dir_avail $dir)" = 0 ];then + if [ "$(dir_avail $dir)" = 0 ]; then $echo "\033[31m路径错误!请重新设置!\033[0m" set_cust_dir fi } -echo ----------------------------------------------- -$echo "\033[33m注意:安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" -if [ -n "$systype" ];then - [ "$systype" = "Padavan" ] && dir=/etc/storage - [ "$systype" = "mi_snapshot" ] && { - $echo "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" - [ "$(dir_avail /data)" -gt 256 ] && $echo " 1 安装到 /data 目录(推荐,支持软固化功能)" - [ "$(dir_avail /userdisk)" -gt 256 ] && $echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)" - $echo " 3 安装到自定义目录(不推荐,不明勿用!)" - $echo " 0 退出安装" - echo ----------------------------------------------- - read -p "请输入相应数字 > " num - case "$num" in - 1) - dir=/data - ;; - 2) - dir=/userdisk - ;; - 3) - set_cust_dir - ;; - *) - exit 1 ;; - esac - } - [ "$systype" = "asusrouter" ] && { - $echo "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m" - $echo " 1 基于USB设备安装(限23年9月之前固件,须插入\033[31m任意\033[0mUSB设备)" - $echo " 2 基于自启脚本安装(仅支持梅林及部分非koolshare官改固件)" - $echo " 3 基于U盘+下载大师安装(支持所有固件,限ARM设备,须插入U盘或移动硬盘)" - $echo " 0 退出安装" - echo ----------------------------------------------- - read -p "请输入相应数字 > " num - case "$num" in - 1) - read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res - [ "$res" = "1" ] && set_usb_dir || dir=/jffs - usb_status=1 - ;; - 2) - $echo "如无法正常开机启动,请重新使用USB方式安装!" - sleep 2 - dir=/jffs - ;; - 3) - echo -e "请先在路由器网页后台安装下载大师并启用,之后选择外置存储所在目录!" - sleep 2 - set_asus_dir - ;; - *) - exit 1 ;; - esac - } - [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt -else - $echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" - $echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" - $echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" - $echo " 4 在\033[32m外置存储\033[0m中安装" - $echo " 5 手动设置安装目录" - $echo " 0 退出安装" echo ----------------------------------------------- - read -p "请输入相应数字 > " num - #设置目录 - if [ -z $num ];then - echo 安装已取消 - exit 1; - elif [ "$num" = "1" ];then - dir=/etc - elif [ "$num" = "2" ];then - dir=/usr/share - elif [ "$num" = "3" ];then - dir=~/.local/share - mkdir -p ~/.config/systemd/user - elif [ "$num" = "4" ];then - set_usb_dir - elif [ "$num" = "5" ];then - set_cust_dir + $echo "\033[33m注意:安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" + if [ -n "$systype" ]; then + [ "$systype" = "Padavan" ] && dir=/etc/storage + [ "$systype" = "mi_snapshot" ] && { + $echo "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" + [ "$(dir_avail /data)" -gt 256 ] && $echo " 1 安装到 /data 目录(推荐,支持软固化功能)" + [ "$(dir_avail /userdisk)" -gt 256 ] && $echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)" + $echo " 3 安装到自定义目录(不推荐,不明勿用!)" + $echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + dir=/data + ;; + 2) + dir=/userdisk + ;; + 3) + set_cust_dir + ;; + *) + exit 1 + ;; + esac + } + [ "$systype" = "asusrouter" ] && { + $echo "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m" + $echo " 1 基于USB设备安装(限23年9月之前固件,须插入\033[31m任意\033[0mUSB设备)" + $echo " 2 基于自启脚本安装(仅支持梅林及部分非koolshare官改固件)" + $echo " 3 基于U盘+下载大师安装(支持所有固件,限ARM设备,须插入U盘或移动硬盘)" + $echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res + [ "$res" = "1" ] && set_usb_dir || dir=/jffs + usb_status=1 + ;; + 2) + $echo "如无法正常开机启动,请重新使用USB方式安装!" + sleep 2 + dir=/jffs + ;; + 3) + echo -e "请先在路由器网页后台安装下载大师并启用,之后选择外置存储所在目录!" + sleep 2 + set_asus_dir + ;; + *) + exit 1 + ;; + esac + } + [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt else - echo 安装已取消!!! - exit 1; + $echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" + $echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" + $echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" + $echo " 4 在\033[32m外置存储\033[0m中安装" + $echo " 5 手动设置安装目录" + $echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + #设置目录 + if [ -z $num ]; then + echo 安装已取消 + exit 1 + elif [ "$num" = "1" ]; then + dir=/etc + elif [ "$num" = "2" ]; then + dir=/usr/share + elif [ "$num" = "3" ]; then + dir=~/.local/share + mkdir -p ~/.config/systemd/user + elif [ "$num" = "4" ]; then + set_usb_dir + elif [ "$num" = "5" ]; then + set_cust_dir + else + echo 安装已取消!!! + exit 1 + fi fi -fi -if [ ! -w $dir ];then - $echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir -else - $echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" - read -p "确认安装?(1/0) > " res - [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir -fi + if [ ! -w $dir ]; then + $echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir + else + $echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" + read -p "确认安装?(1/0) > " res + [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir + fi } -install(){ -echo ----------------------------------------------- -echo 开始从服务器获取安装文件! -echo ----------------------------------------------- -gettar -echo ----------------------------------------------- -echo ShellCrash 已经安装成功! -[ "$profile" = "~/.bashrc" ] && echo "请执行【. ~/.bashrc &> /dev/null】命令以加载环境变量!" -[ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && echo "请执行【. ~/.zshrc &> /dev/null】命令以加载环境变量!" -echo ----------------------------------------------- -$echo "\033[33m输入\033[30;47m crash \033[0;33m命令即可管理!!!\033[0m" -echo ----------------------------------------------- -} -setversion(){ +install() { echo ----------------------------------------------- - $echo "\033[33m请选择想要安装的版本:\033[0m" + echo 开始从服务器获取安装文件! + echo ----------------------------------------------- + gettar + echo ----------------------------------------------- + echo ShellCrash 已经安装成功! + [ "$profile" = "~/.bashrc" ] && echo "请执行【. ~/.bashrc &> /dev/null】命令以加载环境变量!" + [ -n "$(ls -l /bin/sh | grep -oE 'zsh')" ] && echo "请执行【. ~/.zshrc &> /dev/null】命令以加载环境变量!" + echo ----------------------------------------------- + $echo "\033[33m输入\033[30;47m crash \033[0;33m命令即可管理!!!\033[0m" + echo ----------------------------------------------- +} +setversion() { + echo ----------------------------------------------- + $echo "\033[33m请选择想要安装的版本:\033[0m" $echo " 1 \033[32m公测版(推荐)\033[0m" $echo " 2 \033[36m稳定版\033[0m" $echo " 3 \033[31m开发版\033[0m" @@ -220,29 +222,28 @@ setversion(){ case "$num" in 2) url=$(echo $url | sed 's/master/stable/') - ;; + ;; 3) url=$(echo $url | sed 's/master/dev/') - ;; - *) - ;; + ;; + *) ;; esac } #特殊固件识别及标记 [ -f "/etc/storage/started_script.sh" ] && { systype=Padavan #老毛子固件 initdir='/etc/storage/started_script.sh' - } +} [ -d "/jffs" ] && { systype=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 #小米设备 -[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 +[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 #检查root权限 -if [ "$USER" != "root" -a -z "$systype" ];then +if [ "$USER" != "root" -a -z "$systype" ]; then echo 当前用户:$USER $echo "\033[31m请尽量使用root用户(不要直接使用sudo命令!)执行安装!\033[0m" echo ----------------------------------------------- @@ -250,7 +251,7 @@ if [ "$USER" != "root" -a -z "$systype" ];then [ "$res" != "1" ] && exit 1 fi -if [ -n "$(echo $url | grep master)" ];then +if [ -n "$(echo $url | grep master)" ]; then setversion fi #获取版本信息 @@ -265,26 +266,26 @@ $echo "\033[44m如遇问题请加TG群反馈:\033[42;30m t.me/ShellClash \033[ $echo "\033[37m支持各种基于openwrt的路由器设备" $echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" -if [ -n "$CRASHDIR" ];then +if [ -n "$CRASHDIR" ]; then echo ----------------------------------------------- $echo "检测到旧的安装目录\033[36m$CRASHDIR\033[0m,是否覆盖安装?" $echo "\033[32m覆盖安装时不会移除配置文件!\033[0m" read -p "覆盖安装/卸载旧版本?(1/0) > " res - if [ "$res" = "1" ];then + if [ "$res" = "1" ]; then install - elif [ "$res" = "0" ];then + elif [ "$res" = "0" ]; then rm -rf $CRASHDIR echo ----------------------------------------------- $echo "\033[31m 旧版本文件已卸载!\033[0m" setdir install - elif [ "$res" = "9" ];then + elif [ "$res" = "9" ]; then echo 测试模式,变更安装位置 setdir install else $echo "\033[31m输入错误!已取消安装!\033[0m" - exit 1; + exit 1 fi else setdir diff --git a/scripts/init.sh b/scripts/init.sh index 48af98c..d26735d 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -3,163 +3,164 @@ version=1.9.1rc9 -setdir(){ - dir_avail(){ - df $2 $1 |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 -E 'Ava|可用' |awk '{print $2}' +setdir() { + dir_avail() { + df $2 $1 | 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 -E 'Ava|可用' | awk '{print $2}' } - set_usb_dir(){ + set_usb_dir() { echo -e "请选择安装目录" du -hL /mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) - if [ -z "$dir" ];then + if [ -z "$dir" ]; then echo -e "\033[31m输入错误!请重新设置!\033[0m" set_usb_dir fi } - set_asus_dir(){ + set_asus_dir() { echo -e "请选择U盘目录" du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num dir=$(du -hL /tmp/mnt | awk '{print $2}' | sed -n "$num"p) - if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ];then + if [ ! -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ]; then echo -e "\033[31m未找到下载大师自启文件:$dir/asusware.arm/etc/init.d/S50downloadmaster,请检查设置!\033[0m" set_asus_dir fi } - set_cust_dir(){ + set_cust_dir() { echo ----------------------------------------------- echo '可用路径 剩余空间:' - df -h | awk '{print $6,$4}'| sed 1d + df -h | awk '{print $6,$4}' | sed 1d echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' read -p "请输入自定义路径 > " dir - if [ "$(dir_avail $dir)" = 0 ];then + if [ "$(dir_avail $dir)" = 0 ]; then echo "\033[31m路径错误!请重新设置!\033[0m" set_cust_dir fi } -echo ----------------------------------------------- -if [ -n "$systype" ];then - [ "$systype" = "Padavan" ] && dir=/etc/storage - [ "$systype" = "mi_snapshot" ] && { - echo -e "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" - [ "$(dir_avail /data)" -gt 256 ] && echo " 1 安装到 /data 目录(推荐,支持软固化功能)" - [ "$(dir_avail /userdisk)" -gt 256 ] && echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)" - echo " 3 安装自定义目录(不推荐,不明勿用!)" - echo " 0 退出安装" - echo ----------------------------------------------- - read -p "请输入相应数字 > " num - case "$num" in - 1) - dir=/data - ;; - 2) - dir=/userdisk - ;; - 3) - set_cust_dir - ;; - *) - exit 1 ;; - esac - } - [ "$systype" = "asusrouter" ] && { - echo -e "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m" - echo -e " 1 基于USB设备安装(限23年9月之前固件,须插入\033[31m任意\033[0mUSB设备)" - echo -e " 2 基于自启脚本安装(仅支持梅林及部分非koolshare官改固件)" - echo -e " 3 基于U盘+下载大师安装(支持所有固件,限ARM设备,须插入U盘或移动硬盘)" + echo ----------------------------------------------- + if [ -n "$systype" ]; then + [ "$systype" = "Padavan" ] && dir=/etc/storage + [ "$systype" = "mi_snapshot" ] && { + echo -e "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m" + [ "$(dir_avail /data)" -gt 256 ] && echo " 1 安装到 /data 目录(推荐,支持软固化功能)" + [ "$(dir_avail /userdisk)" -gt 256 ] && echo " 2 安装到 /userdisk 目录(推荐,支持软固化功能)" + echo " 3 安装自定义目录(不推荐,不明勿用!)" + echo " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + dir=/data + ;; + 2) + dir=/userdisk + ;; + 3) + set_cust_dir + ;; + *) + exit 1 + ;; + esac + } + [ "$systype" = "asusrouter" ] && { + echo -e "\033[33m检测到当前设备为华硕固件,请选择安装方式\033[0m" + echo -e " 1 基于USB设备安装(限23年9月之前固件,须插入\033[31m任意\033[0mUSB设备)" + echo -e " 2 基于自启脚本安装(仅支持梅林及部分非koolshare官改固件)" + echo -e " 3 基于U盘+下载大师安装(支持所有固件,限ARM设备,须插入U盘或移动硬盘)" + echo -e " 0 退出安装" + echo ----------------------------------------------- + read -p "请输入相应数字 > " num + case "$num" in + 1) + read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res + [ "$res" = "1" ] && set_usb_dir || dir=/jffs + usb_status=1 + ;; + 2) + echo -e "如无法正常开机启动,请重新使用USB方式安装!" + sleep 2 + dir=/jffs + ;; + 3) + echo -e "请先在路由器网页后台安装下载大师并启用,之后选择外置存储所在目录!" + sleep 2 + set_asus_dir + ;; + *) + exit 1 + ;; + esac + } + [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt + else + echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" + echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" + echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" + echo -e " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" + echo -e " 4 在\033[32m外置存储\033[0m中安装" + echo -e " 5 手动设置安装目录" echo -e " 0 退出安装" echo ----------------------------------------------- read -p "请输入相应数字 > " num - case "$num" in - 1) - read -p "将脚本安装到USB存储/系统闪存?(1/0) > " res - [ "$res" = "1" ] && set_usb_dir || dir=/jffs - usb_status=1 - ;; - 2) - echo -e "如无法正常开机启动,请重新使用USB方式安装!" - sleep 2 - dir=/jffs - ;; - 3) - echo -e "请先在路由器网页后台安装下载大师并启用,之后选择外置存储所在目录!" - sleep 2 - set_asus_dir - ;; - *) - exit 1 - ;; - esac - } - [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt -else - echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" - echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" - echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" - echo -e " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" - echo -e " 4 在\033[32m外置存储\033[0m中安装" - echo -e " 5 手动设置安装目录" - echo -e " 0 退出安装" - echo ----------------------------------------------- - read -p "请输入相应数字 > " num - #设置目录 - if [ -z $num ];then - echo 安装已取消 - exit 1; - elif [ "$num" = "1" ];then - dir=/etc - elif [ "$num" = "2" ];then - dir=/usr/share - elif [ "$num" = "3" ];then - dir=~/.local/share - mkdir -p ~/.config/systemd/user - elif [ "$num" = "4" ];then - set_usb_dir - elif [ "$num" = "5" ];then - echo ----------------------------------------------- - echo '可用路径 剩余空间:' - df -h | awk '{print $6,$4}'| sed 1d - echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' - read -p "请输入自定义路径 > " dir - if [ -z "$dir" ];then - echo -e "\033[31m路径错误!请重新设置!\033[0m" - setdir + #设置目录 + if [ -z $num ]; then + echo 安装已取消 + exit 1 + elif [ "$num" = "1" ]; then + dir=/etc + elif [ "$num" = "2" ]; then + dir=/usr/share + elif [ "$num" = "3" ]; then + dir=~/.local/share + mkdir -p ~/.config/systemd/user + elif [ "$num" = "4" ]; then + set_usb_dir + elif [ "$num" = "5" ]; then + echo ----------------------------------------------- + echo '可用路径 剩余空间:' + df -h | awk '{print $6,$4}' | sed 1d + echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' + read -p "请输入自定义路径 > " dir + if [ -z "$dir" ]; then + echo -e "\033[31m路径错误!请重新设置!\033[0m" + setdir + fi + else + echo 安装已取消!!! + exit 1 fi - else - echo 安装已取消!!! - exit 1; fi -fi -if [ ! -w $dir ];then - echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir -else - echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" - read -p "确认安装?(1/0) > " res - [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir -fi + if [ ! -w $dir ]; then + echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir + else + echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)" + read -p "确认安装?(1/0) > " res + [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir + fi } -setconfig(){ +setconfig() { #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}" - [ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >> $configpath + [ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >>$configpath } #特殊固件识别及标记 [ -f "/etc/storage/started_script.sh" ] && { systype=Padavan #老毛子固件 initdir='/etc/storage/started_script.sh' - } +} [ -d "/jffs" ] && { systype=asusrouter #华硕固件 [ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter' - [ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start' + [ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start' #华硕启用jffs nvram set jffs2_scripts="1" nvram commit - } +} [ -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设备 #检查环境变量 [ -z "$CRASHDIR" -a -n "$clashdir" ] && CRASHDIR=$clashdir @@ -170,16 +171,16 @@ mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null #初始化 mkdir -p ${CRASHDIR}/configs -[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' > ${CRASHDIR}/configs/ShellCrash.cfg +[ -f "${CRASHDIR}/configs/ShellCrash.cfg" ] || echo '#ShellCrash配置文件,不明勿动!' >${CRASHDIR}/configs/ShellCrash.cfg #判断系统类型写入不同的启动文件 -if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then - #设为init.d方式启动 - cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash - chmod 755 /etc/init.d/shellcrash +if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then + #设为init.d方式启动 + cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash + chmod 755 /etc/init.d/shellcrash else [ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system [ -w /etc/systemd/system ] && sysdir=/etc/systemd/system - if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ];then + if [ -n "$sysdir" -a "$USER" = "root" -a "$(cat /proc/1/comm)" = "systemd" ]; then #创建shellcrash用户 userdel shellcrash 2>/dev/null sed -i '/0:7890/d' /etc/passwd @@ -188,7 +189,7 @@ else useradd shellcrash -u 7890 2>/dev/null sed -Ei s/7890:7890/0:7890/g /etc/passwd else - echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >> /etc/passwd + echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >>/etc/passwd fi #配置systemd mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null @@ -202,9 +203,9 @@ else fi fi #修饰文件及版本号 -command -v bash >/dev/null 2>&1 && shtype=bash -[ -x /bin/ash ] && shtype=ash -for file in start.sh task.sh menu.sh;do +command -v bash >/dev/null 2>&1 && shtype=bash +[ -x /bin/ash ] && shtype=ash +for file in start.sh task.sh menu.sh; do sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file} chmod 755 ${CRASHDIR}/${file} done @@ -215,9 +216,9 @@ setconfig versionsh_l $version BINDIR=${CRASHDIR} touch ${CRASHDIR}/configs/command.env setconfig TMPDIR ${TMPDIR} ${CRASHDIR}/configs/command.env - setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env + setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env } -if [ -n "$(grep 'crashcore=singbox' ${CRASHDIR}/configs/ShellCrash.cfg)" ];then +if [ -n "$(grep 'crashcore=singbox' ${CRASHDIR}/configs/ShellCrash.cfg)" ]; then COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"' else COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' @@ -236,23 +237,23 @@ grep -q 'firewall_mod' "$CRASHDIR/configs/ShellClash.cfg" 2>/dev/null || { [ -w /jffs/configs/profile.add ] && profile=/jffs/configs/profile.add [ -w ~/.bashrc ] && profile=~/.bashrc [ -w /etc/profile ] && profile=/etc/profile -if [ -n "$profile" ];then +if [ -n "$profile" ]; then sed -i '/alias crash=*/'d $profile - echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量 + echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >>$profile #设置快捷命令环境变量 sed -i '/alias clash=*/'d $profile - echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >> $profile #设置快捷命令环境变量 + echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >>$profile #设置快捷命令环境变量 sed -i '/export CRASHDIR=*/'d $profile - echo "export CRASHDIR=\"$CRASHDIR\"" >> $profile #设置路径环境变量 + echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile #设置路径环境变量 source $profile >/dev/null 2>&1 || echo 运行错误!请使用bash而不是dash运行安装命令!!! #适配zsh环境变量 - [ -n "$(cat /etc/shells 2>/dev/null|grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null|grep CRASHDIR)" ] && { + [ -n "$(cat /etc/shells 2>/dev/null | grep -oE 'zsh')" ] && [ -z "$(cat ~/.zshrc 2>/dev/null | grep CRASHDIR)" ] && { sed -i '/alias crash=*/'d ~/.zshrc 2>/dev/null - echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc - # 兼容 clash 命令 + echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >>~/.zshrc + # 兼容 clash 命令 sed -i '/alias clash=*/'d ~/.zshrc 2>/dev/null - echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc + echo "alias clash=\"$shtype $CRASHDIR/menu.sh\"" >>~/.zshrc sed -i '/export CRASHDIR=*/'d ~/.zshrc 2>/dev/null - echo "export CRASHDIR=\"$CRASHDIR\"" >> ~/.zshrc + echo "export CRASHDIR=\"$CRASHDIR\"" >>~/.zshrc source ~/.zshrc >/dev/null 2>&1 } else @@ -261,7 +262,7 @@ else fi #在允许的情况下创建/usr/bin/crash文件 touch /usr/bin/crash 2>/dev/null && { - cat > /usr/bin/crash </usr/bin/crash <> $initdir + echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >>$initdir chmod a+rx $initdir 2>/dev/null setconfig initdir $initdir } #Padavan额外设置 [ -f "/etc/storage/started_script.sh" ] && mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式 #镜像化OpenWrt(snapshot)额外设置 -if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ];then +if [ "$systype" = "mi_snapshot" -o "$systype" = "ng_snapshot" ]; then chmod 755 ${CRASHDIR}/misnap_init.sh uci delete firewall.ShellClash 2>/dev/null uci delete firewall.ShellCrash 2>/dev/null @@ -292,13 +293,13 @@ else rm -rf ${CRASHDIR}/misnap_init.sh fi #华硕USB启动额外设置 -[ "$usb_status" = "1" ] && { - echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" > ${CRASHDIR}/asus_usb_mount.sh +[ "$usb_status" = "1" ] && { + echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >${CRASHDIR}/asus_usb_mount.sh nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh" nvram commit } #华硕下载大师启动额外设置 -[ -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ] && [ -z "$(grep 'ShellCrash' $dir/asusware.arm/etc/init.d/S50downloadmaster)" ] && \ +[ -f "$dir/asusware.arm/etc/init.d/S50downloadmaster" ] && [ -z "$(grep 'ShellCrash' $dir/asusware.arm/etc/init.d/S50downloadmaster)" ] && sed -i "/^PATH=/a\\$CRASHDIR/start.sh init & #ShellCrash初始化脚本" "$dir/asusware.arm/etc/init.d/S50downloadmaster" #删除临时文件 rm -rf /tmp/*rash*gz @@ -308,26 +309,26 @@ mkdir -p ${CRASHDIR}/yamls mkdir -p ${CRASHDIR}/jsons mkdir -p ${CRASHDIR}/tools mkdir -p ${CRASHDIR}/task -for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml ;do +for file in config.yaml.bak user.yaml proxies.yaml proxy-groups.yaml rules.yaml others.yaml; do mv -f ${CRASHDIR}/$file ${CRASHDIR}/yamls/$file 2>/dev/null done - [ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null -for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list singbox_providers.list clash_providers.list;do +[ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null +for file in fake_ip_filter mac web_save servers.list fake_ip_filter.list fallback_filter.list singbox_providers.list clash_providers.list; do mv -f ${CRASHDIR}/$file ${CRASHDIR}/configs/$file 2>/dev/null done - #配置文件改名 - mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null - mv -f ${CRASHDIR}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null - #数据库改名 - mv -f ${CRASHDIR}/geosite.dat ${CRASHDIR}/GeoSite.dat 2>/dev/null - #内核改名 - mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null - #内核压缩 - [ -f ${CRASHDIR}/CrashCore ] && tar -zcf ${CRASHDIR}/CrashCore.tar.gz -C ${CRASHDIR} CrashCore -for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh;do +#配置文件改名 +mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null +mv -f ${CRASHDIR}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null +#数据库改名 +mv -f ${CRASHDIR}/geosite.dat ${CRASHDIR}/GeoSite.dat 2>/dev/null +#内核改名 +mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null +#内核压缩 +[ -f ${CRASHDIR}/CrashCore ] && tar -zcf ${CRASHDIR}/CrashCore.tar.gz -C ${CRASHDIR} CrashCore +for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh; do mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null done -for file in cron task.sh task.list;do +for file in cron task.sh task.list; do mv -f ${CRASHDIR}/$file ${CRASHDIR}/task/$file 2>/dev/null done #旧版文件清理 @@ -336,7 +337,7 @@ sed -i '/shellclash/d' /etc/passwd sed -i '/shellclash/d' /etc/group rm -rf /etc/init.d/clash [ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/clash -for file in CrashCore clash.sh getdate.sh shellcrash.rc core.new clashservice log shellcrash.service mark? mark.bak;do +for file in CrashCore clash.sh getdate.sh shellcrash.rc core.new clashservice log shellcrash.service mark? mark.bak; do rm -rf ${CRASHDIR}/$file done #旧版变量改名 diff --git a/scripts/menu.sh b/scripts/menu.sh index 1f52367..ab90189 100644 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -1,7 +1,10 @@ #!/bin/sh # Copyright (C) Juewuy -CRASHDIR=$(cd $(dirname $0);pwd) +CRASHDIR=$( + cd $(dirname $0) + pwd +) CFG_PATH=${CRASHDIR}/configs/ShellCrash.cfg YAMLSDIR=${CRASHDIR}/yamls JSONSDIR=${CRASHDIR}/jsons @@ -9,23 +12,23 @@ JSONSDIR=${CRASHDIR}/jsons source ${CRASHDIR}/configs/command.env 2>/dev/null [ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && source ${CRASHDIR}/init.sh >/dev/null 2>&1 [ ! -f ${TMPDIR} ] && mkdir -p ${TMPDIR} -[ -n "$(tar --help 2>&1|grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容 +[ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容 #读取配置相关 -setconfig(){ +setconfig() { #参数1代表变量名,参数2代表变量值,参数3即文件路径 [ -z "$3" ] && configpath=${CFG_PATH} || configpath="${3}" grep -q "${1}=" "$configpath" && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || sed -i "\$a\\${1}=${2}" $configpath } -ckcmd(){ +ckcmd() { command -v sh >/dev/null 2>&1 && command -v $1 >/dev/null 2>&1 || type $1 >/dev/null 2>&1 } #脚本启动前检查 -ckstatus(){ +ckstatus() { #检查/读取脚本配置文件 - if [ -f $CFG_PATH ];then - [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH > $CFG_PATH #检查重复行并去除 + if [ -f $CFG_PATH ]; then + [ -n "$(awk 'a[$0]++' $CFG_PATH)" ] && awk '!a[$0]++' $CFG_PATH >$CFG_PATH #检查重复行并去除 source $CFG_PATH 2>/dev/null else source ${CRASHDIR}/init.sh >/dev/null 2>&1 @@ -43,12 +46,12 @@ ckstatus(){ #检查mac地址记录 [ ! -f ${CRASHDIR}/configs/mac ] && touch ${CRASHDIR}/configs/mac #获取本机host地址 - [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';) + [ -z "$host" ] && host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'lan' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E ' 1(92|0|72)\.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1) [ -z "$host" ] && host='设备IP地址' #dashboard目录位置 - if [ -f /www/clash/index.html ];then + if [ -f /www/clash/index.html ]; then dbdir=/www/clash hostdir=/clash else @@ -56,9 +59,9 @@ ckstatus(){ hostdir=":$db_port/ui" fi #开机自启检测 - if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ];then + if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then [ -n "$(find /etc/rc.d -name '*shellcrash')" ] && autostart=enable || autostart=disable - elif ckcmd systemctl;then + elif ckcmd systemctl; then [ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && autostart=enable || autostart=disable else [ -f ${CRASHDIR}/.dis_startup ] && autostart=disable || autostart=enable @@ -73,19 +76,19 @@ ckstatus(){ fi #获取运行状态 PID=$(pidof CrashCore | awk '{print $NF}') - if [ -n "$PID" ];then + if [ -n "$PID" ]; then run="\033[32m正在运行($redir_mod)\033[0m" - VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk 'unit="MB" {printf "%.2f %s\n", $2/1000, unit}'` + VmRSS=$(cat /proc/$PID/status | grep -w VmRSS | awk 'unit="MB" {printf "%.2f %s\n", $2/1000, unit}') #获取运行时长 touch ${TMPDIR}/crash_start_time #用于延迟启动的校验 start_time=$(cat ${TMPDIR}/crash_start_time) - if [ -n "$start_time" ]; then - time=$((`date +%s`-start_time)) - day=$((time/86400)) + if [ -n "$start_time" ]; then + time=$(($(date +%s) - start_time)) + day=$((time / 86400)) [ "$day" = "0" ] && day='' || day="$day天" - time=`date -u -d @${time} +%H小时%M分%S秒` + time=$(date -u -d @${time} +%H小时%M分%S秒) fi - elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ];then + elif [ "$firewall_area" = 5 ] && [ -n "$(ip route list table 100)" ]; then run="\033[32m已设置($redir_mod)\033[0m" else run="\033[31m没有运行($redir_mod)\033[0m" @@ -99,58 +102,58 @@ ckstatus(){ echo ----------------------------------------------- echo -e "\033[30;46m欢迎使用ShellCrash!\033[0m 版本:$versionsh_l" echo -e "$corename服务"$run","$auto"" - if [ -n "$PID" ];then + if [ -n "$PID" ]; then echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m" fi echo -e "TG频道:\033[36;4mhttps://t.me/ShellClash\033[0m" echo ----------------------------------------------- #检查新手引导 - if [ -z "$userguide" ];then + if [ -z "$userguide" ]; then setconfig userguide 1 source ${CRASHDIR}/webget.sh && userguide fi #检查执行权限 [ ! -x ${CRASHDIR}/start.sh ] && chmod +x ${CRASHDIR}/start.sh #检查/tmp内核文件 - for file in `ls -F /tmp | grep -v [/\$] | grep -v ' ' | grep -Ev ".*(gz|zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box|^clash.meta.*'` ; do + for file in $(ls -F /tmp | grep -v [/$] | grep -v ' ' | grep -Ev ".*(gz|zip|7z|tar)$" | grep -iE 'CrashCore|^clash$|^clash-linux.*|^mihomo.*|^sing.*box|^clash.meta.*'); do file=/tmp/$file chmod +x $file echo -e "发现可用的内核文件: \033[36m$file\033[0m " - read -p "是否加载(会停止当前服务)?(1/0) > " res - [ "$res" = 1 ] && { - ${CRASHDIR}/start.sh stop - core_v=$($file -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //') - [ -z "$core_v" ] && core_v=$($file version 2>/dev/null | grep -Eo 'version .*' | sed 's/version //') - if [ -n "$core_v" ];then - source ${CRASHDIR}/webget.sh && setcoretype && \ - mv -f $file ${TMPDIR}/CrashCore && \ - tar -zcf ${BINDIR}/CrashCore.tar.gz ${tar_para} -C ${TMPDIR} CrashCore && \ - echo -e "\033[32m内核加载完成!\033[0m " && \ - setconfig crashcore $crashcore && \ - setconfig core_v $core_v && \ + read -p "是否加载(会停止当前服务)?(1/0) > " res + [ "$res" = 1 ] && { + ${CRASHDIR}/start.sh stop + core_v=$($file -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //') + [ -z "$core_v" ] && core_v=$($file version 2>/dev/null | grep -Eo 'version .*' | sed 's/version //') + if [ -n "$core_v" ]; then + source ${CRASHDIR}/webget.sh && setcoretype && + mv -f $file ${TMPDIR}/CrashCore && + tar -zcf ${BINDIR}/CrashCore.tar.gz ${tar_para} -C ${TMPDIR} CrashCore && + echo -e "\033[32m内核加载完成!\033[0m " && + setconfig crashcore $crashcore && + setconfig core_v $core_v && switch_core - sleep 1 - else - echo -e "\033[33m检测到不可用的内核文件!可能是文件受损或CPU架构不匹配!\033[0m" - rm -rf $file - echo -e "\033[33m内核文件已移除,请认真检查后重新上传!\033[0m" - sleep 2 - fi - } + sleep 1 + else + echo -e "\033[33m检测到不可用的内核文件!可能是文件受损或CPU架构不匹配!\033[0m" + rm -rf $file + echo -e "\033[33m内核文件已移除,请认真检查后重新上传!\033[0m" + sleep 2 + fi + } echo ----------------------------------------------- done #检查/tmp配置文件 - for file in `ls -F /tmp | grep -v [/\$] | grep -v ' ' | grep -iE '.yaml$|.yml$|config.json$'` ; do + for file in $(ls -F /tmp | grep -v [/$] | grep -v ' ' | grep -iE '.yaml$|.yml$|config.json$'); do file=/tmp/$file echo -e "发现内核配置文件: \033[36m$file\033[0m " read -p "是否加载为$crashcore的配置文件?(1/0) > " res [ "$res" = 1 ] && { - if [ -n "$(echo $file | grep -iE '.json$')" ];then + if [ -n "$(echo $file | grep -iE '.json$')" ]; then mv -f $file ${CRASHDIR}/jsons/config.json else mv -f $file ${CRASHDIR}/yamls/config.yaml fi - echo -e "\033[32m配置文件加载完成!\033[0m " + echo -e "\033[32m配置文件加载完成!\033[0m " sleep 1 } done @@ -158,49 +161,49 @@ ckstatus(){ [ "$disoverride" = "1" ] && { echo -e "\033[33m你已经禁用了配置文件覆写功能,这会导致大量脚本功能无法使用!\033[0m " read -p "是否取消禁用?(1/0) > " res - [ "$res" = 1 ] && unset disoverride && setconfig disoverride + [ "$res" = 1 ] && unset disoverride && setconfig disoverride echo ----------------------------------------------- } } -errornum(){ +errornum() { echo ----------------------------------------------- echo -e "\033[31m请输入正确的字母或数字!\033[0m" } -startover(){ +startover() { echo -e "\033[32m服务已启动!\033[0m" echo -e "请使用 \033[4;36mhttp://$host$hostdir\033[0m 管理内置规则" - if [ "$redir_mod" = "纯净模式" ];then + if [ "$redir_mod" = "纯净模式" ]; then echo ----------------------------------------------- echo -e "其他设备可以使用PAC配置连接:\033[4;32mhttp://$host:$db_port/ui/pac\033[0m" echo -e "或者使用HTTP/SOCK5方式连接:IP{\033[36m$host\033[0m}端口{\033[36m$mix_port\033[0m}" fi return 0 } -start_core(){ - if [ "$crashcore" = singbox -o "$crashcore" = singboxp ];then +start_core() { + if [ "$crashcore" = singbox -o "$crashcore" = singboxp ]; then core_config=${CRASHDIR}/jsons/config.json else core_config=${CRASHDIR}/yamls/config.yaml fi echo ----------------------------------------------- - if [ ! -s $core_config -a -s $CRASHDIR/configs/providers.cfg ];then + if [ ! -s $core_config -a -s $CRASHDIR/configs/providers.cfg ]; then echo -e "\033[33m没有找到${crashcore}配置文件,尝试生成providers配置文件!\033[0m" [ "$crashcore" = singboxp ] && coretype=singbox [ "$crashcore" = meta -o "$crashcore" = clashpre ] && coretype=clash source ${CRASHDIR}/webget.sh && gen_${coretype}_providers - elif [ -s $core_config -o -n "$Url" -o -n "$Https" ];then + elif [ -s $core_config -o -n "$Url" -o -n "$Https" ]; then ${CRASHDIR}/start.sh start #设置循环检测以判定服务启动是否成功 i=1 - while [ -z "$test" -a "$i" -lt 10 ];do + while [ -z "$test" -a "$i" -lt 10 ]; do sleep 1 - if curl --version > /dev/null 2>&1;then + if curl --version >/dev/null 2>&1; then test=$(curl -s http://127.0.0.1:${db_port}/configs | grep -o port) else test=$(wget -q -O - http://127.0.0.1:${db_port}/configs | grep -o port) fi - i=$((i+1)) + i=$((i + 1)) done [ -n "$test" -o -n "$(pidof CrashCore)" ] && startover else @@ -208,15 +211,15 @@ start_core(){ source ${CRASHDIR}/webget.sh && set_core_config fi } -start_service(){ - if [ "$firewall_area" = 5 ];then +start_service() { + if [ "$firewall_area" = 5 ]; then ${CRASHDIR}/start.sh start echo -e "\033[32m已完成防火墙设置!\033[0m" else start_core fi } -checkrestart(){ +checkrestart() { echo ----------------------------------------------- echo -e "\033[32m检测到已变更的内容,请重启服务!\033[0m" echo ----------------------------------------------- @@ -224,7 +227,7 @@ checkrestart(){ [ "$res" = 1 ] && start_service } #功能相关 -log_pusher(){ #日志菜单 +log_pusher() { #日志菜单 [ -n "$push_TG" ] && stat_TG=32m已启用 || stat_TG=33m未启用 [ -n "$push_Deer" ] && stat_Deer=32m已启用 || stat_Deer=33m未启用 [ -n "$push_bark" ] && stat_bark=32m已启用 || stat_bark=33m未启用 @@ -243,10 +246,10 @@ log_pusher(){ #日志菜单 echo -e " 8 设置设备名称 ——\033[$device_s\033[0m" echo -e " 9 清空日志文件" echo ----------------------------------------------- - read -p "请输入对应数字 > " num + read -p "请输入对应数字 > " num case $num in 1) - if [ -s ${TMPDIR}/ShellCrash.log ];then + if [ -s ${TMPDIR}/ShellCrash.log ]; then echo ----------------------------------------------- cat ${TMPDIR}/ShellCrash.log exit 0 @@ -254,10 +257,10 @@ log_pusher(){ #日志菜单 echo -e "\033[31m未找到相关日志!\033[0m" fi sleep 1 - ;; + ;; 2) echo ----------------------------------------------- - if [ -n "$push_TG" ];then + if [ -n "$push_TG" ]; then read -p "确认关闭TG日志推送?(1/0) > " res [ "$res" = 1 ] && { push_TG= @@ -274,17 +277,17 @@ log_pusher(){ #日志菜单 echo -e "请向\033[32m你申请的机器人\033[31m而不是BotFather\033[0m,发送任意几条消息!" echo ----------------------------------------------- read -p "我已经发送完成(1/0) > " res - if [ "$res" = 1 ];then + if [ "$res" = 1 ]; then url_tg=https://api.telegram.org/bot${TOKEN}/getUpdates [ -n "$authentication" ] && auth="$authentication@" export https_proxy="http://${auth}127.0.0.1:$mix_port" - if curl --version >/dev/null 2>&1;then - chat=$(curl -kfsSl $url_tg 2>/dev/null| tail -n -1) + if curl --version >/dev/null 2>&1; then + chat=$(curl -kfsSl $url_tg 2>/dev/null | tail -n -1) else chat=$(wget -Y on -q -O - $url_tg | tail -n -1) fi - [ -n "$chat" ] && chat_ID=$(echo $chat | grep -oE '"id":.*,"is_bot":false' | sed s'/"id"://'g | sed s'/,"is_bot":false//'g) - if [ -n "$chat_ID" ];then + [ -n "$chat" ] && chat_ID=$(echo $chat | grep -oE '"id":.*,"is_bot":false' | sed s'/"id"://'g | sed s'/,"is_bot":false//'g) + if [ -n "$chat_ID" ]; then push_TG=$TOKEN setconfig push_TG $TOKEN setconfig chat_ID $chat_ID @@ -296,10 +299,10 @@ log_pusher(){ #日志菜单 sleep 1 fi log_pusher - ;; + ;; 3) echo ----------------------------------------------- - if [ -n "$push_Deer" ];then + if [ -n "$push_Deer" ]; then read -p "确认关闭PushDeer日志推送?(1/0) > " res [ "$res" = 1 ] && { push_Deer= @@ -313,7 +316,7 @@ log_pusher(){ #日志菜单 echo -e "\033[36m切换到「秘钥」标签页,点击右上角的加号,创建一个秘钥,并复制\033[0m" echo ----------------------------------------------- read -p "请输入你复制的秘钥 > " url - if [ -n "$url" ];then + if [ -n "$url" ]; then push_Deer=$url setconfig push_Deer $url ${CRASHDIR}/start.sh logger "已完成PushDeer日志推送设置!" 32 @@ -323,10 +326,10 @@ log_pusher(){ #日志菜单 sleep 1 fi log_pusher - ;; + ;; 4) echo ----------------------------------------------- - if [ -n "$push_bark" ];then + if [ -n "$push_bark" ]; then read -p "确认关闭Bark日志推送?(1/0) > " res [ "$res" = 1 ] && { push_bark= @@ -340,7 +343,7 @@ log_pusher(){ #日志菜单 echo -e "\033[32m请安装Bark-IOS客户端,并在客户端中找到专属推送链接\033[0m" echo ----------------------------------------------- read -p "请输入你的Bark推送链接 > " url - if [ -n "$url" ];then + if [ -n "$url" ]; then push_bark=$url setconfig push_bark $url ${CRASHDIR}/start.sh logger "已完成Bark日志推送设置!" 32 @@ -350,10 +353,10 @@ log_pusher(){ #日志菜单 sleep 1 fi log_pusher - ;; + ;; 5) echo ----------------------------------------------- - if [ -n "$push_Po" ];then + if [ -n "$push_Po" ]; then read -p "确认关闭Pushover日志推送?(1/0) > " res [ "$res" = 1 ] && { push_Po= @@ -366,15 +369,15 @@ log_pusher(){ #日志菜单 echo -e "请先通过 \033[32;4mhttps://pushover.net/\033[0m 注册账号并获取\033[36mUser Key\033[0m" echo ----------------------------------------------- read -p "请输入你的User Key > " key - if [ -n "$key" ];then + if [ -n "$key" ]; then echo ----------------------------------------------- echo -e "\033[33m请检查注册邮箱,完成账户验证\033[0m" - read -p "我已经验证完成(1/0) > " + read -p "我已经验证完成(1/0) > " echo ----------------------------------------------- echo -e "请通过 \033[32;4mhttps://pushover.net/apps/build\033[0m 生成\033[36mAPI Token\033[0m" echo ----------------------------------------------- read -p "请输入你的API Token > " Token - if [ -n "$Token" ];then + if [ -n "$Token" ]; then push_Po=$Token push_Po_key=$key setconfig push_Po $Token @@ -389,10 +392,10 @@ log_pusher(){ #日志菜单 fi sleep 1 log_pusher - ;; + ;; 6) echo ----------------------------------------------- - if [ -n "$push_PP" ];then + if [ -n "$push_PP" ]; then read -p "确认关闭PushPlus日志推送?(1/0) > " res [ "$res" = 1 ] && { push_PP= @@ -403,7 +406,7 @@ log_pusher(){ #日志菜单 echo -e "请先通过 \033[32;4mhttps://www.pushplus.plus/push1.html\033[0m 注册账号并获取\033[36mtoken\033[0m" echo ----------------------------------------------- read -p "请输入你的token > " Token - if [ -n "$Token" ];then + if [ -n "$Token" ]; then push_PP=$Token setconfig push_PP $Token ${CRASHDIR}/start.sh logger "已完成PushPlus日志推送设置!" 32 @@ -413,33 +416,33 @@ log_pusher(){ #日志菜单 fi sleep 1 log_pusher - ;; - 7) + ;; + 7) [ "$task_push" = 1 ] && task_push='' || task_push=1 setconfig task_push $task_push sleep 1 - log_pusher - ;; - 8) + log_pusher + ;; + 8) read -p "请输入本设备自定义推送名称 > " device_name setconfig device_name $device_name sleep 1 - log_pusher - ;; - 9) + log_pusher + ;; + 9) echo -e "\033[33m运行日志及任务日志均已清空!\033[0m" rm -rf ${TMPDIR}/ShellCrash.log sleep 1 - log_pusher - ;; - *) errornum ;; + log_pusher + ;; + *) errornum ;; esac } -setport(){ #端口设置 - source $CFG_PATH > /dev/null +setport() { #端口设置 + source $CFG_PATH >/dev/null [ -z "$secret" ] && secret=未设置 [ -z "$authentication" ] && auth=未设置 || auth=****** - inputport(){ + inputport() { read -p "请输入端口号(1-65535) > " portx if [ -z "$portx" ]; then setport @@ -449,11 +452,11 @@ setport(){ #端口设置 elif [ -n "$(echo "|$mix_port|$redir_port|$dns_port|$db_port|" | grep "|$portx|")" ]; then echo -e "\033[31m输入错误!请不要输入重复的端口!\033[0m" inputport - elif [ -n "$(netstat -ntul |grep ":$portx ")" ];then + elif [ -n "$(netstat -ntul | grep ":$portx ")" ]; then echo -e "\033[31m当前端口已被其他进程占用,请重新输入!\033[0m" inputport else - setconfig $xport $portx + setconfig $xport $portx echo -e "\033[32m设置成功!!!\033[0m" setport fi @@ -469,7 +472,7 @@ setport(){ #端口设置 echo -e " 8 自定义本机host地址: \033[36m$host\033[0m" echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num - if [ -z "$num" ]; then + if [ -z "$num" ]; then errornum elif [ "$num" = 1 ]; then xport=mix_port @@ -481,12 +484,12 @@ setport(){ #端口设置 echo "输入 0 删除密码" echo ----------------------------------------------- read -p "请输入Http/Sock5用户名及密码 > " input - if [ "$input" = "0" ];then + if [ "$input" = "0" ]; then authentication="" setconfig authentication echo 密码已移除! else - if [ "$local_proxy" = "已开启" -a "$local_type" = "环境变量" ];then + if [ "$local_proxy" = "已开启" -a "$local_type" = "环境变量" ]; then echo ----------------------------------------------- echo -e "\033[33m请先禁用本机代理功能或使用增强模式!\033[0m" sleep 1 @@ -539,12 +542,12 @@ setport(){ #端口设置 echo -e "\033[31m设置后如本机host地址有变动,请务必重新修改!\033[0m" echo ----------------------------------------------- read -p "请输入自定义host地址(输入0移除自定义host) > " host - if [ "$host" = "0" ];then + if [ "$host" = "0" ]; then host="" setconfig host $host echo -e "\033[32m已经移除自定义host地址,请重新运行脚本以自动获取host!!!\033[0m" exit 0 - elif [ -n "$(echo $host |grep -E -o '\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[01][0-9]|22[0-3])\>(\.\<([0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>){2}\.\<([1-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4])\>' )" ]; then + elif [ -n "$(echo $host | grep -E -o '\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[01][0-9]|22[0-3])\>(\.\<([0-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>){2}\.\<([1-9]|[0-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4])\>')" ]; then setconfig host $host echo -e "\033[32m设置成功!!!\033[0m" else @@ -553,9 +556,9 @@ setport(){ #端口设置 fi sleep 1 setport - fi + fi } -setdns(){ #DNS设置 +setdns() { #DNS设置 [ -z "$dns_nameserver" ] && dns_nameserver='114.114.114.114, 223.5.5.5' [ -z "$dns_fallback" ] && dns_fallback='1.0.0.1, 8.8.4.4' [ -z "$hosts_opt" ] && hosts_opt=已开启 @@ -578,7 +581,7 @@ setdns(){ #DNS设置 echo -e " 0 返回上级菜单" echo ----------------------------------------------- read -p "请输入对应数字 > " num - if [ -z "$num" ]; then + if [ -z "$num" ]; then errornum elif [ "$num" = 1 ]; then read -p "请输入新的DNS > " dns_nameserver @@ -588,16 +591,16 @@ setdns(){ #DNS设置 echo -e "\033[32m设置成功!!!\033[0m" fi setdns - + elif [ "$num" = 2 ]; then read -p "请输入新的DNS > " dns_fallback dns_fallback=$(echo $dns_fallback | sed 's/|/\,\ /g') if [ -n "$dns_fallback" ]; then - setconfig dns_fallback \'"$dns_fallback"\' + setconfig dns_fallback \'"$dns_fallback"\' echo -e "\033[32m设置成功!!!\033[0m" fi setdns - + elif [ "$num" = 3 ]; then dns_nameserver="" dns_fallback="" @@ -605,22 +608,22 @@ setdns(){ #DNS设置 setconfig dns_fallback echo -e "\033[33mDNS配置已重置!!!\033[0m" setdns - + elif [ "$num" = 4 ]; then echo ----------------------------------------------- openssldir="$(openssl version -d 2>&1 | awk -F '"' '{print $2}')" - if [ -s "$openssldir/certs/ca-certificates.crt" -o -s "/etc/ssl/certs/ca-certificates.crt" ];then + if [ -s "$openssldir/certs/ca-certificates.crt" -o -s "/etc/ssl/certs/ca-certificates.crt" ]; then dns_nameserver='https://223.5.5.5/dns-query, https://doh.pub/dns-query, tls://dns.rubyfish.cn:853' dns_fallback='tls://1.0.0.1:853, tls://8.8.4.4:853, https://doh.opendns.com/dns-query' setconfig dns_nameserver \'"$dns_nameserver"\' - setconfig dns_fallback \'"$dns_fallback"\' + setconfig dns_fallback \'"$dns_fallback"\' echo -e "\033[32m已设置加密DNS,如出现DNS解析问题,请尝试重置DNS配置!\033[0m" else echo -e "\033[31m找不到根证书文件,无法启用加密DNS,Linux系统请自行搜索安装OpenSSL的方式!\033[0m" fi sleep 2 setdns - + elif [ "$num" = 5 ]; then echo ----------------------------------------------- if [ "$hosts_opt" = "已启用" ]; then @@ -633,18 +636,18 @@ setdns(){ #DNS设置 sleep 1 setconfig hosts_opt $hosts_opt setdns - + elif [ "$num" = 6 ]; then echo ----------------------------------------------- - if [ "$dns_redir" = "未开启" ]; then + if [ "$dns_redir" = "未开启" ]; then echo -e "\033[31m将使用OpenWrt中Dnsmasq插件自带的DNS转发功能转发DNS请求至内核!\033[0m" echo -e "\033[33m启用后将禁用本插件自带的iptables转发功能\033[0m" dns_redir=已开启 echo -e "\033[32m已启用Dnsmasq转发DNS功能!!!\033[0m" sleep 1 else - uci del dhcp.@dnsmasq[-1].server - uci set dhcp.@dnsmasq[0].noresolv=0 + uci del dhcp.@dnsmasq[-1].server + uci set dhcp.@dnsmasq[0].noresolv=0 uci commit dhcp /etc/init.d/dnsmasq restart echo -e "\033[33m禁用成功!!如有报错请重启设备!\033[0m" @@ -653,7 +656,7 @@ setdns(){ #DNS设置 sleep 1 setconfig dns_redir $dns_redir setdns - + elif [ "$num" = 7 ]; then echo ----------------------------------------------- if [ "$dns_no" = "未禁用" ]; then @@ -669,22 +672,21 @@ setdns(){ #DNS设置 setdns fi } -setipv6(){ #ipv6设置 +setipv6() { #ipv6设置 [ -z "$ipv6_redir" ] && ipv6_redir=未开启 [ -z "$ipv6_dns" ] && ipv6_dns=已开启 [ -z "$cn_ipv6_route" ] && cn_ipv6_route=未开启 echo ----------------------------------------------- echo -e " 1 ipv6透明代理: \033[36m$ipv6_redir\033[0m ——代理ipv6流量" - [ "$disoverride" != "1" ] && echo -e " 2 ipv6-DNS解析: \033[36m$ipv6_dns\033[0m ——决定内置DNS是否返回ipv6地址" - echo -e " 3 CNV6绕过内核: \033[36m$cn_ipv6_route\033[0m ——优化性能,不兼容fake-ip" + [ "$disoverride" != "1" ] && echo -e " 2 ipv6-DNS解析: \033[36m$ipv6_dns\033[0m ——决定内置DNS是否返回ipv6地址" + echo -e " 3 CNV6绕过内核: \033[36m$cn_ipv6_route\033[0m ——优化性能,不兼容fake-ip" echo -e " 0 返回上级菜单" echo ----------------------------------------------- - read -p "请输入对应数字 > " num + read -p "请输入对应数字 > " num case $num in - 0) - ;; + 0) ;; 1) - if [ "$ipv6_redir" = "未开启" ]; then + if [ "$ipv6_redir" = "未开启" ]; then ipv6_support=已开启 ipv6_redir=已开启 sleep 2 @@ -693,13 +695,13 @@ setipv6(){ #ipv6设置 fi setconfig ipv6_redir $ipv6_redir setconfig ipv6_support $ipv6_support - setipv6 - ;; + setipv6 + ;; 2) [ "$ipv6_dns" = "未开启" ] && ipv6_dns=已开启 || ipv6_dns=未开启 setconfig ipv6_dns $ipv6_dns setipv6 - ;; + ;; 3) if [ "$ipv6_redir" = "未开启" ]; then ipv6_support=已开启 @@ -707,7 +709,7 @@ setipv6(){ #ipv6设置 setconfig ipv6_redir $ipv6_redir setconfig ipv6_support $ipv6_support fi - if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = nftables ];then + if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = nftables ]; then [ "$cn_ipv6_route" = "未开启" ] && cn_ipv6_route=已开启 || cn_ipv6_route=未开启 setconfig cn_ipv6_route $cn_ipv6_route else @@ -715,18 +717,18 @@ setipv6(){ #ipv6设置 sleep 1 fi setipv6 - ;; + ;; *) errornum - ;; + ;; esac } -setfirewall(){ #防火墙设置 - set_cust_host_ipv4(){ +setfirewall() { #防火墙设置 + set_cust_host_ipv4() { [ -z "$replace_default_host_ipv4" ] && replace_default_host_ipv4="未启用" 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$(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[36m$cust_host_ipv4\033[0m" echo ----------------------------------------------- echo -e " 1 移除所有自定义网段" @@ -742,16 +744,15 @@ setfirewall(){ #防火墙设置 fi setconfig replace_default_host_ipv4 "$replace_default_host_ipv4" set_cust_host_ipv4 - ;; + ;; 1) unset cust_host_ipv4 setconfig cust_host_ipv4 set_cust_host_ipv4 - ;; - 0) - ;; + ;; + 0) ;; *) - if [ -n "$(echo $text | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" -a -z "$(echo $cust_host_ipv4 | grep "$text")" ];then + if [ -n "$(echo $text | grep -Eo '^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}'$)" -a -z "$(echo $cust_host_ipv4 | grep "$text")" ]; then cust_host_ipv4="$cust_host_ipv4 $text" setconfig cust_host_ipv4 "'$cust_host_ipv4'" else @@ -760,7 +761,7 @@ setfirewall(){ #防火墙设置 fi sleep 1 set_cust_host_ipv4 - ;; + ;; esac } [ -z "$public_support" ] && public_support=未开启 @@ -770,23 +771,23 @@ setfirewall(){ #防火墙设置 echo ----------------------------------------------- echo -e " 1 公网访问Dashboard面板: \033[36m$public_support\033[0m" echo -e " 2 公网访问Socks/Http代理: \033[36m$public_mixport\033[0m" - echo -e " 3 自定义透明路由ipv4网段: 适合vlan等复杂网络环境" - echo -e " 4 自定义保留地址ipv4网段: 需要以保留地址为访问目标的环境" + echo -e " 3 自定义透明路由ipv4网段: 适合vlan等复杂网络环境" + echo -e " 4 自定义保留地址ipv4网段: 需要以保留地址为访问目标的环境" echo ----------------------------------------------- - read -p "请输入对应数字 > " num + read -p "请输入对应数字 > " num case $num in 1) - if [ "$public_support" = "未开启" ]; then + if [ "$public_support" = "未开启" ]; then public_support=已开启 else public_support=未开启 fi setconfig public_support $public_support - setfirewall - ;; + setfirewall + ;; 2) - if [ "$public_mixport" = "未开启" ]; then - if [ "$mix_port" = "7890" -o -z "$authentication" ];then + if [ "$public_mixport" = "未开启" ]; then + if [ "$mix_port" = "7890" -o -z "$authentication" ]; then echo ----------------------------------------------- echo -e "\033[33m为了安全考虑,请先修改默认Socks/Http端口并设置代理密码\033[0m" sleep 1 @@ -798,19 +799,20 @@ setfirewall(){ #防火墙设置 public_mixport=未开启 fi setconfig public_mixport $public_mixport - setfirewall - ;; + setfirewall + ;; 3) set_cust_host_ipv4 setfirewall - ;; + ;; 4) [ -z "$reserve_ipv4" ] && reserve_ipv4="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 100.64.0.0/10 169.254.0.0/16 172.16.0.0/12 192.168.0.0/16 224.0.0.0/4 240.0.0.0/4" echo -e "当前网段:\033[36m$reserve_ipv4\033[0m" echo -e "\033[33m地址必须是空格分隔,错误的设置可能导致网络回环或启动报错,请务必谨慎!\033[0m" read -p "请输入 > " text - if [ -n "$(echo $text |grep -E "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+" -)" ];then + if [ -n "$( + echo $text | grep -E "(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[1-2]?[0-9]))( +|$)+" + )" ]; then reserve_ipv4="$text" echo -e "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m" setconfig reserve_ipv4 "\'$reserve_ipv4\'" @@ -819,33 +821,33 @@ setfirewall(){ #防火墙设置 fi sleep 1 setfirewall - ;; + ;; *) errornum - ;; + ;; esac } -checkport(){ #自动检查端口冲突 - for portx in $dns_port $mix_port $redir_port $db_port ;do - if [ -n "$(netstat -ntul 2>&1 |grep ':$portx ')" ];then +checkport() { #自动检查端口冲突 + for portx in $dns_port $mix_port $redir_port $db_port; do + if [ -n "$(netstat -ntul 2>&1 | grep ':$portx ')" ]; then echo ----------------------------------------------- echo -e "检测到端口【$portx】被以下进程占用!内核可能无法正常启动!\033[33m" echo $(netstat -ntul | grep :$portx | head -n 1) echo -e "\033[0m-----------------------------------------------" echo -e "\033[36m请修改默认端口配置!\033[0m" setport - source $CFG_PATH > /dev/null + source $CFG_PATH >/dev/null checkport fi done } -macfilter(){ #局域网设备过滤 - get_devinfo(){ +macfilter() { #局域网设备过滤 + get_devinfo() { dev_ip=$(cat $dhcpdir | grep $dev | awk '{print $3}') && [ -z "$dev_ip" ] && dev_ip=$dev dev_mac=$(cat $dhcpdir | grep $dev | awk '{print $2}') && [ -z "$dev_mac" ] && dev_mac=$dev - dev_name=$(cat $dhcpdir | grep $dev | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' + dev_name=$(cat $dhcpdir | grep $dev | awk '{print $4}') && [ -z "$dev_name" ] && dev_name='未知设备' } - add_mac(){ + add_mac() { echo ----------------------------------------------- echo 已添加的mac地址: cat ${CRASHDIR}/configs/mac 2>/dev/null @@ -859,9 +861,9 @@ macfilter(){ #局域网设备过滤 read -p "请输入对应序号或直接输入mac地址 > " num if [ -z "$num" -o "$num" = 0 ]; then i= - elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ];then - if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$num")" ];then - echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >> ${CRASHDIR}/configs/mac + elif [ -n "$(echo $num | grep -aE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')" ]; then + if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$num")" ]; then + echo $num | grep -oE '^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$' >>${CRASHDIR}/configs/mac else echo ----------------------------------------------- echo -e "\033[31m已添加的设备,请勿重复添加!\033[0m" @@ -869,8 +871,8 @@ macfilter(){ #局域网设备过滤 add_mac elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then macadd=$(cat $dhcpdir | awk '{print $2}' | sed -n "$num"p) - if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$macadd")" ];then - echo $macadd >> ${CRASHDIR}/configs/mac + if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$macadd")" ]; then + echo $macadd >>${CRASHDIR}/configs/mac else echo ----------------------------------------------- echo -e "\033[31m已添加的设备,请勿重复添加!\033[0m" @@ -882,7 +884,7 @@ macfilter(){ #局域网设备过滤 add_mac fi } - add_ip(){ + add_ip() { echo ----------------------------------------------- echo "已添加的IP地址(段):" cat ${CRASHDIR}/configs/ip_filter 2>/dev/null @@ -897,9 +899,9 @@ macfilter(){ #局域网设备过滤 read -p "请输入对应序号或直接输入IP地址段 > " num if [ -z "$num" -o "$num" = 0 ]; then i= - elif [ -n "$(echo $num | grep -aE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$')" ];then - if [ -z "$(cat ${CRASHDIR}/configs/ip_filter | grep -E "$num")" ];then - echo $num | grep -oE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$' >> ${CRASHDIR}/configs/ip_filter + elif [ -n "$(echo $num | grep -aE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$')" ]; then + if [ -z "$(cat ${CRASHDIR}/configs/ip_filter | grep -E "$num")" ]; then + echo $num | grep -oE '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[12]?[0-9]))?$' >>${CRASHDIR}/configs/ip_filter else echo ----------------------------------------------- echo -e "\033[31m已添加的地址,请勿重复添加!\033[0m" @@ -907,8 +909,8 @@ macfilter(){ #局域网设备过滤 add_ip elif [ $num -le $(cat $dhcpdir 2>/dev/null | awk 'END{print NR}') ]; then ipadd=$(cat $dhcpdir | awk '{print $3}' | sed -n "$num"p) - if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$ipadd")" ];then - echo $ipadd >> ${CRASHDIR}/configs/ip_filter + if [ -z "$(cat ${CRASHDIR}/configs/mac | grep -E "$ipadd")" ]; then + echo $ipadd >>${CRASHDIR}/configs/ip_filter else echo ----------------------------------------------- echo -e "\033[31m已添加的地址,请勿重复添加!\033[0m" @@ -920,9 +922,9 @@ macfilter(){ #局域网设备过滤 add_ip fi } - del_all(){ + del_all() { echo ----------------------------------------------- - if [ -z "$(cat ${CRASHDIR}/configs/mac ${CRASHDIR}/configs/ip_filter 2>/dev/null)" ];then + if [ -z "$(cat ${CRASHDIR}/configs/mac ${CRASHDIR}/configs/ip_filter 2>/dev/null)" ]; then echo -e "\033[31m列表中没有需要移除的设备!\033[0m" sleep 1 else @@ -939,14 +941,14 @@ macfilter(){ #局域网设备过滤 read -p "请输入需要移除的设备的对应序号 > " num mac_filter_rows=$(cat ${CRASHDIR}/configs/mac 2>/dev/null | wc -l) ip_filter_rows=$(cat ${CRASHDIR}/configs/ip_filter 2>/dev/null | wc -l) - if [ -z "$num" ]||[ "$num" -le 0 ]; then + if [ -z "$num" ] || [ "$num" -le 0 ]; then n= - elif [ $num -le $mac_filter_rows ];then + elif [ $num -le $mac_filter_rows ]; then sed -i "${num}d" ${CRASHDIR}/configs/mac echo ----------------------------------------------- echo -e "\033[32m对应设备已移除!\033[0m" del_all - elif [ $num -le $((mac_filter_rows + ip_filter_rows)) ];then + elif [ $num -le $((mac_filter_rows + ip_filter_rows)) ]; then num=$((num - mac_filter_rows)) sed -i "${num}d" ${CRASHDIR}/configs/ip_filter echo ----------------------------------------------- @@ -965,8 +967,8 @@ macfilter(){ #局域网设备过滤 [ -z "$dhcpdir" ] && [ -f /tmp/dhcp.leases ] && dhcpdir='/tmp/dhcp.leases' [ -z "$dhcpdir" ] && [ -f /tmp/dnsmasq.leases ] && dhcpdir='/tmp/dnsmasq.leases' [ -z "$dhcpdir" ] && dhcpdir='/dev/null' - [ -z "$macfilter_type" ] && macfilter_type='黑名单' - if [ "$macfilter_type" = "黑名单" ];then + [ -z "$macfilter_type" ] && macfilter_type='黑名单' + if [ "$macfilter_type" = "黑名单" ]; then macfilter_over='白名单' macfilter_scrip='不' else @@ -999,40 +1001,39 @@ macfilter(){ #局域网设备过滤 echo -e " 0 返回上级菜单" read -p "请输入对应数字 > " num case "$num" in - 0) - ;; + 0) ;; 1) macfilter_type=$macfilter_over setconfig macfilter_type $macfilter_type echo ----------------------------------------------- echo -e "\033[32m已切换为$macfilter_type模式!\033[0m" macfilter - ;; + ;; 2) add_mac macfilter - ;; + ;; 3) add_ip macfilter - ;; + ;; 4) del_all macfilter - ;; + ;; 9) - :>${CRASHDIR}/configs/mac - :>${CRASHDIR}/configs/ip_filter + : >${CRASHDIR}/configs/mac + : >${CRASHDIR}/configs/ip_filter echo ----------------------------------------------- echo -e "\033[31m设备列表已清空!\033[0m" macfilter - ;; + ;; *) errornum - ;; + ;; esac } -setboot(){ #启动相关设置 +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允许" @@ -1050,70 +1051,69 @@ setboot(){ #启动相关设置 read -p "请输入对应数字 > " num echo ----------------------------------------------- case "$num" in - 0) - ;; - 1) + 0) ;; + 1) if [ "$autostart" = "enable" ]; 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 + [ -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 touch ${CRASHDIR}/.dis_startup autostart=disable echo -e "\033[33m已禁止ShellCrash开机启动!\033[0m" elif [ "$autostart" = "disable" ]; then [ -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 + ckcmd systemctl && systemctl enable shellcrash.service >/dev/null 2>&1 rm -rf ${CRASHDIR}/.dis_startup autostart=enable echo -e "\033[32m已设置ShellCrash开机启动!\033[0m" fi setboot - ;; + ;; 2) - if [ "$start_old" = "未开启" ] > /dev/null 2>&1; then + 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 + [ -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 start_old=已开启 setconfig start_old $start_old ${CRASHDIR}/start.sh stop else - if [ "$(cat /proc/1/comm)" = "procd" -o "$(cat /proc/1/comm)" = "systemd" ];then + if [ "$(cat /proc/1/comm)" = "procd" -o "$(cat /proc/1/comm)" = "systemd" ]; then echo -e "\033[32m改为使用系统守护进程启动服务!!\033[0m" ${CRASHDIR}/start.sh cronset "ShellCrash初始化" start_old=未开启 setconfig start_old $start_old ${CRASHDIR}/start.sh stop - + else echo -e "\033[31m当前设备不支持以其他模式启动!!\033[0m" fi fi - sleep 1 + sleep 1 setboot - ;; + ;; 3) echo -e "\033[33m如果你的设备启动后可以正常使用,则无需设置!!\033[0m" echo -e "\033[36m推荐设置为30~120秒之间,请根据设备问题自行试验\033[0m" read -p "请输入启动延迟时间(0~300秒) > " sec case "$sec" in - [0-9]|[0-9][0-9]|[0-2][0-9][0-9]|300) + [0-9] | [0-9][0-9] | [0-2][0-9][0-9] | 300) start_delay=$sec setconfig start_delay $sec echo -e "\033[32m设置成功!\033[0m" - ;; + ;; *) echo -e "\033[31m输入有误,或超过300秒,请重新输入!\033[0m" - ;; + ;; esac sleep 1 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}') - if [ "$mini_clash" = "未开启" ]; then - if [ "$dir_size" -gt 20480 ];then + 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" - elif [ "start_old" != '已开启' -a "$(cat /proc/1/comm)" = "systemd" ];then + elif [ "start_old" != '已开启' -a "$(cat /proc/1/comm)" = "systemd" ]; then echo -e "\033[33m不支持systemd启动模式,请先启用保守模式!\033[0m" else [ "$BINDIR" = "$CRASHDIR" ] && BINDIR="$TMPDIR" @@ -1121,7 +1121,7 @@ setboot(){ #启动相关设置 echo -e "如需更换目录,请使用【设置小闪存目录】功能\033[0m" fi else - if [ "$dir_size" -lt 8192 ];then + if [ "$dir_size" -lt 8192 ]; then echo -e "\033[31m您的设备剩余空间不足8M,停用后可能无法正常运行!\033[0m" read -p "确认停用此功能?(1/0) > " res [ "$res" = 1 ] && BINDIR="$CRASHDIR" && echo -e "\033[33m已经停用小闪存功能!\033[0m" @@ -1132,9 +1132,9 @@ setboot(){ #启动相关设置 fi fi setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env - sleep 1 + sleep 1 setboot - ;; + ;; 5) echo -e "\033[33m如设置到内存,则每次开机后都自动重新下载相关文件\033[0m" echo -e "\033[33m请确保安装源可用裸连,否则会导致启动失败\033[0m" @@ -1142,46 +1142,47 @@ setboot(){ #启动相关设置 echo " 2 选择U盘目录" echo " 3 自定义目录" read -p "请输入相应数字 > " num - case "$num" in + case "$num" in 1) - BINDIR="$TMPDIR" ;; + BINDIR="$TMPDIR" + ;; 2) - set_usb_dir(){ + set_usb_dir() { echo "请选择安装目录" du -hL /mnt | awk '{print " "NR" "$2" "$1}' read -p "请输入相应数字 > " num BINDIR=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) - if [ -z "$BINDIR" ];then + if [ -z "$BINDIR" ]; then echo "\033[31m输入错误!请重新设置!\033[0m" set_usb_dir fi } set_usb_dir - ;; + ;; 3) - input_dir(){ + input_dir() { read -p "请输入自定义目录 > " BINDIR - if [ ! -d "$BINDIR" ];then + if [ ! -d "$BINDIR" ]; then echo "\033[31m输入错误!请重新设置!\033[0m" input_dir fi } input_dir - ;; + ;; *) errornum - ;; + ;; esac setconfig BINDIR ${BINDIR} ${CRASHDIR}/configs/command.env setboot - ;; - *) + ;; + *) errornum - ;; - esac + ;; + esac } -set_firewall_area(){ #防火墙模式设置 +set_firewall_area() { #防火墙模式设置 [ -z "$vm_redir" ] && vm_redir='未开启' echo ----------------------------------------------- echo -e "\033[31m注意:\033[0m基于桥接网卡的Docker/虚拟机流量,请单独启用6!" @@ -1195,23 +1196,22 @@ set_firewall_area(){ #防火墙模式设置 echo -e " 6 劫持容器/虚拟机流量: \033[36m$vm_redir\033[0m" echo -e " 0 返回上级菜单" echo ----------------------------------------------- - read -p "请输入对应数字 > " num + read -p "请输入对应数字 > " num case $num in - 0) - ;; - [1-4]) + 0) ;; + [1-4]) [ $firewall_area -ge 4 ] && { redir_mod=Redir模式 - setconfig redir_mod $redir_mod + setconfig redir_mod $redir_mod } [ "$num" = 4 ] && { redir_mod=纯净模式 - setconfig redir_mod $redir_mod + setconfig redir_mod $redir_mod } firewall_area=$num setconfig firewall_area $firewall_area - ;; - 5) + ;; + 5) echo ----------------------------------------------- echo -e "\033[31m注意:\033[0m此功能存在多种风险如无网络基础请勿尝试!" echo -e "\033[33m说明:\033[0m此功能不启动内核仅配置防火墙转发,且子设备无需额外设置网关DNS" @@ -1227,9 +1227,9 @@ set_firewall_area(){ #防火墙模式设置 redir_mod=TCP旁路转发 setconfig redir_mod $redir_mod } - ;; - 6) - if [ -n "$vm_ipv4" ];then + ;; + 6) + if [ -n "$vm_ipv4" ]; then vm_des='当前劫持' else vm_ipv4=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep 'brd' | grep -E 'docker|podman|virbr|vnet|ovs|vmbr|veth|vmnic|vboxnet|lxcbr|xenbr|vEthernet' | sed 's/.*inet.//g' | sed 's/ br.*$//g' | sed 's/metric.*$//g' | tr '\n' ' ') @@ -1244,38 +1244,37 @@ set_firewall_area(){ #防火墙模式设置 echo -e " 3 \033[31m禁用劫持\033[0m" echo -e " 0 返回上级菜单" echo ----------------------------------------------- - read -p "请输入对应数字 > " num + read -p "请输入对应数字 > " num case $num in 1) vm_redir=已开启 - ;; + ;; 2) echo -e "多个网段请用空格连接,可运行容器后使用【ip route】命令查看网段地址" echo -e "示例:\033[32m10.88.0.0/16 172.17.0.0/16\033[0m" read -p "请输入自定义网段 > " text - [ -n "$text" ] && vm_ipv4=$text + [ -n "$text" ] && vm_ipv4=$text vm_redir=已开启 - ;; + ;; 3) vm_redir=未开启 unset vm_ipv4 - ;; - *) - ;; + ;; + *) ;; esac setconfig vm_redir $vm_redir setconfig vm_ipv4 "\'$vm_ipv4\'" - set_firewall_area - ;; + set_firewall_area + ;; *) errornum ;; esac sleep 1 } -set_redir_mod(){ #代理模式设置 - set_redir_config(){ +set_redir_mod() { #代理模式设置 + set_redir_config() { setconfig redir_mod $redir_mod - setconfig dns_mod $dns_mod - echo ----------------------------------------------- + setconfig dns_mod $dns_mod + echo ----------------------------------------------- echo -e "\033[36m已设为 $redir_mod !!\033[0m" } [ -n "$(ls /dev/net/tun 2>/dev/null)" ] || ip tuntap >/dev/null 2>&1 && sup_tun=1 @@ -1302,16 +1301,16 @@ set_redir_mod(){ #代理模式设置 echo -e " 8 切换防火墙应用:\033[47;30m$firewall_mod\033[0m" echo -e " 9 ipv6设置:\033[47;30m$ipv6_redir\033[0m" echo " 0 返回上级菜单" - read -p "请输入对应数字 > " num - case $num in + read -p "请输入对应数字 > " num + case $num in 0) ;; 1) redir_mod=Redir模式 set_redir_config set_redir_mod - ;; + ;; 2) - if [ -n "$sup_tun" ];then + if [ -n "$sup_tun" ]; then redir_mod=混合模式 set_redir_config else @@ -1319,36 +1318,36 @@ set_redir_mod(){ #代理模式设置 sleep 1 fi set_redir_mod - ;; + ;; 3) - if [ "$firewall_mod" = "iptables" ] ;then - if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ] ;then + if [ "$firewall_mod" = "iptables" ]; then + if [ -f /etc/init.d/qca-nss-ecm -a "$systype" = "mi_snapshot" ]; then read -p "xiaomi设备的QOS服务与本模式冲突,是否禁用相关功能?(1/0) > " res [ "$res" = '1' ] && { ${CRASHDIR}/misnap_init.sh tproxyfix redir_mod=Tproxy模式 set_redir_config } - elif grep -qE '^TPROXY$' /proc/net/ip_tables_targets || modprobe xt_TPROXY >/dev/null 2>&1;then + elif grep -qE '^TPROXY$' /proc/net/ip_tables_targets || modprobe xt_TPROXY >/dev/null 2>&1; then redir_mod=Tproxy模式 set_redir_config else echo -e "\033[31m设备未检测到iptables-mod-tproxy模块,请尝试其他模式或者安装相关依赖!\033[0m" - sleep 1 - fi - elif [ "$firewall_mod" = "nftables" ] ;then - if modprobe nft_tproxy >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q nft_tproxy;then + sleep 1 + fi + elif [ "$firewall_mod" = "nftables" ]; then + if modprobe nft_tproxy >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q nft_tproxy; then redir_mod=Tproxy模式 set_redir_config else echo -e "\033[31m设备未检测到nft_tproxy内核模块,请尝试其他模式或者安装相关依赖!\033[0m" - sleep 1 + sleep 1 fi fi set_redir_mod - ;; + ;; 4) - if [ -n "$sup_tun" ];then + if [ -n "$sup_tun" ]; then redir_mod=Tun模式 set_redir_config else @@ -1356,125 +1355,126 @@ set_redir_mod(){ #代理模式设置 sleep 1 fi set_redir_mod - ;; + ;; 5) redir_mod=TCP旁路转发 set_redir_config set_redir_mod - ;; + ;; 6) - redir_mod=T&U旁路转发 + redir_mod=T & + U旁路转发 set_redir_config set_redir_mod - ;; + ;; 7) set_firewall_area set_redir_mod - ;; + ;; 8) - if [ "$firewall_mod" = 'iptables' ];then - if nft add table inet shellcrash 2>/dev/null;then + if [ "$firewall_mod" = 'iptables' ]; then + if nft add table inet shellcrash 2>/dev/null; then firewall_mod=nftables redir_mod=Redir模式 setconfig redir_mod $redir_mod else - echo -e "\033[31m当前设备未安装nftables或者nftables版本过低(<1.0.2),无法切换!\033[0m" + echo -e "\033[31m当前设备未安装nftables或者nftables版本过低(<1.0.2),无法切换!\033[0m" fi - elif [ "$firewall_mod" = 'nftables' ];then - if ckcmd iptables;then + elif [ "$firewall_mod" = 'nftables' ]; then + if ckcmd iptables; then firewall_mod=iptables redir_mod=Redir模式 setconfig redir_mod $redir_mod else - echo -e "\033[31m当前设备未安装iptables,无法切换!\033[0m" + echo -e "\033[31m当前设备未安装iptables,无法切换!\033[0m" fi else iptables -j REDIRECT -h >/dev/null 2>&1 && firewall_mod=iptables nft add table inet shellcrash 2>/dev/null && firewall_mod=nftables - if [ -n "$firewall_mod" ];then + if [ -n "$firewall_mod" ]; then redir_mod=Redir模式 setconfig redir_mod $redir_mod setconfig firewall_mod $firewall_mod else - echo -e "\033[31m检测不到可用的防火墙应用(iptables/nftables),无法切换!\033[0m" + echo -e "\033[31m检测不到可用的防火墙应用(iptables/nftables),无法切换!\033[0m" fi fi sleep 1 setconfig firewall_mod $firewall_mod set_redir_mod - ;; + ;; 9) setipv6 set_redir_mod - ;; + ;; *) errornum - ;; + ;; esac } -set_dns_mod(){ #DNS设置 +set_dns_mod() { #DNS设置 echo ----------------------------------------------- echo -e "当前DNS运行模式为:\033[47;30m $dns_mod \033[0m" echo -e "\033[33m切换模式后需要手动重启服务以生效!\033[0m" echo ----------------------------------------------- echo -e " 1 fake-ip模式: \033[32m响应速度更快\033[0m" echo -e " 不支持绕过CN-IP功能" - if [ "$crashcore" = singbox -o "$crashcore" = singboxp ];then + if [ "$crashcore" = singbox -o "$crashcore" = singboxp ]; then echo -e " 3 mix混合模式: \033[32m内部realip外部fakeip\033[0m" echo -e " 依赖geosite-cn.(db/srs)数据库" - elif [ "$crashcore" = meta ];then + elif [ "$crashcore" = meta ]; then echo -e " 2 redir_host模式:\033[32m兼容性更好\033[0m" echo -e " 需搭配加密DNS使用" fi echo -e " 4 \033[36mDNS进阶设置\033[0m" echo " 0 返回上级菜单" read -p "请输入对应数字 > " num - case $num in + case $num in 0) ;; 1) dns_mod=fake-ip - setconfig dns_mod $dns_mod - echo ----------------------------------------------- + setconfig dns_mod $dns_mod + echo ----------------------------------------------- echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" - ;; + ;; 2) dns_mod=redir_host - setconfig dns_mod $dns_mod - echo ----------------------------------------------- + setconfig dns_mod $dns_mod + echo ----------------------------------------------- echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" - ;; + ;; 3) - if [ "$crashcore" = singbox -o "$crashcore" = singboxp ];then + if [ "$crashcore" = singbox -o "$crashcore" = singboxp ]; then dns_mod=mix - setconfig dns_mod $dns_mod - echo ----------------------------------------------- + setconfig dns_mod $dns_mod + echo ----------------------------------------------- echo -e "\033[36m已设为 $dns_mod 模式!!\033[0m" else echo -e "\033[31m当前内核不支持的功能!!!\033[0m" sleep 1 fi - ;; + ;; 4) setdns set_dns_mod - ;; + ;; *) errornum - ;; + ;; esac } -fake_ip_filter(){ +fake_ip_filter() { echo -e "\033[32m用于解决Fake-ip模式下部分地址或应用无法连接的问题\033[0m" echo -e "\033[31m脚本已经内置了大量地址,你只需要添加出现问题的地址!\033[0m" echo -e "\033[36m示例:a.b.com" echo -e "示例:*.b.com" echo -e "示例:*.*.b.com\033[0m" echo ----------------------------------------------- - if [ -s ${CRASHDIR}/configs/fake_ip_filter ];then + if [ -s ${CRASHDIR}/configs/fake_ip_filter ]; then echo -e "\033[33m已添加Fake-ip过滤地址:\033[0m" cat ${CRASHDIR}/configs/fake_ip_filter | awk '{print NR" "$1}' else - echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m" + echo -e "\033[33m你还未添加Fake-ip过滤地址\033[0m" fi echo ----------------------------------------------- echo -e "\033[32m输入数字直接移除对应地址,输入地址直接添加!\033[0m" @@ -1483,19 +1483,19 @@ fake_ip_filter(){ 0) ;; '') ;; [0-99]) - sed -i "${input}d" ${CRASHDIR}/configs/fake_ip_filter 2>/dev/null - echo -e "\033[32m移除成功!\033[0m" + sed -i "${input}d" ${CRASHDIR}/configs/fake_ip_filter 2>/dev/null + echo -e "\033[32m移除成功!\033[0m" fake_ip_filter - ;; + ;; *) - echo -e "你输入的地址是:\033[32m$input\033[0m" + echo -e "你输入的地址是:\033[32m$input\033[0m" read -p "确认添加?(1/0) > " res - [ "$res" = 1 ] && echo $input >> ${CRASHDIR}/configs/fake_ip_filter + [ "$res" = 1 ] && echo $input >>${CRASHDIR}/configs/fake_ip_filter fake_ip_filter - ;; + ;; esac } -normal_set(){ #基础设置 +normal_set() { #基础设置 #获取设置默认显示 [ -z "$skip_cert" ] && skip_cert=已开启 [ -z "$common_ports" ] && common_ports=已开启 @@ -1518,10 +1518,10 @@ normal_set(){ #基础设置 echo -e " 5 过滤局域网设备: \033[36m$mac_return\033[0m ————使用黑/白名单进行过滤" echo -e " 7 屏蔽QUIC流量: \033[36m$quic_rj\033[0m ————优化视频性能" [ "$disoverride" != "1" ] && { - [ "$dns_mod" != "fake-ip" ] && \ - echo -e " 8 CN_IP绕过内核: \033[36m$cn_ip_route\033[0m ————优化性能,不兼容Fake-ip" - [ "$dns_mod" != "redir_host" ] && \ - echo -e " 9 管理Fake-ip过滤列表" + [ "$dns_mod" != "fake-ip" ] && + echo -e " 8 CN_IP绕过内核: \033[36m$cn_ip_route\033[0m ————优化性能,不兼容Fake-ip" + [ "$dns_mod" != "redir_host" ] && + echo -e " 9 管理Fake-ip过滤列表" } echo ----------------------------------------------- echo -e " 0 返回上级菜单 \033[0m" @@ -1532,7 +1532,7 @@ normal_set(){ #基础设置 elif [ "$num" = 0 ]; then i= elif [ "$num" = 1 ]; then - if [ "$USER" != "root" -a "$USER" != "admin" ];then + if [ "$USER" != "root" -a "$USER" != "admin" ]; then echo ----------------------------------------------- read -p "非root用户可能无法正确配置其他模式!依然尝试吗?(1/0) > " res [ "$res" = 1 ] && set_redir_mod @@ -1540,26 +1540,26 @@ normal_set(){ #基础设置 set_redir_mod fi normal_set - + elif [ "$num" = 2 ]; then set_dns_mod normal_set - - elif [ "$num" = 3 ]; then + + elif [ "$num" = 3 ]; then echo ----------------------------------------------- - if [ "$skip_cert" = "未开启" ] > /dev/null 2>&1; then + if [ "$skip_cert" = "未开启" ] >/dev/null 2>&1; then echo -e "\033[33m已设为开启跳过本地证书验证!!\033[0m" skip_cert=已开启 else echo -e "\033[33m已设为禁止跳过本地证书验证!!\033[0m" skip_cert=未开启 fi - setconfig skip_cert $skip_cert + setconfig skip_cert $skip_cert normal_set - - elif [ "$num" = 4 ]; then - set_common_ports(){ - if [ "$common_ports" = "未开启" ]; then + + elif [ "$num" = 4 ]; then + set_common_ports() { + if [ "$common_ports" = "未开启" ]; then echo -e "\033[33m已设为仅代理【$multiport】等常用端口!!\033[0m" echo -e "\033[31m注意,fake-ip模式下,非常用端口的域名连接将不受影响!!\033[0m" common_ports=已开启 @@ -1571,27 +1571,27 @@ normal_set(){ #基础设置 setconfig common_ports $common_ports } echo ----------------------------------------------- - if [ -n "$(pidof CrashCore)" ];then + if [ -n "$(pidof CrashCore)" ]; then read -p "切换时将停止服务,是否继续?(1/0) > " res [ "$res" = 1 ] && ${CRASHDIR}/start.sh stop && set_common_ports else set_common_ports fi - normal_set + normal_set - elif [ "$num" = 5 ]; then + elif [ "$num" = 5 ]; then checkcfg_mac=$(cat ${CRASHDIR}/configs/mac) macfilter - if [ -n "$PID" ];then + if [ -n "$PID" ]; then checkcfg_mac_new=$(cat ${CRASHDIR}/configs/mac) [ "$checkcfg_mac" != "$checkcfg_mac_new" ] && checkrestart fi normal_set - - elif [ "$num" = 7 ]; then + + elif [ "$num" = 7 ]; then echo ----------------------------------------------- - if [ -n "$(echo "$redir_mod" | grep -oE '混合|Tproxy|Tun')" ];then - if [ "$quic_rj" = "未开启" ]; then + if [ -n "$(echo "$redir_mod" | grep -oE '混合|Tproxy|Tun')" ]; then + if [ "$quic_rj" = "未开启" ]; then echo -e "\033[33m已禁止QUIC流量通过ShellCrash内核!!\033[0m" quic_rj=已启用 else @@ -1603,11 +1603,11 @@ normal_set(){ #基础设置 echo -e "\033[33m当前模式默认不会代理UDP流量,无需设置!!\033[0m" fi sleep 1 - normal_set - - elif [ "$num" = 8 ]; then - if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ];then - if [ "$cn_ip_route" = "未开启" ]; then + normal_set + + elif [ "$num" = 8 ]; then + if [ -n "$(ipset -v 2>/dev/null)" ] || [ "$firewall_mod" = 'nftables' ]; then + if [ "$cn_ip_route" = "未开启" ]; then echo -e "\033[32m已开启CN_IP绕过内核功能!!\033[0m" echo -e "\033[31m注意!!!此功能会导致全局模式及一切CN相关规则失效!!!\033[0m" cn_ip_route=已开启 @@ -1622,17 +1622,17 @@ normal_set(){ #基础设置 sleep 1 fi normal_set - + elif [ "$num" = 9 ]; then echo ----------------------------------------------- fake_ip_filter - normal_set - + normal_set + else errornum fi } -advanced_set(){ #进阶设置 +advanced_set() { #进阶设置 #获取设置默认显示 [ -z "$proxies_bypass" ] && proxies_bypass=未启用 [ -z "$start_old" ] && start_old=未开启 @@ -1658,16 +1658,15 @@ advanced_set(){ #进阶设置 echo ----------------------------------------------- read -p "请输入对应数字 > " num case "$num" in - 0) - ;; + 0) ;; 3) setfirewall - advanced_set - ;; + advanced_set + ;; 4) echo ----------------------------------------------- - if [ "$sniffer" = "未启用" ];then - if [ "$crashcore" = "clash" ];then + if [ "$sniffer" = "未启用" ]; then + if [ "$crashcore" = "clash" ]; then rm -rf ${TMPDIR}/CrashCore rm -rf ${CRASHDIR}/CrashCore rm -rf ${CRASHDIR}/CrashCore.tar.gz @@ -1676,30 +1675,30 @@ advanced_set(){ #进阶设置 echo "已将ShellCrash内核切换为Meta内核!域名嗅探依赖Meta或者高版本clashpre内核!" fi sniffer=已启用 - elif [ "$crashcore" = "clashpre" -a "$dns_mod" = "redir_host" ];then + elif [ "$crashcore" = "clashpre" -a "$dns_mod" = "redir_host" ]; then echo -e "\033[31m使用clashpre内核且开启redir-host模式时无法关闭!\033[0m" else sniffer=未启用 fi setconfig sniffer $sniffer echo -e "\033[32m设置成功!\033[0m" - sleep 1 + sleep 1 advanced_set - ;; + ;; 5) - if [ -n "$(pidof CrashCore)" ];then + if [ -n "$(pidof CrashCore)" ]; then echo ----------------------------------------------- echo -e "\033[33m检测到服务正在运行,需要先停止服务!\033[0m" read -p "是否停止服务?(1/0) > " res - if [ "$res" = "1" ];then + if [ "$res" = "1" ]; then ${CRASHDIR}/start.sh stop setport fi else setport - fi + fi advanced_set - ;; + ;; 9) echo -e " 1 备份脚本设置" echo -e " 2 还原脚本设置" @@ -1715,7 +1714,7 @@ advanced_set(){ #进阶设置 cp -f $CFG_PATH $CFG_PATH.bak echo -e "\033[32m脚本设置已备份!\033[0m" elif [ "$num" = 2 ]; then - if [ -f "$CFG_PATH.bak" ];then + if [ -f "$CFG_PATH.bak" ]; then mv -f $CFG_PATH $CFG_PATH.bak2 mv -f $CFG_PATH.bak $CFG_PATH mv -f $CFG_PATH.bak2 $CFG_PATH.bak @@ -1730,12 +1729,12 @@ advanced_set(){ #进阶设置 fi echo -e "\033[33m请重新启动脚本!\033[0m" exit 0 - ;; - *) errornum ;; + ;; + *) errornum ;; esac } #工具脚本 -autoSSH(){ +autoSSH() { echo ----------------------------------------------- echo -e "\033[33m本功能使用软件命令进行固化不保证100%成功!\033[0m" echo -e "\033[33m如有问题请加群反馈:\033[36;4mhttps://t.me/ShellClash\033[0m" @@ -1744,10 +1743,10 @@ autoSSH(){ cp -f /etc/dropbear/dropbear_rsa_host_key ${CRASHDIR}/configs/dropbear_rsa_host_key 2>/dev/null cp -f /etc/dropbear/authorized_keys ${CRASHDIR}/configs/authorized_keys 2>/dev/null ckcmd nvram && { - nvram set ssh_en=1 - nvram set telnet_en=1 - nvram set uart_en=1 - nvram set boot_wait=on + nvram set ssh_en=1 + nvram set telnet_en=1 + nvram set uart_en=1 + nvram set boot_wait=on nvram commit } echo -e "\033[32m设置成功!\033[0m" @@ -1755,7 +1754,7 @@ autoSSH(){ setconfig mi_autoSSH_pwd $mi_autoSSH_pwd sleep 1 } -uninstall(){ +uninstall() { read -p "确认卸载ShellCrash?(警告:该操作不可逆!)[1/0] > " res if [ "$res" = '1' ]; then ${CRASHDIR}/start.sh stop 2>/dev/null @@ -1807,9 +1806,9 @@ uninstall(){ fi echo -e "\033[31m操作已取消!\033[0m" } -tools(){ - ssh_tools(){ - stop_iptables(){ +tools() { + ssh_tools() { + stop_iptables() { iptables -w -t nat -D PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 >/dev/null 2>&1 ip6tables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 >/dev/null 2>&1 } @@ -1826,52 +1825,52 @@ tools(){ echo -e " 0 返回上级菜单 \033[0m" echo ----------------------------------------------- read -p "请输入对应数字 > " num + if [ -z "$num" ]; then + errornum + elif [ "$num" = 0 ]; then + i= + + elif [ "$num" = 1 ]; then + read -p "请输入端口号(1000-65535) > " num if [ -z "$num" ]; then errornum - elif [ "$num" = 0 ]; then - i= - - elif [ "$num" = 1 ]; then - read -p "请输入端口号(1000-65535) > " num - if [ -z "$num" ]; then - errornum - elif [ $num -gt 65535 -o $num -le 999 ]; then - echo -e "\033[31m输入错误!请输入正确的数值(1000-65535)!\033[0m" - elif [ -n "$(netstat -ntul |grep :$num)" ];then - echo -e "\033[31m当前端口已被其他进程占用,请重新输入!\033[0m" - else - ssh_port=$num - setconfig ssh_port $ssh_port - sed -i "/启用外网访问SSH服务/d" /etc/firewall.user - stop_iptables - echo -e "\033[32m设置成功,请重新开启外网访问SSH功能!!!\033[0m" - fi - sleep 1 - ssh_tools - - elif [ "$num" = 2 ]; then - passwd - sleep 1 - ssh_tools - - elif [ "$num" = 3 ]; then - if [ "$ssh_ol" = "开启" ];then - iptables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 - [ -n "$(ckcmd ip6tables)" ] && ip6tables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 - echo "iptables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 #启用外网访问SSH服务" >> /etc/firewall.user - [ -n "$(ckcmd ip6tables)" ] && echo "ip6tables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 #启用外网访问SSH服务" >> /etc/firewall.user - echo ----------------------------------------------- - echo -e "已开启外网访问SSH功能!" - else - sed -i "/启用外网访问SSH服务/d" /etc/firewall.user - stop_iptables - echo ----------------------------------------------- - echo -e "已禁止外网访问SSH!" - fi + elif [ $num -gt 65535 -o $num -le 999 ]; then + echo -e "\033[31m输入错误!请输入正确的数值(1000-65535)!\033[0m" + elif [ -n "$(netstat -ntul | grep :$num)" ]; then + echo -e "\033[31m当前端口已被其他进程占用,请重新输入!\033[0m" else - errornum + ssh_port=$num + setconfig ssh_port $ssh_port + sed -i "/启用外网访问SSH服务/d" /etc/firewall.user + stop_iptables + echo -e "\033[32m设置成功,请重新开启外网访问SSH功能!!!\033[0m" fi - } + sleep 1 + ssh_tools + + elif [ "$num" = 2 ]; then + passwd + sleep 1 + ssh_tools + + elif [ "$num" = 3 ]; then + if [ "$ssh_ol" = "开启" ]; then + iptables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 + [ -n "$(ckcmd ip6tables)" ] && ip6tables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 + echo "iptables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 #启用外网访问SSH服务" >>/etc/firewall.user + [ -n "$(ckcmd ip6tables)" ] && echo "ip6tables -w -t nat -A PREROUTING -p tcp -m multiport --dports $ssh_port -j REDIRECT --to-ports 22 #启用外网访问SSH服务" >>/etc/firewall.user + echo ----------------------------------------------- + echo -e "已开启外网访问SSH功能!" + else + sed -i "/启用外网访问SSH服务/d" /etc/firewall.user + stop_iptables + echo ----------------------------------------------- + echo -e "已禁止外网访问SSH!" + fi + else + errornum + fi + } #获取设置默认显示 grep -qE "^\s*[^#].*otapredownload" /etc/crontabs/root >/dev/null 2>&1 && mi_update=禁用 || mi_update=启用 [ "$mi_autoSSH" = "已配置" ] && mi_autoSSH_type=32m已配置 || mi_autoSSH_type=31m未配置 @@ -1899,28 +1898,28 @@ tools(){ errornum elif [ "$num" = 0 ]; then i= - + elif [ "$num" = 1 ]; then - source ${CRASHDIR}/webget.sh && testcommand - + source ${CRASHDIR}/webget.sh && testcommand + elif [ "$num" = 2 ]; then source ${CRASHDIR}/webget.sh && userguide - + elif [ "$num" = 3 ]; then log_pusher tools - + elif [ "$num" = 4 ]; then ssh_tools sleep 1 - tools - + tools + elif [ "$num" = 7 ]; then echo ----------------------------------------------- - if [ ! -f ${CRASHDIR}/tools/ShellDDNS.sh ];then + if [ ! -f ${CRASHDIR}/tools/ShellDDNS.sh ]; then echo -e "正在获取在线脚本……" ${CRASHDIR}/start.sh get_bin ${TMPDIR}/ShellDDNS.sh tools/ShellDDNS.sh - if [ "$?" = "0" ];then + if [ "$?" = "0" ]; then mv -f ${TMPDIR}/ShellDDNS.sh ${CRASHDIR}/tools/ShellDDNS.sh source ${CRASHDIR}/tools/ShellDDNS.sh else @@ -1930,50 +1929,50 @@ tools(){ source ${CRASHDIR}/tools/ShellDDNS.sh fi sleep 1 - tools - - elif [ -x /usr/sbin/otapredownload ] && [ "$num" = 5 ]; then - if [ "$mi_update" = "禁用" ]; then - grep -q "otapredownload" /etc/crontabs/root && \ - sed -i "/^[^\#]*otapredownload/ s/^/#/" /etc/crontabs/root || \ - echo "#15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >> /etc/crontabs/root + tools + + elif [ -x /usr/sbin/otapredownload ] && [ "$num" = 5 ]; then + if [ "$mi_update" = "禁用" ]; then + grep -q "otapredownload" /etc/crontabs/root && + sed -i "/^[^\#]*otapredownload/ s/^/#/" /etc/crontabs/root || + echo "#15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >>/etc/crontabs/root else - grep -q "otapredownload" /etc/crontabs/root && \ - sed -i "/^\s*#.*otapredownload/ s/^\s*#//" /etc/crontabs/root || \ - echo "15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >> /etc/crontabs/root + grep -q "otapredownload" /etc/crontabs/root && + sed -i "/^\s*#.*otapredownload/ s/^\s*#//" /etc/crontabs/root || + echo "15 3,4,5 * * * /usr/sbin/otapredownload >/dev/null 2>&1" >>/etc/crontabs/root fi echo ----------------------------------------------- echo -e "已\033[33m$mi_update\033[0m小米路由器的自动更新,如未生效,请在官方APP中同步设置!" sleep 1 - tools - + tools + elif [ "$num" = 6 ]; then - if [ "$systype" = "mi_snapshot" ];then + if [ "$systype" = "mi_snapshot" ]; then autoSSH else echo 不支持的设备! fi - tools + tools elif [ "$num" = 8 ]; then - if [ -f ${CRASHDIR}/tools/tun.ko ];then + if [ -f ${CRASHDIR}/tools/tun.ko ]; then read -p "是否禁用此功能并移除相关补丁?(1/0) > " res [ "$res" = 1 ] && { rm -rf ${CRASHDIR}/tools/tun.ko echo -e "\033[33m补丁文件已移除,请立即重启设备以防止出错!\033[0m" } - elif [ -z "$(modinfo tun)" ];then + elif [ -z "$(modinfo tun)" ]; then echo -e "\033[33m本功能需要修改系统文件,不保证没有任何风险!\033[0m" echo -e "\033[33m本功能采集的Tun模块并不一定适用于你的设备!\033[0m" sleep 1 read -p "我已知晓,出现问题会自行承担!(1/0) > " res - if [ "$res" = 1 ];then + if [ "$res" = 1 ]; then echo ----------------------------------------------- echo 正在连接服务器获取Tun模块补丁文件………… ${CRASHDIR}/start.sh get_bin ${TMPDIR}/tun.ko bin/fix/tun.ko - if [ "$?" = "0" ];then - mv -f ${TMPDIR}/tun.ko ${CRASHDIR}/tools/tun.ko && \ - ${CRASHDIR}/misnap_init.sh tunfix && \ - echo -e "\033[32m设置成功!请重启服务!\033[0m" + if [ "$?" = "0" ]; then + mv -f ${TMPDIR}/tun.ko ${CRASHDIR}/tools/tun.ko && + ${CRASHDIR}/misnap_init.sh tunfix && + echo -e "\033[32m设置成功!请重启服务!\033[0m" else echo -e "\033[31m文件下载失败,请重试!\033[0m" fi @@ -1982,13 +1981,13 @@ tools(){ echo -e "\033[31m当前设备无需设置,请勿尝试!\033[0m" sleep 1 fi - tools + tools else errornum fi } #主菜单 -main_menu(){ +main_menu() { ############################# ckstatus ############################# @@ -2004,21 +2003,21 @@ main_menu(){ echo ----------------------------------------------- echo -e " 0 \033[0m退出脚本\033[0m" read -p "请输入对应数字 > " num - if [ -z "$num" ];then + if [ -z "$num" ]; then errornum - exit; - + exit + elif [ "$num" = 0 ]; then - exit; - + exit + elif [ "$num" = 1 ]; then start_service - exit; - + exit + elif [ "$num" = 2 ]; then checkcfg=$(cat $CFG_PATH) normal_set - if [ -n "$PID" ];then + if [ -n "$PID" ]; then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi @@ -2038,15 +2037,15 @@ main_menu(){ elif [ "$num" = 5 ]; then source ${CRASHDIR}/task/task.sh && task_menu main_menu - + elif [ "$num" = 6 ]; then source ${CRASHDIR}/webget.sh && set_core_config main_menu - + elif [ "$num" = 7 ]; then checkcfg=$(cat $CFG_PATH) advanced_set - if [ -n "$PID" ];then + if [ -n "$PID" ]; then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi @@ -2059,88 +2058,91 @@ main_menu(){ elif [ "$num" = 9 ]; then checkcfg=$(cat $CFG_PATH) source ${CRASHDIR}/webget.sh && update - if [ -n "$PID" ];then + if [ -n "$PID" ]; then checkcfg_new=$(cat $CFG_PATH) [ "$checkcfg" != "$checkcfg_new" ] && checkrestart fi main_menu - + else errornum - exit; + exit fi } [ -z "$CRASHDIR" ] && { echo 环境变量配置有误!正在初始化~~~ - CRASHDIR=$(cd `dirname $0`; pwd) + CRASHDIR=$( + cd $(dirname $0) + pwd + ) source ${CRASHDIR}/init.sh sleep 1 echo 请重启SSH窗口以完成初始化! exit } - + [ -z "$1" ] && main_menu case "$1" in - -h) - echo ----------------------------------------- - echo "欢迎使用ShellCrash" - echo ----------------------------------------- - echo " -t 测试模式" - echo " -h 帮助列表" - echo " -u 卸载脚本" - echo " -i 初始化脚本" - echo " -d 测试运行" - echo ----------------------------------------- - echo " crash -s start 启动服务" - echo " crash -s stop 停止服务" - echo " 安装目录/start.sh init 开机初始化" - echo ----------------------------------------- - echo "在线求助:t.me/ShellClash" - echo "官方博客:juewuy.github.io" - echo "发布页面:github.com/juewuy/ShellCrash" - echo ----------------------------------------- +-h) + echo ----------------------------------------- + echo "欢迎使用ShellCrash" + echo ----------------------------------------- + echo " -t 测试模式" + echo " -h 帮助列表" + echo " -u 卸载脚本" + echo " -i 初始化脚本" + echo " -d 测试运行" + echo ----------------------------------------- + echo " crash -s start 启动服务" + echo " crash -s stop 停止服务" + echo " 安装目录/start.sh init 开机初始化" + echo ----------------------------------------- + echo "在线求助:t.me/ShellClash" + echo "官方博客:juewuy.github.io" + echo "发布页面:github.com/juewuy/ShellCrash" + echo ----------------------------------------- ;; - -t) - shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash - $shtype -x ${CRASHDIR}/menu.sh +-t) + shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash + $shtype -x ${CRASHDIR}/menu.sh ;; - -s) - ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 +-s) + ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 ;; - -i) - source ${CRASHDIR}/init.sh +-i) + source ${CRASHDIR}/init.sh ;; - -st) - shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash - $shtype -x ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 +-st) + shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash + $shtype -x ${CRASHDIR}/start.sh $2 $3 $4 $5 $6 ;; - -d) - shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash - echo -e "正在测试运行!如发现错误请截图后前往\033[32;4mt.me/ShellClash\033[0m咨询" - $shtype ${CRASHDIR}/start.sh debug >/dev/null 2>${TMPDIR}/debug_sh_bug.log - $shtype -x ${CRASHDIR}/start.sh debug >/dev/null 2>${TMPDIR}/debug_sh.log - echo ----------------------------------------- - cat ${TMPDIR}/debug_sh_bug.log | grep 'start\.sh' > ${TMPDIR}/sh_bug - if [ -s ${TMPDIR}/sh_bug ];then - while read line ;do - echo -e "发现错误:\033[33;4m$line\033[0m" - grep -A 1 -B 3 "$line" ${TMPDIR}/debug_sh.log - echo ----------------------------------------- - done < ${TMPDIR}/sh_bug - rm -rf ${TMPDIR}/sh_bug - echo -e "\033[32m测试完成!\033[0m完整执行记录请查看:\033[36m${TMPDIR}/debug_sh.log\033[0m" - else - echo -e "\033[32m测试完成!没有发现问题,请重新启动服务~\033[0m" - rm -rf ${TMPDIR}/debug_sh.log - fi - ${CRASHDIR}/start.sh stop +-d) + shtype=sh && [ -n "$(ls -l /bin/sh | grep -o dash)" ] && shtype=bash + echo -e "正在测试运行!如发现错误请截图后前往\033[32;4mt.me/ShellClash\033[0m咨询" + $shtype ${CRASHDIR}/start.sh debug >/dev/null 2>${TMPDIR}/debug_sh_bug.log + $shtype -x ${CRASHDIR}/start.sh debug >/dev/null 2>${TMPDIR}/debug_sh.log + echo ----------------------------------------- + cat ${TMPDIR}/debug_sh_bug.log | grep 'start\.sh' >${TMPDIR}/sh_bug + if [ -s ${TMPDIR}/sh_bug ]; then + while read line; do + echo -e "发现错误:\033[33;4m$line\033[0m" + grep -A 1 -B 3 "$line" ${TMPDIR}/debug_sh.log + echo ----------------------------------------- + done <${TMPDIR}/sh_bug + rm -rf ${TMPDIR}/sh_bug + echo -e "\033[32m测试完成!\033[0m完整执行记录请查看:\033[36m${TMPDIR}/debug_sh.log\033[0m" + else + echo -e "\033[32m测试完成!没有发现问题,请重新启动服务~\033[0m" + rm -rf ${TMPDIR}/debug_sh.log + fi + ${CRASHDIR}/start.sh stop ;; - -u) - uninstall +-u) + uninstall ;; - *) - $0 -h +*) + $0 -h ;; esac diff --git a/scripts/shellcrash.procd b/scripts/shellcrash.procd index 6ccfd22..1227661 100644 --- a/scripts/shellcrash.procd +++ b/scripts/shellcrash.procd @@ -11,14 +11,14 @@ CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}') source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录 start_service() { - if [ -n "$(cat $CRASHDIR/configs/ShellCrash.cfg | grep 'firewall_area=5')" ];then + if [ -n "$(cat $CRASHDIR/configs/ShellCrash.cfg | grep 'firewall_area=5')" ]; then $CRASHDIR/start.sh start_firewall #主旁转发 else #本机代理用户 [ -n "$(grep 'shellcrash:x:0:7890' /etc/passwd)" ] && USER=shellcrash || USER=root #检测必须文件 $CRASHDIR/start.sh bfstart - if [ "$?" = "0" ];then + if [ "$?" = "0" ]; then #使用procd创建clash后台进程 procd_open_instance procd_set_param user $USER @@ -32,8 +32,8 @@ start_service() { fi fi } -stop_service(){ +stop_service() { procd_close_instance - $CRASHDIR/start.sh stop_firewall + $CRASHDIR/start.sh stop_firewall $CRASHDIR/start.sh unset_proxy } diff --git a/scripts/start.sh b/scripts/start.sh index 6a64658..490bdd9 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,7 +2,10 @@ # Copyright (C) Juewuy #初始化目录 -CRASHDIR=$(cd $(dirname $0);pwd) +CRASHDIR=$( + cd $(dirname $0) + pwd +) #加载执行目录,失败则初始化 . "$CRASHDIR"/configs/command.env >/dev/null 2>&1 [ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && . "$CRASHDIR"/init.sh >/dev/null 2>&1 @@ -55,7 +58,7 @@ setconfig() { #脚本配置工具 ckcmd() { #检查命令是否存在 command -v sh >/dev/null 2>&1 && command -v "$1" >/dev/null 2>&1 || type "$1" >/dev/null 2>&1 } -ckgeo() { #查找及下载Geo数据文件 +ckgeo() { #查找及下载Geo数据文件 find --help 2>&1 | grep -q size && find_para=' -size +20' #find命令兼容 [ -z "$(find "$BINDIR"/"$1" "$find_para" 2>/dev/null)" ] && { if [ -n "$(find "$CRASHDIR"/"$1" "$find_para" 2>/dev/null)" ]; then @@ -190,7 +193,7 @@ getlanip() { #获取局域网host地址 i=1 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/br.*$//g' | sed 's/metric.*$//g') #ipv4局域网网段 - [ "$ipv6_redir" = "已开启" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g') #ipv6公网地址段 + [ "$ipv6_redir" = "已开启" ] && host_ipv6=$(ip a 2>&1 | grep -w 'inet6' | grep -E 'global' | sed 's/.*inet6.//g' | sed 's/scope.*$//g') #ipv6公网地址段 [ -f "$TMPDIR"/ShellCrash.log ] && break [ -n "$host_ipv4" -a "$ipv6_redir" != "已开启" ] && break [ -n "$host_ipv4" -a -n "$host_ipv6" ] && break @@ -603,20 +606,20 @@ EOF [ "$dns_mod" = "fake-ip" ] && { global_dns=dns_fakeip fake_ip_filter_domain=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -Ev '#|\*|\+|Mijia' | sed '/^\s*$/d' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') - fake_ip_filter_suffix=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -v '.\*' | grep -E '\*|\+' | sed 's/^[*+]\.//' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') - fake_ip_filter_regex=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep '.\*' | sed 's/\./\\\\./g' | sed 's/\*/.\*/' | sed 's/^+/.\+/' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') + fake_ip_filter_suffix=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -v '.\*' | grep -E '\*|\+' | sed 's/^[*+]\.//' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') + fake_ip_filter_regex=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep '.\*' | sed 's/\./\\\\./g' | sed 's/\*/.\*/' | sed 's/^+/.\+/' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') [ -n "$fake_ip_filter_domain" ] && fake_ip_filter_domain="{ \"domain\": [$fake_ip_filter_domain], \"server\": \"dns_direct\" }," - [ -n "$fake_ip_filter_suffix" ] && fake_ip_filter_suffix="{ \"domain_suffix\": [$fake_ip_filter_suffix], \"server\": \"dns_direct\" }," - [ -n "$fake_ip_filter_regex" ] && fake_ip_filter_regex="{ \"domain_regex\": [$fake_ip_filter_regex], \"server\": \"dns_direct\" }," + [ -n "$fake_ip_filter_suffix" ] && fake_ip_filter_suffix="{ \"domain_suffix\": [$fake_ip_filter_suffix], \"server\": \"dns_direct\" }," + [ -n "$fake_ip_filter_regex" ] && fake_ip_filter_regex="{ \"domain_regex\": [$fake_ip_filter_regex], \"server\": \"dns_direct\" }," } [ "$dns_mod" = "mix" ] && { global_dns=dns_fakeip fake_ip_filter_domain=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -Ev '#|\*|\+|Mijia' | sed '/^\s*$/d' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') - fake_ip_filter_suffix=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -v '.\*' | grep -E '\*|\+' | sed 's/^[*+]\.//' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') - fake_ip_filter_regex=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep '.\*' | sed 's/^*/.\*/' | sed 's/^+/.\+/' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') + fake_ip_filter_suffix=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep -v '.\*' | grep -E '\*|\+' | sed 's/^[*+]\.//' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') + fake_ip_filter_regex=$(cat ${CRASHDIR}/configs/fake_ip_filter ${CRASHDIR}/configs/fake_ip_filter.list 2>/dev/null | grep '.\*' | sed 's/^*/.\*/' | sed 's/^+/.\+/' | awk '{printf "\"%s\", ",$1}' | sed 's/, $//') [ -n "$fake_ip_filter_domain" ] && fake_ip_filter_domain="{ \"domain\": [$fake_ip_filter_domain], \"server\": \"dns_direct\" }," - [ -n "$fake_ip_filter_suffix" ] && fake_ip_filter_suffix="{ \"domain_suffix\": [$fake_ip_filter_suffix], \"server\": \"dns_direct\" }," - [ -n "$fake_ip_filter_regex" ] && fake_ip_filter_regex="{ \"domain_regex\": [$fake_ip_filter_regex], \"server\": \"dns_direct\" }," + [ -n "$fake_ip_filter_suffix" ] && fake_ip_filter_suffix="{ \"domain_suffix\": [$fake_ip_filter_suffix], \"server\": \"dns_direct\" }," + [ -n "$fake_ip_filter_regex" ] && fake_ip_filter_regex="{ \"domain_regex\": [$fake_ip_filter_regex], \"server\": \"dns_direct\" }," if [ -z "$(echo "$core_v" | grep -E '^1\.7.*')" ]; then direct_dns="{ \"rule_set\": [\"geosite-cn\"], \"server\": \"dns_direct\" }," #生成add_rule_set.json @@ -872,10 +875,10 @@ cn_ip_route() { #CN-IP绕过 ckgeo cn_ip.txt china_ip_list.txt [ -f "$BINDIR"/cn_ip.txt ] && [ "$firewall_mod" = iptables ] && { # see https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt - echo "create cn_ip hash:net family inet hashsize 10240 maxelem 10240" > "$TMPDIR"/cn_ip.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' "$BINDIR"/cn_ip.txt >> "$TMPDIR"/cn_ip.ipset + echo "create cn_ip hash:net family inet hashsize 10240 maxelem 10240" >"$TMPDIR"/cn_ip.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip %s'" "'\n",$0)}' "$BINDIR"/cn_ip.txt >>"$TMPDIR"/cn_ip.ipset ipset destroy cn_ip >/dev/null 2>&1 - ipset -! restore < "$TMPDIR"/cn_ip.ipset + ipset -! restore <"$TMPDIR"/cn_ip.ipset rm -rf "$TMPDIR"/cn_ip.ipset } } @@ -884,10 +887,10 @@ cn_ipv6_route() { #CN-IPV6绕过 [ -f "$BINDIR"/cn_ipv6.txt ] && [ "$firewall_mod" = iptables ] && { #ipv6 #see https://ispip.clang.cn/all_cn_ipv6.txt - echo "create cn_ip6 hash:net family inet6 hashsize 5120 maxelem 5120" > "$TMPDIR"/cn_ipv6.ipset - awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' "$BINDIR"/cn_ipv6.txt >> "$TMPDIR"/cn_ipv6.ipset + echo "create cn_ip6 hash:net family inet6 hashsize 5120 maxelem 5120" >"$TMPDIR"/cn_ipv6.ipset + awk '!/^$/&&!/^#/{printf("add cn_ip6 %s'" "'\n",$0)}' "$BINDIR"/cn_ipv6.txt >>"$TMPDIR"/cn_ipv6.ipset ipset destroy cn_ip6 >/dev/null 2>&1 - ipset -! restore < "$TMPDIR"/cn_ipv6.ipset + ipset -! restore <"$TMPDIR"/cn_ipv6.ipset rm -rf "$TMPDIR"/cn_ipv6.ipset } } @@ -928,26 +931,26 @@ start_ipt_route() { #iptables-route通用工具 [ "$1" = ip6tables ] && [ "$dns_mod" != "fake-ip" ] && [ "$cn_ipv6_route" = "已开启" ] && [ -f "$BINDIR"/cn_ipv6.txt ] && $1 $w -t $2 -A $4 -m set --match-set cn_ip6 dst -j RETURN 2>/dev/null #局域网mac地址黑名单过滤 [ "$3" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && { - [ -s "$CRASHDIR"/configs/mac ] && \ - for mac in $(cat "$CRASHDIR"/configs/mac); do - $1 $w -t $2 -A $4 -m mac --mac-source $mac -j RETURN - done - [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ - for ip in $(cat "$CRASHDIR"/configs/ip_filter); do - $1 $w -t $2 -A $4 -s $ip -j RETURN - done + [ -s "$CRASHDIR"/configs/mac ] && + for mac in $(cat "$CRASHDIR"/configs/mac); do + $1 $w -t $2 -A $4 -m mac --mac-source $mac -j RETURN + done + [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && + for ip in $(cat "$CRASHDIR"/configs/ip_filter); do + $1 $w -t $2 -A $4 -s $ip -j RETURN + done } #tcp&udp分别进代理链 proxy_set() { - if [ "$3" = 'PREROUTING' ] && [ "$4" != 'shellcrash_vm' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ];then - [ -s "$CRASHDIR"/configs/mac ] && \ - for mac in $(cat "$CRASHDIR"/configs/mac); do - $1 $w -t $2 -A $4 -p $5 -m mac --mac-source $mac -j $JUMP - done - [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ - for ip in $(cat "$CRASHDIR"/configs/ip_filter); do - $1 $w -t $2 -A $4 -p $5 -s $ip -j $JUMP - done + if [ "$3" = 'PREROUTING' ] && [ "$4" != 'shellcrash_vm' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ]; then + [ -s "$CRASHDIR"/configs/mac ] && + for mac in $(cat "$CRASHDIR"/configs/mac); do + $1 $w -t $2 -A $4 -p $5 -m mac --mac-source $mac -j $JUMP + done + [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && + for ip in $(cat "$CRASHDIR"/configs/ip_filter); do + $1 $w -t $2 -A $4 -p $5 -s $ip -j $JUMP + done else for ip in $HOST_IP; do #仅限指定网段流量 $1 $w -t $2 -A $4 -p $5 -s $ip -j $JUMP @@ -985,26 +988,26 @@ start_ipt_dns() { #iptables-dns通用工具 } #局域网mac地址黑名单过滤 [ "$2" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && { - [ -s "$CRASHDIR"/configs/mac ] && \ - for mac in $(cat "$CRASHDIR"/configs/mac); do - $1 $w -t nat -A $3 -m mac --mac-source $mac -j RETURN - done - [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ - for ip in $(cat "$CRASHDIR"/configs/ip_filter); do - $1 $w -t nat -A $3 -s $ip -j RETURN - done + [ -s "$CRASHDIR"/configs/mac ] && + for mac in $(cat "$CRASHDIR"/configs/mac); do + $1 $w -t nat -A $3 -m mac --mac-source $mac -j RETURN + done + [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && + for ip in $(cat "$CRASHDIR"/configs/ip_filter); do + $1 $w -t nat -A $3 -s $ip -j RETURN + done } - if [ "$2" = 'PREROUTING' ] && [ "$3" != 'shellcrash_vm_dns' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ];then - [ -s "$CRASHDIR"/configs/mac ] && \ - for mac in $(cat "$CRASHDIR"/configs/mac); do - $1 $w -t nat -A $3 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $dns_port - $1 $w -t nat -A $3 -p udp -m mac --mac-source $mac -j REDIRECT --to-ports $dns_port - done - [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ - for ip in $(cat "$CRASHDIR"/configs/ip_filter); do - $1 $w -t nat -A $3 -p tcp -s $ip -j REDIRECT --to-ports $dns_port - $1 $w -t nat -A $3 -p udp -s $ip -j REDIRECT --to-ports $dns_port - done + if [ "$2" = 'PREROUTING' ] && [ "$3" != 'shellcrash_vm_dns' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ]; then + [ -s "$CRASHDIR"/configs/mac ] && + for mac in $(cat "$CRASHDIR"/configs/mac); do + $1 $w -t nat -A $3 -p tcp -m mac --mac-source $mac -j REDIRECT --to-ports $dns_port + $1 $w -t nat -A $3 -p udp -m mac --mac-source $mac -j REDIRECT --to-ports $dns_port + done + [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && + for ip in $(cat "$CRASHDIR"/configs/ip_filter); do + $1 $w -t nat -A $3 -p tcp -s $ip -j REDIRECT --to-ports $dns_port + $1 $w -t nat -A $3 -p udp -s $ip -j REDIRECT --to-ports $dns_port + done else for ip in $HOST_IP; do #仅限指定网段流量 $1 $w -t nat -A $3 -p tcp -s $ip -j REDIRECT --to-ports $dns_port @@ -1090,7 +1093,7 @@ start_iptables() { #iptables配置总入口 else logger "当前设备内核可能缺少kmod_ipt_tproxy模块支持,已放弃启动相关规则!" 31 fi - [ "$ipv6_redir" = "已开启" ] && { + [ "$ipv6_redir" = "已开启" ] && { if $ip6table -j TPROXY -h 2>/dev/null | grep -q '\--on-port'; then JUMP="TPROXY --on-port $tproxy_port --tproxy-mark $fwmark" #跳转劫持的具体命令 [ "$lan_proxy" = true ] && start_ipt_route ip6tables mangle PREROUTING shellcrashv6_mark all @@ -1136,8 +1139,8 @@ start_iptables() { #iptables配置总入口 } } [ "$vm_redir" = "已开启" ] && [ -n "$$vm_ipv4" ] && { - JUMP="REDIRECT --to-ports $redir_port" #跳转劫持的具体命令 - start_ipt_dns iptables PREROUTING shellcrash_vm_dns #ipv4-局域网dns转发 + JUMP="REDIRECT --to-ports $redir_port" #跳转劫持的具体命令 + start_ipt_dns iptables PREROUTING shellcrash_vm_dns #ipv4-局域网dns转发 start_ipt_route iptables nat PREROUTING shellcrash_vm tcp #ipv4-局域网tcp转发 } #启动DNS劫持 @@ -1201,19 +1204,19 @@ start_nft_route() { #nftables-route通用工具 FL_IP=$(awk '{printf "%s, ",$1}' "$CRASHDIR"/configs/ip_filter) nft add rule inet shellcrash $1 ip saddr {$FL_IP} return } - nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量 + nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量 } [ "$macfilter_type" = "白名单" ] && { [ -s "$CRASHDIR"/configs/mac ] && MAC=$(awk '{printf "%s, ",$1}' "$CRASHDIR"/configs/mac) [ -s "$CRASHDIR"/configs/ip_filter ] && FL_IP=$(awk '{printf "%s, ",$1}' "$CRASHDIR"/configs/ip_filter) - if [ -n "$MAC" ] && [ -n "$FL_IP" ];then + if [ -n "$MAC" ] && [ -n "$FL_IP" ]; then nft add rule inet shellcrash $1 ether saddr != {$MAC} ip saddr != {$FL_IP} return - elif [ -n "$MAC" ];then + elif [ -n "$MAC" ]; then nft add rule inet shellcrash $1 ether saddr != {$MAC} return - elif [ -n "$FL_IP" ];then + elif [ -n "$FL_IP" ]; then nft add rule inet shellcrash $1 ip saddr != {$FL_IP} return else - nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量 + nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量 fi } } @@ -1273,7 +1276,7 @@ start_nft_dns() { #nftables-dns nft add rule inet shellcrash "$1"_dns meta mark $routing_mark return nft add rule inet shellcrash "$1"_dns meta skgid { 453, 7890 } return [ "$firewall_area" = 5 ] && nft add rule inet shellcrash "$1"_dns ip saddr $bypass_host return - nft add rule inet shellcrash "$1"_dns ip saddr != {$HOST_IP} return #屏蔽外部请求 + nft add rule inet shellcrash "$1"_dns ip saddr != {$HOST_IP} return #屏蔽外部请求 [ "$1" = 'prerouting' ] && nft add rule inet shellcrash "$1"_dns ip6 saddr != {$HOST_IP6} reject #屏蔽外部请求 #过滤局域网设备 [ "$1" = 'prerouting' ] && [ -s "$CRASHDIR"/configs/mac ] && { @@ -1317,7 +1320,7 @@ start_nftables() { #nftables配置总入口 #启动DNS劫持 [ "$dns_no" != "已禁用" -a "$dns_redir" != "已开启" -a "$firewall_area" -le 3 ] && { [ "$lan_proxy" = true ] && start_nft_dns prerouting prerouting #局域网dns转发 - [ "$local_proxy" = true ] && start_nft_dns output output #本机dns转发 + [ "$local_proxy" = true ] && start_nft_dns output output #本机dns转发 } #分模式设置流量劫持 [ "$redir_mod" = "Redir模式" ] && { @@ -1325,7 +1328,7 @@ start_nftables() { #nftables配置总入口 [ "$lan_proxy" = true ] && start_nft_route prerouting prerouting nat -100 [ "$local_proxy" = true ] && start_nft_route output output nat -100 } - [ "$redir_mod" = "Tproxy模式" ] && ( modprobe nft_tproxy >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q nft_tproxy ) && { + [ "$redir_mod" = "Tproxy模式" ] && (modprobe nft_tproxy >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q nft_tproxy) && { JUMP="meta l4proto {tcp, udp} mark set $fwmark tproxy to :$tproxy_port" #跳转劫持的具体命令 [ "$lan_proxy" = true ] && start_nft_route prerouting prerouting filter -150 [ "$local_proxy" = true ] && { @@ -1653,7 +1656,7 @@ EOF compare "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac [ "$?" = 0 ] && rm -rf "$TMPDIR"/shellcrash_pac || mv -f "$TMPDIR"/shellcrash_pac "$BINDIR"/ui/pac } -core_check() { #检查及下载内核文件 +core_check() { #检查及下载内核文件 [ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容 [ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容 tar_core() { @@ -1714,10 +1717,10 @@ clash_check() { #clash启动前检查 #检测是否存在高级版规则或者tun模式 if [ "$crashcore" = "clash" ]; then [ -n "$(cat $core_config | grep -aiE '^script:|proxy-providers|rule-providers|rule-set')" ] || - [ "$redir_mod" = "混合模式" ] || + [ "$redir_mod" = "混合模式" ] || [ "$redir_mod" = "Tun模式" ] && core_exchange meta '当前内核不支持的配置' fi - [ "$crashcore" = "clash" ] && [ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && [ -z "$(grep '0:7890' /etc/passwd)" ] && \ + [ "$crashcore" = "clash" ] && [ "$firewall_area" = 2 -o "$firewall_area" = 3 ] && [ -z "$(grep '0:7890' /etc/passwd)" ] && core_exchange meta '当前内核不支持非root用户启用本机代理' core_check #预下载GeoIP数据库 @@ -1808,8 +1811,8 @@ afstart() { #启动后 [ -z "$firewall_area" ] && firewall_area=1 #延迟启动 [ ! -f "$TMPDIR"/crash_start_time ] && [ -n "$start_delay" ] && [ "$start_delay" -gt 0 ] && { - logger "ShellCrash将延迟$start_delay秒启动" 31 - sleep $start_delay + logger "ShellCrash将延迟$start_delay秒启动" 31 + sleep $start_delay } #设置循环检测面板端口以判定服务启动是否成功 i=1 @@ -1929,9 +1932,9 @@ start) else bfstart && start_old fi - if [ "$2" = "infinity" ]; then #增加容器自启方式,请将CMD设置为"$CRASHDIR"/start.sh start infinity - sleep infinity - fi + if [ "$2" = "infinity" ]; then #增加容器自启方式,请将CMD设置为"$CRASHDIR"/start.sh start infinity + sleep infinity + fi ;; stop) logger ShellCrash服务即将关闭…… @@ -1957,7 +1960,7 @@ restart) $0 start ;; daemon) - if [ -f $TMPDIR/crash_start_time ];then + if [ -f $TMPDIR/crash_start_time ]; then $0 start else sleep 60 && touch $TMPDIR/crash_start_time @@ -2005,7 +2008,7 @@ init) echo "alias crash=\"$CRASHDIR/menu.sh\"" >>$profile echo "alias clash=\"$CRASHDIR/menu.sh\"" >>$profile echo "export CRASHDIR=\"$CRASHDIR\"" >>$profile - [ -f "$CRASHDIR"/.dis_startup ] && cronset "保守模式守护进程" || $0 start + [ -f "$CRASHDIR"/.dis_startup ] && cronset "保守模式守护进程" || $0 start ;; webget) #设置临时代理 diff --git a/tools/ShellDDNS.sh b/tools/ShellDDNS.sh index 5649cf3..d352cbe 100644 --- a/tools/ShellDDNS.sh +++ b/tools/ShellDDNS.sh @@ -7,10 +7,10 @@ tmp_dir=/tmp/ddns_$USER [ ! -f "$ddns_dir" -o ! -d "/etc/ddns" ] && echo -e "本脚本依赖OpenWrt内置的DDNS服务,当前设备无法运行,已退出!" && exit 1 echo ----------------------------------------------- echo -e "\033[30;46m欢迎使用ShellDDNS!\033[0m" -echo -e "TG群:\033[36;4mhttps://t.me/clashfm\033[0m" +echo -e "TG群:\033[36;4mhttps://t.me/ShellCrash\033[0m" -add_ddns(){ - cat >> $ddns_dir << EOF +add_ddns() { + cat >>$ddns_dir < " str [ -z "$str" ] && domain=$domain || domain=$str @@ -58,7 +58,7 @@ set_ddns(){ [ "$res" = 1 ] && add_ddns || set_ddns } -set_service(){ +set_service() { services_dir=/etc/ddns/$services echo ----------------------------------------------- echo -e "\033[32m请选择服务提供商\033[0m" @@ -78,7 +78,7 @@ set_service(){ fi } -network_type(){ +network_type() { echo ----------------------------------------------- echo -e "\033[32m请选择网络模式\033[0m" echo -e " 1 \033[36mIPV4\033[0m" @@ -86,11 +86,11 @@ network_type(){ read -p "请输入对应数字 > " num if [ -z "$num" ]; then i= - elif [ "$num" = 1 ];then + elif [ "$num" = 1 ]; then use_ipv6=0 services=services set_service - elif [ "$num" = 2 ];then + elif [ "$num" = 2 ]; then use_ipv6=1 services=services_ipv6 set_service @@ -101,13 +101,13 @@ network_type(){ fi } -rev_service(){ +rev_service() { enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}') [ "$enabled" = 1 ] && enabled_b="停用" || enabled_b="启用" echo ----------------------------------------------- echo -e " 1 \033[32m立即更新\033[0m" echo -e " 2 编辑当前服务\033[0m" - echo -e " 3 $enabled_b当前服务" + echo -e " 3 $enabled_b当前服务" echo -e " 4 移除当前服务" echo -e " 0 返回上级菜单" echo ----------------------------------------------- @@ -133,21 +133,21 @@ rev_service(){ fi } -load_ddns(){ +load_ddns() { nr=0 - cat $ddns_dir | grep 'config service' | awk '{print $3}' | sed "s/\'//g" > $tmp_dir + cat $ddns_dir | grep 'config service' | awk '{print $3}' | sed "s/\'//g" >$tmp_dir echo ----------------------------------------------- echo -e "列表 域名 启用 IP地址" echo ----------------------------------------------- - for service in $(cat $tmp_dir) ;do - echo $service >> $tmp_dir - nr=$((nr+1)) + for service in $(cat $tmp_dir); do + echo $service >>$tmp_dir + nr=$((nr + 1)) enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}') domain=$(uci show ddns.$service | grep 'domain' | awk -F "\'" '{print $2}') local_ip=$(cat /var/log/ddns/$service.log | grep 'Local IP' | tail -1 | awk -F "\'" '{print $2}') echo -e " $nr $domain $enabled $local_ip" done - echo -e " $((nr+1)) 添加DDNS服务" + echo -e " $((nr + 1)) 添加DDNS服务" echo -e " 0 退出" echo ----------------------------------------------- read -p "请输入对应序号 > " num @@ -165,7 +165,5 @@ load_ddns(){ fi } - load_ddns rm -rf $tmp_dir -