version="2.0"
codename="Rigel"

pre1=(
"Package updates:"
"New features:"
"MATE 1.8.x"
)

pre2=(
"Package updates:"
"New features:"
)

rc1=(
"Package updates:"
"New features:"
)

rc2=(
"Package updates:"
"New features:"
)

stable=(
"Package updates:"
""
"New features:"
""
)

# $1 is release
# $2 is news
# $3 is author
output()
{
	local _previous
	local _current
	local _addendum
	local _news
	local _entry
	local _in_group=0
	case $1 in
		pre1)
			_previous="$(echo $version-0.1 | bc)"
			_current="${version}pre1"
			_addendum="the first technical preview of the upcoming $version stable release."
			_news=("${pre1[@]}")
			;;
		pre2)
			_previous="${version}pre1"
			_current="${version}pre2"
			_addendum="the second technical preview of the upcoming $version stable release."
			_news=("${pre2[@]}")
			;;
		rc1)
			_previous="${version}pre2"
			_current="${version}rc1"
			_addendum="the first candidate of the upcoming $version stable release."
			_news=("${rc1[@]}")
			;;
		rc2)
			_previous="${version}rc1"
			_current="${version}rc2"
			_addendum="the second candidate of the upcoming $version stable release."
			_news=("${rc2[@]}")
			;;
		stable)
			;;
	esac
	printf "%2c<post>\n" ' '
	printf "%4c<id>$2</id>\n" ' '
	printf "%4c<title>Frugalware $_current ($codename) released</title>\n" ' '
	printf "%4c<date>$(date -R)</date>\n" ' '
	printf "%4c<author>$3</author>\n" ' '
	printf "%4c<hidden>0</hidden>\n" ' '
	printf "%4c<content><![CDATA[\n" ' '
	printf "%6cThe Frugalware Developer Team is pleased to <a href="/news/$2">announce</a> the immediate availability of Frugalware $_current, $_addendum</p>\n" ' '
	printf "%4c<p>Here are some of the major improvements, fixes and updates since $_previous:<br/>\n" ' '
	printf "%6c<ul>\n" ' '
	for _i in `seq 0 ${#_news[@]}`; do
		_entry="${_news[$_i]}"
		if echo $_entry | grep -q ':$'; then
			if [ "$_in_group" -eq 0 ]; then
				_in_group=1
				printf "%8c<li>$_entry\n" ' '
				printf "%10c<ul>\n" ' '
			else
				printf "%10c</ul>\n" ' '
				printf "%8c</li>\n" ' '
				printf "%8c<li>$_entry\n" ' '
				printf "%10c<ul>\n" ' '
			fi
		elif [ -z "$_entry" ]; then
			printf "%10c</ul>\n" ' '
			printf "%8c</li>\n" ' '
		else
			printf "%12c<li>$_entry</li>\n" ' '
		fi
	done
	printf "%6c</ul>\n" ' '
	printf "%6cPlease refer to the Frugalware <a href="http://ftp.frugalware.org/pub/frugalware/frugalware-testing/ChangeLog.txt">Testing ChangeLog</a> for more information.<br/>\n" ' '
	printf "%6cDownload for x86_64: See our <a href="http://frugalware.org/download/frugalware-testing-iso">mirror list</a>. Don't forget to check the <a href="http://frugalware.org/download/frugalware-testing-iso/SHA1SUMS">integrity</a> of the install images before burning!<br/>\n" ' '
	printf "%6c<b>NOTE</b>: Click <a href="/docs/install#_choosing_installation_flavor">here</a> to read more about what media you need for the installation.<br/>\n" ' '
	printf "%8c]]>\n" ' '
	printf "%4c</content>\n" ' '
	printf "%2c</post>\n" ' '
}

if [ -z "$3" ]; then
	echo "Usage: $0 <release> <news> <author>"
	exit 1
fi

output "$1" "$2" "$3"
