aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2021-06-25 14:14:27 -0400
committerB. Watson <yalhcru@gmail.com>2021-06-25 14:14:27 -0400
commit3d35e2ba0cc2b2de58287ab24585082552d544d6 (patch)
tree326796ab7b3aea90f352aa67446dd942ebc66d89 /bin
parenta5a96cd7ae566bb1ee168cae14e1d1101bcd1797 (diff)
downloadlimnoria.slackfacts.plugins-3d35e2ba0cc2b2de58287ab24585082552d544d6.tar.gz
SBoTools: add DB update cron script, twiddle search result formatting
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sbotools-update-db.sh38
1 files changed, 38 insertions, 0 deletions
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