diff --git a/bin/clashfm.tar.gz b/bin/clashfm.tar.gz index b10a161..125bf87 100644 Binary files a/bin/clashfm.tar.gz and b/bin/clashfm.tar.gz differ diff --git a/bin/version b/bin/version index dd1a46b..0c5e688 100644 --- a/bin/version +++ b/bin/version @@ -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 diff --git a/scripts/clash.sh b/scripts/clash.sh index 71e8458..e922eb8 100644 --- a/scripts/clash.sh +++ b/scripts/clash.sh @@ -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服务" diff --git a/scripts/start.sh b/scripts/start.sh index d04a396..a775a30 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -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`