#!/bin/bash
# add2cdd - cdd project
# Antonio Maschio 2006-2007 <tbin at libero dot it>

# add2cdd adds records to the cdd database in a friendly way 
# there are no options

# Getting custom data
source custom.data

#####################################
#      MAIN 
#####################################

# if an option is given, set it as filename
if [ "$1" != "" ]; then
        filename=$1
fi

# hello and instructions
echo
echo "You're gonna add records to $filename:"
echo "enter nothing as the Artist name when you're over."
read

# start asking
read -p 'Artist    : ' artist
while [ -n "$artist" ]; do
        read -p 'Title     : ' title
        read -p 'Issue year: ' year
        read -p 'CD date   : ' cddate
        read -p 'Notes     : ' notes
        echo "${artist}${separator}${title}${separator}${year}${separator}${cddate}${separator}${notes}" | tr '[A-Z]' '[a-z]' >> $filename
        echo
        # log
	date >> ${cddlog}
        echo "   added " ${artist} " -> " ${title} | tr '[A-Z]' '[a-z]' >> ${cddlog}
	# restart cycle
        read -p 'Artist    : ' artist
done

# sorting and exiting as last operations
sort $filename -o $filename
echo "Inserted and sorted: we're through!"
echo
exit
