v1.0.0beta6

~优化定时任务脚本,修复bug
~优化版本更新机制
~重写启动脚本,全面兼容debian及centos
~支持linux的systemd方式启动
~优化cdn下载链接
This commit is contained in:
juewuy
2020-09-18 21:09:06 +08:00
parent 248e85d7a5
commit d151100c25
8 changed files with 290 additions and 290 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +1,2 @@
GeoIP_v=20200913
versionsh=1.0.0.beta5
GeoIP_v=20200917
versionsh=1223

View File

@@ -7,7 +7,8 @@ echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
url="http://127.0.0.1:8080/clash-for-Miwifi/"
#release_new=$(curl -kfsSL --resolve api.github.com:443:140.82.113.5 "https://api.github.com/repos/juewuy/ShellClash/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
[ -z "$release_new" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
echo -e "最新版本:\033[32m$release_new\033[0m"
@@ -45,7 +46,8 @@ fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tarurl=$url@release_new/bin/clashfm.tar.gz
#tarurl=$url@$release_new/bin/clashfm.tar.gz
tarurl=$url/bin/clashfm.tar.gz
if command -v curl &> /dev/null; then
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
else $result
@@ -59,18 +61,33 @@ echo 开始解压文件!
mkdir -p $dir/clash > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#初始化文件目录
mv $dir/clash/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
#判断系统类型写入不同的启动文件
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
rm -rf $dir/clash/clash.service
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service
rm -rf $dir/clash/clashservice
rm -rf /etc/init.d/clash
fi
#初始化文件目录
if [ ! -f "$dir/clash/mark" ]; then
cat >$dir/clash/mark<<EOF
#标识clash运行状态的文件不明勿动
EOF
fi
sed -i '/versionsh_l=*/'d $dir/clash/mark
sed -i "1i\versionsh_l=$versionsh" $dir/clash/mark
#设置环境变量
#修饰文件及版本号
shtype=sh && [ -n $(ls -l /bin/sh|grep -o dash) ] && shtype=bash
sed -i "s%#!/bin/sh%#!/bin/$shtype%g" $dir/clash/start.sh
chmod 777 $dir/clash/start.sh
sed -i '/versionsh_l=*/'d $dir/clash/mark
sed -i "1i\versionsh_l=$release_new" $dir/clash/mark
#设置环境变量
sed -i '/alias clash=*/'d /etc/profile
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
sed -i '/export clashdir=*/'d /etc/profile

View File

@@ -1,9 +1,31 @@
#!/bin/bash
#!/bin/sh
# Copyright (C) Juewuy
getconfig(){
#系统类型
systype=$(cat /proc/version | grep -io openwrt)
if [ -n "$systype" ];then
ps_type=ps
sh_type=sh
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}';)
if [ -f /etc/rc.d/*clash ];then
autostart=enable_rc
else
autostart=disable_rc
fi
else
ps_type='ps aux'
sh_type=bash
host=$(ip a|grep -w 'inet'|grep 'global'|grep -E '192.|10.'|sed 's/.*inet.//g'|sed 's/\/[0-9][0-9].*$//g')
[ -z $host ] && host=127.0.0.1
if [ -n "$(systemctl list-unit-files clash.service | grep -o enable)" ];then
autostart=enable_sys
else
autostart=disable_sys
fi
fi
#服务器地址
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest
[ -z "$update_url" ] && update_url=https://cdn.jsdelivr.net/gh/juewuy/ShellClash
#文件路径
[ -z "$clashdir" ] && clashdir=$(dirname $(readlink -f "$0")) && echo "export clashdir=\"$clashdir\"" >> /etc/profile
ccfg=$clashdir/mark
@@ -22,7 +44,7 @@ source $ccfg
if [ "$start_old" = "已开启" ];then
auto="\033[33m已设置保守模式\033[0m"
auto1="\033[36m设为\033[0m常规模式启动"
elif [ -f /etc/rc.d/*clash ];then
elif [ "$autostart" = "enable_rc" -o "$autostart" = "enable_sys" ]; then
auto="\033[32m已设置开机启动\033[0m"
auto1="\033[36m禁用\033[0mclash开机启动"
else
@@ -35,11 +57,10 @@ if [ -z "$redir_mod" ];then
redir_mod=Redir模式
fi
#获取运行状态
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
PID=$(pidof clash)
if [ -n "$PID" ];then
run="\033[32m正在运行$redir_mod\033[0m"
uid=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|awk '{print $1}'`
VmRSS=`cat /proc/$uid/status|grep -w VmRSS|awk '{print $2,$3}'`
VmRSS=`cat /proc/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
#获取运行时长
if [ -n "$start_time" ]; then
time=$((`date +%s`-$start_time))
@@ -59,7 +80,7 @@ fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;46m欢迎使用ShellClash\033[0m 版本:$versionsh_l"
echo -e "Clash服务"$run""$auto""
if [ $status -gt 0 ];then
if [ -n "$PID" ];then
echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m已运行\033[46;30m"$day"\033[44;37m"$time"\033[0m"
fi
echo -e "TG群\033[36;4mhttps://t.me/clashfm\033[0m"
@@ -80,55 +101,26 @@ if [ ! -f $clashdir/Country.mmdb ];then
clashstart
fi
}
clashstop(){
source $clashdir/start.sh && stop_old
/etc/init.d/clash stop > /dev/null 2>&1
}
clashstart(){
if [ ! -f "$yaml" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m没有找到配置文件请先导入节点/订阅链接!\033[0m"
clashlink
fi
if [ $status -gt 0 ];then
if [ -n "$PID" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clashstop
$sh_type $clashdir/start.sh stop
echo -e "\033[31mClash服务已停止\033[0m"
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && start_old
$sh_type $clashdir/start.sh start
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
status=`$ps_type |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败\033[0m"
sed -i /start_old=*/d $ccfg
exit
fi
else
/etc/init.d/clash start
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败\033[0m"
read -p "是否尝试使用保守方式启动?[1/0] > " res
if [ "$res" = '1' ]; then
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
if [ -z "$status" ];then
echo -e "\033[31mclash启动失败\033[0m"
sed -i /start_old=*/d $ccfg
exit
fi
else
echo -e "\033[33m操作取消\033[0m"
exit
fi
fi
fi
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}';)
echo -e "\033[32mclash服务已启动\033[0m"
if [ -d /www/clash ];then
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
@@ -338,7 +330,6 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
redir_mod=混合模式
elif [[ $num == 4 ]]; then
redir_mod=纯净模式
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}';)
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m已经设置为纯净模式\033[0m"
echo -e "\033[33m当前模式必须手动在设备WiFi或应用中配置HTTP或sock5代理\033[0m"
@@ -584,13 +575,13 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
echo -e "\033[33m改为使用保守方式启动clash服务\033[0m"
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动\033[0m"
start_old=已开启
/etc/init.d/clash stop > /dev/null 2>&1
$sh_type $clashdir/start.sh stop > /dev/null 2>&1
sleep 2
else
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m改为使用默认方式启动clash服务\033[0m"
start_old=未开启
source $clashdir/start.sh && stop_old
$sh_type $clashdir/start.sh stop > /dev/null 2>&1
fi
clashadv
@@ -689,11 +680,15 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
/etc/init.d/clash stop
rm -rf $clashdir
rm -rf /etc/init.d/clash
rm -rf /etc/systemd/system/clash.service
rm -rf /usr/lib/systemd/system/clash.service
rm -rf /www/clash
rm -rf $csh
sed -i '/alias clash=*/'d /etc/profile
sed -i '/export clashdir=*/'d /etc/profile
source /etc/profile > /dev/null 2>&1
echo 已卸载clash相关文件
exit
fi
echo -e "\033[31m操作已取消\033[0m"
exit;
@@ -816,19 +811,19 @@ elif [[ $num == 0 ]]; then
elif [[ $num == 1 ]]; then
cronname=重启clash服务
cronset='source /etc/profile && source $clashdir/start.sh && restart'
cronset="$clashdir/start.sh restart"
setcron
elif [[ $num == 2 ]]; then
cronname=停止clash服务
cronset='source /etc/profile && source $clashdir/start.sh && stop'
cronset="$clashdir/start.sh stop"
setcron
elif [[ $num == 3 ]]; then
cronname=开启clash服务
cronset='source /etc/profile && source $clashdir/start.sh && start'
cronset="$clashdir/start.sh start"
setcron
elif [[ $num == 4 ]]; then
cronname=更新订阅链接
cronset="source /etc/profile && source $clashdir/getdate.sh && getyaml"
cronset="$clashdir/start.sh getyaml"
setcron
else
@@ -866,7 +861,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
clashcfg
elif [[ $num == 3 ]]; then
clashstop
$sh_type $clashdir/start.sh stop
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31mClash服务已停止\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -879,12 +874,20 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
sed -i "1i\start_old=未开启" $ccfg
echo -e "\033[32m已设为使用默认方式启动clash服务\033[0m"
start_old=未开启
elif [ -f /etc/rc.d/*clash ]; then
elif [ "$autostart" = "enable_rc" ]; then
/etc/init.d/clash disable
echo -e "\033[33m已禁止Clash开机启动\033[0m"
else
elif [ "$autostart" = "disable_rc" ]; then
/etc/init.d/clash enable
echo -e "\033[32m已设置Clash开机启动\033[0m"
elif [ "$autostart" = "enable_sys" ]; then
systemctl disable clash.service
echo -e "\033[33m已禁止Clash开机启动\033[0m"
elif [ "$autostart" = "disable_sys" ]; then
systemctl enable clash.service
echo -e "\033[32m已设置Clash开机启动\033[0m"
else
echo -e "\033[32m当前系统不支持设置开启启动\033[0m"
fi
clashsh
@@ -920,7 +923,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 0 ]]; then
clashsh
elif [[ $num == 1 ]]; then
clashstop
$sh_type $clashdir/start.sh stop
echo -----------------------------------------------
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
echo -----------------------------------------------
@@ -964,7 +967,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
elif [[ $num == 7 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for PID in $(ps|awk '{print $1}');do
for PID in $($ps_type|awk '{print $1}');do
[ -f "/proc/$PID/status" ] && vmrss=$(cat /proc/$PID/status|grep -w VmRSS|awk '{print $2}')
[ -n "$vmrss" ] && echo $vmrss $(cat /proc/$PID/status|grep -w Name|awk '{print $2}')
done

View File

@@ -8,12 +8,6 @@ START=92
start_service() {
#开机加载环境变量保证找到文件路径
source /etc/profile > /dev/null 2>&1
#加载修饰脚本
source $clashdir/start.sh
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
procd_open_instance
procd_set_param respawn
@@ -21,17 +15,6 @@ start_service() {
procd_set_param stdout 1
procd_set_param command $clashdir/clash -d $clashdir
procd_close_instance
#修改iptables规则使流量进入clash
stop_iptables
[ "$redir_mod" != "纯净模式" ] && start_dns
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#标记启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=未开启" $ccfg
}
stop_service() {
source $clashdir/start.sh
stop_iptables
#其他设置
sh $clashdir/start.sh afstart
}

View File

@@ -1,160 +1,6 @@
#!/bin/bash
# Copyright (C) Juewuy
getyaml(){
ccfg=$clashdir/mark
source $ccfg
#前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF
subconverter-web.now.sh
subconverter.herokuapp.com
subcon.py6.pw
api.dler.io
api.wcc.best
skapi.cool
EOF`
Config=`sed -n ""$rule_link"p"<<EOF
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
EOF`
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z $Https ];then
#echo $Url
Https="https://$Server/sub?target=clashr&insert=true&new_name=true&scv=true&exclude=$exclude&url=$Url&config=$Config"
markhttp=1
fi
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/config.yaml
rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m配置文件获取失败\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo
if [ -z $markhttp ];then
echo 请尝试使用导入节点/链接功能!
getlink
else
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [[ $server_link -ge 6 ]]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
Https=""
getyaml
fi
#exit;
fi
else
Https=""
if cat $yamlnew | grep ', server:' >/dev/null;then
#检测旧格式
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m已经停止对旧格式配置文件的支持\033[0m"
echo -e "请使用新格式或者使用\033[32m导入节点/订阅\033[0m功能"
sleep 2
clashlink
fi
#检测不支持的加密协议
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
if [ "$clashcore" = "clash" -o "$clashcore" = "clashpre" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心$clashcore不支持chacha20加密\033[0m"
echo -e "请更换使用clashR核心"
sleep 2
getcore
fi
fi
#替换文件
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
killall -9 clash &> /dev/null
start_over(){
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}';)
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clashsh
}
if [ "$start_old" = "已开启" ];then
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
fi
else
/etc/init.d/clash start
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
else
echo -e "\033[31mclash服务启动失败\033[0m"
echo -e "\033[33m5秒后尝试使用保守方式启动使用ctrl+c退出\033[0m"
echo 5&&sleep 1&&echo 4&&sleep 1&&echo 3&&sleep 1&&echo 2&&sleep 1&&echo 1&&sleep 1
source $clashdir/start.sh && start_old
sleep 1
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
if [[ $status -gt 0 ]];then
start_over
fi
fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -f $yaml.bak ];then
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
mv $yaml.bak $yaml
/etc/init.d/clash start
sleep 1
clashsh
else
echo -e "\033[31mclash服务启动失败请查看报错信息\033[0m"
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
exit;
fi
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,30p' $yamlnew
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
#exit;
fi
#exit
}
linkconfig(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
@@ -263,7 +109,7 @@ if [ -n $Url ];then
sed -i "6i\Url=\'$Url\'" $ccfg
Https=""
#获取在线yaml文件
getyaml
$sh_type $clashdir/start.sh getyaml
elif [ "$num" = '2' ]; then
linkfilter
linkset
@@ -366,7 +212,7 @@ if [ -n $Https ];then
sed -i '/Https=*/'d $ccfg
sed -i "6i\Https=\'$Https\'" $ccfg
#获取在线yaml文件
getyaml
$sh_type $clashdir/start.sh getyaml
fi
clashlink
fi
@@ -398,12 +244,22 @@ if [ "$res" = '1' ]; then
mkdir -p $clashdir > /dev/null
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ > /dev/null
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
#初始化文件目录
mv $clashdir/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
#判断系统类型写入不同的启动文件
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
mv $dir/clash/clashservice /etc/init.d/clash #将rc服务文件移动到系统目录
chmod 777 /etc/init.d/clash #授予权限
rm -rf $dir/clash/clash.service
else
[ -d /etc/systemd/system ] && sysdir=/etc/systemd/system
[ -d /usr/lib/systemd/system/ ] && sysdir=/usr/lib/systemd/system/
mv $dir/clash/clash.service $sysdir/clash.service #将service服务文件移动到系统目录
sed -i "s%/etc/clash%${dir}/clash%g" $sysdir/clash.service
rm -rf $dir/clash/clashservice
rm -rf /etc/init.d/clash
fi
#写入版本号
sed -i '/versionsh_l=*/'d $ccfg
sed -i "1i\versionsh_l=$versionsh" $ccfg
sed -i "1i\versionsh_l=$release_new" $ccfg
#删除临时文件
rm -rf /tmp/clashfm.tar.gz
rm -rf /tmp/clashversion
@@ -433,6 +289,7 @@ cpucore=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cpucore | grep -E "linux.*mips.*")" ] && cpucore="mipsle-softfloat"
[ -n "$(echo $cpucore | grep -E "linux.*x86.*")" ] && cpucore="386"
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="amd64"
[ -n "$(echo $cpucore | grep -E "linux.*x86_64.*")" ] && cpucore="amd64"
###
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "当前clash核心\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
@@ -549,7 +406,7 @@ clashsh
fi
}
getdb(){
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}';)
#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}';)
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[36m安装本地版dashboard管理面板\033[0m"
echo -----------------------------------------------
@@ -618,7 +475,7 @@ update
catpac(){
#检测目录
[ ! -d /www/clash -a ! -d $clashdir/ui ]&&echo 未检测到本地Dashboard面板请先安装面板&&sleep 1&&getdb
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}';)
#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}';)
[ -d /www/clash ]&&dir="/www/clash"&&pac=http://$host/clash/pac
[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:9999/ui/pac
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -677,7 +534,7 @@ elif [[ $num == 4 ]]; then
update
fi
elif [[ $num == 9 ]]; then
update_url='https://juewuy.xyz/clash'
update_url='http://127.0.0.1:8080/clash-for-Miwifi'
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"

View File

@@ -2,6 +2,8 @@
# Copyright (C) Juewuy
getconfig(){
#加载环境变量
[ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1
ccfg=$clashdir/mark
if [ ! -f "$ccfg" ]; then
echo mark文件不存在默认以Redir模式运行
@@ -20,6 +22,137 @@ for portx in 1053 7890 7892 9999 ;do
[ -n "$(netstat -ntulp |grep :$portx|grep -v clash)" ] && echo -e "检测到端口:\033[30;47m $portx \033[0m被以下进程占用clash无法启动" && echo $(netstat -ntulp |grep :$portx) && exit;
done
}
getyaml(){
#前后端订阅服务器地址索引,可在此处添加!
Server=`sed -n ""$server_link"p"<<EOF
subconverter-web.now.sh
subconverter.herokuapp.com
subcon.py6.pw
api.dler.io
api.wcc.best
skapi.cool
EOF`
Config=`sed -n ""$rule_link"p"<<EOF
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_MultiMode.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_AdblockPlus.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoReject.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Mini_NoAuto.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_Netflix.ini
https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/config/ACL4SSR_Online_Full_AdblockPlus.ini
EOF`
#如果传来的是Url链接则合成Https链接否则直接使用Https链接
if [ -z $Https ];then
#echo $Url
Https="https://$Server/sub?target=clashr&insert=true&new_name=true&scv=true&exclude=$exclude&url=$Url&config=$Config"
markhttp=1
fi
#
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/config.yaml
rm -rf $yamlnew > /dev/null 2>&1
result=$(curl -w %{http_code} -kLo $yamlnew $Https)
if [ "$result" != "200" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m配置文件获取失败\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo
if [ -z $markhttp ];then
echo 请尝试使用导入节点/链接功能!
getlink
else
read -p "是否更换后端地址后重试?[1/0] > " res
if [ "$res" = '1' ]; then
sed -i '/server_link=*/'d $ccfg
if [[ $server_link -ge 6 ]]; then
server_link=0
fi
server_link=$(($server_link + 1))
echo $server_link
sed -i "1i\server_link=$server_link" $ccfg
Https=""
getyaml
fi
#exit;
fi
else
Https=""
if cat $yamlnew | grep ', server:' >/dev/null;then
#检测旧格式
if cat $yamlnew | grep 'Proxy Group:' >/dev/null;then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m已经停止对旧格式配置文件的支持\033[0m"
echo -e "请使用新格式或者使用\033[32m导入节点/订阅\033[0m功能"
sleep 2
clashlink
fi
#检测不支持的加密协议
if cat $yamlnew | grep 'cipher: chacha20,' >/dev/null;then
if [ "$clashcore" = "clash" -o "$clashcore" = "clashpre" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m当前核心$clashcore不支持chacha20加密\033[0m"
echo -e "请更换使用clashR核心"
sleep 2
getcore
fi
fi
#替换文件
[ -f $yaml ] && mv $yaml $yaml.bak
mv $yamlnew $yaml
echo 配置文件已生成正在启动clash使其生效
#重启clash服务
$0 stop
start_over(){
echo -e "\033[32mclash服务已启动\033[0m"
echo -e "可以使用\033[30;47m http://clash.razord.top \033[0m管理内置规则"
echo -e "Host地址:\033[36m $host \033[0m 端口:\033[36m 9999 \033[0m"
echo -e "也可前往更新菜单安装本地Dashboard面板连接更稳定\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
$0 start
sleep 1
PID=$(pidof clash)
if [ -n "$PID" ];then
start_over
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ -f $yaml.bak ];then
echo -e "\033[31mclash服务启动失败已还原配置文件并重启clash\033[0m"
mv $yaml.bak $yaml
$0 start
sleep 1
else
echo -e "\033[31mclash服务启动失败请查看报错信息\033[0m"
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
exit;
fi
fi
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m获取到了配置文件但格式似乎不对\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sed -n '1,30p' $yamlnew
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m请检查如上配置文件信息:\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fi
#exit;
fi
#exit
}
modify_yaml(){
##########需要变更的配置###########
mix='mixed-port: 7890'
@@ -78,7 +211,7 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
mark_time(){
start_time=`date +%s`
sed -i '/start_time*/'d $clashdir/mark
sed -i "3i\start_time=$start_time" $clashdir/mark
sed -i "1i\start_time=$start_time" $clashdir/mark
}
start_redir(){
#修改iptables规则使流量进入clash
@@ -144,6 +277,7 @@ start_dns(){
daemon_old(){
#守护进程状态
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh)
[ -z $status ] && status=$(ps aux |grep -w 'clash'|grep -v grep|grep -v clash.sh)
if [ -z $status ];then
$clashdir/clash -d $clashdir> /dev/null &
mark_time
@@ -159,52 +293,58 @@ checkcron(){
clashsh
fi
}
start_old(){
afstart(){
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#创建clash后台进程
$clashdir/clash -d $clashdir> /dev/null &
#修改iptables规则使流量进入clash
stop_iptables
[ "$redir_mod" != "纯净模式" ] && start_dns
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
#标记启动时间
mark_time
#创建守护进程
checkcron
sed -i /start.sh/d $cronpath
echo "*/1 * * * * source /etc/profile && source $clashdir/start.sh && daemon_old >/dev/null 2>&1" >> $cronpath
#设定启动方式
sed -i /start_old=*/d $ccfg
sed -i "1i\start_old=已开启" $ccfg
}
stop_old(){
case "$1" in
afstart)
afstart
;;
start)
#读取配置文件
getconfig
#使用内置规则强行覆盖config配置文件
[ "$modify_yaml" != "已开启" ] && modify_yaml
#使用不同方式启动clash服务
if [ "$start_old" = "已开启" ];then
$clashdir/clash -d $clashdir> /dev/null &
afstart
elif [ -f /etc/rc.common ];then
/etc/init.d/clash start
else
systemctl start clash.service
fi
;;
stop)
#删除守护
checkcron
sed -i /start.sh/d $cronpath
#结束进程
#多种方式结束进程
if [ -f /etc/rc.common ];then
/etc/init.d/clash stop &> /dev/null
else
systemctl stop clash.service &> /dev/null
fi
killall -9 clash &> /dev/null
#清理iptables
stop_iptables
}
start(){
;;
restart)
$0 stop
$0 start
;;
getyaml)
getconfig
if [ "$start_old" ="已开启" ];then
start_old
else
/etc/init.d/clash start
fi
}
stop(){
getconfig
if [ "$start_old" ="已开启" ];then
stop_old
else
/etc/init.d/clash stop
fi
}
restart(){
stop
start
}
getyaml
;;
esac
exit 0