Code that generates this site

buildsite

#!/bin/sh
HOMEDIR=/data/debian
cd $HOMEDIR

# LICENSE FOR this file
# ================================

# This notice is a simplified BSD license.

# Copyright 2010 Jean-Christophe Dubacq. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:

# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY JEAN-CHRISTOPHE DUBACQ ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JEAN-CHRISTOPHE DUBACQ OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# The views and conclusions contained in the software and documentation
# are those of the authors and should not be interpreted as representing
# official policies, either expressed or implied, of Jean-Christophe Dubacq.

##### Work

[ -d cache ] || mkdir cache
[ -d html ] || mkdir html
[ -d txt ] || mkdir txt
rm -rf html/*.html txt/*
DISTS=$(grep ^Codename: conf/distributions|cut -f2 -d:)
for dist in $DISTS; do
    sh template/release.html $dist > html/$dist.html
done
sh template/packages.html > html/packages.html
for i in $(sort -u < txt/srcpages); do
    sh template/src.html "$i" > html/srcpkg.$i.html
done
for i in $(sort -u < txt/binpages); do
    sh template/bin.html "$i" > html/binpkg.$i.html
done
sh template/index.html > html/index.html
sh template/author.html > html/author.html
sh template/news.html > html/news.html
sh template/code.html > html/code.html
exit 0

template/bin.html

#!/bin/sh
HOMEDIR=/data/debian

SOURCELESS=txt/list.sourceless
UNUSED=txt/list.unused
USED=txt/list.used

binpkg="$1"
TITLE="${binpkg} binary package"
TOPURL=packages.html
. $HOMEDIR/template/common
. $HOMEDIR/template/common-packages

components=$(find txt -name "used_arches.*")
NORMALARCHES=$(echo "$components"|xargs cat|LANG=C sort -u|tr '\n' ' '|sed -e 's/ /, /g;s/, $//g')

count=0
rowspan=6
innerclass='" style="min-height:10ex;'
rowmodulo=$((12/rowspan))
beforetitle='<h3>'
aftertitle='</h3>'

binary_interstage()  {
    OP="txt/tmp.$ARCH.$1"
    echo "$ARCH" >> txt/tmp.x.$1
    return
}

treat_binarypackage() {
    for vers in $(grep ^${binpkg}% txt/list.binary.txt|cut -f2 -d%|LANG=C sort -ur); do
	echo "<h2 id=\"version$vers\">Version $vers</h2>"
        rm -f txt/tmp.*
	for version in $(grep ^${binpkg}%${vers}% txt/list.binary.txt|LANG=C sort -u); do
	    
	    VERSION=$(binary_info Version $version)
	    ARCH=$(binary_info Architecture $version)
	    binary_interstage 2
	    echo "<li>Short description: $(binary_info Description $version)</li>" >> $OP
	    echo "<li>Long description:<p>" >> $OP
	    cat txt/binary%${version}.txt |sed -ne '/^Description:/,/^[^ ]/ b lab' -e 'd' -e ':lab' -e '/^[^ ]/ d' -e 's/^ [.]$/<\/p><p>/g' -e 'p' >> $OP
	    echo "</p></li>"
            LASTMD=''
            LASTSIZE=''
            INDIST=''
	    for art in Homepage $(grep "^Vcs-" "txt/binary%$version.txt"|cut -f1 -d:|LANG=C sort -u) Depends Recommends Suggests Conflicts Breaks Provides Maintainer Source Section Size MD5sum Filename; do 
		RESULT=$(binary_info $art $version)
 		if [ "$art" = "Source" ]; then
		    if [ -z "$RESULT" ]; then
			RESULT="$binpkg"
			RESULTVERS=''
		    else
			RESULTVERS="$(echo -n ${RESULTVERS}|sed -ne 's/^.*(\(.*\))$/(\1/g;/^[^(]/ d;s/^(//g;p')"
			RESULT=${RESULT% *}
		    fi
		    if [ -z "$RESULTVERS" ]; then
			RESULTVERS="$(echo -n ${vers}|sed -e 's/+b[0-9][0-9]*//g')"
		    fi
		fi
		if [ -n "$RESULT" ]; then
		    case $art in
			Homepage|Vcs-*)
			    binary_interstage 2
			    echo -n "<li><a href=\"$RESULT\">" >> $OP
			    case $art in
				Homepage)
				    echo -n "Project's homepage" >> $OP
				    ;;
				Vcs-*)
				    echo -n "${art#Vcs-} access to the packaging source repository" >> $OP
				    ;;
			    esac
			    echo "</a></li>" >> $OP
			    ;;
			Depends|Recommends|Suggests|Conflicts|Breaks|Provides)
			    binary_interstage 3
			    echo "<li>$art:<ul>" >> $OP
			    treat_dep "$RESULT" "$ARCH" >> $OP
			    echo "</ul></li>" >> $OP
			    ;;
			Maintainer|Source)
			    binary_interstage 4
			    if [ "$art" = "Maintainer" ]; then
				echo "<li>$art: $RESULT</li>" >> $OP
			    fi
			    if [ "$art" = "Source" ]; then
				if [ -f "txt/source%${RESULT}%${RESULTVERS}.txt" ]; then
				    
				    echo "<li>Source package: <a href=\"srcpkg.${RESULT}.html#version${RESULTVERS}\"\">${RESULT}</a></li>" >> $OP
				else
				    if [ $(grep "^${RESULT}%" txt/list.sources.txt | wc -l) -gt 0 ]; then
					echo "<li>Source package: <a href=\"srcpkg.${RESULT}.html\">${RESULT}</a> (version $RESULTVERS)</li>" >> $OP
				    else
					echo "<li>Source package: ${RESULT} (version $RESULTVERS)</li>" >> $OP
				    fi
				fi
			    fi
			    ;;
                        Section)
    			    binary_interstage 5
			    if [ "$art" = "Section" ]; then
				echo "<li>Debian's classification: $RESULT</li>" >> $OP
			    fi
                            ;;
                        Size)
                            LASTSIZE=$RESULT
                            ;;
                        MD5sum)
			    LASTMD=$RESULT
                            ;;
                        Filename)
			    binary_interstage 5
                            DISTS=$(grep "^${version} "<txt/release.binary.txt|cut -f2 -d' '|LANG=C sort -u)
	                    for dist in $DISTS; do
	                        INDIST="${INDIST} <a href=\"${dist}.html\">$dist</a>," || true
	                    done
	                    INDIST=${INDIST%,}
	                    echo "<li>Available in: $INDIST</li>" >> $OP
                            TITLE="MD5: $LASTMD, $LASTSIZE bytes"
  			    echo '<li>Download: <a rel="tooltip" title="'$TITLE'" href="../'$RESULT'">'$RESULT'</a></li>' >> $OP
                            ;;
		    esac
		fi
	    done
	done
        for stage in 2 3 4 5; do
            if [ -f txt/tmp.x.$stage ]; then
                for subarch in $(cat txt/tmp.x.$stage|LANG=C sort -u); do
                    if [ -f txt/tmp.$subarch.$stage ]; then
                        echo -n "$subarch:" >> txt/tmp.sum.$stage
                        md5sum < txt/tmp.$subarch.$stage|cut -c1-32 >> txt/tmp.sum.$stage
                    fi
                done
                for sum in $(cat txt/tmp.sum.$stage|cut -f2 -d:|LANG=C sort -u); do
                    subarches=""
                    firstarch=""
                    for subarch in $(grep ":$sum$" < txt/tmp.sum.$stage|cut -f1 -d:); do
                        subarches="${subarches}${subarch}, "
                        if [ -z "$firstarch" ]; then firstarch=$subarch; fi
                    done
                    subarches=${subarches%, }
                    if [ "$subarches" = "$NORMALARCHES" ]; then subarches="any"; fi
                    case $stage in
                        2)
                            card="Description"
                            ;;
                        3)
                            card="Package relationships"
                            ;;
                        4)
                            card="Package building"
                            ;;
                        5)
                            card="Archiving"
                            ;;
                    esac
                    begin_card "$card <small>${subarches}</small>"
                    echo '<ul>'
                    cat txt/tmp.$firstarch.$stage
                    echo '</ul>'
                    end_card
                done
            fi
        done
        last_card
        rm -rf txt/tmp.*
    done
}

