|
@@ -530,47 +530,40 @@ boot() {
|
|
|
fi
|
|
|
}
|
|
|
do_crontab(){
|
|
|
-crontab_updatecore
|
|
|
-crontab_cutquerylog
|
|
|
-}
|
|
|
-crontab_updatecore(){
|
|
|
- config_get autoupdate $CONFIGURATION autoupdate "0"
|
|
|
- local line=$(grep "/usr/share/AdGuardHome/update_core.sh" $CRON_FILE)
|
|
|
- if [ -n "$line" -a "${line:0:1}" != "#" ]; then
|
|
|
- if [ $autoupdate -eq 1 ]; then
|
|
|
- return
|
|
|
- else
|
|
|
- sed -i '\,/usr/share/AdGuardHome/update_core.sh,'d $CRON_FILE
|
|
|
- echo "#$line" >> $CRON_FILE
|
|
|
- /etc/init.d/cron restart
|
|
|
- fi
|
|
|
- else
|
|
|
- if [ $autoupdate -eq 1 ]; then
|
|
|
- [ -z "$line" ] && line="#30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1"
|
|
|
- sed -i '\,/usr/share/AdGuardHome/update_core.sh,'d $CRON_FILE
|
|
|
- echo "${line:1}" >> $CRON_FILE
|
|
|
- /etc/init.d/cron restart
|
|
|
- else
|
|
|
- return
|
|
|
- fi
|
|
|
+ config_get crontab $CONFIGURATION crontab ""
|
|
|
+ local findstr default enable
|
|
|
+ findstr="/usr/share/AdGuardHome/update_core.sh"
|
|
|
+ default="#30 3 * * * /usr/share/AdGuardHome/update_core.sh 2>&1"
|
|
|
+ [ "${crontab//autoupdate/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ crontab_editor
|
|
|
+
|
|
|
+ findstr="tail -n [0-9]* .*/data/querylog.json > .*/data/querylog.json"
|
|
|
+ default="#0 * * * * tail -n 2000 $workdir/data/querylog.json > $workdir/data/querylog.json"
|
|
|
+ [ "${crontab//cutquerylog/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ crontab_editor
|
|
|
+
|
|
|
+ config_get logfile $CONFIGURATION logfile ""
|
|
|
+ if [ "$logfile" != "syslog" -a "$logfile" != "" ]; then
|
|
|
+ findstr="tail -n [0-9]* $logfile > $logfile"
|
|
|
+ default="#30 3 * * * tail -n 2000 $logfile > $logfile"
|
|
|
+ [ "${crontab//cutruntimelog/}" == "$crontab" ] && enable=0 || enable=1
|
|
|
+ crontab_editor
|
|
|
fi
|
|
|
}
|
|
|
-crontab_cutquerylog(){
|
|
|
- config_get cutquerylog $CONFIGURATION cutquerylog "0"
|
|
|
- config_get workdir $CONFIGURATION workdir "/usr/bin/AdGuardHome"
|
|
|
- local line=$(grep "tail -n [0-9]* $workdir/data/querylog.json > $workdir/data/querylog.json" $CRON_FILE)
|
|
|
+crontab_editor(){
|
|
|
+ local line="$(grep "$findstr" $CRON_FILE)"
|
|
|
if [ -n "$line" -a "${line:0:1}" != "#" ]; then
|
|
|
- if [ $cutquerylog -eq 1 ]; then
|
|
|
+ if [ $enable -eq 1 ]; then
|
|
|
return
|
|
|
else
|
|
|
- sed -i "\,tail -n [0-9]* .*/data/querylog.json > .*/data/querylog.json,d" $CRON_FILE
|
|
|
+ sed -i "\,$findstr,d" $CRON_FILE
|
|
|
echo "#$line" >> $CRON_FILE
|
|
|
/etc/init.d/cron restart
|
|
|
fi
|
|
|
else
|
|
|
- if [ $cutquerylog -eq 1 ]; then
|
|
|
- [ -z "$line" ] && line="#0 * * * * tail -n 2000 $workdir/data/querylog.json > $workdir/data/querylog.json"
|
|
|
- sed -i "\,tail -n [0-9]* .*/data/querylog.json > .*/data/querylog.json,d" $CRON_FILE
|
|
|
+ if [ $enable -eq 1 ]; then
|
|
|
+ [ -z "$line" ] && line="$default"
|
|
|
+ sed -i "\,$findstr,d" $CRON_FILE
|
|
|
echo "${line:1}" >> $CRON_FILE
|
|
|
/etc/init.d/cron restart
|
|
|
else
|