Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(See issue #68) #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions update.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
#!/bin/sh

cleanup () {
[ -n "$TMPDIR" ] && [ -e "$TMPDIR" ] && rm -rf "$TMPDIR"
}

die () {
[ -n "$1" ] && echo $1 >&2
cleanup
exit 1
}

WORKDIR='/Users/steve/greasefire'
TMPDIR="$WORKDIR/tmp"
SCRAPERDIR="$WORKDIR/greasefire/java/greasefire-scraper"
INDEXES='skrul.com/projects/greasefire/indexes'

DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
DEST="index_$DATE.jar"

# Download scripts
cd /Users/steve/greasefire
java -jar greasefire/java/greasefire-scraper/downloadscripts.jar scripts $1
cd "$WORKDIR" || die
java -jar "$SCRAPERDIR/downloadscripts.jar" scripts "$1" || die

# Generate indexes into tmp
mkdir tmp
java -Xmx512m -jar greasefire/java/greasefire-scraper/generateindex.jar scripts tmp
# Generate indexes into TMPDIR
mkdir "$TMPDIR" || die
java -Xmx512m -jar "$SCRAPERDIR/generateindex.jar" scripts "$TMPDIR" || die

# Jar up indexes
cd tmp
cd "$TMPDIR" || die
echo "[indexes]" > info.ini
echo "date=$DATE" >> info.ini
jar cvfM $DEST include.dat exclude.dat scripts.db info.ini
mkdir $DATE
cp include.png exclude.png $DATE
jar cvfM "$DEST" include.dat exclude.dat scripts.db info.ini || die

# Copy indexes to skrul.com
scp -r ./$DEST ./$DATE [email protected]:skrul.com/projects/greasefire/indexes
mkdir "$DATE" || die
cp include.png exclude.png "$DATE" || die

[ -n "$DEST" -a -f "./$DEST" ] || die "no $DEST file"
[ -n "$DATE" -a -d "./$DATE" ] || die "no $DATE directory"

# Clean up tmp
cd ..
rm -r tmp
# Copy indexes to skrul.com
scp -r ./"$DEST" ./"$DATE" \
[email protected]:skrul.com/projects/greasefire/indexes || die

# Update latest file on skrul.com
ssh [email protected] "echo $DATE > skrul.com/projects/greasefire/indexes/latest"
ssh [email protected] "echo $DATE > "'"'"$INDEXES"'"'"/latest"

# Delete indexes older than a week
ssh [email protected] "find skrul.com/projects/greasefire/indexes/index_* -type f -mtime 7 -exec rm {} \;"
ssh [email protected] "find "'"'"$INDEXES"'"'"/index_* -type f -mtime 7 -exec rm {} \;"

# # Clean up TMPDIR
cleanup