header_html

echo "<h1>${binpkg} package</h1>"
treat_binarypackage

closer_html

template/release.html

#!/bin/sh
HOMEDIR=/data/debian
release=${1:-sid}

SOURCELESS=txt/list.${release}.sourceless
UNUSED=txt/list.${release}.unused
USED=txt/list.${release}.used

TOPURL=$release.html

ReleaseSuite=''
eval $(cat conf/distributions |sed -ne "/^Codename: $release/,/^\$/ p" |sed -n -e '/^$/ d' -e 's/^\(.*\): *\(.*\)$/Release\1="\2"/g;p')
NORMALARCHES=$(echo $ReleaseArchitectures|tr ' ' '\n'|LANG=C sort -u|egrep -v '(^source$)|(^$)')
NORMALARCHESCOUNT=$(echo "$NORMALARCHES"|wc -l)
XTITLE="$ReleaseCodename"
TITLE="$XTITLE"
[ -n "$ReleaseSuite" ] && XTITLE="$TITLE <small>($ReleaseSuite)</small>"
. $HOMEDIR/template/common
. $HOMEDIR/template/common-packages

DEBIANARCHIVEPATH=.

processRelease() {
    if [ ! -d "dists/$release" ]; then
        return
    fi
    TREATSOURCE=0
    if [ -n "$(echo $ReleaseArchitectures|grep source)" ]; then
	TREATSOURCE=1
    fi
    for component in $ReleaseComponents; do
	processComponent
    done
    touch txt/notsourceless_${release}.txt
    touch txt/list.binary_${release}.txt
    processBinarySourceRelations
    (cut -f1 -d% txt/list.binary_$release.txt|LANG=C sort -u;cat txt/notsourceless_${release}.txt txt/notsourceless_${release}.txt)|LANG=C sort| uniq -u > txt/sourceless_${release}
}

processComponent() {
    # This creates a list of all source and binary packages with version and arch info
    SOURCEFILE="${DEBIANARCHIVEPATH}/dists/${release}/${component}/source/Sources"
    LIST="txt/list.sources_${release}_${component}.txt"
    LISTRELEASE="txt/list.sources_${release}.txt"
    LISTALL="txt/list.sources.txt"
    COMPALL="txt/list.components.sources.txt"
    if [ $(stat -c%s "$SOURCEFILE") -gt 0 ]; then
	source_snippets $SOURCEFILE $LIST
    else
        touch $LIST
    fi
    if [ -f "$LIST" ]; then
        cat $LIST >> $LISTRELEASE
        cat $LIST >> $LISTALL
        sed -e 's/$/%'${release}%${component}'/g' < $LIST >> $COMPALL
    fi
    BLIST="txt/list.binary_${release}_${component}.txt"
    BLISTRELEASE="txt/list.binary_${release}.txt"
    BLISTALL="txt/list.binary.txt"
    touch $BLIST
    for arch in $NORMALARCHES; do
        PACKAGEFILE="${DEBIANARCHIVEPATH}/dists/${release}/${component}/binary-${arch}/Packages"
        if [ $(stat -c%s "$PACKAGEFILE") -gt 0 ]; then
            binary_snippets $PACKAGEFILE $BLIST
            echo "$arch" >> txt/used_arches.${release}_${component}
        fi
    done
    if [ -f "$BLIST" ]; then
        cat $BLIST >> $BLISTRELEASE
        cat $BLIST >> $BLISTALL
        sed -e 's/$/ '${release}'/g' $BLIST >> txt/release.binary.txt
    fi
}

