#!/bin/bash

echo "Finding Zero Byte Files..."
find . -type f -size 0

echo "Chmodding..."
chmod 644 *.htm
rm -f *.bak

# check for that dumb emdash
# cat $i | sed -e 's/–/-/g' > $i.out

# check for missing speaker ID
# grep "\]  [A-Za-z0-0]" *.htm

for i in `ls *.htm`
do
  echo "Dumping $i"
  /usr/bin/lynx -width=400 -dump -nolist -display_charset=utf-8 $i > $i.txt
  file=`echo $i.txt | sed -e 's/\.htm//g'`
  cat $i.txt | /usr/bin/grep "^\[" > $file
  rm -f $i.txt
done

for i in `ls *.txt`
do
  FILENAME=`echo "Off The Hook" $i|sed 's/\.txt//g'`
  echo "Moving $FILENAME"
  /bin/mv -f $i "/www/cgi-bin/2600/$FILENAME"
done

cd /www/2600/hope/transcripts/

chmod 644.txt

for i in `ls *.txt`
do
		FILENAME=`echo "HOPE" $i|sed 's/\.txt//g'`
		echo "Copying $FILENAME"
		/bin/cp -f $i "/www/cgi-bin/2600/$FILENAME"
done

cd /www/cgi-bin

echo "Adding `date` to data-date.txt..." 
echo `date` > /www/cgi-bin/2600/data-date.txt

echo "Tar'ing up the 2600 directory..."
/usr/bin/tar czf 2600-search.tar.gz 2600.main.cgi 2600.cgi 2600/

echo "Moving 2600-search.tar.gz to ~/GitHub/2600-Article-Search"
mv -f 2600-search.tar.gz ~/GitHub/2600-Article-Search/
