mirror of
https://github.com/juewuy/ShellCrash.git
synced 2024-11-15 19:22:54 +08:00
格式化代码
This commit is contained in:
parent
b2a457908d
commit
59d36e8c65
289
install.sh
289
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
|
||||
|
|
307
scripts/init.sh
307
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 <<EOF
|
||||
cat >/usr/bin/crash <<EOF
|
||||
#/bin/$shtype
|
||||
$CRASHDIR/menu.sh \$1 \$2 \$3 \$4 \$5
|
||||
EOF
|
||||
|
@ -271,14 +272,14 @@ EOF
|
|||
[ -n "$initdir" ] && {
|
||||
sed -i '/ShellCrash初始化/'d $initdir
|
||||
touch $initdir
|
||||
echo "$CRASHDIR/start.sh init & #ShellCrash初始化脚本" >> $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
|
||||
#旧版变量改名
|
||||
|
|
1022
scripts/menu.sh
1022
scripts/menu.sh
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
}
|
||||
|
|
151
scripts/start.sh
151
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)
|
||||
#设置临时代理
|
||||
|
|
|
@ -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 <<EOF
|
||||
config service '$service'
|
||||
option enabled '1'
|
||||
option force_unit 'hours'
|
||||
|
@ -31,7 +31,7 @@ EOF
|
|||
sleep 3
|
||||
echo 服务已经添加!
|
||||
}
|
||||
set_ddns(){
|
||||
set_ddns() {
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入你的域名 > " 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user