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
127
install.sh
127
install.sh
|
@ -4,7 +4,7 @@
|
|||
[ -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)" ] && {
|
||||
[ -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'
|
||||
|
@ -43,14 +43,14 @@ webget(){
|
|||
[ $? -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"
|
||||
}
|
||||
#安装及初始化
|
||||
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,9 +59,9 @@ 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
|
||||
|
@ -71,41 +71,41 @@ gettar(){
|
|||
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
|
||||
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"
|
||||
|
@ -126,7 +126,8 @@ if [ -n "$systype" ];then
|
|||
set_cust_dir
|
||||
;;
|
||||
*)
|
||||
exit 1 ;;
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
[ "$systype" = "asusrouter" ] && {
|
||||
|
@ -154,11 +155,12 @@ if [ -n "$systype" ];then
|
|||
set_asus_dir
|
||||
;;
|
||||
*)
|
||||
exit 1 ;;
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
|
||||
else
|
||||
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用户)"
|
||||
|
@ -168,48 +170,48 @@ else
|
|||
echo -----------------------------------------------
|
||||
read -p "请输入相应数字 > " num
|
||||
#设置目录
|
||||
if [ -z $num ];then
|
||||
if [ -z $num ]; then
|
||||
echo 安装已取消
|
||||
exit 1;
|
||||
elif [ "$num" = "1" ];then
|
||||
exit 1
|
||||
elif [ "$num" = "1" ]; then
|
||||
dir=/etc
|
||||
elif [ "$num" = "2" ];then
|
||||
elif [ "$num" = "2" ]; then
|
||||
dir=/usr/share
|
||||
elif [ "$num" = "3" ];then
|
||||
elif [ "$num" = "3" ]; then
|
||||
dir=~/.local/share
|
||||
mkdir -p ~/.config/systemd/user
|
||||
elif [ "$num" = "4" ];then
|
||||
elif [ "$num" = "4" ]; then
|
||||
set_usb_dir
|
||||
elif [ "$num" = "5" ];then
|
||||
elif [ "$num" = "5" ]; then
|
||||
set_cust_dir
|
||||
else
|
||||
echo 安装已取消!!!
|
||||
exit 1;
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -w $dir ];then
|
||||
if [ ! -w $dir ]; then
|
||||
$echo "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
|
||||
else
|
||||
else
|
||||
$echo "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
||||
read -p "确认安装?(1/0) > " res
|
||||
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
|
||||
fi
|
||||
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 -----------------------------------------------
|
||||
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(){
|
||||
setversion() {
|
||||
echo -----------------------------------------------
|
||||
$echo "\033[33m请选择想要安装的版本:\033[0m"
|
||||
$echo " 1 \033[32m公测版(推荐)\033[0m"
|
||||
|
@ -224,25 +226,24 @@ setversion(){
|
|||
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'
|
||||
}
|
||||
}
|
||||
[ -f "/data/etc/crontabs/root" ] && systype=mi_snapshot #小米设备
|
||||
[ -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
|
||||
|
|
133
scripts/init.sh
133
scripts/init.sh
|
@ -3,43 +3,43 @@
|
|||
|
||||
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
|
||||
echo -----------------------------------------------
|
||||
if [ -n "$systype" ]; then
|
||||
[ "$systype" = "Padavan" ] && dir=/etc/storage
|
||||
[ "$systype" = "mi_snapshot" ] && {
|
||||
echo -e "\033[33m检测到当前设备为小米官方系统,请选择安装位置\033[0m"
|
||||
|
@ -60,7 +60,8 @@ if [ -n "$systype" ];then
|
|||
set_cust_dir
|
||||
;;
|
||||
*)
|
||||
exit 1 ;;
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
[ "$systype" = "asusrouter" ] && {
|
||||
|
@ -93,7 +94,7 @@ if [ -n "$systype" ];then
|
|||
esac
|
||||
}
|
||||
[ "$systype" = "ng_snapshot" ] && dir=/tmp/mnt
|
||||
else
|
||||
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系统)"
|
||||
|
@ -104,52 +105,52 @@ else
|
|||
echo -----------------------------------------------
|
||||
read -p "请输入相应数字 > " num
|
||||
#设置目录
|
||||
if [ -z $num ];then
|
||||
if [ -z $num ]; then
|
||||
echo 安装已取消
|
||||
exit 1;
|
||||
elif [ "$num" = "1" ];then
|
||||
exit 1
|
||||
elif [ "$num" = "1" ]; then
|
||||
dir=/etc
|
||||
elif [ "$num" = "2" ];then
|
||||
elif [ "$num" = "2" ]; then
|
||||
dir=/usr/share
|
||||
elif [ "$num" = "3" ];then
|
||||
elif [ "$num" = "3" ]; then
|
||||
dir=~/.local/share
|
||||
mkdir -p ~/.config/systemd/user
|
||||
elif [ "$num" = "4" ];then
|
||||
elif [ "$num" = "4" ]; then
|
||||
set_usb_dir
|
||||
elif [ "$num" = "5" ];then
|
||||
elif [ "$num" = "5" ]; then
|
||||
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 [ -z "$dir" ];then
|
||||
if [ -z "$dir" ]; then
|
||||
echo -e "\033[31m路径错误!请重新设置!\033[0m"
|
||||
setdir
|
||||
fi
|
||||
else
|
||||
echo 安装已取消!!!
|
||||
exit 1;
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -w $dir ];then
|
||||
if [ ! -w $dir ]; then
|
||||
echo -e "\033[31m没有$dir目录写入权限!请重新设置!\033[0m" && sleep 1 && setdir
|
||||
else
|
||||
else
|
||||
echo -e "目标目录\033[32m$dir\033[0m空间剩余:$(dir_avail $dir -h)"
|
||||
read -p "确认安装?(1/0) > " res
|
||||
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
|
||||
fi
|
||||
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'
|
||||
|
@ -157,7 +158,7 @@ setconfig(){
|
|||
#华硕启用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设备
|
||||
|
||||
|
@ -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
|
||||
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
|
||||
|
@ -204,7 +205,7 @@ 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
|
||||
for file in start.sh task.sh menu.sh; do
|
||||
sed -i "s|/bin/sh|/bin/$shtype|" ${CRASHDIR}/${file}
|
||||
chmod 755 ${CRASHDIR}/${file}
|
||||
done
|
||||
|
@ -217,7 +218,7 @@ setconfig versionsh_l $version
|
|||
setconfig TMPDIR ${TMPDIR} ${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
|
||||
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
|
||||
|
@ -293,12 +294,12 @@ else
|
|||
fi
|
||||
#华硕USB启动额外设置
|
||||
[ "$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 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
|
||||
#旧版变量改名
|
||||
|
|
452
scripts/menu.sh
452
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,7 +32,7 @@ start_service() {
|
|||
fi
|
||||
fi
|
||||
}
|
||||
stop_service(){
|
||||
stop_service() {
|
||||
procd_close_instance
|
||||
$CRASHDIR/start.sh stop_firewall
|
||||
$CRASHDIR/start.sh unset_proxy
|
||||
|
|
|
@ -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
|
||||
|
@ -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,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
|
||||
#局域网mac地址黑名单过滤
|
||||
[ "$3" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && {
|
||||
[ -s "$CRASHDIR"/configs/mac ] && \
|
||||
[ -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' ] && \
|
||||
[ -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 ] && \
|
||||
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' ] && \
|
||||
[ -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
|
||||
|
@ -985,22 +988,22 @@ start_ipt_dns() { #iptables-dns通用工具
|
|||
}
|
||||
#局域网mac地址黑名单过滤
|
||||
[ "$2" = 'PREROUTING' ] && [ "$macfilter_type" != "白名单" ] && {
|
||||
[ -s "$CRASHDIR"/configs/mac ] && \
|
||||
[ -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' ] && \
|
||||
[ -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 ] && \
|
||||
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' ] && \
|
||||
[ -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
|
||||
|
@ -1206,11 +1209,11 @@ start_nft_route() { #nftables-route通用工具
|
|||
[ "$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 #仅代理本机局域网网段流量
|
||||
|
@ -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 ] && {
|
||||
|
@ -1717,7 +1720,7 @@ clash_check() { #clash启动前检查
|
|||
[ "$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数据库
|
||||
|
@ -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
|
||||
|
|
|
@ -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,7 +101,7 @@ 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 -----------------------------------------------
|
||||
|
@ -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