processBinarySourceRelations() {
    cat txt/list.binary_${release}.txt | LANG=C sort -u | while read binpack; do
        if [ -f txt/binary%${binpack}.src ]; then
            SOURCE=$(cat txt/binary%${binpack}.src)
        else
            SOURCE=$(binary_info Source $binpack)
            if [ -z "$SOURCE" ]; then SOURCE=${binpack%[%]*}; fi
            if [ "${SOURCE#*%}" = "$SOURCE" ]; then V=${binpack#*%};SOURCE="${SOURCE}%${V%[%]*}"; fi
            echo "$SOURCE" > txt/binary%${binpack}.src
        fi
        grep -q "^${SOURCE}"'$' txt/list.sources_${release}.txt && echo "$binpack" >> txt/list.${release}.sourced && echo "$SOURCE $binpack"  >> ${USED}  || echo "${SOURCE} $binpack" >> ${SOURCELESS}
    done
    touch ${SOURCELESS}
    touch ${USED}
    (cut -f1 -d' ' ${USED};cat txt/list.sources_${release}.txt) | LANG=C sort | uniq -u |sed -e 's/$/ __none/g'> ${UNUSED}
    cat ${SOURCELESS} >> txt/list.sourceless
    cat ${USED} >> txt/list.used
}

processRelease










header_html
cat <<EOF
<div>
<h1>${XTITLE}</h1>
<p>To access this repository (compatible with Debian $release release), you should include the following lines in your <code>sources.list</code> file.</p>
EOF
echo -n "<pre>"
cat help/debian.dubacq.fr.$release.list
echo "</pre>"
cat <<EOF
<p>You can also download this file and save it into <code>/etc/apt/sources.list.d/debian.dubacq.fr.$release.list</code></p>
<p><a href="../help/debian.dubacq.fr.$release.list" class="btn btn-primary">Download this file &raquo;</a></p>
</div>
EOF
if [ -f template/release-$release ]; then
    cat template/release-$release
fi


components=$(find txt -name "used_arches.${release}_*")
rowspan=4
innerclass='" style="min-height:20ex;'
rowmodulo=$((12/rowspan))
beforetitle='<h2>'
aftertitle='</h2>'

# rowspan="6"
# innerclass="well"
# rowmodulo=1
# belowtitle='</div></div><div class="span6"><div>'
# beforetitle='<h4>'
# aftertitle='</h4>'

summary_release

closer_html

template/code.html

#!/bin/sh
HOMEDIR=/data/debian
TITLE="Home"
TOPURL="index.html"

. $HOMEDIR/template/common

EXTRA_HEADERS='<link href="../assets/js/google-code-prettify/prettify.css" rel="stylesheet">'
EXTRA_SCRIPT='<script src="../assets/js/bootstrap-tab.js"></script><script src="../assets/js/google-code-prettify/prettify.js"></script><script type="text/javascript">prettyPrint()</script>'
header_html
echo '<h1>Code that generates this site</h1>'
echo '<ul class="nav nav-tabs">'
x=buildsite
echo '<li class="active"><a href="#'$x'" data-toggle="tab">'$x'</a></li>'
for i in $(find template -type f); do
    x=$(basename "$i" .html)
    echo '<li><a href="#'$x'" data-toggle="tab">'$x'</a></li>'
done
echo '</ul>'
echo '<div class="tab-content">'
echo '<div class="tab-pane active" id="buildsite">'
echo '<h2>buildsite</h2>'
echo '<pre class="prettyprint lang-sh">'
cat < bin/buildsite
echo '</pre>'
echo '</div>'

for template in $(find template -type f); do
    x=$(basename "$template" .html)
    echo '<div class="tab-pane" id="'$x'">'
    echo "<h2>$template</h2>"
    echo '<pre class="prettyprint lang-sh">'
    sed -e 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' < $template
    echo '</pre>'
    echo '</div>'
done
echo '</div>'
closer_html

template/common

#!/bin/sh
SITEKEY=debian.dubacq.fr.key
SITENICK="debian.dubacq.fr"
URL="http://debian.dubacq.fr"
AUTHOR="Jean-Christophe Dubacq"
COPYRIGHT="&copy; $AUTHOR"
SITENAME="debian@jcdubacq"
TITLE="${TITLE}|${SITENAME}"

cdata() {
    echo "$@"|sed -e 's/&/\&amp;/g;s/"/\&quot;/g;s/</\&lt;/g;s/>/\&gt;/g'
}

navbar() {
 cat <<EOF
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="index.html">$(cdata $SITENAME)</a>
          <div class="nav-collapse collapse">
            <ul class="nav">
EOF
while read line; do
    text=${line#*:}
    link=${line%%:*}
    if [ "$link" = "$TOPURL" ]; then
        echo "<li class="'"'"active"'"'"><a href="'"'"$link"'"'">$text</a></li>"
    else
        echo "<li><a href="'"'"$link"'"'">$text</a></li>"
    fi
done < template/navbar
cat <<EOF
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>
EOF
    
}

header_html() {
    cat <<-EOF
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>$TITLE</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="$(cdata "$SITENAME")">
    <meta name="author" content="$(cdata "$AUTHOR")">
    <link href="../assets/css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
    </style>
    <link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
      <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
                    <link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
                                   <link rel="shortcut icon" href="../assets/ico/favicon.png">
${EXTRA_HEADERS}
  </head>
  <body>
EOF
navbar
echo '<div class="container">'

}
closer_html() {
cat <<-EOF
      <hr/>
      <footer>
      <p>This page was regenerated $(date +on\ %Y-%m-%d\ at\ %H:%M) by <a href="code.html">a bunch of scripts</a>. $COPYRIGHT</p>
      </footer>

    </div> <!-- /container -->
    <script src="../assets/js/jquery.js"></script>
    $EXTRA_SCRIPT
    <script src="../assets/js/bootstrap-transition.js"></script>
    <script src="../assets/js/bootstrap-alert.js"></script>
    <script src="../assets/js/bootstrap-tooltip.js"></script>
    <script src="../assets/js/bootstrap-button.js"></script>
    <script src="../assets/js/bootstrap-collapse.js"></script>
    <script src="../assets/js/site.js"></script>
  </body>
</html>

EOF
}
begin_card() {
    # begin_card TITLE [MORE CLASSES]
    # We expect defined: $count $rowspan $innerclass $rowmodulo $beforetitle $aftertitle
    if [ "$((count%rowmodulo))" = 0 ]; then
        echo -n '<div class="row">'
    fi
    echo '<div class="span'$rowspan'">'
    echo '<div class="'$2 $innerclass'">'
    echo "${beforetitle}${1}${aftertitle}"
    echo $belowtitle
}
end_card() {
    # We expect defined: $count $rowspan $innerclass $rowmodulo $beforetitle $aftertitle
    echo -n '</div>'
    echo -n '</div>'
    count=$((count+1))
    if [ "$((count%rowmodulo))" = 0 ]; then
        echo -n '</div>'
    fi
}
last_card() {
    if [ "$((count%rowmodulo))" -gt 0 ]; then
        echo -n '</div>'
    fi
    count=0
}

template/index.html

#!/bin/sh
HOMEDIR=/data/debian
TITLE="Home"
TOPURL="index.html"

. $HOMEDIR/template/common

header_html

cat <<EOF
<div>
<h1>Release security</h1>
<p>All these packages are signed with a gpg key. The key ID (4219112DFBEFB8A2) corresponds to the hosting system. This key is used only for this purpose.</p>
<p>if apt-get update gives you warning about an unverified key such as
<code>NO_PUBKEY 4219112DFBEFB8A2</code>, you can get it with (for
example):</p>
<pre>wget -O - ${URL}/help/$SITEKEY|sudo apt-key add -
# or by downloading from a PGP key server
gpg --keyserver wwwkeys.eu.pgp.net --recv-key 4219112DFBEFB8A2
gpg --export --armor 4219112DFBEFB8A2 | sudo apt-key add -</pre>

<p class="alert alert-block"><button type="button" class="close" data-dismiss="alert">&times;</button>
Note that you should really read the documentation about apt-key and
gpg if you are concerned (and you should) by security and you do not
understand what you do with the three lines above.</p>
<p>You should also install the <code>jcdubacq-archive-keyring</code> package from this repository, but you will run into the chicken-and-egg problem if you skip the above indications. This package will install a separate keyring in <code>/etc/apt/trusted.gpg.d/</code> and remove the key from your main keyring.</p>
<p><a href="../help/debian.dubacq.fr.key" class="btn btn-primary">Download the key &raquo;</a></p>
</div>
<div class="row">

<div class="span3">
EOF
TOPNEWS=$(find news|sort -nr|head -n 1)
TOPDATE=$(date -u --date='@'$(basename ${TOPNEWS}) +'%F %T')
sed -e '1 s|</h2>| <small>'"${TOPDATE}"'</small></h2>|g' < $TOPNEWS
cat <<EOF
<p><a class="btn" href="news.html">More news &raquo;</a></p>
</div>
<div class="span3">
<h2>Author</h2>
<p>Jean-Christophe Dubacq is a Debian user and system administrator since 1998.</p>
<p><a class="btn" href="author.html">View details &raquo;</a></p>
</div>

<div class="span3">
<h2>Releases</h2>
<p>This repository provides packages for three releases:</p>
<ul>
EOF
RELEASES=$(grep ^Codename: conf/distributions|cut -f2 -d:)
for release in $RELEASES; do
    components=$(find txt -name "used_arches.${release}_*")
    nbcomp=$(echo "$components"|wc -l)
    arches=$(echo "$components"|xargs --no-run-if-empty cat|LANG=C sort -u)
    nbarches=$(echo "$arches"|tr ' ' '\n'|wc -l)
    nbbopack=$(sort -u < txt/list.${release}.sourceless|wc -l)
    nbsopack=$(sort -u < txt/list.${release}.unused|wc -l)
    nbbpack=$(sort -u < txt/list.${release}.used|wc -l)
    nbspack=$(cut -f1 -d' '< txt/list.${release}.used|sort -u|wc -l)
    nbp=$((nbbopack+nbsopack+nbspack+nbbpack))
    if [ "$nbp" -gt 0 ]; then
        echo -n '<li><a href="'$release'.html">'$release'</a> ('
        (
            [ "$nbbpack" -gt 0 ]&&echo '<span class="badge">'$nbbpack'</span>'
            [ "$nbbopack" -gt 0 ]&&echo '<span class="badge badge-inverse">'$nbbopack'</span>'
            [ "$nbspack" -gt 0 ]&&echo '<span class="badge badge-success">'$nbspack'</span>'
            [ "$nbsopack" -gt 0 ]&&echo '<span class="badge badge-info">'$nbsopack'</span>'
        )|sed -e 's/$/+/g;$ s/+$//g'
            echo ' packages)</li>'
    else
        echo '<li><a href="'$release'.html">'$release'</a> (empty release)</li>'
    fi
done
cat <<EOF
</ul>
</div>
<div class="span3">
<h2>Packages</h2>
<p>Some information is extracted automatically from all packages stored in this repository.</p>
<p><a class="btn" href="packages.html">View details &raquo;</a></p>
</div>
</div>
EOF
closer_html

template/packages.html

#!/bin/sh
HOMEDIR=/data/debian
release=''

SOURCELESS=txt/list.sourceless
UNUSED=txt/list.unused
USED=txt/list.used
(cut -f1 -d' ' ${USED};cat txt/list.sources.txt) | LANG=C sort | uniq -u |sed -e 's/$/ __none/g'> ${UNUSED}

TITLE="Packages"
TOPURL=packages.html
. $HOMEDIR/template/common
. $HOMEDIR/template/common-packages

header_html

components=$(find txt -name "used_arches.*")
NORMALARCHES=$(echo "$components"|xargs cat|LANG=C sort -u)
rowspan=4
innerclass='" style="min-height:20ex;'
rowmodulo=$((12/rowspan))
beforetitle='<h2>'
aftertitle='</h2>'

# rowspan="6"
# innerclass="well"
# rowmodulo=1
# belowtitle='</div></div><div class="span6"><div>'
# beforetitle='<h4>'
# aftertitle='</h4>'


summary_release

closer_html

template/src.html

#!/bin/sh
HOMEDIR=/data/debian

SOURCELESS=txt/list.sourceless
UNUSED=txt/list.unused
USED=txt/list.used

pack="$1"
TITLE="${pack} source package"
TOPURL=packages.html
. $HOMEDIR/template/common
. $HOMEDIR/template/common-packages

rowspan=6
innerclass='" style="min-height:20ex;'
rowmodulo=$((12/rowspan))
beforetitle='<h3>'
aftertitle='</h3>'



header_html

echo "<h1>${pack} source package</h1>"
treat_sourcepackage

closer_html

template/common-packages

#!/bin/sh
binary_snippets() {
    perl -e 'while (<>) {unless (/^$/) {$pack=$1 if (/^Package: (.*)$/);$vers=$1 if (/^Version: (.*)$/);$arch=$1 if (/^Architecture: (.*)$/);$line.=$_;next;};open OUT,">txt/binary%$pack%$vers%$arch.txt";print OUT $line;close OUT;print "$pack%$vers%$arch\n";$line="";};' < $1 >> $2
}
source_snippets() {
    perl -e 'while (<>) {unless (/^$/) {$pack=$1 if (/^Package: (.*)$/);$vers=$1 if (/^Version: (.*)$/);$line.=$_;next;};open OUT,">txt/source%$pack%$vers.txt";print OUT $line;close OUT;print "$pack%$vers\n";$line="";};' < $1 >> $2
}
source_info() {
    grep "^$1: " "txt/source%$2.txt"|cut -f2- -d' '
}
source_list() {
    grep "^${1}: " "txt/source%$2.txt"|cut -f2- -d' '|sed -e 's/, / /g'
}
binary_info() {
    grep "^$1: " "txt/binary%$2.txt"|cut -f2- -d' '
}
binary_list() {
    grep "^${1}: " "txt/binary%$2.txt"|cut -f2- -d' '|sed -e 's/, / /g'
}
summary_binary() {
    srcpack="$1"
    binpack="$2"
    srccomp="$3"
    echo "$1 $2 $3" >> /tmp/b
    echo "${binpack}" >> txt/binpages
    ARCHES="";BINVERSIONS=""
    echo -n "" > txt/tmp
    rm -f txt/tmp.binversion
    cat ${USED} ${SOURCELESS} |grep "^$1 $2%"|LANG=C sort -u|cut -f2 -d' '|while read binpackage; do
        binarch=${binpackage##*%}
        withoutbinarch=${binpackage%[%]*}
        binversion=${withoutbinarch##*%}
        echo "$binversion" >> txt/tmp.binversion
        echo "$binarch" >> txt/tmp.binarch.$binversion
        binary_info Description $binpackage >> txt/tmp.description
        binary_info Section $binpackage|sed -e '/^[^/]*$/ s/^/main\//g;s/\/.*$//g'>> txt/tmp.component
    done
    tooltip=$(cat txt/tmp.description|LANG=C sort|uniq -c|LANG=C sort -nr|head -n 1|cut -c8-)
    if [ $(LANG=C sort -u txt/tmp.description|wc -l) -gt 1 ]; then tooltip="${tooltip} (there are other descriptions)"; fi
    tooltipOption='rel="tooltip" '
    if [ $((count%rowmodulo)) = 0 ]; then
        tooltipOption="${tooltipOption} data-placement=\"right\""
    else
        if [ $((count%rowmodulo)) = $((rowmodulo-1)) ]; then
            tooltipOption="${tooltipOption} data-placement=\"left\""
        fi
    fi
    echo -n '<li><a '${tooltipOption}'href="binpkg.'${binpack}'.html" title="'$(cdata "$tooltip")'">'$binpack'</a> '
    if [ "$(LANG=C sort -u < txt/tmp.binversion|wc -l)" -gt 1 ]; then
        for localversion in $(cat txt/tmp.binversion); do
            echo -n '<span class="label">['
            ARCHES=$(LANG=C sort -u < txt/tmp.binarch.$localversion)
            if [ "$ARCHES" = "$NORMALARCHES" ]; then
                echo "any"
            else
                echo "$ARCHES"
            fi
            echo -n "= ${localversion}"
            echo ']</span>'
        done
    else
        localversion=$(LANG=C sort -u < txt/tmp.binversion)
        echo -n '<span class="label">['
        ARCHES=$(LANG=C sort -u < txt/tmp.binarch.$localversion)
        if [ "$ARCHES" = "$NORMALARCHES" ]; then
            echo "any"
        else
            echo "$ARCHES"
        fi
        echo -n "= ${localversion}"
        echo ']</span>'
    fi
    BCOMPONENTS=$(LANG=C sort -u < txt/tmp.component)
    if [ "$BCOMPONENTS" != "$srccomp" ]; then
        echo ' in <b>'${BCOMPONENTS}'</b>'
    fi
    set +x
    rm -f txt/tmp.*
    return
}


summary_source() {
    # We expext defined: $pack
    VERSION=${pack#*%}
    if [ -f "txt/source%${pack}.txt" ]; then
        COMPALL="txt/list.components.sources.txt"
        if [ -z "${release}" ]; then
            xrelease=''
        else
            xrelease="${release}%"
        fi
        FULL=$(grep "^${pack}%${xrelease}" < $COMPALL|head -n 1)
        COMPONENT=${FULL##*[%]}
        echo '<li>Source version <span class="label label-success">'${VERSION}'</span> in <b>'${COMPONENT}'</b>'
    else
        COMPONENT=__unknown
        echo '<li>Source version <span class="label label-inverse">'${VERSION}'</span></b> <b>unavailable</b>'
    fi
    BINS=0
    for binpack in $(cat "${USED}" "${SOURCELESS}"|grep "^${pack} "|cut -f2 -d' '|cut -f1 -d%|LANG=C sort -u); do
        if [ "$BINS" = 0 ]; then echo ' for:<ul>'; BINS=1; fi
        summary_binary $pack $binpack "$COMPONENT"
    done
    if [ "$BINS" = 1 ]; then echo -n '</ul>'; else echo -n ' with no binary packages'; fi
    echo '</li>'
}

summary_release() {
    # We expect defined:
    # $components
    # $SOURCELESS
    # $USED
    # $UNUSED
    # $rowspan $innerclass $rowmodulo $beforetitle $aftertitle
    nbcomp=$(echo "$components"|wc -l)
    arches=$(echo "$components"|xargs --no-run-if-empty cat|LANG=C sort -u)
    nbarches=$(echo "$arches"|tr ' ' '\n'|wc -l)
    nbbopack=$(sort -u < ${SOURCELESS}|wc -l)
    nbsopack=$(sort -u < ${UNUSED}|wc -l)
    nbbpack=$(sort -u < ${USED}|wc -l)
    nbspack=$(cut -f1 -d' '< ${USED}|sort -u|wc -l)
    nbp=$((nbbopack+nbsopack+nbspack+nbbpack))
    count=0
    if [ "$nbp" -lt 1 ]; then
        echo '<h2>Activity</h2>'
        echo '<div class="alert alert-warning"><h4>Empty release!</h4><p>There are no packages of any sort in this release</p></div>'
        return
    fi
    begin_card 'Activity' 'well well-small'
    [ "$nbbpack" -gt 0 ] && echo '<li><span class="badge badge-success">'$nbspack'</span> source packages → <span class="badge">'$nbbpack'</span> binary packages</li>' 
    [ "$nbsopack" -gt 0 ] && echo '<li><span class="badge badge-info">'$nbsopack'</span> source packages without any binary packages</li>' 
    [ "$nbbopack" -gt 0 ] && echo '<li><span class="badge badge-inverse">'$nbbopack'</span> sourceless binary packages</li>' 
    echo -n '<li>'$nbcomp' components: '$(echo "$components"|sed -e 's/$/,/g;s/txt\/used_arches.\([a-z]*\)_\(.*\)$/\2/g;$ s/,$//g')'</li>'    
    echo -n '<li>'$nbarches' architectures: '$(echo "$arches"|sed -e 's/$/,/g;$ s/,$//g')'</li>'
    end_card
    SOURCEPACKAGES=$(cat ${USED} ${UNUSED} ${SOURCELESS}|LANG=C sort -u)
    for NAME in $(echo "$SOURCEPACKAGES"|cut -f1 -d'%'|LANG=C sort -u); do
        echo "$NAME" >> txt/srcpages
        VERSIONS=$(echo "$SOURCEPACKAGES"|cut -f1 -d' '|grep "^${NAME}%"|LANG=C sort -ur|sed -e 's/^.*%//g;s/$/,/g;$ s/,$//g')
        begin_card "${NAME} <small>${VERSIONS}</small>"
        echo '<ul class="unstyled">'
        for pack in $(echo "$SOURCEPACKAGES"|cut -f1 -d' '|grep "^${NAME}%"|LANG=C sort -ur); do
            summary_source
        done
        echo '</ul>'
        echo '<p><a class="btn" href="srcpkg.'${NAME}'.html">View details &raquo;</a></p>'
        end_card
    done
    if [ -z "${release}" ]; then
        begin_card Pool 'well well-small'
        echo '<p>This site is generated automatically from the pool, but you may prefer to inspect it directly.</p>'
        echo '<p><a class="btn" href="'${URL}'/pool/">View details &raquo;</a></p>'
        end_card
    fi
    last_card
}


source_interstage()  {
    set +e
    [ "$STAGE" -lt 1 ] && begin_card "Binary" && echo '<ul class="unstyled">'
    [ "$STAGE" -lt 2 ] && [ "$1" = 2 ] && echo "</ul>" && end_card && begin_card "Information" && echo '<ul class="unstyled">'
    [ "$STAGE" = 2 ] && [ "$1" -gt 2 ] && echo "</ul>" && end_card
    [ "$STAGE" -lt 3 ] && [ "$1" = 3 ] && begin_card "Compilation" && echo '<ul class="unstyled">'
    [ "$STAGE" = 3 ] && [ "$1" -gt 3 ] && echo "</ul>" && end_card
    [ "$STAGE" -lt 4 ] && [ "$1" = 4 ] && begin_card "Archiving" && echo '<ul class="unstyled">'
    [ "$STAGE" = 4 ] && [ "$1" -gt 4 ] && echo "</ul>" && end_card
    [ "$STAGE" -gt 0 ] && [ "$1" = 20 ] && echo "</ul>" && last_card
    set -e
    STAGE=$1
}
treat_dep() {
    RESULT="$1"
    IFS=","
    for b in $RESULT; do
	IFS="|"
	echo -n "<li>"
	second=
	for bb in $b; do
	    unset IFS
	    [ -z "$second" ] || echo " | "||true
	    second=1
	    bb="${bb#  }"
	    bb="${bb# }"
	    bbb="$bb"
	    bbb=${bb%% *}
	    adr=
	    if grep -q "^${bbb}%" txt/list.binary.txt; then
		adr="binpkg.${bbb}.html"
	    fi
	    if [ -z "$adr" ]&& grep -q "^${bbb}:" cache/binary%source; then
		sourcepack=$(grep "^${bbb}:" cache/binary%source|cut -f2 -d:|head -n 1)
		if [ "$sourcepack" != "unknown" ]; then
		    if [ "${sourcepack#lib}" != "${sourcepack}" ]; then
			adr="http://packages.qa.debian.org/${sourcepack%${sourcepack#????}}/${sourcepack}.html"
		    else
			adr="http://packages.qa.debian.org/${sourcepack%${sourcepack#?}}/${sourcepack}.html"
		    fi
		else
		    adr="unknown.html"
		fi
	    fi
	    if [ -z "$adr" ]; then
		if [ "${bbb#lib}" != "${bbb}" ]; then
		    pqdo="http://packages.qa.debian.org/${bbb%${bbb#????}}/${bbb}.html"
		else
		    pqdo="http://packages.qa.debian.org/${bbb%${bbb#?}}/${bbb}.html"
		fi
		a=$(curl -s "$pqdo"|grep '\(head\)\|\(looked for\)')
		if [ "$(echo $a|grep 404|wc -l)" -gt 0 ]; then
		    if [ "$(echo $a|grep looked|wc -l)" -gt 0 ]; then
			sourcepack=$(echo $a|cut -f2 -d\`| cut -f1 -d\')
			echo "$bbb:$sourcepack">> cache/binary%source
			if [ "${sourcepack#lib}" != "${sourcepack}" ]; then
			    adr="http://packages.qa.debian.org/${sourcepack%${sourcepack#????}}/${sourcepack}.html"
			else
			    adr="http://packages.qa.debian.org/${sourcepack%${sourcepack#????}}/${sourcepack}.html"
			fi
		    else
			adr="unknown.html"
			echo "$bbb:unknown">> cache/binary%source
		    fi
		else
		    adr="$pqdo"
		    echo "$bbb:$bbb">> cache/binary%source
		fi
#	    adr="http://packages.debian.org/search?keywords=${bbb}&amp;searchon=names&amp;exact=1&amp;suite=all&amp;section=all"
	    fi
	    if [ "$adr" = "unknown.html" ]; then
		echo -n "$bbb"
	    else
		echo -n "<a href=\"$adr\">$bbb</a>"
	    fi
	    if [ "$bbb" != "$bb" ]; then
		bbc=${bb#* }
		echo -n " $bbc"
	    fi
	done
	echo "</li>"
    done
    unset IFS
}
treat_sourcepackage() {
    VERSIONS=0
    for version in $(grep ^${pack}% txt/list.sources.txt|LANG=C sort -u); do
	VERSION=$(source_info Version $version)
        COMPONENT=$(grep < txt/list.components.sources.txt "^${pack}%${VERSION}%" |cut -f4 -d%|LANG=C sort -u)
	echo "<h2 id=\"version${VERSION}\">Version ${VERSION}</h2>"
	STAGE=0
	for art in Binary Homepage Maintainer $(grep "^Vcs-" "txt/source%$version.txt"|cut -f1 -d:|LANG=C sort -u) Format Standards-Version Architecture Build-Depends Build-Depends-Indep  Section Directory; do 
	    RESULT=$(source_info $art $version)
	    if [ -n "$RESULT" ]; then
		case $art in
                    Binary)
			source_interstage 1
			BINARY=$(cat ${USED}|grep "^${pack}%${VERSION} "|cut -f2 -d' '|cut -f1 -d%|LANG=C sort -u)
                        BIN=0
			for binpack in $BINARY; do
                            if [ "$BIN" = 0 ]; then
                                BIN=1
                            fi
			    summary_binary "${pack}%${VERSION}" $binpack "${COMPONENT}"
			done
                        if [ "$BIN" != 1 ]; then
                            echo '<li>No binary packages!</li>'
                        fi
			;;
		    Homepage|Vcs-*)
			source_interstage 2
			echo -n "<li><a href=\"$RESULT\">"
			case $art in
			    Homepage)
				echo -n "Project's homepage"
				;;
			    Vcs-*)
				echo -n "${art#Vcs-} access to the packaging source repository"
				;;
			esac
			echo "</a></li>"
			;;
		    Maintainer|Format|Standards-Version)
			source_interstage 2
			case "$art" in
			    Maintainer)
				tagline="Debian package maintainer"
				;;
			    *)
				tagline="$art"
				;;
			esac
			echo "<li>$tagline: $RESULT</li>"
			;;
		    Architecture)
			source_interstage 3
			echo "<li>$art: $RESULT</li>"
			;;
		    Build-Depends*)
			source_interstage 3
			echo "<li>$art:<ul>"
			treat_dep "$RESULT" 'noarch'
			echo "</ul></li>"
			;;
		    Section)
			source_interstage 4
			echo "<li>$art: $RESULT</li>"
			;;
		    Directory)
			source_interstage 4
			POOLADR="${URL}/${DEBIANARCHIVEURL}/${RESULT}"
			echo "<li>Pool location: <a href=\"${POOLADR}\">${RESULT}</a></li>"
			;;
		    *)
			echo "<li>$art: $RESULT</li>"
			;;
		esac
	    fi
	done
	source_interstage 4
        DISTS=$(grep < txt/list.components.sources.txt "^${version}%"|cut -f3 -d%)
	for dist in $DISTS; do
	    INDIST="${INDIST} <a href=\"${dist}.html\">$dist</a>," || true
	done
	INDIST=${INDIST%,}
	echo "<li>Available in: $INDIST</li>"
	SUBPOOLADR=$(echo -n "${POOLADR}"|sed -e 's/\//\\\//g')
	cat txt/source%${version}.txt |sed -ne '/^Files:/,/^[^ ]/ b lab' -e 'd' -e ':lab' -e '/^[^ ]/ d' -e 's/^ \([a-f0-9]*\) \([0-9]*\) \(.*\)$/<li><a rel="tooltip" title="MD5: \1, \2 bytes" href="__XXX__\/\3">\3<\/a><\/li>/g' -e "s/__XXX__/${SUBPOOLADR}/g" -e 'p'
	source_interstage 20
        VERSIONS=1
    done
    if [ "$VERSIONS" = 0 ]; then
        echo '<div class="alert">No version of this source package is available. in this repository.</div>'
        echo '<p>You may be interested in the pages of the following binary packages that all use this (hypothetical) source package:</p><ul>'
        for binpack in $(grep < txt/list.sourceless "^${pack}%" | cut -f2 -d' '|cut -f1 -d'%'|LANG=C sort -u); do
            echo '<li><a href="binpkg.'${binpack}'.html">'${binpack}'</a></li>'
        done
    fi
}

template/news.html

#!/bin/sh
HOMEDIR=/data/debian

SOURCELESS=txt/list.sourceless
UNUSED=txt/list.unused
USED=txt/list.used

binpkg="$1"
TITLE="${binpkg} binary package"
TOPURL=packages.html
. $HOMEDIR/template/common

components=$(find txt -name "used_arches.*")
NORMALARCHES=$(echo "$components"|xargs cat|LANG=C sort -u|tr '\n' ' '|sed -e 's/ /, /g;s/, $//g')

count=0
rowspan=6
innerclass='" style="min-height:10ex;'
rowmodulo=$((12/rowspan))
beforetitle=''
aftertitle=''

header_html

echo "<h1>News from the repositories</h1>"
for TOPNEWS in $(find news -type f|sort -nr); do
    TOPDATE=$(date -u --date='@'$(basename ${TOPNEWS}) +'%F %T')
    begin_card ''
    sed -e '1 s|</h2>| <small>'"${TOPDATE}"'</small></h2>|g' < $TOPNEWS
    end_card
done
last_card

closer_html

template/release-squeeze

<p class="alert">This distribution may also contain packages that compile only for squeeze-backports. In this case, you will need to use backports from <a href=\"http://backports.debian.org\">Debian backports</a>.</p>

template/author.html

#!/bin/sh
HOMEDIR=/data/debian
TITLE="About"
TOPURL="author.html"

. $HOMEDIR/template/common

header_html

cat <<EOF
<div>
<h1>Administrator of this repository</h1>
<p>Jean-Christophe Dubacq is a Debian user and system administrator since 1998...</p>
<blockquote>
<p>I discovered Debian during my military service at École polytechnique (France). I had the duty of system administration in a place that had only been cared about by cheap young guys (like me) for a few years. The system was a total mess, combining a mix of bo and hamm Debian releases with workstations mostly running Linux.</p>
<p>Before that (and for a little time after that), I had used SunOs 4 and 5 (renamed Solaris) and took care of students-managed software at École normale supérieure de Lyon with a bunch of friends. That was a good place to learn Debian, apparently, since many alumni became Debian Developers later.</p>
<p>I am now tenured assistant professor in computer science (French <i>maître de conférences</i>) at University <i>Paris Nord / Paris 13</i>. My field of work is large-scale distributed computing. After managing the client installs for a few years in the computer science laboratory, and a few servers with that, I left that in the hands of people with more time than me for these tasks. I am therefore moving my own collection of packages to this repository.</p>
</blockquote>
<div class="row">
<div class="span3">
<h2>Security</h2>
<p>Since I use the packages myself, I do have a strong commitment to keep these packages as safe as possible.</p>
<p>Please send me an email if you discover anything of concern in these packages.</p>
</div>
<div class="span3">
<h2>Access</h2>
<p>This server is behind an ADSL line. A fast one, but this is just ADSL, with A standing for <i>Asymetric</i>. This means that is not that fast. This server is located in Paris, France.</p>
</div>
<div class="span3">
<h2>GPG</h2>
<p>My GPG public key is pub 1024D/38D092B4 2006-03-15, and the fingerprint is 080F 4FC3 E825 0080 207D 4464 90CD 8287 38D0 92B4, but you do not have to trust this page on that matter.</p>
</div>
<div class="span3">
<h2>This site</h2>
<p>This site is built upon <a href="http://twitter.github.com/bootstrap/index.html">Bootstrap</a> by <a href="code.html">a bunch of scripts</a>. It is a static site rebuilt after each upload. The scripts are mine and available under a BSD licence.</p>
</div>
</div>
EOF
closer_html