v1.4.1-test

~适配部分没有crontab的梅林设备
This commit is contained in:
juewuy 2021-06-24 23:16:28 +08:00
parent 79b31af092
commit 19fe2f183e
4 changed files with 42 additions and 18 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
clash_v=1.6.0
clashpre_v=2021.05.08
versionsh=1.4.0
GeoIP_v=20210623
versionsh=1.4.1-test

View File

@ -1053,7 +1053,19 @@ tools(){
fi
}
clashcron(){
croncmd(){
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
crontab $1
else
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
[ ! -w "$crondir" ] && echo "你的设备不支持定时任务配置,脚本大量功能无法启用,请前往 https://t.me/clashfm 申请适配!"
[ "$1" = "-l" ] && cat $crondir/$USER 2>/dev/null
[ -f "$1" ] && cat $1 > $crondir/$USER
fi
}
setcron(){
setcrontab(){
#设置具体时间
@ -1082,13 +1094,14 @@ clashcron(){
read -p "是否确认添加定时任务?(1/0) > " res
if [ "$res" = '1' ]; then
cronwords="$min $hour * * $week $cronset >/dev/null 2>&1 #$week1的$hour点$min分$cronname"
crondir=/tmp/cron_$USER
crontab -l > $crondir
sed -i "/$cronname/d" $crondir
sed -i '/^$/d' $crondir
echo "$cronwords" >> $crondir && crontab $crondir
tmpcron=/tmp/cron_$USER
croncmd -l > $tmpcron
sed -i "/$cronname/d" $tmpcron
sed -i '/^$/d' $tmpcron
echo "$cronwords" >> $tmpcron
croncmd $tmpcron
#华硕/Padavan固件存档在本地,其他则删除
[ "$clashdir" = "/jffs/clash" -o "$clashdir" = "/etc/storage/clash" ] && mv -f $crondir $clashdir/cron || rm -f $crondir
[ "$clashdir" = "/jffs/clash" -o "$clashdir" = "/etc/storage/clash" ] && mv -f $tmpcron $clashdir/cron || rm -f $tmpcron
echo -----------------------------------------------
echo -e "\033[31m定时任务已添加\033[0m"
fi
@ -1111,8 +1124,8 @@ clashcron(){
elif [ "$num" = 0 ]; then
i=
elif [ "$num" = 9 ]; then
crontab -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && crontab /tmp/conf
sed -i "/$cronname/d" $clashdir/cron
croncmd -l > /tmp/conf && sed -i "/$cronname/d" /tmp/conf && croncmd /tmp/conf
sed -i "/$cronname/d" $clashdir/cron 2>/dev/null
rm -f /tmp/conf
echo -----------------------------------------------
echo -e "\033[31m定时任务$cronname已删除\033[0m"
@ -1134,7 +1147,7 @@ clashcron(){
echo -e "\033[44m 实验性功能遇问题请加TG群反馈\033[42;30m t.me/clashfm \033[0m"
echo -----------------------------------------------
echo -e "\033[33m已添加的定时任务\033[36m"
crontab -l | grep -oE ' #.*'
croncmd -l | grep -oE ' #.*'
echo -e "\033[0m"-----------------------------------------------
echo -e " 1 设置\033[33m定时重启\033[0mclash服务"
echo -e " 2 设置\033[31m定时停止\033[0mclash服务"

View File

@ -54,14 +54,25 @@ logger(){
[ "$(wc -l $clashdir/log | awk '{print $1}')" -gt 30 ] && sed -i '1,5d' $clashdir/log
}
cronset(){
if [ -n "$(crontab -h 2>&1 | grep '\-l')" ];then
crontab $1
else
crondir="$(crond -h 2>&1 | grep -oE 'Default:.*' | awk -F ":" '{print $2}')"
[ ! -w "$crondir" ] && crondir="/etc/storage/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron/crontabs"
[ ! -w "$crondir" ] && crondir="/var/spool/cron"
[ ! -w "$crondir" ] && echo "你的设备不支持定时任务配置,脚本大量功能无法启用,请前往 https://t.me/clashfm 申请适配!"
[ "$1" = "-l" ] && cat $crondir/$USER 2>/dev/null
[ -f "$1" ] && cat $1 > $crondir/$USER
fi
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
crondir=/tmp/cron_$USER
crontab -l > $crondir 2>/dev/null
sed -i "/$1/d" $crondir
sed -i '/^$/d' $crondir
echo "$2" >> $crondir
crontab $crondir
rm -f $crondir
tmpcron=/tmp/cron_$USER
croncmd -l > $tmpcron
sed -i "/$1/d" $tmpcron
sed -i '/^$/d' $tmpcron
echo "$2" >> $tmpcron
croncmd $tmpcron
rm -f $tmpcron
}
mark_time(){
start_time=`date +%s`