#!/bin/bash -e

target=/srv/public_html/index.html

cat >${target}.tmp <<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>pkgbuild.com</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" type="text/css" href="/static/archweb.css" media="screen" />
  <link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
  <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
</head>
<body>
  <div id="archnavbar"><!-- Arch Linux global navigation bar -->
    <div id="archnavbarlogo">
      <p><a href="http://www.archlinux.org/" title="Arch news, packages, projects and more"></a></p>
    </div>
  </div>
  <div id="content">
    <div id="archdev-navbar">
    </div>
    <div id="content-left-wrapper">
      <div id="content-left">
        <div id="intro" class="box">
          <h2>Public HTML server</h2>
          <p>This machine allows Arch Linux staff to make files and web documents available publicly.</p>
          <p>The server is paid from <a href="https://www.archlinux.org/donate/" alt="Pls donate we need bigger servers">donations</a> (❤️) and is available to all Trusted Users and Developers.</p>
        </div>
      </div>
    </div>
    <div id="content-right">
      <div id="pkg-updates" class="widget box">
        <h3>TU/Dev User Dirs</h3>
        <ul>
END

cd /
sudo -u http find /home -mindepth 1 -maxdepth 1 \
  -exec test -r {}/public_html \; \
  -printf '           <li><a href="/~%P">%P</a></li>\n' \
  | sort >> ${target}.tmp

cat >>${target}.tmp <<END
        </ul>
      </div>
    </div>
    <div id="footer">
      <p>
          Copyright &copy; 2002-{{ '%Y' | strftime }}
        <a href="mailto:jvinet@zeroflux.org" title="Contact Judd Vinet">Judd Vinet</a>
        and <a href="mailto:aaron@archlinux.org" title="Contact Aaron Griffin">Aaron Griffin</a>.
      </p>
      <p>
        The Arch Linux name and logo are recognized
        <a href="https://wiki.archlinux.org/index.php/DeveloperWiki:TrademarkPolicy" title="Arch Linux Trademark Policy">trademarks</a>.
        Some rights reserved.
      </p>
      <p>
        The registered trademark Linux® is used pursuant to a sublicense from LMI,
        the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide basis.
      </p>
    </div><!-- #footer -->
  </div><!-- #content -->
</body>
</html>
END

mv ${target}.tmp ${target}
