install-osrf.sh: set ejabberd host correctly during registration on prod
[sitka/sitka-tools.git] / marc_export_custom / sitka-full-export-parallel-outlook-wrapper.sh
CommitLineData
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
5CURL_USERNAME=$1
6CURL_PASSWORD=$2
7
e38e56a8 8export DIR=$(readlink -f $(dirname $0))
d10c96dc 9NAME=outlook
55318b37
RJ
10if [ -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
15fi
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 18cd $OUTDIR
5e85b8ab 19echo Prep $(date -uR)/@$(date +%s)
ec4760e5 20$DIR/fetch-shortcodes.sh shortcodes-$T.csv
e404bb37 21cd $DIR
5e85b8ab 22echo Exporting $(date -uR)/@$(date +%s)
d10c96dc 23export PERLOPT=-X
ff03d26c 24time ./sitka-full-export-parallel.sh >$OUTDIR/script.log 2>&1
368b2926 25rc=$?
e404bb37
RJ
26cd $OUTDIR
27mkdir split
3f5a4340 28mv *-split* split/
5e85b8ab 29echo Compressing $(date -uR)/@$(date +%s)
2ec1922a
RJ
30pbzip2 -9nk -p4 *{marc,log}
31pbzip2 -9n -p4 split/*{marc,log}
5e85b8ab 32echo Stats $(date -uR)/@$(date +%s)
ff03d26c 33DELETE=1 $DIR/stats.sh >$OUTDIR/stats.log 2>&1
619e205d 34# Look for zeros in the output marc
d10c96dc 35echo Sanity $(date -uR)/@$(date +%s)
619e205d 36egrep -vsq '^([[:space:]]*0){2}.*marc$' *stats
368b2926 37grep_result=$?
619e205d 38# halt if found
368b2926 39if [ $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
43fi
ec4760e5
JD
44
45# upload fails if curl username/password not provided
46if [ -z "${CURL_PASSWORD}" ]; then
47 echo "Missing curl auth parameter(s), cannot upload to Outlook" 1>&2
48 exit 1
49fi
50
51# individually upload all required output files with curl
52for 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
55done
56
d10c96dc
RJ
57cp $DIR/email-template-${NAME}.sh $OUTDIR/
58chmod +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