Commit | Line | Data |
---|---|---|
e404bb37 RJ |
1 | #!/bin/bash |
2 | # This is meant to be fire-and-forget | |
3 | # Only use it if you trust the output! | |
ec4760e5 JD |
4 | |
5 | CURL_USERNAME=$1 | |
6 | CURL_PASSWORD=$2 | |
7 | ||
e38e56a8 | 8 | export DIR=$(readlink -f $(dirname $0)) |
d10c96dc | 9 | NAME=outlook |
55318b37 RJ |
10 | if [ -z "${MAKEOPTS}" ]; then |
11 | echo "MAKEOPTS env variable is not set" | |
12 | echo "If you really want this to be serialized, export MAKEOPTS=-j1" | |
13 | echo "Otherwise set it about 1.5x your number of CPUs!" | |
14 | exit 1 | |
15 | fi | |
e404bb37 | 16 | [ -z "${T}" ] && export T=$(date -u +%Y%m%dT%H%M%SZ) |
d10c96dc | 17 | [ -z "${OUTDIR}" ] && export OUTDIR=$(mktemp --tmpdir -d ${NAME}_export.$T.XXXXXXX) |
e404bb37 | 18 | cd $OUTDIR |
5e85b8ab | 19 | echo Prep $(date -uR)/@$(date +%s) |
ec4760e5 | 20 | $DIR/fetch-shortcodes.sh shortcodes-$T.csv |
e404bb37 | 21 | cd $DIR |
5e85b8ab | 22 | echo Exporting $(date -uR)/@$(date +%s) |
d10c96dc | 23 | export PERLOPT=-X |
ff03d26c | 24 | time ./sitka-full-export-parallel.sh >$OUTDIR/script.log 2>&1 |
368b2926 | 25 | rc=$? |
e404bb37 RJ |
26 | cd $OUTDIR |
27 | mkdir split | |
28 | mv *split* split/ | |
5e85b8ab | 29 | echo Compressing $(date -uR)/@$(date +%s) |
2ec1922a RJ |
30 | pbzip2 -9nk -p4 *{marc,log} |
31 | pbzip2 -9n -p4 split/*{marc,log} | |
5e85b8ab | 32 | echo Stats $(date -uR)/@$(date +%s) |
ff03d26c | 33 | DELETE=1 $DIR/stats.sh >$OUTDIR/stats.log 2>&1 |
619e205d | 34 | # Look for zeros in the output marc |
d10c96dc | 35 | echo Sanity $(date -uR)/@$(date +%s) |
619e205d | 36 | egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats |
368b2926 | 37 | grep_result=$? |
619e205d | 38 | # halt if found |
368b2926 | 39 | if [ $rc -ne 0 -o $grep_result -ne 0 ]; then |
619e205d | 40 | echo "Failed to run export! Human needed! export=$rc grep_sanity=$grep_result" 1>&2 |
368b2926 RJ |
41 | cat *stats 1>&2 |
42 | exit 1 | |
43 | fi | |
ec4760e5 JD |
44 | |
45 | # upload fails if curl username/password not provided | |
46 | if [ -z "${CURL_PASSWORD}" ]; then | |
47 | echo "Missing curl auth parameter(s), cannot upload to Outlook" 1>&2 | |
48 | exit 1 | |
49 | fi | |
50 | ||
51 | # individually upload all required output files with curl | |
52 | for CURL_FILE in `ls $OUTDIR | egrep '(.bz2|.stats|.csv)$' | grep -v script.log.bz2` ; do | |
53 | $DIR/outlook-curl.sh $CURL_FILE $CURL_USERNAME $CURL_PASSWORD | |
54 | echo $CURL_FILE >> $OUTDIR/Manifest | |
55 | done | |
56 | ||
d10c96dc RJ |
57 | cp $DIR/email-template-${NAME}.sh $OUTDIR/ |
58 | chmod +x email-template-${NAME}.sh | |
59 | ./email-template-${NAME}.sh "$T" "@$(date +%s)" >email.txt | |
0e3cccc0 | 60 | /usr/lib/sendmail -t -f sitka-tier2@bc.libraries.coop <email.txt |