#!/bin/sh
DATADIR="data"
DESTDIR="."
LISTLONG="$DESTDIR/materials_long.txt"
LISTSHORT="$DESTDIR/materials_short.txt"
LISTCSV="$DESTDIR/materials.csv"
LISTPHP="$DESTDIR/materials.inc.php"
LISTMAT="$DESTDIR/materials.pm"

# Create the long list
echo "Generating long list..."
echo -n "Last updated: " > "$LISTLONG"
date >> "$LISTLONG"
echo "" >> "$LISTLONG"
cat $DATADIR/*.mat | perl -w parsematerial.pl -dump >> "$LISTLONG"


# Create the short and CSV lists
echo "Generating short list"
echo -n "Last updated: " > "$LISTSHORT"
date >> "$LISTSHORT"
echo "" >> "$LISTSHORT"
cat $DATADIR/*.mat | perl -w parsematerial.pl -table >> "$LISTSHORT"

echo "Generating CSV"
cat $DATADIR/*.mat | perl -w parsematerial.pl -csv > "$LISTCSV"

echo "Generating PHP ..."
cat $DATADIR/*.mat | perl -w parsematerial.pl -php > "$LISTPHP"

echo "Generating Perl data ..."
cat $DATADIR/*.mat | perl -w parsematerial.pl -perl > "$LISTMAT"

echo "Uploading ..."
scp -C "$LISTLONG" "$LISTSHORT" "$LISTCSV" "$LISTPHP" ccr@tnsp.org:/var/www/tnsp.org/mat/
