v1.0.0beta15.7
~同步premium最新测试版核心,修复tun模式下回环bug ~优化了本机代理实现方式,增加了选项菜单 ~优化了定时任务实现方式,适配更多设备 ~优化了配置文件修饰方式 ~优化了启动和关闭进程时的检测,修复错误 ~优化了非root用户体验 ~优化脚本结构
This commit is contained in:
@@ -12,6 +12,8 @@ getconfig(){
|
||||
#检查/读取标识文件
|
||||
[ ! -f $ccfg ] && echo '#标识clash运行状态的文件,不明勿动!' > $ccfg
|
||||
source $ccfg
|
||||
#设置默认核心资源目录
|
||||
[ -z "$bindir" ] && bindir=$clashdir
|
||||
#设置默认端口及变量
|
||||
[ -z "$mix_port" ] && mix_port=7890
|
||||
[ -z "$redir_port" ] && redir_port=7892
|
||||
@@ -21,12 +23,9 @@ getconfig(){
|
||||
#检查mac地址记录
|
||||
[ ! -f $clashdir/mac ] && touch $clashdir/mac
|
||||
#获取本机host地址
|
||||
if [ -f /bin/opkg ];then
|
||||
host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
|
||||
else
|
||||
host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g'|head -n 1)
|
||||
[ -z "$host" ] && host=127.0.0.1
|
||||
fi
|
||||
host=$(ubus call network.interface.lan status 2>&1 | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
|
||||
[ -z "$host" ] && host=$(ip a 2>&1 | grep -w 'inet' | grep 'global' | grep -E '192.|10.' | sed 's/.*inet.//g' | sed 's/\/[0-9][0-9].*$//g' | head -n 1)
|
||||
[ -z "$host" ] && host=127.0.0.1
|
||||
#dashboard目录位置
|
||||
[ -d $clashdir/ui ] && dbdir=$clashdir/ui && hostdir=":$db_port/ui"
|
||||
[ -d /www/clash ] && dbdir=/www/clash && hostdir=/clash
|
||||
@@ -95,28 +94,6 @@ errornum(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m请输入正确的数字!\033[0m"
|
||||
}
|
||||
catpac(){
|
||||
cat > /tmp/clash_pac <<EOF
|
||||
function FindProxyForURL(url, host) {
|
||||
if (
|
||||
isInNet(host, "0.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "10.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "127.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "224.0.0.0", "224.0.0.0")||
|
||||
isInNet(host, "240.0.0.0", "240.0.0.0")||
|
||||
isInNet(host, "172.16.0.0", "255.240.0.0")||
|
||||
isInNet(host, "192.168.0.0", "255.255.0.0")||
|
||||
isInNet(host, "169.254.0.0", "255.255.0.0")
|
||||
)
|
||||
return "DIRECT";
|
||||
else
|
||||
return "SOCKS5 $host:$mix_port; PROXY $host:$mix_port; DIRECT;"
|
||||
}
|
||||
EOF
|
||||
[ ! -d $clashdir/ui ] && mkdir -p $clashdir/ui
|
||||
cmp -s /tmp/clash_pac $clashdir/ui/pac
|
||||
[ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $clashdir/ui/pac
|
||||
}
|
||||
startover(){
|
||||
echo -e "\033[32mclash服务已启动!\033[0m"
|
||||
if [ -n "$hostdir" ];then
|
||||
@@ -133,25 +110,12 @@ startover(){
|
||||
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
|
||||
@@ -699,6 +663,7 @@ clashadv(){
|
||||
[ -z "$ipv6_support" ] && ipv6_support=未开启
|
||||
[ -z "$start_old" ] && start_old=未开启
|
||||
[ -z "$tproxy_mod" ] && tproxy_mod=未开启
|
||||
[ "$bindir" = "/tmp/clash_$USER" ] && mini_clash=已开启 || mini_clash=未开启
|
||||
#
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[30;47m欢迎使用进阶模式菜单:\033[0m"
|
||||
@@ -709,8 +674,9 @@ clashadv(){
|
||||
echo -e " 2 启用ipv6支持: \033[36m$ipv6_support\033[0m ————实验性功能,可能不稳定"
|
||||
echo -e " 3 使用保守方式启动: \033[36m$start_old\033[0m ————切换时会停止clash服务"
|
||||
echo -e " 4 Redir模式udp转发: \033[36m$tproxy_mod\033[0m ————依赖iptables-mod-tproxy"
|
||||
echo -e " 5 配置内置DNS服务: \033[36m$dns_no\033[0m"
|
||||
echo -e " 6 手动指定clash运行端口及秘钥"
|
||||
echo -e " 5 启用小闪存模式: \033[36m$mini_clash\033[0m ————启动时方下载核心及数据库文件"
|
||||
echo -e " 6 配置内置DNS服务: \033[36m$dns_no\033[0m"
|
||||
echo -e " 7 手动指定clash运行端口及秘钥"
|
||||
echo -----------------------------------------------
|
||||
echo -e " 8 \033[31m重置\033[0m配置文件"
|
||||
echo -e " 9 \033[32m重启\033[0mclash服务"
|
||||
@@ -792,11 +758,38 @@ clashadv(){
|
||||
sleep 1
|
||||
clashadv
|
||||
|
||||
elif [ "$num" = 5 ]; then
|
||||
elif [ "$num" = 5 ]; then
|
||||
echo -----------------------------------------------
|
||||
dir_size=$(df $clashdir | awk '{print $4}' | sed 1d)
|
||||
if [ "$mini_clash" = "未开启" ]; then
|
||||
if [ "$dir_size" -gt 20480 ];then
|
||||
echo -e "\033[33m您的设备空间充足(>20M),无需开启!\033[0m"
|
||||
elif pidof systemd >/dev/null 2>&1;then
|
||||
echo -e "\033[33m该设备不支持开启此模式!\033[0m"
|
||||
else
|
||||
bindir="/tmp/clash_$USER"
|
||||
echo -e "\033[32m已经启用小闪存功能!\033[0m"
|
||||
echo -e "核心及数据库文件将存储在内存中执行,并在每次开机运行后自动下载\033[0m"
|
||||
fi
|
||||
else
|
||||
if [ "$dir_size" -lt 8192 ];then
|
||||
echo -e "\033[31m您的设备剩余空间不足8M,停用后可能无法正常运行!\033[0m"
|
||||
read -p "确认停用此功能?(1/0) > " res
|
||||
[ "$res" = 1 ] && bindir="$clashdir" && echo -e "\033[33m已经停用小闪存功能!\033[0m"
|
||||
else
|
||||
bindir="$clashdir"
|
||||
echo -e "\033[33m已经停用小闪存功能!\033[0m"
|
||||
fi
|
||||
fi
|
||||
setconfig bindir $bindir
|
||||
sleep 1
|
||||
clashadv
|
||||
|
||||
elif [ "$num" = 6 ]; then
|
||||
setdns
|
||||
clashadv
|
||||
|
||||
elif [ "$num" = 6 ]; then
|
||||
elif [ "$num" = 7 ]; then
|
||||
setport
|
||||
clashadv
|
||||
|
||||
|
||||
@@ -5,15 +5,20 @@ START=92
|
||||
SERVICE_DAEMONIZE=1
|
||||
SERVICE_WRITE_PID=1
|
||||
USE_PROCD=1
|
||||
DIR=$(cat /etc/profile|grep clashdir|awk -F "\"" '{print $2}')
|
||||
#获取目录
|
||||
DIR=$(cat /etc/profile | grep clashdir | awk -F "\"" '{print $2}')
|
||||
BINDIR=$(cat $DIR/mark | grep bindir | awk -F "=" '{print $2}')
|
||||
[ -z "$BINDIR" ] && BINDIR=$DIR
|
||||
|
||||
start_service() {
|
||||
#检测必须文件
|
||||
$DIR/start.sh bfstart
|
||||
#使用procd创建clash后台进程
|
||||
procd_open_instance
|
||||
procd_set_param respawn
|
||||
procd_set_param stderr 1
|
||||
procd_set_param stdout 1
|
||||
procd_set_param command $DIR/clash -d $DIR
|
||||
procd_set_param command $BINDIR/clash -d $BINDIR
|
||||
procd_close_instance
|
||||
#其他设置
|
||||
$DIR/start.sh afstart
|
||||
@@ -21,8 +26,10 @@ start_service() {
|
||||
|
||||
start() {
|
||||
if [ -z "$(pidof procd)" ];then
|
||||
#检测必须文件
|
||||
$DIR/start.sh bfstart
|
||||
#创建后台进程
|
||||
service_start $DIR/clash -d $DIR
|
||||
service_start $BINDIR/clash -d $BINDIR
|
||||
#其他设置
|
||||
$DIR/start.sh afstart
|
||||
#设置守护进程
|
||||
|
||||
@@ -443,33 +443,42 @@ getsh(){
|
||||
update
|
||||
fi
|
||||
}
|
||||
getcpucore(){
|
||||
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
|
||||
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && cpucore="armv7"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
|
||||
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
|
||||
mipstype=$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
|
||||
[ "$mipstype" = "1" ] && cpucore="mipsle-softfloat" || cpucore="mips-softfloat"
|
||||
fi
|
||||
[ -n "$cpucore" ] && setconfig cpucore $cpucore
|
||||
}
|
||||
getcore(){
|
||||
[ -z "$clashcore" ] && clashcore=clashpre
|
||||
[ -z "$cpucore" ] && getcpucore
|
||||
#生成链接
|
||||
corelink="$update_url/bin/$clashcore/clash-linux-$cpucore"
|
||||
#获取在线clash核心文件
|
||||
webget /tmp/clash.new $corelink
|
||||
if [ "$result" != "200" ];then
|
||||
exit 1
|
||||
else
|
||||
mv -f /tmp/clash.new $bindir/clash
|
||||
chmod 777 $bindir/clash #授予权限
|
||||
fi
|
||||
}
|
||||
setcore(){
|
||||
#获取核心及版本信息
|
||||
[ ! -f $clashdir/clash ] && clashcore="未安装核心"
|
||||
#获取设备处理器架构
|
||||
getcputype(){
|
||||
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
|
||||
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && cpucore="armv7"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="armv8"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
|
||||
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
|
||||
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
|
||||
mipstype=$(echo -n I | hexdump -o | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
|
||||
if [ "$mipstype" = "1" ];then
|
||||
cpucore="mipsle-softfloat"
|
||||
#[ -n "$(uname -a | grep -E "M2100")" ] && cpucore="mipsle-hardfloat"
|
||||
else
|
||||
cpucore="mips-softfloat"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
###
|
||||
echo -----------------------------------------------
|
||||
[ -z "$cpucore" ] && getcputype
|
||||
[ -z "$cpucore" ] && getcpucore
|
||||
echo -e "当前clash核心:\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
|
||||
echo -e "当前系统处理器架构:\033[32m $cpucore \033[0m"
|
||||
echo -e "\033[33m请选择需要下载的核心版本!\033[0m"
|
||||
echo -e "\033[33m请选择需要使用的核心版本!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo "1 clash: 稳定,内存占用小,推荐!"
|
||||
echo "(官方正式版) 不支持Tun模式、混合模式"
|
||||
@@ -493,7 +502,7 @@ getcore(){
|
||||
clashcore=clashpre
|
||||
version=$clashpre_v
|
||||
elif [ "$num" = 3 ]; then
|
||||
cpucore_list="armv5 armv7 armv8 386 amd64 mipsle-softfloat mipsle-hardfloat mips-softfloat"
|
||||
cpucore_list="armv5 armv7 armv8 386 amd64 \nmipsle-softfloat mipsle-hardfloat mips-softfloat"
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m仅适合脚本无法正确识别核心或核心无法正常运行时使用!\033[0m"
|
||||
echo -e "当前可供在线下载的处理器架构为:"
|
||||
@@ -506,42 +515,34 @@ getcore(){
|
||||
echo -e "\033[31m请输入正确的处理器架构!\033[0m"
|
||||
sleep 1
|
||||
cpucore=""
|
||||
else
|
||||
setconfig cpucore $cpucore
|
||||
fi
|
||||
getcore
|
||||
setcore
|
||||
else
|
||||
errornum
|
||||
update
|
||||
fi
|
||||
#生成链接
|
||||
corelink="$update_url/bin/$clashcore/clash-linux-$cpucore"
|
||||
echo -----------------------------------------------
|
||||
echo 正在连接服务器获取clash核心文件…………链接地址为:
|
||||
echo -e "\033[4;32m$corelink\033[0m"
|
||||
echo 如无法正常下载可以手动复制到浏览器下载核心文件!
|
||||
echo -e "\033[36m-----------------------------------------------"
|
||||
echo -e "| |"
|
||||
echo -e "| 需要一点时间,请耐心等待! |"
|
||||
echo -e "| \033[0m如长时间没有数据请用ctrl+c退出 |"
|
||||
echo -e "-----------------------------------------------\033[0m"
|
||||
#获取在线clash核心文件
|
||||
webget /tmp/clash.new $corelink
|
||||
if [ "$result" != "200" ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m核心文件下载失败!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
getcore
|
||||
else
|
||||
echo -e "\033[32m$clashcore核心下载成功,正在替换!\033[0m"
|
||||
mv -f /tmp/clash.new $clashdir/clash
|
||||
chmod 777 $clashdir/clash #授予权限
|
||||
echo 在线获取clash核心文件……
|
||||
getcore
|
||||
if [ "$?" = 0 ];then
|
||||
echo -e "\033[32m$clashcore核心下载成功!\033[0m"
|
||||
setconfig clashcore $clashcore
|
||||
setconfig clashv $version
|
||||
rm -rf /tmp/clashversion
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32m$clashcore核心安装成功!\033[0m"
|
||||
fi
|
||||
else
|
||||
echo -e "\033[31m核心文件下载失败!\033[0m"
|
||||
fi
|
||||
}
|
||||
getgeo(){
|
||||
webget /tmp/Country.mmdb $update_url/bin/Country.mmdb
|
||||
if [ "$result" != "200" ];then
|
||||
exit 1
|
||||
else
|
||||
mv -f /tmp/Country.mmdb $bindir/Country.mmdb
|
||||
fi
|
||||
}
|
||||
setgeo(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "当前GeoIP版本为:\033[33m $Geo_v \033[0m"
|
||||
echo -e "最新GeoIP版本为:\033[32m $GeoIP_v \033[0m"
|
||||
@@ -550,18 +551,14 @@ getgeo(){
|
||||
if [ "$res" = '1' ]; then
|
||||
echo -----------------------------------------------
|
||||
echo 正在从服务器获取数据库文件…………
|
||||
webget /tmp/Country.mmdb $update_url/bin/Country.mmdb
|
||||
if [ "$result" != "200" ];then
|
||||
getgeo
|
||||
if [ "$?" != 0 ];then
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[31m文件下载失败!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
getgeo
|
||||
else
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[32mGeoIP数据库文件下载成功!\033[0m"
|
||||
mv -f /tmp/Country.mmdb $clashdir/Country.mmdb
|
||||
setconfig Geo_v $GeoIP_v
|
||||
rm -rf /tmp/clashversion
|
||||
fi
|
||||
else
|
||||
update
|
||||
@@ -651,8 +648,8 @@ getdb(){
|
||||
[ $? -ne 0 ] && echo "文件解压失败!" && rm -rf /tmp/clashfm.tar.gz && exit 1
|
||||
#修改默认host和端口
|
||||
if [ "$db_type" = "clashdb" ];then
|
||||
sed -i "s/127.0.0.1/${host}/g" $dbdir/js/*.js
|
||||
sed -i "s/9090/${db_port}/g" $dbdir/js/*.js
|
||||
sed -i "s/127.0.0.1/${host}/g" $dbdir/static/js/*.js
|
||||
sed -i "s/9090/${db_port}/g" $dbdir/static/js/*.js
|
||||
else
|
||||
sed -i "s/127.0.0.1/${host}/g" $dbdir/app*.js
|
||||
sed -i "s/7892/${db_port}/g" $dbdir/app*.js
|
||||
@@ -811,12 +808,74 @@ exit;
|
||||
}
|
||||
#新手引导
|
||||
userguide(){
|
||||
echo 欢迎使用ShellClash新手引导!
|
||||
|
||||
|
||||
whichmod(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[36m 是否需要代理UDP(主要用于游戏)? \033[0m"
|
||||
echo -e "\033[0m你之后依然可以在设置中更改各种配置\033[0m"
|
||||
echo -e " 1 \033[36m不需要代理UDP流量\033[0m"
|
||||
modinfo tun >/dev/null 2>&1 && [ "$?" = 0 ] && \
|
||||
echo -e " 2 \033[36m使用Tun虚拟网卡代理UDP流量(更低的延迟但更多的CPU消耗)\033[0m" || \
|
||||
echo -e " x \033[36m(你的设备不支持此模式,如为虚拟机运行请调整虚拟网络)\033[0m"
|
||||
[ -n "$(iptables -j TPROXY 2>&1 | grep 'on-port')" ] && \
|
||||
echo -e " 3 \033[36m使用Tproxy模式代理UDP流量(较低CPU消耗但更高的延迟)033[0m"
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ] || [ "$num" -gt 4 ];then
|
||||
errornum
|
||||
whichmod
|
||||
elif [ "$num" = 1 ];then
|
||||
setconfig redir_mod "Redir模式"
|
||||
setconfig clashcore "clash"
|
||||
elif [ "$num" = 2 ];then
|
||||
setconfig redir_mod "混合模式"
|
||||
setconfig clashcore "clashpre"
|
||||
elif [ "$num" = 3 ];then
|
||||
setconfig redir_mod "Redir模式"
|
||||
setconfig clashcore "clash"
|
||||
setconfig tproxy_mod "已开启"
|
||||
fi
|
||||
}
|
||||
forwhat(){
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[30;46m 欢迎使用ShellClash新手引导! \033[0m"
|
||||
echo -----------------------------------------------
|
||||
echo -e "\033[33m 请选择你的使用环境! \033[0m"
|
||||
echo -e " 1 \033[32m各类路由设备\033[0m,配置局域网透明路由"
|
||||
echo -e " 2 \033[36mLinux系统带GUI桌面\033[0m,配置本机路由"
|
||||
echo -e " 3 \033[32m服务器Linux系统\033[0m,配置本机路由"
|
||||
echo -e " 4 \033[36m多功能设备\033[0m,配置本机及局域网路由"
|
||||
echo -----------------------------------------------
|
||||
read -p "请输入对应数字 > " num
|
||||
if [ -z "$num" ] || [ "$num" -gt 4 ];then
|
||||
errornum
|
||||
forwhat
|
||||
elif [ "$num" = 1 ];then
|
||||
whichmod
|
||||
elif [ "$num" = 2 -o "$num" = 3 ];then
|
||||
setconfig redir_mod "纯净模式"
|
||||
setconfig clashcore "clash"
|
||||
echo -e "\033[36m请选择设置本机代理的方式\033[0m"
|
||||
localproxy
|
||||
elif [ "$num" = 4 ];then
|
||||
whichmod
|
||||
fi
|
||||
}
|
||||
|
||||
checkupdate
|
||||
getcore
|
||||
getgeo
|
||||
getdb
|
||||
clashlink
|
||||
forwhat
|
||||
dir_size=$(df $clashdir | awk '{print $4}' | sed 1d)
|
||||
if [ "$dir_size" -lt 10240 ];then
|
||||
echo -e "\033[33m检测到你的安装目录空间不足10M,是否开启小闪存模式?\033[0m"
|
||||
echo -e "\033[33m开启后核心及数据库文件将被下载到内存中!\033[0m"
|
||||
read -p "是否开启?(1/0) > " res
|
||||
[ "$res" = 1 ] && setconfig bindir="/tmp/clash_$USER"
|
||||
fi
|
||||
read -p "需要安装本地Dashboard面板吗?(1/0) > " res
|
||||
[ "$res" = 1 ] && getdb
|
||||
read -p "现在导入订阅或者配置文件链接?(1/0) > " res
|
||||
[ "$res" = 1 ] && clashlink
|
||||
}
|
||||
#测试菜单
|
||||
testcommand(){
|
||||
@@ -824,7 +883,7 @@ testcommand(){
|
||||
echo -e "\033[30;47m这里是测试命令菜单\033[0m"
|
||||
echo -e "\033[33m如遇问题尽量运行相应命令后截图发群\033[0m"
|
||||
echo -e "磁盘占用/所在目录:"
|
||||
du -h $clashdir
|
||||
du -sh $clashdir
|
||||
echo -----------------------------------------------
|
||||
echo " 1 查看clash运行时的报错信息"
|
||||
echo " 2 查看系统DNS端口(:53)占用 "
|
||||
|
||||
163
scripts/start.sh
163
scripts/start.sh
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) Juewuy
|
||||
|
||||
#相关工具
|
||||
#脚本内部工具
|
||||
getconfig(){
|
||||
#加载配置文件
|
||||
[ -z "$clashdir" ] && source /etc/profile > /dev/null
|
||||
@@ -9,6 +9,7 @@ getconfig(){
|
||||
ccfg=$clashdir/mark
|
||||
[ -f $ccfg ] && source $ccfg
|
||||
#默认设置
|
||||
[ -z "$bindir" ] && bindir=$clashdir
|
||||
[ -z "$redir_mod" ] && [ "$USER" = "root" -o "$USER" = "admin" ] && redir_mod=Redir模式
|
||||
[ -z "$redir_mod" ] && redir_mod=纯净模式
|
||||
[ -z "$skip_cert" ] && skip_cert=已开启
|
||||
@@ -28,8 +29,31 @@ getconfig(){
|
||||
#是否代理常用端口
|
||||
[ "$common_ports" = "已开启" ] && ports='-m multiport --dports 53,587,465,995,993,143,80,443 '
|
||||
}
|
||||
setconfig(){
|
||||
#参数1代表变量名,参数2代表变量值,参数3即文件路径
|
||||
[ -z "$3" ] && configpath=$clashdir/mark || configpath=$3
|
||||
sed -i "/${1}*/"d $configpath
|
||||
echo "${1}=${2}" >> $configpath
|
||||
}
|
||||
webget(){
|
||||
[ -n "$(pidof clash)" ] && export all_proxy="http://127.0.0.1:$mix_port" #设置临时http代理
|
||||
#参数【$1】代表下载目录,【$2】代表在线地址
|
||||
#参数【$3】代表输出显示,【$4】不启用重定向
|
||||
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)
|
||||
else
|
||||
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
|
||||
[ "$3" = "echoon" ] && progress=''
|
||||
[ -z "$4" ] && redirect='' || redirect='--max-redirect=0'
|
||||
wget -Y on $progress $redirect --no-check-certificate --timeout=5 -O $1 $2
|
||||
[ $? -eq 0 ] && result="200"
|
||||
fi
|
||||
export all_proxy=''
|
||||
}
|
||||
logger(){
|
||||
[ -z "$2" ] && echo -e "\033[31m$1\033[0m"
|
||||
[ -n "$2" ] && echo -e "\033[$2m$1\033[0m"
|
||||
echo `date "+%G-%m-%d %H:%M:%S"` $1 >> $clashdir/log
|
||||
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1,5d' $clashdir/log
|
||||
}
|
||||
@@ -84,32 +108,27 @@ EOF`
|
||||
echo 正在连接服务器获取配置文件…………链接地址为:
|
||||
echo -e "\033[4;32m$Https\033[0m"
|
||||
echo 可以手动复制该链接到浏览器打开并查看数据是否正常!
|
||||
echo -e "\033[36m-----------------------------------------------"
|
||||
echo -e "| |"
|
||||
echo -e "| 需要一点时间,请耐心等待! |"
|
||||
echo -e "| \033[0m如长时间没有数据请用ctrl+c退出\033[36m |"
|
||||
echo -e "-----------------------------------------------\033[0m"
|
||||
#获取在线yaml文件
|
||||
yaml=$clashdir/config.yaml
|
||||
yamlnew=/tmp/clash_config_$USER.yaml
|
||||
rm -rf $yamlnew
|
||||
source $clashdir/getdate.sh && webget $yamlnew $Https
|
||||
webget $yamlnew $Https
|
||||
if [ "$result" != "200" ];then
|
||||
if [ -z "$markhttp" ];then
|
||||
echo -----------------------------------------------
|
||||
logger "配置文件获取失败!"
|
||||
logger "配置文件获取失败!" 31
|
||||
echo -e "\033[31m请尝试使用【导入订阅】功能!\033[0m"
|
||||
echo -----------------------------------------------
|
||||
exit 1
|
||||
else
|
||||
if [ "$retry" -ge 5 ];then
|
||||
logger "无法获取配置文件,请检查链接格式以及网络连接状态!"
|
||||
logger "无法获取配置文件,请检查链接格式以及网络连接状态!" 31
|
||||
exit 1
|
||||
else
|
||||
retry=$((retry+1))
|
||||
logger "配置文件获取失败!"
|
||||
logger "配置文件获取失败!" 31
|
||||
echo -e "\033[32m尝试使用其他服务器获取配置!\033[0m"
|
||||
logger "正在重试第$retry次/共5次!"
|
||||
logger "正在重试第$retry次/共5次!" 32
|
||||
sed -i '/server_link=*/'d $ccfg
|
||||
if [ "$server_link" -ge 5 ]; then
|
||||
server_link=0
|
||||
@@ -125,7 +144,7 @@ EOF`
|
||||
#检测节点
|
||||
if [ -z "$(cat $yamlnew | grep 'server:' | grep -v 'nameserver')" ];then
|
||||
echo -----------------------------------------------
|
||||
logger "获取到了配置文件,但似乎并不包含正确的节点信息!"
|
||||
logger "获取到了配置文件,但似乎并不包含正确的节点信息!" 31
|
||||
echo -----------------------------------------------
|
||||
sed -n '1,30p' $yamlnew
|
||||
echo -----------------------------------------------
|
||||
@@ -136,7 +155,7 @@ EOF`
|
||||
#检测旧格式
|
||||
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
|
||||
echo -----------------------------------------------
|
||||
logger "已经停止对旧格式配置文件的支持!!!"
|
||||
logger "已经停止对旧格式配置文件的支持!!!" 31
|
||||
echo -e "请使用新格式或者使用【导入节点/链接】功能!"
|
||||
echo -----------------------------------------------
|
||||
exit 1
|
||||
@@ -144,7 +163,7 @@ EOF`
|
||||
#检测不支持的加密协议
|
||||
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
|
||||
echo -----------------------------------------------
|
||||
logger "不支持chacha20加密,请更换节点加密协议!!!"
|
||||
logger "不支持chacha20加密,请更换节点加密协议!!!" 31
|
||||
echo -----------------------------------------------
|
||||
exit 1
|
||||
fi
|
||||
@@ -160,13 +179,15 @@ EOF`
|
||||
$0 stop
|
||||
$0 start
|
||||
if [ "$?" = 0 ];then
|
||||
logger "配置文件获取成功!clash服务已启动!" echooff
|
||||
logger "配置文件获取成功!clash服务已启动!"
|
||||
exit 0
|
||||
else
|
||||
if [ -f $yaml.bak ];then
|
||||
$0 stop
|
||||
mv -f $yaml.bak $yaml
|
||||
$0 start
|
||||
[ "$?" = 0 ] && logger "已还原配置文件并重启clash!" && exit 0
|
||||
[ "$?" = 0 ] && logger "已还原配置文件并重启clash!" 32 && exit 0
|
||||
logger "已还原配置文件但依然无法启动clash!" 31 && exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -189,18 +210,19 @@ modify_yaml(){
|
||||
dns='dns: {enable: true, ipv6: true, listen: 0.0.0.0:'$dns_port', use-hosts: true, enhanced-mode: redir-host, nameserver: ['$dns_nameserver$dns_local'], fallback: ['$dns_fallback'], fallback-filter: {geoip: true}}'
|
||||
fi
|
||||
###################################
|
||||
#设置目录
|
||||
yaml=$clashdir/config.yaml
|
||||
tmp_clash=/tmp/clash_$USER
|
||||
tmpdir=/tmp/clash_$USER
|
||||
#预删除需要添加的项目
|
||||
a=$(grep -n "port:" $yaml | head -1 | cut -d ":" -f 1)
|
||||
b=$(grep -n "^prox" $yaml | head -1 | cut -d ":" -f 1)
|
||||
b=$((b-1))
|
||||
mkdir -p $tmp_clash > /dev/null
|
||||
sed "${a},${b}d" $yaml > $tmp_clash/rule.yaml
|
||||
mkdir -p $tmpdir > /dev/null
|
||||
sed "${a},${b}d" $yaml > $tmpdir/rule.yaml
|
||||
#跳过本地tls证书验证
|
||||
[ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmp_clash/rule.yaml
|
||||
[ "$skip_cert" = "已开启" ] && sed -i '10,99s/skip-cert-verify: false/skip-cert-verify: true/' $tmpdir/rule.yaml
|
||||
#添加配置
|
||||
cat > $tmp_clash/set.yaml <<EOF
|
||||
cat > $tmpdir/set.yaml <<EOF
|
||||
mixed-port: $mix_port
|
||||
redir-port: $redir_port
|
||||
authentication: ["$authentication"]
|
||||
@@ -215,11 +237,13 @@ $tun
|
||||
$exper
|
||||
$dns
|
||||
EOF
|
||||
cat $tmp_clash/set.yaml $tmp_clash/rule.yaml > $tmp_clash/config.yaml
|
||||
cmp -s $tmp_clash/config.yaml $yaml
|
||||
[ "$?" != 0 ] && mv -f $tmp_clash/config.yaml $yaml || rm -f $tmp_clash/config.yaml
|
||||
rm -f $tmp_clash/set.yaml
|
||||
rm -f $tmp_clash/rule.yaml
|
||||
cat $tmpdir/set.yaml $tmpdir/rule.yaml > $tmpdir/config.yaml
|
||||
if [ "$tmpdir" != "$bindir" ];then #如果没有使用小闪存模式
|
||||
cmp -s $tmpdir/config.yaml $yaml
|
||||
[ "$?" != 0 ] && mv -f $tmpdir/config.yaml $yaml || rm -f $tmpdir/config.yaml
|
||||
fi
|
||||
rm -f $tmpdir/set.yaml
|
||||
rm -f $tmpdir/rule.yaml
|
||||
}
|
||||
#设置路由规则
|
||||
start_redir(){
|
||||
@@ -327,7 +351,7 @@ web_save(){
|
||||
elif [ -n "$(wget --help 2>&1|grep '\-\-method')" ];then
|
||||
wget -q --header="Authorization: Bearer ${secret}" --header="Content-Type:application/json" -O - "$1"
|
||||
else
|
||||
logger 当前系统未安装curl且wget的版本太低,无法保存节点配置!
|
||||
logger 当前系统未安装curl且wget的版本太低,无法保存节点配置! 31
|
||||
getconfig
|
||||
cronset '保存节点配置'
|
||||
fi
|
||||
@@ -369,10 +393,76 @@ web_restore(){
|
||||
exit 0
|
||||
}
|
||||
#启动相关
|
||||
catpac(){
|
||||
host=$(ubus call network.interface.lan status | grep \"address\" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}';)
|
||||
[ -z "$host" ] && host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g'|head -n 1)
|
||||
[ -z "$host" ] && host=127.0.0.1
|
||||
cat > /tmp/clash_pac <<EOF
|
||||
function FindProxyForURL(url, host) {
|
||||
if (
|
||||
isInNet(host, "0.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "10.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "127.0.0.0", "255.0.0.0")||
|
||||
isInNet(host, "224.0.0.0", "224.0.0.0")||
|
||||
isInNet(host, "240.0.0.0", "240.0.0.0")||
|
||||
isInNet(host, "172.16.0.0", "255.240.0.0")||
|
||||
isInNet(host, "192.168.0.0", "255.255.0.0")||
|
||||
isInNet(host, "169.254.0.0", "255.255.0.0")
|
||||
)
|
||||
return "DIRECT";
|
||||
else
|
||||
return "SOCKS5 $host:$mix_port; PROXY $host:$mix_port; DIRECT;"
|
||||
}
|
||||
EOF
|
||||
cmp -s /tmp/clash_pac $bindir/ui/pac
|
||||
[ "$?" = 0 ] && rm -rf /tmp/clash_pac || mv -f /tmp/clash_pac $bindir/ui/pac
|
||||
}
|
||||
bfstart(){
|
||||
[ ! -d $bindir/ui ] && mkdir -p $bindir/ui
|
||||
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash
|
||||
#检查clash核心
|
||||
if [ ! -f $bindir/clash ];then
|
||||
if [ -f $clashdir/clash ];then
|
||||
mv $clashdir/clash $bindir/clash && chmod 777 $bindir/clash
|
||||
else
|
||||
logger "未找到clash核心,正在下载!" 33
|
||||
[ -z "$clashcore" ] && clashcore=clash
|
||||
[ -z "$cpucore" ] && source $clashdir/getdate.sh && getcpucore
|
||||
webget $bindir/clash "$update_url/bin/$clashcore/clash-linux-$cpucore"
|
||||
[ "$?" = 1 ] && logger "核心下载失败,已退出!" 31 && rm -f $bindir/clash && exit 1
|
||||
fi
|
||||
fi
|
||||
#检查数据库文件
|
||||
if [ ! -f $bindir/Country.mmdb ];then
|
||||
if [ -f $clashdir/Country.mmdb ];then
|
||||
mv $clashdir/Country.mmdb $bindir/Country.mmdb
|
||||
else
|
||||
logger "未找到GeoIP数据库,正在下载!" 33
|
||||
webget /tmp/Country.mmdb $update_url/bin/Country.mmdb
|
||||
[ "$?" = 1 ] && logger "数据库下载失败,已退出!" 31 && rm -f $bindir/Country.mmdb && exit 1
|
||||
fi
|
||||
fi
|
||||
#检查dashboard文件
|
||||
if [ -f $clashdir/ui/index.html -a ! -f $bindir/ui/index.html ];then
|
||||
cp -rf $clashdir/ui $bindir
|
||||
fi
|
||||
catpac #生成pac文件
|
||||
#检查yaml配置文件
|
||||
if [ ! -f $clashdir/config.yaml ];then
|
||||
if [ -n "$Url" -o -n "$Https" ];then
|
||||
logger "未找到配置文件,正在下载!" 33
|
||||
getyaml
|
||||
exit 0
|
||||
else
|
||||
logger "未找到配置文件链接,请先导入配置文件!" 31
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
afstart(){
|
||||
#读取配置文件
|
||||
getconfig
|
||||
$clashdir/clash -t -d $clashdir >/dev/null
|
||||
$bindir/clash -t -d $bindir >/dev/null
|
||||
if [ "$?" = 0 ];then
|
||||
#修改iptables规则使流量进入clash
|
||||
[ "$redir_mod" != "纯净模式" ] && [ "$dns_no" != "已禁用" ] && start_dns
|
||||
@@ -386,27 +476,33 @@ afstart(){
|
||||
cronset '#每10分钟保存节点配置' "*/10 * * * * test -n \"$(pidof clash)\" && $clashdir/start.sh web_save #每10分钟保存节点配置"
|
||||
[ -f $clashdir/web_save ] && web_restore & #后台还原面板配置
|
||||
else
|
||||
logger "clash服务启动失败!请查看报错信息!"
|
||||
logger `$clashdir/clash -t -d $clashdir 1>&0`
|
||||
logger "clash服务启动失败!请查看报错信息!" 31
|
||||
logger `$bindir/clash -t -d $bindir 1>&0` 0
|
||||
$0 stop &
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
start_old(){
|
||||
$clashdir/clash -d $clashdir >/dev/null &
|
||||
#使用传统后台执行二进制文件的方式执行
|
||||
$bindir/clash -d $bindir >/dev/null &
|
||||
afstart
|
||||
daemon
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
||||
bfstart)
|
||||
bfstart
|
||||
;;
|
||||
afstart)
|
||||
afstart
|
||||
;;
|
||||
start)
|
||||
[ -n "$(pidof clash)" ] && $0 stop #禁止多实例
|
||||
getconfig
|
||||
#检测必须文件并下载
|
||||
bfstart
|
||||
#使用内置规则强行覆盖config配置文件
|
||||
[ "$modify_yaml" != "已开启" ] && modify_yaml
|
||||
#使用不同方式启动clash服务
|
||||
@@ -444,6 +540,9 @@ getyaml)
|
||||
getconfig
|
||||
getyaml
|
||||
;;
|
||||
webget)
|
||||
webget $1 $2 $3 $4
|
||||
;;
|
||||
web_save)
|
||||
getconfig
|
||||
web_save
|
||||
|
||||
Reference in New Issue
Block a user