#! /bin/bash
#
# Available environment variables:
# CONF		Configuration file
# DISTS		Distribution list
# URL		UpdateRepository::URL
# ARCHIVE_URL	URL of archived repository
# IMPRESSUM_URL URL of the impressum
# EMAIL_URL	E-mail address or URL for e-mails
# MAINTAINER	Maintainer of the repository
# ORIGIN	APT::FTPArchive::Release::Origin
# LABEL		APT::FTPArchive::Release::Label
# DESCRIPTION	APT::FTPArchive::Release::Description
#
cat << EOF
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>$DESCRIPTION</title>
    <link rel="stylesheet" href="conf/style.css">
  </head>
  <body class='readme'>
    <h1>$DESCRIPTION</h1>

    <p id='p1'>Packages for the following releases are available:</p>
EOF

# Newest distribution first
for DIST in $(echo "$DISTS" | xargs -n1 | tac | xargs); do
	STATUS=$(apt_config_tree "$CONF" "$DIST" "Tree::UpdateRepository::Status")
	echo "<p class='release'> &nbsp; &nbsp; <a href='dists/$DIST/readme.html'>$DIST</a>${STATUS:+ &nbsp; <em>($STATUS)</em>}</p>"
done

cat << EOF
    <p id='p2'>Have fun!</p>

    <p class='navigation'>
      <a href=".">Browse repository</a>
      ${ARCHIVE_URL:+&nbsp; | &nbsp; <a href="$ARCHIVE_URL">Archive</a>}
      ${IMPRESSUM_URL:+&nbsp; | &nbsp; <a href="$IMPRESSUM_URL">Impressum</a>}
      ${EMAIL_URL:+&nbsp; | &nbsp; <a href="$EMAIL_URL">E-mail</a>}
    </p>
  </body>
</html>
EOF
