From 3d35e2ba0cc2b2de58287ab24585082552d544d6 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 25 Jun 2021 14:14:27 -0400 Subject: SBoTools: add DB update cron script, twiddle search result formatting --- bin/sbotools-update-db.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 bin/sbotools-update-db.sh (limited to 'bin') diff --git a/bin/sbotools-update-db.sh b/bin/sbotools-update-db.sh new file mode 100755 index 0000000..07ef9ec --- /dev/null +++ b/bin/sbotools-update-db.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +# update the SBoTools.sqlite3 for the SBoTools limnoria plugin. +# should be run from cron probably daily. also can be run manually. +# run this as the slackfacts user, not root. + +# configurables: +BOTDIR=/home/slackfacts/supybot +DBFILE=$BOTDIR/SBoTools.sqlite3 +SCRIPT=$BOTDIR/limnoria.slackfacts.plugins/bin/sbodb.pl +SBOTREE=/data/mirrors/slackbuilds.org/14.2 +SQLITE3=/usr/bin/sqlite3 +LOG=$BOTDIR/sbotools-update-db.log +DATEFILE=$BOTDIR/sbotools-update-db.lastdate + +# 1st line of ChangeLog.txt is the date of the last SBo update. +head -n 1 $SBOTREE/ChangeLog.txt > $DATEFILE.new + +# 'diff' returns true if the files are the same (non-intuitive). +# if there hasn't been an SBo update since the last DB update, we +# don't need to update the DB again. +if [ -e $DATEFILE && diff $DATEFILE $DATEFILE.new > /dev/null ]; then + rm -f $DATEFILE.new + exit 0 +fi + +( $SCRIPT $SBOTREE | $SQLITE3 $DBFILE.update ) &> $LOG + +if [ "$?" = "0" ]; then + mv $DBFILE.update $DBFILE.new + mv $DATEFILE.new $DATEFILE + rm -f $LOG + exit 0 +else + echo "$0: update failed" + cat $LOG + exit 1 +fi -- cgit v1.2.3