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