v1.0.0beta6
~优化定时任务脚本,修复bug ~优化版本更新机制 ~重写启动脚本,全面兼容debian及centos ~支持linux的systemd方式启动 ~优化cdn下载链接
This commit is contained in:
BIN
bin/Country.mmdb
BIN
bin/Country.mmdb
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
|||||||
GeoIP_v=20200913
|
GeoIP_v=20200917
|
||||||
versionsh=1.0.0.beta5
|
versionsh=1223
|
||||||
|
|||||||
29
install.sh
29
install.sh
@@ -7,7 +7,8 @@ echo "** ShellClash **"
|
|||||||
echo "** by Juewuy **"
|
echo "** by Juewuy **"
|
||||||
echo "***********************************************"
|
echo "***********************************************"
|
||||||
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash"
|
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" ] && release_new=$(curl -kfsSL $url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
|
||||||
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
|
[ -z "$release_new" ] && echo "无法连接服务器!" && exit
|
||||||
echo -e "最新版本:\033[32m$release_new\033[0m"
|
echo -e "最新版本:\033[32m$release_new\033[0m"
|
||||||
@@ -45,7 +46,8 @@ fi
|
|||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo 开始从服务器获取安装文件!
|
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
|
if command -v curl &> /dev/null; then
|
||||||
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
|
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
|
||||||
else $result
|
else $result
|
||||||
@@ -59,18 +61,33 @@ echo 开始解压文件!
|
|||||||
mkdir -p $dir/clash > /dev/null
|
mkdir -p $dir/clash > /dev/null
|
||||||
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
|
tar -zxvf '/tmp/clashfm.tar.gz' -C $dir/clash/
|
||||||
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
||||||
|
#判断系统类型写入不同的启动文件
|
||||||
|
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
|
||||||
#初始化文件目录
|
#初始化文件目录
|
||||||
mv $dir/clash/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
|
|
||||||
chmod 777 /etc/init.d/clash #授予权限
|
|
||||||
if [ ! -f "$dir/clash/mark" ]; then
|
if [ ! -f "$dir/clash/mark" ]; then
|
||||||
cat >$dir/clash/mark<<EOF
|
cat >$dir/clash/mark<<EOF
|
||||||
#标识clash运行状态的文件,不明勿动!
|
#标识clash运行状态的文件,不明勿动!
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
#修饰文件及版本号
|
||||||
|
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 '/versionsh_l=*/'d $dir/clash/mark
|
||||||
sed -i "1i\versionsh_l=$versionsh" $dir/clash/mark
|
sed -i "1i\versionsh_l=$release_new" $dir/clash/mark
|
||||||
#设置环境变量
|
#设置环境变量
|
||||||
shtype=sh&&[ -n $(ls -l /bin/sh|grep -o dash) ]&&shtype=bash
|
|
||||||
sed -i '/alias clash=*/'d /etc/profile
|
sed -i '/alias clash=*/'d /etc/profile
|
||||||
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
|
echo "alias clash=\"$shtype $dir/clash/clash.sh\"" >> /etc/profile #设置快捷命令环境变量
|
||||||
sed -i '/export clashdir=*/'d /etc/profile
|
sed -i '/export clashdir=*/'d /etc/profile
|
||||||
|
|||||||
119
scripts/clash.sh
119
scripts/clash.sh
@@ -1,9 +1,31 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# Copyright (C) Juewuy
|
# Copyright (C) Juewuy
|
||||||
|
|
||||||
getconfig(){
|
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
|
[ -z "$clashdir" ] && clashdir=$(dirname $(readlink -f "$0")) && echo "export clashdir=\"$clashdir\"" >> /etc/profile
|
||||||
ccfg=$clashdir/mark
|
ccfg=$clashdir/mark
|
||||||
@@ -22,7 +44,7 @@ source $ccfg
|
|||||||
if [ "$start_old" = "已开启" ];then
|
if [ "$start_old" = "已开启" ];then
|
||||||
auto="\033[33m已设置保守模式!\033[0m"
|
auto="\033[33m已设置保守模式!\033[0m"
|
||||||
auto1="\033[36m设为\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"
|
auto="\033[32m已设置开机启动!\033[0m"
|
||||||
auto1="\033[36m禁用\033[0mclash开机启动"
|
auto1="\033[36m禁用\033[0mclash开机启动"
|
||||||
else
|
else
|
||||||
@@ -35,11 +57,10 @@ if [ -z "$redir_mod" ];then
|
|||||||
redir_mod=Redir模式
|
redir_mod=Redir模式
|
||||||
fi
|
fi
|
||||||
#获取运行状态
|
#获取运行状态
|
||||||
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh|wc -l`
|
PID=$(pidof clash)
|
||||||
if [[ $status -gt 0 ]];then
|
if [ -n "$PID" ];then
|
||||||
run="\033[32m正在运行($redir_mod)\033[0m"
|
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/$PID/status|grep -w VmRSS|awk '{print $2,$3}'`
|
||||||
VmRSS=`cat /proc/$uid/status|grep -w VmRSS|awk '{print $2,$3}'`
|
|
||||||
#获取运行时长
|
#获取运行时长
|
||||||
if [ -n "$start_time" ]; then
|
if [ -n "$start_time" ]; then
|
||||||
time=$((`date +%s`-$start_time))
|
time=$((`date +%s`-$start_time))
|
||||||
@@ -59,7 +80,7 @@ fi
|
|||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l"
|
echo -e "\033[30;46m欢迎使用ShellClash!\033[0m 版本:$versionsh_l"
|
||||||
echo -e "Clash服务"$run","$auto""
|
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"
|
echo -e "当前内存占用:\033[44m"$VmRSS"\033[0m,已运行:\033[46;30m"$day"\033[44;37m"$time"\033[0m"
|
||||||
fi
|
fi
|
||||||
echo -e "TG群:\033[36;4mhttps://t.me/clashfm\033[0m"
|
echo -e "TG群:\033[36;4mhttps://t.me/clashfm\033[0m"
|
||||||
@@ -80,55 +101,26 @@ if [ ! -f $clashdir/Country.mmdb ];then
|
|||||||
clashstart
|
clashstart
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
clashstop(){
|
|
||||||
source $clashdir/start.sh && stop_old
|
|
||||||
/etc/init.d/clash stop > /dev/null 2>&1
|
|
||||||
}
|
|
||||||
clashstart(){
|
clashstart(){
|
||||||
if [ ! -f "$yaml" ];then
|
if [ ! -f "$yaml" ];then
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[31m没有找到配置文件,请先导入节点/订阅链接!\033[0m"
|
echo -e "\033[31m没有找到配置文件,请先导入节点/订阅链接!\033[0m"
|
||||||
clashlink
|
clashlink
|
||||||
fi
|
fi
|
||||||
if [ $status -gt 0 ];then
|
if [ -n "$PID" ];then
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
clashstop
|
$sh_type $clashdir/start.sh stop
|
||||||
echo -e "\033[31mClash服务已停止!\033[0m"
|
echo -e "\033[31mClash服务已停止!\033[0m"
|
||||||
fi
|
fi
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
if [ "$start_old" = "已开启" ];then
|
$sh_type $clashdir/start.sh start
|
||||||
source $clashdir/start.sh && start_old
|
sleep 1
|
||||||
sleep 1
|
status=`$ps_type |grep -w 'clash'|grep -v grep|grep -v clash.sh`
|
||||||
status=`ps |grep -w 'clash'|grep -v grep|grep -v clash.sh`
|
if [ -z "$status" ];then
|
||||||
if [ -z "$status" ];then
|
echo -e "\033[31mclash启动失败!\033[0m"
|
||||||
echo -e "\033[31mclash启动失败!\033[0m"
|
exit
|
||||||
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
|
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"
|
echo -e "\033[32mclash服务已启动!\033[0m"
|
||||||
if [ -d /www/clash ];then
|
if [ -d /www/clash ];then
|
||||||
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
|
echo -e "请使用\033[30;47m http://$host/clash \033[0m管理内置规则"
|
||||||
@@ -337,8 +329,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
redir_mod=混合模式
|
redir_mod=混合模式
|
||||||
elif [[ $num == 4 ]]; then
|
elif [[ $num == 4 ]]; then
|
||||||
redir_mod=纯净模式
|
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[32m已经设置为纯净模式!\033[0m"
|
echo -e "\033[32m已经设置为纯净模式!\033[0m"
|
||||||
echo -e "\033[33m当前模式必须手动在设备WiFi或应用中配置HTTP或sock5代理\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[33m改为使用保守方式启动clash服务!!\033[0m"
|
||||||
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动!!\033[0m"
|
echo -e "\033[36m此模式兼容性更好但无法禁用开机启动!!\033[0m"
|
||||||
start_old=已开启
|
start_old=已开启
|
||||||
/etc/init.d/clash stop > /dev/null 2>&1
|
$sh_type $clashdir/start.sh stop > /dev/null 2>&1
|
||||||
sleep 2
|
sleep 2
|
||||||
else
|
else
|
||||||
sed -i "1i\start_old=未开启" $ccfg
|
sed -i "1i\start_old=未开启" $ccfg
|
||||||
echo -e "\033[32m改为使用默认方式启动clash服务!!\033[0m"
|
echo -e "\033[32m改为使用默认方式启动clash服务!!\033[0m"
|
||||||
start_old=未开启
|
start_old=未开启
|
||||||
source $clashdir/start.sh && stop_old
|
$sh_type $clashdir/start.sh stop > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
clashadv
|
clashadv
|
||||||
|
|
||||||
@@ -689,11 +680,15 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
/etc/init.d/clash stop
|
/etc/init.d/clash stop
|
||||||
rm -rf $clashdir
|
rm -rf $clashdir
|
||||||
rm -rf /etc/init.d/clash
|
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 /www/clash
|
||||||
rm -rf $csh
|
rm -rf $csh
|
||||||
sed -i '/alias clash=*/'d /etc/profile
|
sed -i '/alias clash=*/'d /etc/profile
|
||||||
sed -i '/export clashdir=*/'d /etc/profile
|
sed -i '/export clashdir=*/'d /etc/profile
|
||||||
|
source /etc/profile > /dev/null 2>&1
|
||||||
echo 已卸载clash相关文件!
|
echo 已卸载clash相关文件!
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
echo -e "\033[31m操作已取消!\033[0m"
|
echo -e "\033[31m操作已取消!\033[0m"
|
||||||
exit;
|
exit;
|
||||||
@@ -816,19 +811,19 @@ elif [[ $num == 0 ]]; then
|
|||||||
|
|
||||||
elif [[ $num == 1 ]]; then
|
elif [[ $num == 1 ]]; then
|
||||||
cronname=重启clash服务
|
cronname=重启clash服务
|
||||||
cronset='source /etc/profile && source $clashdir/start.sh && restart'
|
cronset="$clashdir/start.sh restart"
|
||||||
setcron
|
setcron
|
||||||
elif [[ $num == 2 ]]; then
|
elif [[ $num == 2 ]]; then
|
||||||
cronname=停止clash服务
|
cronname=停止clash服务
|
||||||
cronset='source /etc/profile && source $clashdir/start.sh && stop'
|
cronset="$clashdir/start.sh stop"
|
||||||
setcron
|
setcron
|
||||||
elif [[ $num == 3 ]]; then
|
elif [[ $num == 3 ]]; then
|
||||||
cronname=开启clash服务
|
cronname=开启clash服务
|
||||||
cronset='source /etc/profile && source $clashdir/start.sh && start'
|
cronset="$clashdir/start.sh start"
|
||||||
setcron
|
setcron
|
||||||
elif [[ $num == 4 ]]; then
|
elif [[ $num == 4 ]]; then
|
||||||
cronname=更新订阅链接
|
cronname=更新订阅链接
|
||||||
cronset="source /etc/profile && source $clashdir/getdate.sh && getyaml"
|
cronset="$clashdir/start.sh getyaml"
|
||||||
setcron
|
setcron
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -866,7 +861,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
clashcfg
|
clashcfg
|
||||||
|
|
||||||
elif [[ $num == 3 ]]; then
|
elif [[ $num == 3 ]]; then
|
||||||
clashstop
|
$sh_type $clashdir/start.sh stop
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[31mClash服务已停止!\033[0m"
|
echo -e "\033[31mClash服务已停止!\033[0m"
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -879,12 +874,20 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
sed -i "1i\start_old=未开启" $ccfg
|
sed -i "1i\start_old=未开启" $ccfg
|
||||||
echo -e "\033[32m已设为使用默认方式启动clash服务!!\033[0m"
|
echo -e "\033[32m已设为使用默认方式启动clash服务!!\033[0m"
|
||||||
start_old=未开启
|
start_old=未开启
|
||||||
elif [ -f /etc/rc.d/*clash ]; then
|
elif [ "$autostart" = "enable_rc" ]; then
|
||||||
/etc/init.d/clash disable
|
/etc/init.d/clash disable
|
||||||
echo -e "\033[33m已禁止Clash开机启动!\033[0m"
|
echo -e "\033[33m已禁止Clash开机启动!\033[0m"
|
||||||
else
|
elif [ "$autostart" = "disable_rc" ]; then
|
||||||
/etc/init.d/clash enable
|
/etc/init.d/clash enable
|
||||||
echo -e "\033[32m已设置Clash开机启动!\033[0m"
|
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
|
fi
|
||||||
clashsh
|
clashsh
|
||||||
|
|
||||||
@@ -920,7 +923,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
elif [[ $num == 0 ]]; then
|
elif [[ $num == 0 ]]; then
|
||||||
clashsh
|
clashsh
|
||||||
elif [[ $num == 1 ]]; then
|
elif [[ $num == 1 ]]; then
|
||||||
clashstop
|
$sh_type $clashdir/start.sh stop
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
|
$clashdir/clash -d $clashdir & { sleep 3 ; kill $! & }
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
@@ -964,7 +967,7 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
|
|||||||
|
|
||||||
elif [[ $num == 7 ]]; then
|
elif [[ $num == 7 ]]; then
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
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}')
|
[ -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}')
|
[ -n "$vmrss" ] && echo $vmrss $(cat /proc/$PID/status|grep -w Name|awk '{print $2}')
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -8,12 +8,6 @@ START=92
|
|||||||
start_service() {
|
start_service() {
|
||||||
#开机加载环境变量保证找到文件路径
|
#开机加载环境变量保证找到文件路径
|
||||||
source /etc/profile > /dev/null 2>&1
|
source /etc/profile > /dev/null 2>&1
|
||||||
#加载修饰脚本
|
|
||||||
source $clashdir/start.sh
|
|
||||||
#读取配置文件
|
|
||||||
getconfig
|
|
||||||
#使用内置规则强行覆盖config配置文件
|
|
||||||
[ "$modify_yaml" != "已开启" ] && modify_yaml
|
|
||||||
#创建clash后台进程
|
#创建clash后台进程
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
procd_set_param respawn
|
procd_set_param respawn
|
||||||
@@ -21,17 +15,6 @@ start_service() {
|
|||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
procd_set_param command $clashdir/clash -d $clashdir
|
procd_set_param command $clashdir/clash -d $clashdir
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
#修改iptables规则使流量进入clash
|
#其他设置
|
||||||
stop_iptables
|
sh $clashdir/start.sh afstart
|
||||||
[ "$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
|
|
||||||
}
|
|
||||||
@@ -1,160 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Copyright (C) Juewuy
|
# 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(){
|
linkconfig(){
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[44m 实验性功能,遇问题请加TG群反馈:\033[42;30m t.me/clashfm \033[0m"
|
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
|
sed -i "6i\Url=\'$Url\'" $ccfg
|
||||||
Https=""
|
Https=""
|
||||||
#获取在线yaml文件
|
#获取在线yaml文件
|
||||||
getyaml
|
$sh_type $clashdir/start.sh getyaml
|
||||||
elif [ "$num" = '2' ]; then
|
elif [ "$num" = '2' ]; then
|
||||||
linkfilter
|
linkfilter
|
||||||
linkset
|
linkset
|
||||||
@@ -366,7 +212,7 @@ if [ -n $Https ];then
|
|||||||
sed -i '/Https=*/'d $ccfg
|
sed -i '/Https=*/'d $ccfg
|
||||||
sed -i "6i\Https=\'$Https\'" $ccfg
|
sed -i "6i\Https=\'$Https\'" $ccfg
|
||||||
#获取在线yaml文件
|
#获取在线yaml文件
|
||||||
getyaml
|
$sh_type $clashdir/start.sh getyaml
|
||||||
fi
|
fi
|
||||||
clashlink
|
clashlink
|
||||||
fi
|
fi
|
||||||
@@ -398,12 +244,22 @@ if [ "$res" = '1' ]; then
|
|||||||
mkdir -p $clashdir > /dev/null
|
mkdir -p $clashdir > /dev/null
|
||||||
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ > /dev/null
|
tar -zxvf '/tmp/clashfm.tar.gz' -C $clashdir/ > /dev/null
|
||||||
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
[ $? -ne 0 ] && echo "文件解压失败!" && exit 1
|
||||||
#初始化文件目录
|
#判断系统类型写入不同的启动文件
|
||||||
mv $clashdir/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
|
if [ -n "$(cat /proc/version | grep -i openwrt)" ];then
|
||||||
chmod 777 /etc/init.d/clash #授予权限
|
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 '/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/clashfm.tar.gz
|
||||||
rm -rf /tmp/clashversion
|
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.*mips.*")" ] && cpucore="mipsle-softfloat"
|
||||||
[ -n "$(echo $cpucore | grep -E "linux.*x86.*")" ] && cpucore="386"
|
[ -n "$(echo $cpucore | grep -E "linux.*x86.*")" ] && cpucore="386"
|
||||||
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="amd64"
|
[ -n "$(echo $cpucore | grep -E "linux.*amd64.*")" ] && cpucore="amd64"
|
||||||
|
[ -n "$(echo $cpucore | grep -E "linux.*x86_64.*")" ] && cpucore="amd64"
|
||||||
###
|
###
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "当前clash核心:\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
|
echo -e "当前clash核心:\033[47;30m $clashcore \033[46;30m$clashv\033[0m"
|
||||||
@@ -549,7 +406,7 @@ clashsh
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
getdb(){
|
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[36m安装本地版dashboard管理面板\033[0m"
|
echo -e "\033[36m安装本地版dashboard管理面板\033[0m"
|
||||||
echo -----------------------------------------------
|
echo -----------------------------------------------
|
||||||
@@ -618,7 +475,7 @@ update
|
|||||||
catpac(){
|
catpac(){
|
||||||
#检测目录
|
#检测目录
|
||||||
[ ! -d /www/clash -a ! -d $clashdir/ui ]&&echo 未检测到本地Dashboard面板,请先安装面板!&&sleep 1&&getdb
|
[ ! -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 /www/clash ]&&dir="/www/clash"&&pac=http://$host/clash/pac
|
||||||
[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:9999/ui/pac
|
[ -d $clashdir/ui ]&&dir="$clashdir/ui"&&pac=http://$host:9999/ui/pac
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -677,7 +534,7 @@ elif [[ $num == 4 ]]; then
|
|||||||
update
|
update
|
||||||
fi
|
fi
|
||||||
elif [[ $num == 9 ]]; then
|
elif [[ $num == 9 ]]; then
|
||||||
update_url='https://juewuy.xyz/clash'
|
update_url='http://127.0.0.1:8080/clash-for-Miwifi'
|
||||||
else
|
else
|
||||||
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
echo -e "\033[31m请输入正确的数字!\033[0m"
|
echo -e "\033[31m请输入正确的数字!\033[0m"
|
||||||
|
|||||||
224
scripts/start.sh
224
scripts/start.sh
@@ -1,7 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (C) Juewuy
|
# Copyright (C) Juewuy
|
||||||
|
|
||||||
getconfig(){
|
getconfig(){
|
||||||
|
#加载环境变量
|
||||||
|
[ -z "$clashdir" ] && source /etc/profile > /dev/null 2>&1
|
||||||
ccfg=$clashdir/mark
|
ccfg=$clashdir/mark
|
||||||
if [ ! -f "$ccfg" ]; then
|
if [ ! -f "$ccfg" ]; then
|
||||||
echo mark文件不存在,默认以Redir模式运行!
|
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;
|
[ -n "$(netstat -ntulp |grep :$portx|grep -v clash)" ] && echo -e "检测到端口:\033[30;47m $portx \033[0m被以下进程占用!clash无法启动!" && echo $(netstat -ntulp |grep :$portx) && exit;
|
||||||
done
|
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(){
|
modify_yaml(){
|
||||||
##########需要变更的配置###########
|
##########需要变更的配置###########
|
||||||
mix='mixed-port: 7890'
|
mix='mixed-port: 7890'
|
||||||
@@ -78,7 +211,7 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
|
|||||||
mark_time(){
|
mark_time(){
|
||||||
start_time=`date +%s`
|
start_time=`date +%s`
|
||||||
sed -i '/start_time*/'d $clashdir/mark
|
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(){
|
start_redir(){
|
||||||
#修改iptables规则使流量进入clash
|
#修改iptables规则使流量进入clash
|
||||||
@@ -144,6 +277,7 @@ start_dns(){
|
|||||||
daemon_old(){
|
daemon_old(){
|
||||||
#守护进程状态
|
#守护进程状态
|
||||||
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh)
|
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
|
if [ -z $status ];then
|
||||||
$clashdir/clash -d $clashdir> /dev/null &
|
$clashdir/clash -d $clashdir> /dev/null &
|
||||||
mark_time
|
mark_time
|
||||||
@@ -159,52 +293,58 @@ checkcron(){
|
|||||||
clashsh
|
clashsh
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
start_old(){
|
afstart(){
|
||||||
#读取配置文件
|
#读取配置文件
|
||||||
getconfig
|
getconfig
|
||||||
#使用内置规则强行覆盖config配置文件
|
|
||||||
[ "$modify_yaml" != "已开启" ] && modify_yaml
|
|
||||||
#创建clash后台进程
|
|
||||||
$clashdir/clash -d $clashdir> /dev/null &
|
|
||||||
#修改iptables规则使流量进入clash
|
#修改iptables规则使流量进入clash
|
||||||
stop_iptables
|
stop_iptables
|
||||||
[ "$redir_mod" != "纯净模式" ] && start_dns
|
[ "$redir_mod" != "纯净模式" ] && start_dns
|
||||||
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
|
[ "$redir_mod" != "纯净模式" ] && [ "$redir_mod" != "Tun模式" ] && start_redir
|
||||||
#标记启动时间
|
#标记启动时间
|
||||||
mark_time
|
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
|
||||||
checkcron
|
|
||||||
sed -i /start.sh/d $cronpath
|
afstart)
|
||||||
#结束进程
|
afstart
|
||||||
killall -9 clash &> /dev/null
|
;;
|
||||||
stop_iptables
|
start)
|
||||||
}
|
#读取配置文件
|
||||||
start(){
|
getconfig
|
||||||
getconfig
|
#使用内置规则强行覆盖config配置文件
|
||||||
if [ "$start_old" ="已开启" ];then
|
[ "$modify_yaml" != "已开启" ] && modify_yaml
|
||||||
start_old
|
#使用不同方式启动clash服务
|
||||||
else
|
if [ "$start_old" = "已开启" ];then
|
||||||
/etc/init.d/clash start
|
$clashdir/clash -d $clashdir> /dev/null &
|
||||||
fi
|
afstart
|
||||||
}
|
elif [ -f /etc/rc.common ];then
|
||||||
stop(){
|
/etc/init.d/clash start
|
||||||
getconfig
|
else
|
||||||
if [ "$start_old" ="已开启" ];then
|
systemctl start clash.service
|
||||||
stop_old
|
fi
|
||||||
else
|
;;
|
||||||
/etc/init.d/clash stop
|
stop)
|
||||||
fi
|
#删除守护
|
||||||
}
|
checkcron
|
||||||
restart(){
|
sed -i /start.sh/d $cronpath
|
||||||
stop
|
#多种方式结束进程
|
||||||
start
|
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
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
$0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
getyaml)
|
||||||
|
getconfig
|
||||||
|
getyaml
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user