v1.0.0beta6

~优化定时任务脚本,修复bug
~优化版本更新机制
This commit is contained in:
juewuy
2020-09-17 14:50:29 +08:00
parent c604739456
commit a2fced324e
5 changed files with 60 additions and 51 deletions

Binary file not shown.

View File

@@ -6,15 +6,15 @@ echo "** 欢迎使用 **"
echo "** ShellClash **"
echo "** by Juewuy **"
echo "***********************************************"
url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $url/bin/version)
[ "$result" != "200" ] && echo "无法连接到服务器!" && exit 1
source /tmp/clashversion
echo -e "~~~~版本:\033[32m$versionsh\033[0m"
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')
[ -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"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[44m如遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -e "\033[37m支持各种基于openwrt的路由器设备"
echo -e "\033[33m有限支持debian、centos等Linux系统\033[0m"
echo -e "\033[33m有限兼容debian、centos等Linux系统\033[0m"
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[32m 1 在默认目录(/etc)安装ShellClash"
echo -e "\033[33m 2 手动设置安装目录(不明勿用!)"
@@ -45,7 +45,7 @@ fi
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 开始从服务器获取安装文件!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tarurl=$url/bin/clashfm.tar.gz
tarurl=$url@release_new/bin/clashfm.tar.gz
if command -v curl &> /dev/null; then
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $tarurl)
else $result

View File

@@ -620,11 +620,18 @@ fi
exit;
}
update(){
if [ -z "$release_new" ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
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 $update_url/bin/version | grep "versionsh" | awk -F "=" '{print $2}')
[ -z "$release_new" ] && echo "检查更新失败!"
fi
[ "$update_url" = "https://cdn.jsdelivr.net/gh/juewuy/ShellClash" ] && update_url=$update_url@$release_new
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用更新功能\033[0m"
echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m"
echo -e "感谢:\033[32malecthw大神提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
[ -n "$release_new" ] && echo -e "当前ShellClash版本:\033[33m $versionsh_l \033[0m"
[ -n "$release_new" ] && echo -e "最新ShellClash版本\033[32m $release_new \033[0m"
echo -----------------------------------------------
echo -e " 1 更新\033[36m管理脚本\033[0m"
echo -e " 2 切换\033[33mclash核心\033[0m"
@@ -632,7 +639,8 @@ echo -e " 3 更新\033[32mGeoIP数据库\033[0m"
echo -e " 4 安装本地\033[35mDashboard\033[0m面板"
echo -e " 5 生成本地PAC文件(需先安装本地面板)"
echo -----------------------------------------------
echo -e " 8 切换\033[36m安装源\033[0m地址"
echo -e " 7 切换\033[36m安装源\033[0m地址"
echo -e " 8 鸣谢"
echo -e " 9 \033[31m卸载\033[34mClash for Miwfi\033[0m"
echo -e " 0 返回上级菜单"
echo -----------------------------------------------
@@ -662,11 +670,18 @@ if [[ $num -le 9 ]] > /dev/null 2>&1; then
source $clashdir/getdate.sh
catpac
update
elif [[ $num == 8 ]]; then
elif [[ $num == 7 ]]; then
source $clashdir/getdate.sh
setserver
elif [[ $num == 8 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "感谢:\033[32mClash \033[0m作者\033[36m Dreamacro\033[0m 项目地址:\033[32mhttps://github.com/Dreamacro/clash\033[0m"
echo -e "感谢:\033[32malecthw大神提供的GeoIP数据库\033[0m 项目地址:\033[32mhttps://github.com/alecthw/mmdb_china_ip_list\033[0m"
echo -e "感谢:\033[32m更多的帮助过我的人\033[0m"
update
elif [[ $num == 9 ]]; then
read -p "确认卸载clash警告该操作不可逆[1/0] " res
if [ "$res" = '1' ]; then
@@ -765,13 +780,10 @@ clashcron(){
clashcron
}
checkcron(){
if [ -d /etc/crontabs/ ]; then
cronpath="/etc/crontabs/root"
elif [ -d /var/spool/cron/ ]; then
cronpath="/var/spool/cron/root"
elif [ -d /var/spool/cron/crontabs/ ]; then
cronpath="/var/spool/cron/crontabs/root"
else
[ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root"
[ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root"
[ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root"
if [ -z $cronpath ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
clashsh
@@ -784,8 +796,8 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m欢迎使用定时任务功能\033[0m"
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -----------------------------------------------
echo -e "\033[33m当前已经添加的定时任务\033[36m"
crontab -l | egrep -o '#.*'
echo -e "\033[33m添加的定时任务:\033[36m"
cat $cronpath | egrep -o ' #.*'
echo -e "\033[0m"-----------------------------------------------
echo -e " 1 设置\033[33m定时重启\033[0mclash服务"
echo -e " 2 设置\033[31m定时停止\033[0mclash服务"

View File

@@ -378,14 +378,9 @@ else
fi
}
getsh(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
echo -----------------------------------------------
echo -e "当前脚本版本为:\033[33m $versionsh_l \033[0m"
echo -e "最新脚本版本为:\033[32m $versionsh \033[0m"
echo -e "最新脚本版本为:\033[32m $release_new \033[0m"
echo -----------------------------------------------
read -p "是否更新脚本?[1/0] > " res
if [ "$res" = '1' ]; then
@@ -393,7 +388,7 @@ if [ "$res" = '1' ]; then
echo 正在获取更新文件
result=$(curl -w %{http_code} -kLo /tmp/clashfm.tar.gz $update_url/bin/clashfm.tar.gz)
else $result
wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $tarurl
wget-ssl -q --no-check-certificate --tries=1 --timeout=10 -O /tmp/clashfm.tar.gz $update_url/bin/clashfm.tar.gz
[ $? -eq 0 ] && result="200"
fi
[ "$result" != "200" ] && echo "文件下载失败!" && exit 1
@@ -418,7 +413,7 @@ if [ "$res" = '1' ]; then
echo -----------------------------------------------
exit;
else
clashsh
update
fi
}
getcore(){
@@ -522,6 +517,7 @@ fi
getgeo(){
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[33m正在检查更新\033[0m"
echo $update_url
result=$(curl -w %{http_code} -skLo /tmp/clashversion $update_url/bin/version)
[ "$result" != "200" ] && echo "检查更新失败!" && exit 1
source /tmp/clashversion
@@ -656,9 +652,9 @@ echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[30;47m您可以在此处切换在线更新时使用的资源地址\033[0m"
echo -e "当前源:\033[4;32m$update_url\033[0m"
echo -----------------------------------------------
echo -e " 1 CDN源(可能有一定的同步延迟)"
echo -e " 2 Github源(不稳定,不推荐)"
echo -e " 3 Github源+clash代理(需开启clash服务,推荐)"
echo -e " 1 Github源(使用host指定IP)"
echo -e " 2 CDN源(版本同步较慢)"
echo -e " 3 Github源+clash代理(需开启clash服务)"
echo -e " 4 自定义输入(请务必确保路径正确)"
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
@@ -667,13 +663,11 @@ if [ -z $num ]; then
echo -e "\033[31m请输入正确的数字\033[0m"
update
elif [[ $num == 1 ]]; then
update_url="https://cdn.jsdelivr.net/gh/juewuy/ShellClash@latest"
elif [[ $num == 9 ]]; then
update_url="https://juewuy.xyz/clash"
update_url='--resolve raw.githubusercontent.com:443:199.232.68.133 https://raw.githubusercontent.com/juewuy/ShellClash/master'
elif [[ $num == 2 ]]; then
update_url="https://raw.githubusercontent.com/juewuy/ShellClash/master"
update_url='https://cdn.jsdelivr.net/gh/juewuy/ShellClash'
elif [[ $num == 3 ]]; then
update_url="-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/ShellClash/master"
update_url='-x 127.0.0.1:7890 https://raw.githubusercontent.com/juewuy/ShellClash/master'
elif [[ $num == 4 ]]; then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
read -p "请输入个人源路径 > " update_url
@@ -682,6 +676,8 @@ elif [[ $num == 4 ]]; then
echo -e "\033[31m取消输入返回上级菜单\033[0m"
update
fi
elif [[ $num == 9 ]]; then
update_url='https://juewuy.xyz/clash'
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo -e "\033[31m请输入正确的数字\033[0m"

View File

@@ -77,8 +77,8 @@ exper='experimental: {ignore-resolve-fail: true, interface-name: en0}'
}
mark_time(){
start_time=`date +%s`
sed -i '/start_time*/'d $ccfg
sed -i "3i\start_time=$start_time" $ccfg
sed -i '/start_time*/'d $clashdir/mark
sed -i "3i\start_time=$start_time" $clashdir/mark
}
start_redir(){
#修改iptables规则使流量进入clash
@@ -144,19 +144,20 @@ start_dns(){
daemon_old(){
#守护进程状态
status=$(ps |grep -w 'clash'|grep -v grep|grep -v clash.sh)
[ -z $status ] && $clashdir/clash -d $clashdir && mark_time
if [ -z $status ];then
$clashdir/clash -d $clashdir> /dev/null &
mark_time
fi
}
checkcron(){
if [ -d /etc/crontabs/ ]; then
cronpath="/etc/crontabs/root"
elif [ -d /var/spool/cron/ ]; then
cronpath="/var/spool/cron/root"
elif [ -d /var/spool/cron/crontabs/ ]; then
cronpath="/var/spool/cron/crontabs/root"
else
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
fi
[ -d /etc/crontabs/ ]&&cronpath="/etc/crontabs/root"
[ -d /var/spool/cron/ ]&&cronpath="/var/spool/cron/root"
[ -d /var/spool/cron/crontabs/ ]&&cronpath="/var/spool/cron/crontabs/root"
if [ -z $cronpath ];then
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "找不到定时任务文件,无法添加定时任务!"
clashsh
fi
}
start_old(){
#读取配置文件