v1.0.0beta15.7
~优化了本机代理实现方式,增加了选项菜单 ~优化了定时任务实现方式,适配更多设备 ~优化了配置文件修饰方式 ~优化了启动和关闭进程时的检测,修复错误 ~优化了非root用户体验 ~优化脚本结构
This commit is contained in:
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
clash_v=1.2.0
|
||||
GeoIP_v=20201021
|
||||
versionsh=123
|
||||
clashpre_v=2020.10.26.gc025a01
|
||||
versionsh=1.0.0beta15.7
|
||||
|
||||
198
scripts/clash.sh
198
scripts/clash.sh
@@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
#读取配置相关
|
||||
getconfig(){
|
||||
#服务器缺省地址
|
||||
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash
|
||||
@@ -37,7 +38,7 @@ getconfig(){
|
||||
fi
|
||||
#开机自启描述
|
||||
if [ "$start_old" = "已开启" ];then
|
||||
auto="\033[33m已设置保守模式!\033[0m"
|
||||
auto="\033[32m保守模式\033[0m"
|
||||
auto1="代理本机:\033[36m$local_proxy\033[0m"
|
||||
elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then
|
||||
auto="\033[32m已设置开机启动!\033[0m"
|
||||
@@ -89,7 +90,8 @@ setconfig(){
|
||||
sed -i "/${1}*/"d $configpath
|
||||
echo "${1}=${2}" >> $configpath
|
||||
}
|
||||
echoerrornum(){
|
||||
#启动相关
|
||||
errornum(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m请输入正确的数字!\033[0m"
|
||||
}
|
||||
@@ -115,7 +117,7 @@ EOF
|
||||
cmp -s /tmp/clash_pac $clashdir/ui/pac
|
||||
[ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $clashdir/ui/pac
|
||||
}
|
||||
start_over(){
|
||||
startover(){
|
||||
echo -e "\033[32mclash服务已启动!\033[0m"
|
||||
if [ -n "$hostdir" ];then
|
||||
echo -e "请使用\033[30;47m http://$host$hostdir \033[0m管理内置规则"
|
||||
@@ -125,6 +127,32 @@ start_over(){
|
||||
echo -e "推荐前往更新菜单安装本地Dashboard面板,连接更稳定!\033[0m"
|
||||
fi
|
||||
}
|
||||
clashstart(){
|
||||
#检查clash核心
|
||||
if [ ! -f $clashdir/clash ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到核心文件,请先下载clash核心!\033[0m"
|
||||
source $clashdir/getdate.sh && checkupdate && getcore
|
||||
fi
|
||||
#检查GeoIP数据库
|
||||
if [ ! -f $clashdir/Country.mmdb ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到GeoIP数据库文件,请下载数据库文件!\033[0m"
|
||||
source $clashdir/getdate.sh && checkupdate && getgeo
|
||||
fi
|
||||
#检查yaml配置文件
|
||||
if [ ! -f "$yaml" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到配置文件,请先导入配置文件!\033[0m"
|
||||
clashlink
|
||||
fi
|
||||
catpac #生成pac自动代理文件
|
||||
echo -----------------------------------------------
|
||||
$clashdir/start.sh start
|
||||
sleep 1
|
||||
[ -n "$(pidof clash)" ] && startover || exit 1
|
||||
}
|
||||
#功能相关
|
||||
setport(){
|
||||
inputport(){
|
||||
read -p "请输入端口号(1000-65535) > " portx
|
||||
@@ -168,7 +196,7 @@ setport(){
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
elif [ "$num" = 1 ]; then
|
||||
xport=mix_port
|
||||
inputport
|
||||
@@ -245,7 +273,7 @@ setdns(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashadv
|
||||
elif [ "$num" = 1 ]; then
|
||||
read -p "请输入新的DNS > " dns_nameserver
|
||||
@@ -293,31 +321,6 @@ checkport(){
|
||||
fi
|
||||
done
|
||||
}
|
||||
clashstart(){
|
||||
#检查clash核心
|
||||
if [ ! -f $clashdir/clash ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到核心文件,请先下载clash核心!\033[0m"
|
||||
source $clashdir/getdate.sh && checkupdate && getcore
|
||||
fi
|
||||
#检查GeoIP数据库
|
||||
if [ ! -f $clashdir/Country.mmdb ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到GeoIP数据库文件,请下载数据库文件!\033[0m"
|
||||
source $clashdir/getdate.sh && checkupdate && getgeo
|
||||
fi
|
||||
#检查yaml配置文件
|
||||
if [ ! -f "$yaml" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m没有找到配置文件,请先导入配置文件!\033[0m"
|
||||
clashlink
|
||||
fi
|
||||
catpac #生成pac自动代理文件
|
||||
echo -----------------------------------------------
|
||||
$clashdir/start.sh start
|
||||
sleep 1
|
||||
[ -n "$(pidof clash)" ] && start_over || exit 1
|
||||
}
|
||||
macfilter(){
|
||||
add_mac(){
|
||||
echo -----------------------------------------------
|
||||
@@ -394,7 +397,7 @@ macfilter(){
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcfg
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashcfg
|
||||
@@ -415,30 +418,72 @@ macfilter(){
|
||||
sleep 1
|
||||
macfilter
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
macfilter
|
||||
fi
|
||||
}
|
||||
set_local_proxy(){
|
||||
localproxy(){
|
||||
[ -z "$local_proxy" ] && local_proxy='未开启'
|
||||
[ -z "$local_proxy_type" ] && local_proxy_type='环境变量'
|
||||
[ "$local_proxy" = "已开启" ] && proxy_set='禁用' || proxy_set='启用'
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m当前本机代理配置方式为:\033[32m$local_proxy_type\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 1 \033[36m$proxy_set本机代理\033[0m"
|
||||
echo -e " 2 使用\033[32m环境变量\033[0m方式配置"
|
||||
echo -e " 3 使用\033[32mGNOME桌面API\033[0m配置"
|
||||
echo -e " 4 使用\033[32mKDE桌面API\033[0m配置"
|
||||
echo -e " 0 返回上级菜单"
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
errornum
|
||||
elif [ "$num" = 1 ]; then
|
||||
echo -----------------------------------------------
|
||||
if [ "$local_proxy" = "未开启" ] > /dev/null 2>&1; then
|
||||
if [ "$local_proxy" = "未开启" ]; then
|
||||
if [ -n "$authentication" ] && [ "$authentication" != "未设置" ] ;then
|
||||
echo -e "\033[32m检测到您已经设置了Http/Sock5代理密码,请先取消密码!\033[0m"
|
||||
sleep 1
|
||||
setport
|
||||
localproxy
|
||||
else
|
||||
local_proxy=已开启
|
||||
$clashdir/start.sh set_proxy $mix_port $db_port
|
||||
echo -e "\033[32m已经成功配置本机代理~\033[0m"
|
||||
echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m"
|
||||
fi
|
||||
echo -e "\033[32m已经成功使用$local_proxy_type方式配置本机代理~\033[0m"
|
||||
[ "$local_proxy_type" = "环境变量" ] && echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m" && sleep 1
|
||||
fi
|
||||
else
|
||||
local_proxy=未开启
|
||||
$clashdir/start.sh unset_proxy
|
||||
echo -e "\033[33m已经停用本机代理规则!!\033[0m"
|
||||
echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m"
|
||||
[ "$local_proxy_type" = "环境变量" ] && echo -e "\033[36m如未生效,请重新启动终端或重新连接SSH!\033[0m" && sleep 1
|
||||
fi
|
||||
setconfig local_proxy $local_proxy
|
||||
elif [ "$num" = 2 ]; then
|
||||
local_proxy_type="环境变量"
|
||||
setconfig local_proxy_type $local_proxy_type
|
||||
localproxy
|
||||
elif [ "$num" = 3 ]; then
|
||||
if gsettings --version >/dev/null 2>&1 ;then
|
||||
local_proxy_type="GNOME"
|
||||
setconfig local_proxy_type $local_proxy_type
|
||||
else
|
||||
echo -e "\033[31m没有找到GNOME桌面!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
localproxy
|
||||
elif [ "$num" = 4 ]; then
|
||||
if kwriteconfig5 -h >/dev/null 2>&1 ;then
|
||||
local_proxy_type="KDE"
|
||||
setconfig local_proxy_type $local_proxy_type
|
||||
else
|
||||
echo -e "\033[31m没有找到KDE桌面!\033[0m"
|
||||
sleep 1
|
||||
fi
|
||||
localproxy
|
||||
else
|
||||
errornum
|
||||
fi
|
||||
}
|
||||
clashcfg(){
|
||||
set_redir_mod(){
|
||||
@@ -462,7 +507,7 @@ clashcfg(){
|
||||
echo " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcfg
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashcfg
|
||||
@@ -509,7 +554,7 @@ clashcfg(){
|
||||
echo -e "PAC的使用教程请参考:\033[4;32mhttps://juewuy.github.io/ehRUeewcv\033[0m"
|
||||
sleep 2
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcfg
|
||||
fi
|
||||
setconfig redir_mod $redir_mod
|
||||
@@ -529,7 +574,7 @@ clashcfg(){
|
||||
echo " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcfg
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashcfg
|
||||
@@ -538,7 +583,7 @@ clashcfg(){
|
||||
elif [ "$num" = 2 ]; then
|
||||
dns_mod=redir_host
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcfg
|
||||
fi
|
||||
setconfig dns_mod $dns_mod
|
||||
@@ -570,7 +615,7 @@ clashcfg(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashsh
|
||||
@@ -631,7 +676,7 @@ clashcfg(){
|
||||
clashcfg
|
||||
|
||||
elif [ "$num" = 7 ]; then
|
||||
set_local_proxy
|
||||
localproxy
|
||||
sleep 1
|
||||
clashcfg
|
||||
|
||||
@@ -639,7 +684,7 @@ clashcfg(){
|
||||
clashstart
|
||||
clashsh
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
}
|
||||
@@ -668,7 +713,7 @@ clashadv(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashsh
|
||||
@@ -712,7 +757,7 @@ clashadv(){
|
||||
$clashdir/start.sh stop
|
||||
sleep 2
|
||||
else
|
||||
if [ -f /etc/init.d/clash -o -f /etc/systemd/system -o -f /usr/lib/systemd/system ];then
|
||||
if [ -f /etc/init.d/clash -o -w /etc/systemd/system -o -w /usr/lib/systemd/system ];then
|
||||
echo -e "\033[32m改为使用默认方式启动clash服务!!\033[0m"
|
||||
start_old=未开启
|
||||
setconfig start_old $start_old
|
||||
@@ -766,7 +811,7 @@ clashadv(){
|
||||
sleep 1
|
||||
clashsh
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
}
|
||||
@@ -784,12 +829,13 @@ clashcron(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashcron
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashcron
|
||||
elif [ "$num" = 9 ]; then
|
||||
crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && crontab /tmp/conf && rm -f /tmp/conf
|
||||
crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && crontab /tmp/conf
|
||||
rm -f /tmp/conf
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m定时任务:$cronname已删除!\033[0m"
|
||||
clashcron
|
||||
@@ -806,10 +852,10 @@ clashcron(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入小时(0-23) > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
setcron
|
||||
elif [ $num -gt 23 ] || [ $num -lt 0 ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
setcron
|
||||
else
|
||||
hour=$num
|
||||
@@ -817,10 +863,10 @@ clashcron(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入分钟(0-60) > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
setcron
|
||||
elif [ $num -gt 60 ] || [ $num -lt 0 ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
setcron
|
||||
else
|
||||
min=$num
|
||||
@@ -830,7 +876,10 @@ clashcron(){
|
||||
read -p "是否确认添加定时任务?(1/0) > " res
|
||||
if [ "$res" = '1' ]; then
|
||||
cronwords="$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname"
|
||||
crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && echo "$cronwords" >> /tmp/conf && crontab /tmp/conf && rm -f /tmp/conf
|
||||
crontab -l > /tmp/conf
|
||||
sed -i "/$cronname/d" /tmp/conf
|
||||
echo "$cronwords" >> /tmp/conf && crontab /tmp/conf
|
||||
rm -f /tmp/conf
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m定时任务已添加!!!\033[0m"
|
||||
fi
|
||||
@@ -852,7 +901,7 @@ clashcron(){
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
|
||||
elif [ "$num" = 0 ]; then
|
||||
@@ -876,10 +925,11 @@ clashcron(){
|
||||
setcron
|
||||
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
}
|
||||
#主菜单
|
||||
clashsh(){
|
||||
#############################
|
||||
getconfig
|
||||
@@ -897,7 +947,7 @@ clashsh(){
|
||||
echo -e " 0 \033[0m退出脚本\033[0m"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ];then
|
||||
echoerrornum
|
||||
errornum
|
||||
exit;
|
||||
|
||||
elif [ "$num" = 0 ]; then
|
||||
@@ -921,7 +971,7 @@ clashsh(){
|
||||
elif [ "$num" = 4 ]; then
|
||||
echo -----------------------------------------------
|
||||
if [ "$start_old" = "已开启" ];then
|
||||
set_local_proxy
|
||||
localproxy
|
||||
elif [ "$autostart" = "enable_rc" ]; then
|
||||
/etc/init.d/clash disable
|
||||
echo -e "\033[33m已禁止Clash开机启动!\033[0m"
|
||||
@@ -955,7 +1005,7 @@ clashsh(){
|
||||
source $clashdir/getdate.sh && update
|
||||
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
exit;
|
||||
fi
|
||||
}
|
||||
@@ -964,19 +1014,23 @@ clashsh(){
|
||||
|
||||
case "$1" in
|
||||
-h)
|
||||
echo -----------------------------------------
|
||||
echo "欢迎使用ShellClash"
|
||||
echo -----------------------------------------
|
||||
echo " -t 测试模式"
|
||||
echo " -h 帮助列表"
|
||||
echo -----------------------------------------
|
||||
echo "在线求助:t.me/clashfm"
|
||||
echo "官方博客:juewuy.github.io"
|
||||
echo "发布页面:github.com/juewuy/ShellClash"
|
||||
echo -----------------------------------------
|
||||
echo -----------------------------------------
|
||||
echo "欢迎使用ShellClash"
|
||||
echo -----------------------------------------
|
||||
echo " -t 测试模式"
|
||||
echo " -h 帮助列表"
|
||||
echo -----------------------------------------
|
||||
echo "在线求助:t.me/clashfm"
|
||||
echo "官方博客:juewuy.github.io"
|
||||
echo "发布页面:github.com/juewuy/ShellClash"
|
||||
echo -----------------------------------------
|
||||
;;
|
||||
-t)
|
||||
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
|
||||
$shtype -x $clashdir/clash.sh
|
||||
shtype=sh && [ -n "$(ls -l /bin/sh|grep -o dash)" ] && shtype=bash
|
||||
$shtype -x $clashdir/clash.sh
|
||||
;;
|
||||
*)
|
||||
echo " -t 测试模式"
|
||||
echo " -h 帮助列表"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -18,6 +18,7 @@ webget(){
|
||||
fi
|
||||
export all_proxy=''
|
||||
}
|
||||
#导入订阅、配置文件相关
|
||||
linkconfig(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
|
||||
@@ -39,7 +40,7 @@ linkconfig(){
|
||||
echo 0 返回上级菜单
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ] || [ "$num" -gt 13 ];then
|
||||
echoerrornum
|
||||
errornum
|
||||
elif [ "$num" = 0 ];then
|
||||
echo
|
||||
elif [ "$num" -le 13 ];then
|
||||
@@ -64,7 +65,7 @@ linkserver(){
|
||||
echo 0 返回上级菜单
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ] || [ "$num" -gt 5 ];then
|
||||
echoerrornum
|
||||
errornum
|
||||
elif [ "$num" = 0 ];then
|
||||
echo
|
||||
elif [ "$num" -le 5 ];then
|
||||
@@ -171,7 +172,7 @@ linkset(){
|
||||
setconfig skip_cert $skip_cert
|
||||
linkset
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
linkset
|
||||
fi
|
||||
clashlink
|
||||
@@ -276,7 +277,7 @@ clashlink(){
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ];then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
elif [ "$num" = 1 ];then
|
||||
if [ -n "$Url" ];then
|
||||
@@ -370,10 +371,11 @@ clashlink(){
|
||||
elif [ "$num" = 0 ];then
|
||||
clashsh
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
}
|
||||
#下载更新相关
|
||||
gettar(){
|
||||
webget /tmp/clashfm.tar.gz $tarurl
|
||||
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
|
||||
@@ -480,7 +482,7 @@ getcore(){
|
||||
echo 0 返回上级菜单
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
update
|
||||
elif [ "$num" = 0 ]; then
|
||||
update
|
||||
@@ -507,7 +509,7 @@ getcore(){
|
||||
fi
|
||||
getcore
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
update
|
||||
fi
|
||||
#生成链接
|
||||
@@ -595,7 +597,7 @@ getdb(){
|
||||
fi
|
||||
update
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
update
|
||||
fi
|
||||
echo -----------------------------------------------
|
||||
@@ -680,7 +682,7 @@ setserver(){
|
||||
echo -e " 0 返回上级菜单"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
update
|
||||
elif [ "$num" = 1 ]; then
|
||||
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash@master'
|
||||
@@ -701,7 +703,7 @@ setserver(){
|
||||
elif [ "$num" = 9 ]; then
|
||||
update_url='http://192.168.31.30:8080/clash-for-Miwifi'
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
update
|
||||
fi
|
||||
#写入mark文件
|
||||
@@ -745,7 +747,7 @@ update(){
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashsh
|
||||
@@ -802,11 +804,12 @@ update(){
|
||||
echo -e "\033[31m操作已取消!\033[0m"
|
||||
update
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
exit;
|
||||
}
|
||||
#新手引导
|
||||
userguide(){
|
||||
echo 欢迎使用ShellClash新手引导!
|
||||
checkupdate
|
||||
@@ -815,6 +818,7 @@ userguide(){
|
||||
getdb
|
||||
clashlink
|
||||
}
|
||||
#测试菜单
|
||||
testcommand(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[30;47m这里是测试命令菜单\033[0m"
|
||||
@@ -834,7 +838,7 @@ testcommand(){
|
||||
echo " 0 返回上级目录!"
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ]; then
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
elif [ "$num" = 0 ]; then
|
||||
clashsh
|
||||
@@ -887,7 +891,7 @@ testcommand(){
|
||||
cat $clashdir/log
|
||||
exit;
|
||||
else
|
||||
echoerrornum
|
||||
errornum
|
||||
clashsh
|
||||
fi
|
||||
}
|
||||
120
scripts/start.sh
120
scripts/start.sh
@@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
#相关工具
|
||||
getconfig(){
|
||||
#加载配置文件
|
||||
[ -z "$clashdir" ] && source /etc/profile > /dev/null
|
||||
@@ -34,9 +35,18 @@ logger(){
|
||||
}
|
||||
cronset(){
|
||||
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
|
||||
crontab -l > /tmp/conf && sed -i "/$1/d" /tmp/conf && echo "$2" >> /tmp/conf && crontab /tmp/conf
|
||||
crontab -l > /tmp/conf
|
||||
sed -i "/$1/d" /tmp/conf
|
||||
echo "$2" >> /tmp/conf
|
||||
crontab /tmp/conf
|
||||
rm -f /tmp/conf
|
||||
}
|
||||
mark_time(){
|
||||
start_time=`date +%s`
|
||||
sed -i '/start_time*/'d $clashdir/mark
|
||||
echo start_time=$start_time >> $clashdir/mark
|
||||
}
|
||||
#配置文件相关
|
||||
getyaml(){
|
||||
[ -z "$rule_link" ] && rule_link=1
|
||||
[ -z "$server_link" ] && server_link=1
|
||||
@@ -209,11 +219,7 @@ EOF
|
||||
rm -f /tmp/clash/set.yaml
|
||||
rm -f /tmp/clash/rule.yaml
|
||||
}
|
||||
mark_time(){
|
||||
start_time=`date +%s`
|
||||
sed -i '/start_time*/'d $clashdir/mark
|
||||
echo start_time=$start_time >> $clashdir/mark
|
||||
}
|
||||
#设置路由规则
|
||||
start_redir(){
|
||||
#流量过滤规则
|
||||
iptables -t nat -N clash
|
||||
@@ -241,6 +247,37 @@ start_redir(){
|
||||
ip6tables -t nat -A PREROUTING -p tcp -j clashv6
|
||||
fi
|
||||
}
|
||||
start_dns(){
|
||||
#允许tun网卡接受流量
|
||||
if [ "$redir_mod" = "Tun模式" -o "$redir_mod" = "混合模式" ];then
|
||||
iptables -I FORWARD -o utun -j ACCEPT
|
||||
[ "$ipv6_support" = "已开启" ] && ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
|
||||
fi
|
||||
#设置dns转发
|
||||
iptables -t nat -N clash_dns
|
||||
for mac in $(cat $clashdir/mac); do
|
||||
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
|
||||
done
|
||||
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to $dns_port
|
||||
iptables -t nat -A clash_dns -p tcp --dport 53 -j REDIRECT --to $dns_port
|
||||
iptables -t nat -A PREROUTING -p udp -j clash_dns
|
||||
#Google home DNS特殊处理
|
||||
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash_dns
|
||||
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash_dns
|
||||
#ipv6DNS
|
||||
ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'Chain')
|
||||
if [ -n "ip6_nat" ];then
|
||||
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
|
||||
for mac in $(cat $clashdir/mac); do
|
||||
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1
|
||||
done
|
||||
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to $dns_port > /dev/null 2>&1
|
||||
ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1
|
||||
else
|
||||
ip6tables -I INPUT -p tcp --dport 53 -j REJECT
|
||||
ip6tables -I INPUT -p udp --dport 53 -j REJECT
|
||||
fi
|
||||
}
|
||||
start_udp(){
|
||||
ip rule add fwmark 1 table 100
|
||||
ip route add local default dev lo table 100
|
||||
@@ -280,37 +317,7 @@ stop_iptables(){
|
||||
ip6tables -t nat -X clashv6_dns > /dev/null 2>&1
|
||||
ip6tables -D FORWARD -o utun -j ACCEPT > /dev/null 2>&1
|
||||
}
|
||||
start_dns(){
|
||||
#允许tun网卡接受流量
|
||||
if [ "$redir_mod" = "Tun模式" -o "$redir_mod" = "混合模式" ];then
|
||||
iptables -I FORWARD -o utun -j ACCEPT
|
||||
[ "$ipv6_support" = "已开启" ] && ip6tables -I FORWARD -o utun -j ACCEPT > /dev/null 2>&1
|
||||
fi
|
||||
#设置dns转发
|
||||
iptables -t nat -N clash_dns
|
||||
for mac in $(cat $clashdir/mac); do
|
||||
iptables -t nat -A clash_dns -m mac --mac-source $mac -j RETURN
|
||||
done
|
||||
iptables -t nat -A clash_dns -p udp --dport 53 -j REDIRECT --to $dns_port
|
||||
iptables -t nat -A clash_dns -p tcp --dport 53 -j REDIRECT --to $dns_port
|
||||
iptables -t nat -A PREROUTING -p udp -j clash_dns
|
||||
#Google home DNS特殊处理
|
||||
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j clash_dns
|
||||
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j clash_dns
|
||||
#ipv6DNS
|
||||
ip6_nat=$(ip6tables -t nat -L 2>&1|grep -o 'Chain')
|
||||
if [ -n "ip6_nat" ];then
|
||||
ip6tables -t nat -N clashv6_dns > /dev/null 2>&1
|
||||
for mac in $(cat $clashdir/mac); do
|
||||
ip6tables -t nat -A clashv6_dns -m mac --mac-source $mac -j RETURN > /dev/null 2>&1
|
||||
done
|
||||
ip6tables -t nat -A clashv6_dns -p udp --dport 53 -j REDIRECT --to $dns_port > /dev/null 2>&1
|
||||
ip6tables -t nat -A PREROUTING -p udp -j clashv6_dns > /dev/null 2>&1
|
||||
else
|
||||
ip6tables -I INPUT -p tcp --dport 53 -j REJECT
|
||||
ip6tables -I INPUT -p udp --dport 53 -j REJECT
|
||||
fi
|
||||
}
|
||||
#面板配置保存相关
|
||||
web_save(){
|
||||
get_save(){
|
||||
if curl --version > /dev/null 2>&1;then
|
||||
@@ -359,11 +366,12 @@ web_restore(){
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
#启动相关
|
||||
afstart(){
|
||||
#读取配置文件
|
||||
getconfig
|
||||
$clashdir/clash -t -d $clashdir >/dev/null
|
||||
if [ "$?" = 0 ];then
|
||||
#读取配置文件
|
||||
getconfig
|
||||
#修改iptables规则使流量进入clash
|
||||
[ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "已禁用" ] && start_dns
|
||||
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
|
||||
@@ -443,22 +451,20 @@ daemon)
|
||||
cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"$(pidof clash)\" && $clashdir/start.sh restart #clash保守模式守护进程"
|
||||
;;
|
||||
set_proxy)
|
||||
getconfig
|
||||
#GNOME配置
|
||||
if gsettings --version >/dev/null 2>&1 ;then
|
||||
gsettings set org.gnome.system.proxy autoconfig-url "http://127.0.0.1:$3/ui/pac"
|
||||
if [ "$local_proxy_type" = "GNOME" ];then
|
||||
gsettings set org.gnome.system.proxy autoconfig-url "http://127.0.0.1:$db_port/ui/pac"
|
||||
gsettings set org.gnome.system.proxy mode "auto"
|
||||
[ "$?" = 0 ] && check=$?
|
||||
#KDE配置
|
||||
elif kwriteconfig5 -h >/dev/null 2>&1 ;then
|
||||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1:$3/ui/pac"
|
||||
elif [ "$local_proxy_type" = "KDE" ];then
|
||||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "Proxy Config Script" "http://127.0.0.1:$db_port/ui/pac"
|
||||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 2
|
||||
[ "$?" = 0 ] && check=$?
|
||||
#环境变量方式
|
||||
fi
|
||||
if [ -z "$check" ];then
|
||||
else
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
echo 'export all_proxy=http://127.0.0.1:'"$2" >> $profile
|
||||
echo 'export all_proxy=http://127.0.0.1:'"$mix_port" >> $profile
|
||||
echo 'export ALL_PROXY=$all_proxy' >> $profile
|
||||
fi
|
||||
;;
|
||||
@@ -466,16 +472,16 @@ unset_proxy)
|
||||
#GNOME配置
|
||||
if gsettings --version >/dev/null 2>&1 ;then
|
||||
gsettings set org.gnome.system.proxy mode "none"
|
||||
#KDE配置
|
||||
elif kwriteconfig5 -h >/dev/null 2>&1 ;then
|
||||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 0
|
||||
#环境变量方式
|
||||
else
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/all_proxy/'d $profile
|
||||
sed -i '/ALL_PROXY/'d $profile
|
||||
fi
|
||||
#KDE配置
|
||||
if kwriteconfig5 -h >/dev/null 2>&1 ;then
|
||||
kwriteconfig5 --file kioslaverc --group "Proxy Settings" --key "ProxyType" 0
|
||||
fi
|
||||
#环境变量方式
|
||||
[ -w ~/.bashrc ] && profile=~/.bashrc
|
||||
[ -w /etc/profile ] && profile=/etc/profile
|
||||
sed -i '/all_proxy/'d $profile
|
||||
sed -i '/ALL_PROXY/'d $profile
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user