aboutsummaryrefslogtreecommitdiff
path: root/bin/sbotools-update-db.sh
blob: 09192f7bce44726082f2f6479be8d5f612dc32f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 -a 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