格式化代码
Some checks failed
core_auto_update / check_version (push) Has been cancelled
core_auto_update / auto_update_singboxp_with_wg (push) Has been cancelled
core_auto_update / cleanup (push) Has been cancelled
bin_update / update (push) Has been cancelled

This commit is contained in:
juewuy 2024-10-20 11:02:19 +08:00
parent b2a457908d
commit 59d36e8c65
6 changed files with 908 additions and 903 deletions

View File

@ -4,7 +4,7 @@
[ -z "$url" ] && url="https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master" [ -z "$url" ] && url="https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master"
type bash &>/dev/null && shtype=bash || shtype=sh type bash &>/dev/null && shtype=bash || shtype=sh
echo='echo -e' echo='echo -e'
[ -n "$(echo -e|grep e)" ] && { [ -n "$(echo -e | grep e)" ] && {
echo "\033[31m不支持dash环境安装请先输入bash命令后再运行安装命令\033[0m" echo "\033[31m不支持dash环境安装请先输入bash命令后再运行安装命令\033[0m"
exit exit
} }
@ -15,23 +15,23 @@ echo "** ShellCrash **"
echo "** by Juewuy **" echo "** by Juewuy **"
echo "***********************************************" echo "***********************************************"
#内置工具 #内置工具
dir_avail(){ 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}' 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 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】代表在线地址 #参数【$1】代表下载目录【$2】代表在线地址
#参数【$3】代表输出显示【$4】不启用重定向 #参数【$3】代表输出显示【$4】不启用重定向
if curl --version > /dev/null 2>&1;then if curl --version >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-s' || progress='-#' [ "$3" = "echooff" ] && progress='-s' || progress='-#'
[ -z "$4" ] && redirect='-L' || redirect='' [ -z "$4" ] && redirect='-L' || redirect=''
result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2) result=$(curl -w %{http_code} --connect-timeout 5 $progress $redirect -ko $1 $2)
[ -n "$(echo $result | grep -e ^2)" ] && result="200" [ -n "$(echo $result | grep -e ^2)" ] && result="200"
else else
if wget --version > /dev/null 2>&1;then if wget --version >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress' [ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect='' [ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
certificate='--no-check-certificate' certificate='--no-check-certificate'
@ -43,14 +43,14 @@ webget(){
[ $? -eq 0 ] && result="200" [ $? -eq 0 ] && result="200"
fi fi
} }
error_down(){ error_down() {
$echo "请参考 \033[32mhttps://github.com/juewuy/ShellCrash/blob/master/README_CN.md" $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" webget /tmp/ShellCrash.tar.gz "$url/bin/ShellCrash.tar.gz"
if [ "$result" != "200" ];then if [ "$result" != "200" ]; then
$echo "\033[33m文件下载失败\033[0m" $echo "\033[33m文件下载失败\033[0m"
error_down error_down
exit 1 exit 1
@ -59,9 +59,9 @@ gettar(){
#解压 #解压
echo ----------------------------------------------- echo -----------------------------------------------
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/ 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" . $CRASHDIR/init.sh >/dev/null || $echo "\033[33m初始化失败请尝试本地安装\033[0m"
else else
rm -rf /tmp/ShellCrash.tar.gz rm -rf /tmp/ShellCrash.tar.gz
@ -71,41 +71,41 @@ gettar(){
fi fi
fi fi
} }
setdir(){ setdir() {
set_usb_dir(){ set_usb_dir() {
$echo "请选择安装目录" $echo "请选择安装目录"
du -hL /mnt | awk '{print " "NR" "$2" "$1}' du -hL /mnt | awk '{print " "NR" "$2" "$1}'
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p)
if [ -z "$dir" ];then if [ -z "$dir" ]; then
$echo "\033[31m输入错误请重新设置\033[0m" $echo "\033[31m输入错误请重新设置\033[0m"
set_usb_dir set_usb_dir
fi fi
} }
set_asus_dir(){ set_asus_dir() {
echo -e "请选择U盘目录" echo -e "请选择U盘目录"
du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}' du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}'
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
dir=$(du -hL /tmp/mnt | awk '{print $2}' | sed -n "$num"p) 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" echo -e "\033[31m未找到下载大师自启文件$dir/asusware.arm/etc/init.d/S50downloadmaster请检查设置\033[0m"
set_asus_dir set_asus_dir
fi fi
} }
set_cust_dir(){ set_cust_dir() {
echo ----------------------------------------------- echo -----------------------------------------------
echo '可用路径 剩余空间:' echo '可用路径 剩余空间:'
df -h | awk '{print $6,$4}'| sed 1d df -h | awk '{print $6,$4}' | sed 1d
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
read -p "请输入自定义路径 > " dir read -p "请输入自定义路径 > " dir
if [ "$(dir_avail $dir)" = 0 ];then if [ "$(dir_avail $dir)" = 0 ]; then
$echo "\033[31m路径错误请重新设置\033[0m" $echo "\033[31m路径错误请重新设置\033[0m"
set_cust_dir set_cust_dir
fi fi
} }
echo ----------------------------------------------- echo -----------------------------------------------
$echo "\033[33m注意安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" $echo "\033[33m注意安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m"
if [ -n "$systype" ];then if [ -n "$systype" ]; then
[ "$systype" = "Padavan" ] && dir=/etc/storage [ "$systype" = "Padavan" ] && dir=/etc/storage
[ "$systype" = "mi_snapshot" ] && { [ "$systype" = "mi_snapshot" ] && {
$echo "\033[33m检测到当前设备为小米官方系统请选择安装位置\033[0m" $echo "\033[33m检测到当前设备为小米官方系统请选择安装位置\033[0m"
@ -126,7 +126,8 @@ if [ -n "$systype" ];then
set_cust_dir set_cust_dir
;; ;;
*) *)
exit 1 ;; exit 1
;;
esac esac
} }
[ "$systype" = "asusrouter" ] && { [ "$systype" = "asusrouter" ] && {
@ -154,11 +155,12 @@ if [ -n "$systype" ];then
set_asus_dir set_asus_dir
;; ;;
*) *)
exit 1 ;; exit 1
;;
esac esac
} }
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
else else
$echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" $echo " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)"
$echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" $echo " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)"
$echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)" $echo " 3 在\033[32m当前用户目录\033[0m下安装(适合非root用户)"
@ -168,48 +170,48 @@ else
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
#设置目录 #设置目录
if [ -z $num ];then if [ -z $num ]; then
echo 安装已取消 echo 安装已取消
exit 1; exit 1
elif [ "$num" = "1" ];then elif [ "$num" = "1" ]; then
dir=/etc dir=/etc
elif [ "$num" = "2" ];then elif [ "$num" = "2" ]; then
dir=/usr/share dir=/usr/share
elif [ "$num" = "3" ];then elif [ "$num" = "3" ]; then
dir=~/.local/share dir=~/.local/share
mkdir -p ~/.config/systemd/user mkdir -p ~/.config/systemd/user
elif [ "$num" = "4" ];then elif [ "$num" = "4" ]; then
set_usb_dir set_usb_dir
elif [ "$num" = "5" ];then elif [ "$num" = "5" ]; then
set_cust_dir set_cust_dir
else else
echo 安装已取消!!! echo 安装已取消!!!
exit 1; exit 1
fi
fi fi
fi
if [ ! -w $dir ];then if [ ! -w $dir ]; then
$echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir $echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
else else
$echo "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)" $echo "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)"
read -p "确认安装?(1/0) > " res read -p "确认安装?(1/0) > " res
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
fi fi
} }
install(){ install() {
echo ----------------------------------------------- echo -----------------------------------------------
echo 开始从服务器获取安装文件! echo 开始从服务器获取安装文件!
echo ----------------------------------------------- echo -----------------------------------------------
gettar gettar
echo ----------------------------------------------- echo -----------------------------------------------
echo ShellCrash 已经安装成功! echo ShellCrash 已经安装成功!
[ "$profile" = "~/.bashrc" ] && echo "请执行【. ~/.bashrc &> /dev/null】命令以加载环境变量" [ "$profile" = "~/.bashrc" ] && echo "请执行【. ~/.bashrc &> /dev/null】命令以加载环境变量"
[ -n "$(ls -l /bin/sh|grep -oE 'zsh')" ] && echo "请执行【. ~/.zshrc &> /dev/null】命令以加载环境变量" [ -n "$(ls -l /bin/sh | grep -oE 'zsh')" ] && echo "请执行【. ~/.zshrc &> /dev/null】命令以加载环境变量"
echo ----------------------------------------------- echo -----------------------------------------------
$echo "\033[33m输入\033[30;47m crash \033[0;33m命令即可管理\033[0m" $echo "\033[33m输入\033[30;47m crash \033[0;33m命令即可管理\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
} }
setversion(){ setversion() {
echo ----------------------------------------------- echo -----------------------------------------------
$echo "\033[33m请选择想要安装的版本\033[0m" $echo "\033[33m请选择想要安装的版本\033[0m"
$echo " 1 \033[32m公测版(推荐)\033[0m" $echo " 1 \033[32m公测版(推荐)\033[0m"
@ -224,25 +226,24 @@ setversion(){
3) 3)
url=$(echo $url | sed 's/master/dev/') url=$(echo $url | sed 's/master/dev/')
;; ;;
*) *) ;;
;;
esac esac
} }
#特殊固件识别及标记 #特殊固件识别及标记
[ -f "/etc/storage/started_script.sh" ] && { [ -f "/etc/storage/started_script.sh" ] && {
systype=Padavan #老毛子固件 systype=Padavan #老毛子固件
initdir='/etc/storage/started_script.sh' initdir='/etc/storage/started_script.sh'
} }
[ -d "/jffs" ] && { [ -d "/jffs" ] && {
systype=asusrouter #华硕固件 systype=asusrouter #华硕固件
[ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter' [ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter'
[ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start' [ -d "/jffs/scripts" ] && initdir='/jffs/scripts/nat-start'
} }
[ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备 [ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备
[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 [ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备
#检查root权限 #检查root权限
if [ "$USER" != "root" -a -z "$systype" ];then if [ "$USER" != "root" -a -z "$systype" ]; then
echo 当前用户:$USER echo 当前用户:$USER
$echo "\033[31m请尽量使用root用户不要直接使用sudo命令执行安装!\033[0m" $echo "\033[31m请尽量使用root用户不要直接使用sudo命令执行安装!\033[0m"
echo ----------------------------------------------- echo -----------------------------------------------
@ -250,7 +251,7 @@ if [ "$USER" != "root" -a -z "$systype" ];then
[ "$res" != "1" ] && exit 1 [ "$res" != "1" ] && exit 1
fi fi
if [ -n "$(echo $url | grep master)" ];then if [ -n "$(echo $url | grep master)" ]; then
setversion setversion
fi fi
#获取版本信息 #获取版本信息
@ -265,26 +266,26 @@ $echo "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/ShellClash \033[
$echo "\033[37m支持各种基于openwrt的路由器设备" $echo "\033[37m支持各种基于openwrt的路由器设备"
$echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m" $echo "\033[33m支持Debian、Centos等标准Linux系统\033[0m"
if [ -n "$CRASHDIR" ];then if [ -n "$CRASHDIR" ]; then
echo ----------------------------------------------- echo -----------------------------------------------
$echo "检测到旧的安装目录\033[36m$CRASHDIR\033[0m是否覆盖安装" $echo "检测到旧的安装目录\033[36m$CRASHDIR\033[0m是否覆盖安装"
$echo "\033[32m覆盖安装时不会移除配置文件\033[0m" $echo "\033[32m覆盖安装时不会移除配置文件\033[0m"
read -p "覆盖安装/卸载旧版本?(1/0) > " res read -p "覆盖安装/卸载旧版本?(1/0) > " res
if [ "$res" = "1" ];then if [ "$res" = "1" ]; then
install install
elif [ "$res" = "0" ];then elif [ "$res" = "0" ]; then
rm -rf $CRASHDIR rm -rf $CRASHDIR
echo ----------------------------------------------- echo -----------------------------------------------
$echo "\033[31m 旧版本文件已卸载!\033[0m" $echo "\033[31m 旧版本文件已卸载!\033[0m"
setdir setdir
install install
elif [ "$res" = "9" ];then elif [ "$res" = "9" ]; then
echo 测试模式,变更安装位置 echo 测试模式,变更安装位置
setdir setdir
install install
else else
$echo "\033[31m输入错误已取消安装\033[0m" $echo "\033[31m输入错误已取消安装\033[0m"
exit 1; exit 1
fi fi
else else
setdir setdir

View File

@ -3,43 +3,43 @@
version=1.9.1rc9 version=1.9.1rc9
setdir(){ setdir() {
dir_avail(){ 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}' 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 "请选择安装目录" echo -e "请选择安装目录"
du -hL /mnt | awk '{print " "NR" "$2" "$1}' du -hL /mnt | awk '{print " "NR" "$2" "$1}'
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
dir=$(du -hL /mnt | awk '{print $2}' | sed -n "$num"p) 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" echo -e "\033[31m输入错误请重新设置\033[0m"
set_usb_dir set_usb_dir
fi fi
} }
set_asus_dir(){ set_asus_dir() {
echo -e "请选择U盘目录" echo -e "请选择U盘目录"
du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}' du -hL /tmp/mnt | awk '{print " "NR" "$2" "$1}'
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
dir=$(du -hL /tmp/mnt | awk '{print $2}' | sed -n "$num"p) 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" echo -e "\033[31m未找到下载大师自启文件$dir/asusware.arm/etc/init.d/S50downloadmaster请检查设置\033[0m"
set_asus_dir set_asus_dir
fi fi
} }
set_cust_dir(){ set_cust_dir() {
echo ----------------------------------------------- echo -----------------------------------------------
echo '可用路径 剩余空间:' echo '可用路径 剩余空间:'
df -h | awk '{print $6,$4}'| sed 1d df -h | awk '{print $6,$4}' | sed 1d
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
read -p "请输入自定义路径 > " dir read -p "请输入自定义路径 > " dir
if [ "$(dir_avail $dir)" = 0 ];then if [ "$(dir_avail $dir)" = 0 ]; then
echo "\033[31m路径错误请重新设置\033[0m" echo "\033[31m路径错误请重新设置\033[0m"
set_cust_dir set_cust_dir
fi fi
} }
echo ----------------------------------------------- echo -----------------------------------------------
if [ -n "$systype" ];then if [ -n "$systype" ]; then
[ "$systype" = "Padavan" ] && dir=/etc/storage [ "$systype" = "Padavan" ] && dir=/etc/storage
[ "$systype" = "mi_snapshot" ] && { [ "$systype" = "mi_snapshot" ] && {
echo -e "\033[33m检测到当前设备为小米官方系统请选择安装位置\033[0m" echo -e "\033[33m检测到当前设备为小米官方系统请选择安装位置\033[0m"
@ -60,7 +60,8 @@ if [ -n "$systype" ];then
set_cust_dir set_cust_dir
;; ;;
*) *)
exit 1 ;; exit 1
;;
esac esac
} }
[ "$systype" = "asusrouter" ] && { [ "$systype" = "asusrouter" ] && {
@ -93,7 +94,7 @@ if [ -n "$systype" ];then
esac esac
} }
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt [ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
else else
echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m" echo -e "\033[33m安装ShellCrash至少需要预留约1MB的磁盘空间\033[0m"
echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)" echo -e " 1 在\033[32m/etc目录\033[0m下安装(适合root用户)"
echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)" echo -e " 2 在\033[32m/usr/share目录\033[0m下安装(适合Linux系统)"
@ -104,52 +105,52 @@ else
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入相应数字 > " num read -p "请输入相应数字 > " num
#设置目录 #设置目录
if [ -z $num ];then if [ -z $num ]; then
echo 安装已取消 echo 安装已取消
exit 1; exit 1
elif [ "$num" = "1" ];then elif [ "$num" = "1" ]; then
dir=/etc dir=/etc
elif [ "$num" = "2" ];then elif [ "$num" = "2" ]; then
dir=/usr/share dir=/usr/share
elif [ "$num" = "3" ];then elif [ "$num" = "3" ]; then
dir=~/.local/share dir=~/.local/share
mkdir -p ~/.config/systemd/user mkdir -p ~/.config/systemd/user
elif [ "$num" = "4" ];then elif [ "$num" = "4" ]; then
set_usb_dir set_usb_dir
elif [ "$num" = "5" ];then elif [ "$num" = "5" ]; then
echo ----------------------------------------------- echo -----------------------------------------------
echo '可用路径 剩余空间:' echo '可用路径 剩余空间:'
df -h | awk '{print $6,$4}'| sed 1d df -h | awk '{print $6,$4}' | sed 1d
echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!' echo '路径是必须带 / 的格式,注意写入虚拟内存(/tmp,/opt,/sys...)的文件会在重启后消失!!!'
read -p "请输入自定义路径 > " dir read -p "请输入自定义路径 > " dir
if [ -z "$dir" ];then if [ -z "$dir" ]; then
echo -e "\033[31m路径错误请重新设置\033[0m" echo -e "\033[31m路径错误请重新设置\033[0m"
setdir setdir
fi fi
else else
echo 安装已取消!!! echo 安装已取消!!!
exit 1; exit 1
fi
fi fi
fi
if [ ! -w $dir ];then if [ ! -w $dir ]; then
echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
else else
echo -e "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)" echo -e "目标目录\033[32m$dir\033[0m空间剩余$(dir_avail $dir -h)"
read -p "确认安装?(1/0) > " res read -p "确认安装?(1/0) > " res
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir [ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
fi fi
} }
setconfig(){ setconfig() {
#参数1代表变量名参数2代表变量值,参数3即文件路径 #参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${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" ] && { [ -f "/etc/storage/started_script.sh" ] && {
systype=Padavan #老毛子固件 systype=Padavan #老毛子固件
initdir='/etc/storage/started_script.sh' initdir='/etc/storage/started_script.sh'
} }
[ -d "/jffs" ] && { [ -d "/jffs" ] && {
systype=asusrouter #华硕固件 systype=asusrouter #华硕固件
[ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter' [ -f "/jffs/.asusrouter" ] && initdir='/jffs/.asusrouter'
@ -157,7 +158,7 @@ setconfig(){
#华硕启用jffs #华硕启用jffs
nvram set jffs2_scripts="1" nvram set jffs2_scripts="1"
nvram commit nvram commit
} }
[ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备 [ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备
[ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备 [ -w "/var/mnt/cfg/firewall" ] && systype=ng_snapshot #NETGEAR设备
@ -170,16 +171,16 @@ mv -f /tmp/SC_tmp/* ${CRASHDIR} 2>/dev/null
#初始化 #初始化
mkdir -p ${CRASHDIR}/configs 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 if [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
#设为init.d方式启动 #设为init.d方式启动
cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash cp -f ${CRASHDIR}/shellcrash.procd /etc/init.d/shellcrash
chmod 755 /etc/init.d/shellcrash chmod 755 /etc/init.d/shellcrash
else else
[ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system [ -w /usr/lib/systemd/system ] && sysdir=/usr/lib/systemd/system
[ -w /etc/systemd/system ] && sysdir=/etc/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用户 #创建shellcrash用户
userdel shellcrash 2>/dev/null userdel shellcrash 2>/dev/null
sed -i '/0:7890/d' /etc/passwd sed -i '/0:7890/d' /etc/passwd
@ -188,7 +189,7 @@ else
useradd shellcrash -u 7890 2>/dev/null useradd shellcrash -u 7890 2>/dev/null
sed -Ei s/7890:7890/0:7890/g /etc/passwd sed -Ei s/7890:7890/0:7890/g /etc/passwd
else else
echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >> /etc/passwd echo "shellcrash:x:0:7890::/home/shellcrash:/bin/sh" >>/etc/passwd
fi fi
#配置systemd #配置systemd
mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null mv -f ${CRASHDIR}/shellcrash.service $sysdir/shellcrash.service 2>/dev/null
@ -204,7 +205,7 @@ fi
#修饰文件及版本号 #修饰文件及版本号
command -v bash >/dev/null 2>&1 && shtype=bash command -v bash >/dev/null 2>&1 && shtype=bash
[ -x /bin/ash ] && shtype=ash [ -x /bin/ash ] && shtype=ash
for file in start.sh task.sh menu.sh;do for file in start.sh task.sh menu.sh; do
sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file} sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file}
chmod 755 ${CRASHDIR}/${file} chmod 755 ${CRASHDIR}/${file}
done done
@ -217,7 +218,7 @@ setconfig versionsh_l $version
setconfig TMPDIR ${TMPDIR} ${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"' COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"'
else else
COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"' 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 /jffs/configs/profile.add ] && profile=/jffs/configs/profile.add
[ -w ~/.bashrc ] && profile=~/.bashrc [ -w ~/.bashrc ] && profile=~/.bashrc
[ -w /etc/profile ] && profile=/etc/profile [ -w /etc/profile ] && profile=/etc/profile
if [ -n "$profile" ];then if [ -n "$profile" ]; then
sed -i '/alias crash=*/'d $profile 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 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 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运行安装命令 source $profile >/dev/null 2>&1 || echo 运行错误请使用bash而不是dash运行安装命令
#适配zsh环境变量 #适配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 sed -i '/alias crash=*/'d ~/.zshrc 2>/dev/null
echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >> ~/.zshrc echo "alias crash=\"$shtype $CRASHDIR/menu.sh\"" >>~/.zshrc
# 兼容 clash 命令 # 兼容 clash 命令
sed -i '/alias clash=*/'d ~/.zshrc 2>/dev/null 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 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 source ~/.zshrc >/dev/null 2>&1
} }
else else
@ -261,7 +262,7 @@ else
fi fi
#在允许的情况下创建/usr/bin/crash文件 #在允许的情况下创建/usr/bin/crash文件
touch /usr/bin/crash 2>/dev/null && { touch /usr/bin/crash 2>/dev/null && {
cat > /usr/bin/crash <<EOF cat >/usr/bin/crash <<EOF
#/bin/$shtype #/bin/$shtype
$CRASHDIR/menu.sh \$1 \$2 \$3 \$4 \$5 $CRASHDIR/menu.sh \$1 \$2 \$3 \$4 \$5
EOF EOF
@ -271,14 +272,14 @@ EOF
[ -n "$initdir" ] && { [ -n "$initdir" ] && {
sed -i '/ShellCrash初始化/'d $initdir sed -i '/ShellCrash初始化/'d $initdir
touch $initdir touch $initdir
echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >> $initdir echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >>$initdir
chmod a+rx $initdir 2>/dev/null chmod a+rx $initdir 2>/dev/null
setconfig initdir $initdir setconfig initdir $initdir
} }
#Padavan额外设置 #Padavan额外设置
[ -f "/etc/storage/started_script.sh" ] && mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式 [ -f "/etc/storage/started_script.sh" ] && mount -t tmpfs -o remount,rw,size=45M tmpfs /tmp #增加/tmp空间以适配新的内核压缩方式
#镜像化OpenWrt(snapshot)额外设置 #镜像化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 chmod 755 ${CRASHDIR}/misnap_init.sh
uci delete firewall.ShellClash 2>/dev/null uci delete firewall.ShellClash 2>/dev/null
uci delete firewall.ShellCrash 2>/dev/null uci delete firewall.ShellCrash 2>/dev/null
@ -293,12 +294,12 @@ else
fi fi
#华硕USB启动额外设置 #华硕USB启动额外设置
[ "$usb_status" = "1" ] && { [ "$usb_status" = "1" ] && {
echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" > ${CRASHDIR}/asus_usb_mount.sh echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >${CRASHDIR}/asus_usb_mount.sh
nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh" nvram set script_usbmount="$CRASHDIR/asus_usb_mount.sh"
nvram commit 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" sed -i "/^PATH=/a\\$CRASHDIR/start.sh init & #ShellCrash初始化脚本" "$dir/asusware.arm/etc/init.d/S50downloadmaster"
#删除临时文件 #删除临时文件
rm -rf /tmp/*rash*gz rm -rf /tmp/*rash*gz
@ -308,26 +309,26 @@ mkdir -p ${CRASHDIR}/yamls
mkdir -p ${CRASHDIR}/jsons mkdir -p ${CRASHDIR}/jsons
mkdir -p ${CRASHDIR}/tools mkdir -p ${CRASHDIR}/tools
mkdir -p ${CRASHDIR}/task 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 mv -f ${CRASHDIR}/$file ${CRASHDIR}/yamls/$file 2>/dev/null
done done
[ ! -L ${CRASHDIR}/config.yaml ] && mv -f ${CRASHDIR}/config.yaml ${CRASHDIR}/yamls/config.yaml 2>/dev/null [ ! -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 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 mv -f ${CRASHDIR}/$file ${CRASHDIR}/configs/$file 2>/dev/null
done done
#配置文件改名 #配置文件改名
mv -f ${CRASHDIR}/mark ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null 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}/configs/ShellClash.cfg ${CRASHDIR}/configs/ShellCrash.cfg 2>/dev/null
#数据库改名 #数据库改名
mv -f ${CRASHDIR}/geosite.dat ${CRASHDIR}/GeoSite.dat 2>/dev/null mv -f ${CRASHDIR}/geosite.dat ${CRASHDIR}/GeoSite.dat 2>/dev/null
#内核改名 #内核改名
mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null mv -f ${CRASHDIR}/clash ${CRASHDIR}/CrashCore 2>/dev/null
#内核压缩 #内核压缩
[ -f ${CRASHDIR}/CrashCore ] && tar -zcf ${CRASHDIR}/CrashCore.tar.gz -C ${CRASHDIR} CrashCore [ -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 for file in dropbear_rsa_host_key authorized_keys tun.ko ShellDDNS.sh; do
mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null mv -f ${CRASHDIR}/$file ${CRASHDIR}/tools/$file 2>/dev/null
done 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 mv -f ${CRASHDIR}/$file ${CRASHDIR}/task/$file 2>/dev/null
done done
#旧版文件清理 #旧版文件清理
@ -336,7 +337,7 @@ sed -i '/shellclash/d' /etc/passwd
sed -i '/shellclash/d' /etc/group sed -i '/shellclash/d' /etc/group
rm -rf /etc/init.d/clash rm -rf /etc/init.d/clash
[ "$systype" = "mi_snapshot" -a "$CRASHDIR" != '/data/clash' ] && rm -rf /data/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 rm -rf ${CRASHDIR}/$file
done done
#旧版变量改名 #旧版变量改名

File diff suppressed because it is too large Load Diff

View File

@ -11,14 +11,14 @@ CRASHDIR=$(cat /etc/profile | grep CRASHDIR | awk -F "\"" '{print $2}')
source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录 source ${CRASHDIR}/configs/command.env #加载启动命令和启动目录
start_service() { 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 #主旁转发 $CRASHDIR/start.sh start_firewall #主旁转发
else else
#本机代理用户 #本机代理用户
[ -n "$(grep 'shellcrash:x:0:7890' /etc/passwd)" ] && USER=shellcrash || USER=root [ -n "$(grep 'shellcrash:x:0:7890' /etc/passwd)" ] && USER=shellcrash || USER=root
#检测必须文件 #检测必须文件
$CRASHDIR/start.sh bfstart $CRASHDIR/start.sh bfstart
if [ "$?" = "0" ];then if [ "$?" = "0" ]; then
#使用procd创建clash后台进程 #使用procd创建clash后台进程
procd_open_instance procd_open_instance
procd_set_param user $USER procd_set_param user $USER
@ -32,7 +32,7 @@ start_service() {
fi fi
fi fi
} }
stop_service(){ stop_service() {
procd_close_instance procd_close_instance
$CRASHDIR/start.sh stop_firewall $CRASHDIR/start.sh stop_firewall
$CRASHDIR/start.sh unset_proxy $CRASHDIR/start.sh unset_proxy

View File

@ -2,7 +2,10 @@
# Copyright (C) Juewuy # Copyright (C) Juewuy
#初始化目录 #初始化目录
CRASHDIR=$(cd $(dirname $0);pwd) CRASHDIR=$(
cd $(dirname $0)
pwd
)
#加载执行目录,失败则初始化 #加载执行目录,失败则初始化
. "$CRASHDIR"/configs/command.env >/dev/null 2>&1 . "$CRASHDIR"/configs/command.env >/dev/null 2>&1
[ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && . "$CRASHDIR"/init.sh >/dev/null 2>&1 [ -z "$BINDIR" -o -z "$TMPDIR" -o -z "$COMMAND" ] && . "$CRASHDIR"/init.sh >/dev/null 2>&1
@ -872,10 +875,10 @@ cn_ip_route() { #CN-IP绕过
ckgeo cn_ip.txt china_ip_list.txt ckgeo cn_ip.txt china_ip_list.txt
[ -f "$BINDIR"/cn_ip.txt ] && [ "$firewall_mod" = iptables ] && { [ -f "$BINDIR"/cn_ip.txt ] && [ "$firewall_mod" = iptables ] && {
# see https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt # 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 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 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 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 rm -rf "$TMPDIR"/cn_ip.ipset
} }
} }
@ -884,10 +887,10 @@ cn_ipv6_route() { #CN-IPV6绕过
[ -f "$BINDIR"/cn_ipv6.txt ] && [ "$firewall_mod" = iptables ] && { [ -f "$BINDIR"/cn_ipv6.txt ] && [ "$firewall_mod" = iptables ] && {
#ipv6 #ipv6
#see https://ispip.clang.cn/all_cn_ipv6.txt #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 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 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 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 rm -rf "$TMPDIR"/cn_ipv6.ipset
} }
} }
@ -928,23 +931,23 @@ 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 [ "$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地址黑名单过滤 #局域网mac地址黑名单过滤
[ "$3" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && { [ "$3" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && {
[ -s "$CRASHDIR"/configs/mac ] && \ [ -s "$CRASHDIR"/configs/mac ] &&
for mac in $(cat "$CRASHDIR"/configs/mac); do for mac in $(cat "$CRASHDIR"/configs/mac); do
$1 $w -t $2 -A $4 -m mac --mac-source $mac -j RETURN $1 $w -t $2 -A $4 -m mac --mac-source $mac -j RETURN
done done
[ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] &&
for ip in $(cat "$CRASHDIR"/configs/ip_filter); do for ip in $(cat "$CRASHDIR"/configs/ip_filter); do
$1 $w -t $2 -A $4 -s $ip -j RETURN $1 $w -t $2 -A $4 -s $ip -j RETURN
done done
} }
#tcp&udp分别进代理链 #tcp&udp分别进代理链
proxy_set() { proxy_set() {
if [ "$3" = 'PREROUTING' ] && [ "$4" != 'shellcrash_vm' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ];then 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 ] && \ [ -s "$CRASHDIR"/configs/mac ] &&
for mac in $(cat "$CRASHDIR"/configs/mac); do for mac in $(cat "$CRASHDIR"/configs/mac); do
$1 $w -t $2 -A $4 -p $5 -m mac --mac-source $mac -j $JUMP $1 $w -t $2 -A $4 -p $5 -m mac --mac-source $mac -j $JUMP
done done
[ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] &&
for ip in $(cat "$CRASHDIR"/configs/ip_filter); do for ip in $(cat "$CRASHDIR"/configs/ip_filter); do
$1 $w -t $2 -A $4 -p $5 -s $ip -j $JUMP $1 $w -t $2 -A $4 -p $5 -s $ip -j $JUMP
done done
@ -985,22 +988,22 @@ start_ipt_dns() { #iptables-dns通用工具
} }
#局域网mac地址黑名单过滤 #局域网mac地址黑名单过滤
[ "$2" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && { [ "$2" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && {
[ -s "$CRASHDIR"/configs/mac ] && \ [ -s "$CRASHDIR"/configs/mac ] &&
for mac in $(cat "$CRASHDIR"/configs/mac); do for mac in $(cat "$CRASHDIR"/configs/mac); do
$1 $w -t nat -A $3 -m mac --mac-source $mac -j RETURN $1 $w -t nat -A $3 -m mac --mac-source $mac -j RETURN
done done
[ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] &&
for ip in $(cat "$CRASHDIR"/configs/ip_filter); do for ip in $(cat "$CRASHDIR"/configs/ip_filter); do
$1 $w -t nat -A $3 -s $ip -j RETURN $1 $w -t nat -A $3 -s $ip -j RETURN
done done
} }
if [ "$2" = 'PREROUTING' ] && [ "$3" != 'shellcrash_vm_dns' ] && [ "$macfilter_type" = "白名单" ] && [ -n "$(cat $CRASHDIR/configs/mac $CRASHDIR/configs/ip_filter 2>/dev/null)" ];then 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 ] && \ [ -s "$CRASHDIR"/configs/mac ] &&
for mac in $(cat "$CRASHDIR"/configs/mac); do 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 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 $1 $w -t nat -A $3 -p udp -m mac --mac-source $mac -j REDIRECT --to-ports $dns_port
done done
[ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] && \ [ -s "$CRASHDIR"/configs/ip_filter ] && [ "$1" = 'iptables' ] &&
for ip in $(cat "$CRASHDIR"/configs/ip_filter); do 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 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 $1 $w -t nat -A $3 -p udp -s $ip -j REDIRECT --to-ports $dns_port
@ -1206,11 +1209,11 @@ start_nft_route() { #nftables-route通用工具
[ "$macfilter_type" = "白名单" ] && { [ "$macfilter_type" = "白名单" ] && {
[ -s "$CRASHDIR"/configs/mac ] && MAC=$(awk '{printf "%s, ",$1}' "$CRASHDIR"/configs/mac) [ -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) [ -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 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 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 nft add rule inet shellcrash $1 ip saddr != {$FL_IP} return
else else
nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量 nft add rule inet shellcrash $1 ip saddr != {$HOST_IP} return #仅代理本机局域网网段流量
@ -1325,7 +1328,7 @@ start_nftables() { #nftables配置总入口
[ "$lan_proxy" = true ] && start_nft_route prerouting prerouting nat -100 [ "$lan_proxy" = true ] && start_nft_route prerouting prerouting nat -100
[ "$local_proxy" = true ] && start_nft_route output output 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" #跳转劫持的具体命令 JUMP="meta l4proto {tcp, udp} mark set $fwmark tproxy to :$tproxy_port" #跳转劫持的具体命令
[ "$lan_proxy" = true ] && start_nft_route prerouting prerouting filter -150 [ "$lan_proxy" = true ] && start_nft_route prerouting prerouting filter -150
[ "$local_proxy" = true ] && { [ "$local_proxy" = true ] && {
@ -1717,7 +1720,7 @@ clash_check() { #clash启动前检查
[ "$redir_mod" = "混合模式" ] || [ "$redir_mod" = "混合模式" ] ||
[ "$redir_mod" = "Tun模式" ] && core_exchange meta '当前内核不支持的配置' [ "$redir_mod" = "Tun模式" ] && core_exchange meta '当前内核不支持的配置'
fi 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_exchange meta '当前内核不支持非root用户启用本机代理'
core_check core_check
#预下载GeoIP数据库 #预下载GeoIP数据库
@ -1957,7 +1960,7 @@ restart)
$0 start $0 start
;; ;;
daemon) daemon)
if [ -f $TMPDIR/crash_start_time ];then if [ -f $TMPDIR/crash_start_time ]; then
$0 start $0 start
else else
sleep 60 && touch $TMPDIR/crash_start_time sleep 60 && touch $TMPDIR/crash_start_time

View File

@ -7,10 +7,10 @@ tmp_dir=/tmp/ddns_$USER
[ ! -f "$ddns_dir" -o ! -d "/etc/ddns" ] && echo -e "本脚本依赖OpenWrt内置的DDNS服务,当前设备无法运行,已退出!" && exit 1 [ ! -f "$ddns_dir" -o ! -d "/etc/ddns" ] && echo -e "本脚本依赖OpenWrt内置的DDNS服务,当前设备无法运行,已退出!" && exit 1
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[30;46m欢迎使用ShellDDNS\033[0m" 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(){ add_ddns() {
cat >> $ddns_dir << EOF cat >>$ddns_dir <<EOF
config service '$service' config service '$service'
option enabled '1' option enabled '1'
option force_unit 'hours' option force_unit 'hours'
@ -31,7 +31,7 @@ EOF
sleep 3 sleep 3
echo 服务已经添加! echo 服务已经添加!
} }
set_ddns(){ set_ddns() {
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入你的域名 > " str read -p "请输入你的域名 > " str
[ -z "$str" ] && domain=$domain || domain=$str [ -z "$str" ] && domain=$domain || domain=$str
@ -58,7 +58,7 @@ set_ddns(){
[ "$res" = 1 ] && add_ddns || set_ddns [ "$res" = 1 ] && add_ddns || set_ddns
} }
set_service(){ set_service() {
services_dir=/etc/ddns/$services services_dir=/etc/ddns/$services
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m请选择服务提供商\033[0m" echo -e "\033[32m请选择服务提供商\033[0m"
@ -78,7 +78,7 @@ set_service(){
fi fi
} }
network_type(){ network_type() {
echo ----------------------------------------------- echo -----------------------------------------------
echo -e "\033[32m请选择网络模式\033[0m" echo -e "\033[32m请选择网络模式\033[0m"
echo -e " 1 \033[36mIPV4\033[0m" echo -e " 1 \033[36mIPV4\033[0m"
@ -86,11 +86,11 @@ network_type(){
read -p "请输入对应数字 > " num read -p "请输入对应数字 > " num
if [ -z "$num" ]; then if [ -z "$num" ]; then
i= i=
elif [ "$num" = 1 ];then elif [ "$num" = 1 ]; then
use_ipv6=0 use_ipv6=0
services=services services=services
set_service set_service
elif [ "$num" = 2 ];then elif [ "$num" = 2 ]; then
use_ipv6=1 use_ipv6=1
services=services_ipv6 services=services_ipv6
set_service set_service
@ -101,7 +101,7 @@ network_type(){
fi fi
} }
rev_service(){ rev_service() {
enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}') enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}')
[ "$enabled" = 1 ] && enabled_b="停用" || enabled_b="启用" [ "$enabled" = 1 ] && enabled_b="停用" || enabled_b="启用"
echo ----------------------------------------------- echo -----------------------------------------------
@ -133,21 +133,21 @@ rev_service(){
fi fi
} }
load_ddns(){ load_ddns() {
nr=0 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 -----------------------------------------------
echo -e "列表 域名 启用 IP地址" echo -e "列表 域名 启用 IP地址"
echo ----------------------------------------------- echo -----------------------------------------------
for service in $(cat $tmp_dir) ;do for service in $(cat $tmp_dir); do
echo $service >> $tmp_dir echo $service >>$tmp_dir
nr=$((nr+1)) nr=$((nr + 1))
enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}') enabled=$(uci show ddns.$service | grep 'enabled' | awk -F "\'" '{print $2}')
domain=$(uci show ddns.$service | grep 'domain' | 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}') local_ip=$(cat /var/log/ddns/$service.log | grep 'Local IP' | tail -1 | awk -F "\'" '{print $2}')
echo -e " $nr $domain $enabled $local_ip" echo -e " $nr $domain $enabled $local_ip"
done done
echo -e " $((nr+1)) 添加DDNS服务" echo -e " $((nr + 1)) 添加DDNS服务"
echo -e " 0 退出" echo -e " 0 退出"
echo ----------------------------------------------- echo -----------------------------------------------
read -p "请输入对应序号 > " num read -p "请输入对应序号 > " num
@ -165,7 +165,5 @@ load_ddns(){
fi fi
} }
load_ddns load_ddns
rm -rf $tmp_dir rm -rf $tmp_dir