#!/bin/bash

DISTVER=VinePlus/5
CATLIST=vine5x
if [ "$1" == "VineSeed" ]; then
  DISTVER=VineSeed
  CATLIST=vineseed
fi

TOPDIR=/home/ftp/pub/Vine
SRPMSDIR=${TOPDIR}/${DISTVER}/pool
CATEGORYLIST=${TOPDIR}/VineSeed/category/packages-${CATLIST}.list

NEWRPMS=""

#NEWRPMS=$(rpm -qp --qf '%{BUILDTIME}\t%{NAME}-%{VERSION}-%{RELEASE}.src.rpm\n' $SRPMSDIR/*.rpm | sort -rn | head -30 | \
#while read buildtime srcrpm
#do
#  echo -n "$srcrpm "
#done)

NEWRPMS=$(ls -1t ${SRPMSDIR}/*.rpm | head -40 | xargs rpm -qp --qf '%{name}-%{version}-%{release}.src.rpm ')

cat template/header.tmpl

cat << EOF
<div id="wrapper">
<!-- start page -->
<div id="page">
  <!-- start content -->
  <div id="content-wide">

<h1 class="title">最近更新された ${DISTVER} パッケージの情報</h1>
<div class="entry">

EOF

# contents
for i in $NEWRPMS
do
  LANG=ja_JP.UTF-8 rpm -qp \
      --qf '<a name="%{NAME}-%{VERSION}-%{RELEASE}">\n' \
      --qf '<h3>%{name}</h3>\n' \
      --qf '</a>\n' \
      --qf '<dd>\n' \
      --qf '  <b>パッケージ名:</b> \n' \
      --qf "  <a href=\"http://updates.vinelinux.org/${DISTVER}/pool/%{NAME}-%{VERSION}-%{RELEASE}.src.rpm\">" \
      --qf '  %{NAME}-%{VERSION}-%{RELEASE}.src.rpm\n' \
      --qf '  </a><br />\n' \
      --qf '  <b>サマリ:</b> %{SUMMARY}<br />\n' \
      --qf '  <br />\n' \
      --qf '  <b>変更履歴:</b><br />\n' \
      --qf '  <blockquote><pre>\n'  $SRPMSDIR/$i
  LANG=ja_JP.UTF-8 rpm -qp \
      --qf '%{changelogtext}\n' $SRPMSDIR/$i | sed -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/@/ at /g'
  echo     '  </pre></blockquote>'
  echo     '</dd>'
  echo     '<br />'
done | sed -e 's/new upstream release/開発元のバージョン更新に追従/g' \
           -e 's/[Ii]nitial build.*/新規パッケージ/g' \
	   -e 's/- .*built with new toolchain/- 新しいtoolchainでリビルド/g' \
	   -e 's/updated \(.*\) to \(.*\)/\1を\2に更新/g' \
	   -e 's/updated to \(.*\)/\1に更新/g' \
	   -e 's/[Rr]ebuil? with \(.*\)/\1でリビルド/g' \

#
cat << EOF
</div>
  </div><!-- end content-wide -->
EOF

# sidebar
cat template/sidebar2.tmpl

# footer
cat template/footer.tmpl
