#!/bin/sh
# Vulpine's NewsPost Script.  It's nothing fancy, but it makes my job so 
# much easier.  :)
# Verison 0.1.0
# 
# Changelog: 0.0.2 - 0.0.3: added auto date
# Changelog: 0.0.3 - 0.0.4: Changed path to files
# Changelog: 0.0.4 - 0.1.0: switch to variables instead of hard coding
# Changelog: 0.1.0 - 0.1.1: Added mood and music snag
# Changelog: 0.1.1 - 0.2.0: Changed music to give user a choice between 
# xmms.play output or manual input.

# INSTALLATION
# 
# First thing you'll want to do is set the variable WEBSITE to the path 
# your webfiles are stored in.  The default assumes they are stored at
# ~/public_html  Your miliage may vary ;)
#
# If your running this script on a server, that's all you need to do, enjoy.  
# if your running it on a machine, and then upload the files...the script 
# can auto scp the news page to your server.  


# Variables
WEBSITE=$HOME/Websites/www.cyberfox.org
LOGIN=vulpine@www.cyberfox.org
WEBPATH=/home/vulpine/web/cyberfox.org/
FILEDATE=`date +%Y%m%d`
MUSIC=$WEBSITE/xmms.play

echo 'NewsPost, version 0.2.0'


# First, backup the old news file, then recreate it.
mv $WEBSITE/news.html $WEBSITE/news.bak

touch $WEBSITE/news.html

# Get the Date and Subject of the news post.
date > $WEBSITE/date.tmp
echo 'Subject:'
cat > $WEBSITE/subject.tmp

# Ask about mood
echo 'Mood:'
cat > $WEBSITE/mood.tmp

# Verify Music
echo 'The current music is:' 
cat $MUSIC
echo 'Do you want to use this, or input something else ?'
        read confirmation
        if [ $confirmation = "yes" ]
                then
                cat $MUSIC > $WEBSITE/music.tmp
        else
echo 'Input current music/tv/whatever:'
        cat > $WEBSITE/music.tmp
        fi

# Write the HTML code for the news posting.  Add in the date and subject
echo '<tr><td><table width="100%" border="2" cellpadding="2" cellspacing="0">'>>$WEBSITE/news.html
echo '<tr><td><B>'>>$WEBSITE/news.html
cat $WEBSITE/subject.tmp >>$WEBSITE/news.html
echo '</B></td><td align="right"><I>'>>$WEBSITE/news.html
cat $WEBSITE/date.tmp >>$WEBSITE/news.html
echo '</I></td>'>>$WEBSITE/news.html
echo '</tr>'>>$WEBSITE/news.html
echo '</table>'>>$WEBSITE/news.html
echo '<table width="100%" border="2" cellpadding="2" cellspacing="0">'>>$WEBSITE/news.html
echo '<tr><td><U>Mood</U>: '>>$WEBSITE/news.html
cat $WEBSITE/mood.tmp>>$WEBSITE/news.html
echo '</td>'>>$WEBSITE/news.html
echo '<td align="right"><U>Music of the Day</U>: '>>$WEBSITE/news.html
cat $WEBSITE/music.tmp >>$WEBSITE/news.html
echo '</td>'>>$WEBSITE/news.html
echo '</table>'>>$WEBSITE/news.html
echo '<table>'>>$WEBSITE/news.html
echo '<tr><td colspan="2">'>>$WEBSITE/news.html

# Turn ViM on so I can write some flern.
vim $WEBSITE/news.htm

# Post the flern to the news file
cat $WEBSITE/news.htm >>$WEBSITE/news.html
cp $WEBSITE/news.htm $HOME/.livejournal/event.html

# Finish out the HTML
echo '</p>'>>$WEBSITE/news.html
echo '</td></tr></table>'>>$WEBSITE/news.html

# Add back all the old entries.
cat $WEBSITE/news.bak >>$WEBSITE/news.html

# Upload to Website
scp -P 2222 $WEBSITE/news.html $LOGIN:$WEBPATH/news.html

#Clear temp files.
mv $WEBSITE/news.bak $HOME/temp/website/$FILEDATE.bak
rm $WEBSITE/*.tmp
rm $WEBSITE/news.htm

echo 'Finished.'

