2 rcsid='$MirOS: contrib/hosted/tg/deb/mkdebidx.sh,v 1.47 2011/04/27 12:59:06 tg Exp $'
4 # Copyright (c) 2008, 2009, 2010, 2011
5 # Thorsten Glaser <tg@mirbsd.org>
7 # Provided that these terms and disclaimer and all copyright notices
8 # are retained or reproduced in an accompanying document, permission
9 # is granted to deal in this work without restriction, including un-
10 # limited rights to use, publicly perform, distribute, sell, modify,
11 # merge, give away, or sublicence.
13 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14 # the utmost extent permitted by applicable law, neither express nor
15 # implied; without malicious intent or gross negligence. In no event
16 # may a licensor, author or contributor be held liable for indirect,
17 # direct, other damage, loss, or other issues arising in any way out
18 # of dealing in the work, even if advised of the possibility of such
19 # damage or existence of a defect, except proven that it results out
20 # of said person's immediate fault when using the work as intended.
22 set -A normarchs -- i386
24 # either '' (locally) or 'remsign user@host.domain.com' (remote ssh)
26 repo_origin='The MirOS Project'
28 repo_title='MirDebian “WTF” Repository'
29 function repo_description {
32 print -nr -- "WTF ${suite_nick} Repository"
36 set -A dpkgarchs -- alpha amd64 arm armeb armel armhf avr32 hppa \
37 i386 ia64 kfreebsd-amd64 kfreebsd-i386 lpia m32r m68k mips mipsel \
38 powerpc powerpcspe ppc64 s390 s390x sh3 sh3eb sh4 sh4eb sparc
44 ssh -fNM -o ControlPath=$tmpfnm "$target"
45 ssh -o ControlPath=$tmpfnm "$target" cat \>$tmpfnm
46 ssh -o ControlPath=$tmpfnm -t "$target" "$* $tmpfnm" 0<&2 1>&2
48 ssh -o ControlPath=$tmpfnm "$target" "cat $tmpfnm.sig; rm -f $tmpfnm $tmpfnm.sig"
49 ssh -o ControlPath=$tmpfnm "$target" -O exit
54 tee $1 | gzip -n9 >$1.gz
60 if [[ $u = -u ]]; then
71 # DJB cdb hash (not via stdio, for speed)
72 typeset -Z11 -Uui16 Lcdbhash_result
73 function Lcdbhash_add {
75 typeset -i i=0 n=${#s}
78 ((# Lcdbhash_result = (Lcdbhash_result * 33) ^ 1#${s:(i++):1} ))
87 rm -f dpkg_578162_workaround
90 dpkgarchl=:all:"${dpkgarchs[*]}":
95 suites=:dists/$suite$suites
99 for suite in dists/*; do
100 allsuites="$allsuites${allsuites:+ }${suite##*/}"
101 [[ $suites = : || $suites = *:"$suite":* ]] || continue
104 suitearchs=${archs:-${normarchs[*]}}
105 components=Components:
106 for dist in $suite/*; do
107 [[ -d $dist/. ]] || continue
108 rm -rf $dist/binary-* $dist/source
110 [[ -s $dist/override.file ]] && ovf=$dist/override.file
111 [[ -s $dist/override.extra ]] && oef="-e $dist/override.extra"
112 [[ -s $dist/override.src ]] && osf="-s $dist/override.src"
113 components="$components ${dist##*/}"
115 [[ -s $dist/distinfo.sh ]] && . $dist/distinfo.sh
116 set -A distarchs -- $(sortlist -u all ${archs:-$suitearchs})
117 IFS=:; distarchl=:"${distarchs[*]}":; IFS=$saveIFS
118 for arch in $(sortlist -u ${distarchs[*]} ${dpkgarchs[*]}); do
119 if [[ $dpkgarchl != *:"$arch":* ]]; then
120 print -u2 "Invalid arch '$arch' in $dist"
122 elif [[ $distarchl != *:"$arch":* ]]; then
123 print "\n===> Linking all =>" \
124 "${dist#dists/}/$arch/Packages"
125 ln -s binary-all $dist/binary-$arch
127 print "\n===> Creating" \
128 "${dist#dists/}/$arch/Packages\n"
129 mkdir -p $dist/binary-$arch
130 dpkg-scanpackages $oef -m -a $arch \
132 putfile $dist/binary-$arch/Packages
135 print "\n===> Creating ${dist#dists/}/Sources"
136 mkdir -p $dist/source
137 [[ -e dpkg_578162_workaround ]] || (dpkg-scansources $oef $osf \
138 $dist $ovf || touch dpkg_578162_workaround) | \
139 putfile $dist/source/Sources
140 [[ -e dpkg_578162_workaround ]] && dpkg-scansources $osf \
142 putfile $dist/source/Sources
145 print "\n===> Creating ${suite#dists/}/Release.gpg"
146 rm -f $suite/Release*
148 Origin: ${repo_origin}
151 Codename: ${suite##*/}
153 Architectures: all ${dpkgarchs[*]} source
155 Description: $(repo_description "$nick")
162 for n in Contents-* */{binary-*,source}/{Packag,Sourc}es*; do
163 [[ -f $n ]] || continue
164 # realpath-ise $n and cache the checksum
166 #XXX once mksh can, use associative arrays instead
169 # simple hash collision solver by increment
170 nc=${cache_fn[Lcdbhash_result]}
171 while [[ -n $nc && $nc != "$nn" ]]; do
172 nc=${cache_fn[++Lcdbhash_result]}
174 if [[ $nc = "$nn" ]]; then
175 nm=${cache_md5[Lcdbhash_result]}
176 ns=${cache_size[Lcdbhash_result]}
178 set -A x -- $(md5sum "$nn")
180 ns=$(stat -c '%s' "$nn")
181 cache_md5[Lcdbhash_result]=$nm
182 cache_size[Lcdbhash_result]=$ns
183 cache_fn[Lcdbhash_result]=$nn
186 done) >$suite/Release
187 $gpg_remote gpg -u $repo_keyid -sb <$suite/Release >$suite/Release.gpg
190 print "\n===> Creating debidx.htm\n"
194 integer nsrc=0 nbin=0 nrpl=0
197 # syntax: ${suitename}/${distname}/${pN}/${pp} <suite>
198 # example: sid/wtf/openntpd/i386 lenny
199 if [[ -s mkdebidx.lnk ]]; then
201 [[ $pn = '#'* ]] && continue
202 if [[ $pn != +([a-z0-9_])/+([a-z0-9_-])/+([!/])/@(%|=|+([a-z0-9])) || \
203 $pd != +([a-z0-9_]) ]]; then
204 print -u2 "Invalid lnk line '$pn' '$pd'"
212 for suite in dists/*; do
213 for dist in $suite/*; do
214 [[ -d $dist/. ]] || continue
215 suitename=${suite##*/}
216 if [[ $suitename != +([a-z0-9_]) ]]; then
217 print -u2 "Invalid suite name '$suitename'"
221 if [[ $distname != +([a-z0-9_-]) ]]; then
222 print -u2 "Invalid dist name '$distname'"
226 gzip -dc $dist/source/Sources.gz |&
227 pn=; pv=; pd=; pp=; Lf=
228 while IFS= read -pr line; do
231 if [[ -n $Lf ]]; then
238 pn=${line##Package:*([ ])}
242 pv=${line##Version:*([ ])}
246 pd=${line##Binary:*([ ])}
250 pp=${line##Directory:*([ ])}
257 if [[ -n $pn && -n $pv && -n $pd && -n $pp ]]; then
259 while (( i < nsrc )); do
260 [[ ${sp_name[i]} = "$pn" && \
261 ${sp_dist[i]} = "$distname" ]] && break
264 if (( i == nsrc )); then
269 eval pvo=\$\{sp_ver_${suitename}[i]\}
270 eval ppo=\$\{sp_dir_${suitename}[i]\}
274 #sp_suites[i]="${sp_suites[i]} $suitename"
276 x=${suitename}/${distname}/${pn}/source
278 while (( j < nrpl )); do
279 [[ ${preplsrc[j]} = "$x" ]] && break
282 (( j < nrpl )) && pv="${pv}
\1afrom ${prepldst[j]}"
284 eval sp_ver_${suitename}[i]='${pvo:+$pvo,}$pv'
285 eval sp_dir_${suitename}[i]='${ppo:+$ppo,}$pp/'
286 sp_desc[i]=${sp_desc[i]},$pd
288 pn=; pv=; pd=; pp=; Lf=
293 gzip -dc $(for f in $dist/binary-*/Packages.gz; do
294 [[ -e $f ]] || continue
297 pn=; pv=; pd=; pp=; pN=; pf=; Lf=
298 while IFS= read -pr line; do
301 if [[ -n $Lf ]]; then
308 pN=${line##Package:*([ ])}
312 pn=${line##Source:*([ ])}
317 pv=${line##Version:*([ ])}
321 pd=${line##Description:*([ ])}
324 pp=${line##Architecture:*([ ])}
328 pf=${line##Filename:*([ ])}
335 if [[ $pf = *:* || $pf = *'%'* ]]; then
336 print -u2 Illegal character in $dist \
337 packages $pp "'Filename: $pf'"
340 [[ -n $pn ]] || pn=$pN
341 if [[ -n $pn && -n $pv && -n $pd && -n $pp ]]; then
343 while (( i < nbin )); do
344 [[ ${bp_disp[i]} = "$pN" && ${bp_desc[i]} = "$pd" && \
345 ${bp_dist[i]} = "$distname" ]] && break
348 (( i == nbin )) && let nbin++
352 #bp_suites[i]="${bp_suites[i]} $suitename"
354 x=${suitename}/${distname}/${pN}/${pp}
356 while (( j < nrpl )); do
357 [[ ${preplsrc[j]} = "$x" ]] && break
360 (( j < nrpl )) && pv="from ${prepldst[j]}"
362 [[ -n $pf ]] && pv="<a href=\"$pf\">$pv</a>"
364 eval x=\${bp_ver_${suitename}[i]}
365 [[ $br$x$br = *"$br$pv$br"* ]] || x=$x${x:+$br}$pv
366 eval bp_ver_${suitename}[i]=\$x
369 pn=; pv=; pd=; pp=; pN=; pf=; Lf=
377 <?xml version="1.0"?>
\r
378 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
379 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
380 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
381 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
382 <meta name="MSSmartTagsPreventParsing" content="TRUE" />
384 print -r -- " <title>${repo_title} Index</title>"
386 <meta name="generator" content="$MirOS: contrib/hosted/tg/deb/mkdebidx.sh,v 1.47 2011/04/27 12:59:06 tg Exp $" />
387 <style type="text/css">
389 border: 1px solid black;
390 border-collapse: collapse;
395 border: 1px solid black;
400 border: 1px solid black;
405 background-color: #000000;
409 border: 1px solid #999999;
414 background-color: #CCCCCC;
417 background-color: #666666;
422 background-color: #999999;
429 print -r -- "<h1>${repo_title}</h1>"
431 <p><a href="dists/">Browse</a> the repository or read about how to amend <a
432 href="sources.txt">/etc/apt/sources.list</a> in order to use it.
434 [[ -s 0-NOTE.txt ]] && print ' Also read my <a href="0-NOTE.txt">notes</a>.'
436 This repository uses <a
437 href="http://pgpkeys.pca.dfn.de/pks/lookup?search=${repo_keyid}&op=vindex">${repo_keyid}</a>
444 allsuites=$(for suitename in $allsuites; do
448 for suitename in $allsuites; do
449 suite=dists/$suitename
451 print -n " <li>${suite##*/}: <a href=\"$suite/\">$desc</a> (dists:"
452 for dist in $suite/*; do
453 [[ -d $dist/. ]] || continue
455 print -n " <a href=\"$suite/$distname/\">$distname</a>"
460 print "<h2>Packages</h2>"
461 print "<table width=\"100%\"><thead>"
462 print "<tr class=\"tablehead\">"
463 print " <th class=\"tableheadcell\">dist</th>"
464 print " <th class=\"tableheadcell\" rowspan=\"2\">Binary / Description</th>"
465 for suitename in $allsuites; do
466 print " <th class=\"tableheadcell\" rowspan=\"2\">$suitename</th>"
468 print "</tr><tr class=\"tablehead\">"
469 print " <th class=\"tableheadcell\">package name</th>"
470 print "</tr></thead><tbody>"
474 while (( i < nbin )); do
475 print $i ${bp_disp[i++]} #${bp_suites[i]}
477 while read -p num rest; do
478 bp_sort[${#bp_sort[*]}]=$num
482 while (( i < nsrc )); do
483 print $i ${sp_name[i++]}
485 while read -p num rest; do
486 print "\n<!-- sp #$num = ${sp_name[num]} -->"
487 print "<tr class=\"srcpkgline\">"
488 print " <td class=\"srcpkgdist\">${sp_dist[num]}</td>"
490 for x in $(tr ', ' '\n' <<<"${sp_desc[num]}" | sort -u); do
491 [[ -n $x ]] && pd="$pd, $x"
493 print " <td rowspan=\"2\" class=\"srcpkgdesc\">${pd#, }</td>"
494 for suitename in $allsuites; do
495 eval pvo=\${sp_ver_${suitename}[num]}
496 eval ppo=\${sp_dir_${suitename}[num]}
501 (( ${#pva[*]} )) || pva[0]=
504 while (( i < ${#pva[*]} )); do
507 if [[ $pv = *"
\1a"* ]]; then
513 if [[ -z $pv ]]; then
516 x=${suitename}/${sp_dist[num]}/${sp_name[num]}/%
518 while (( j < nrpl )); do
519 [[ ${preplsrc[j]} = "$x" ]] && break
522 (( j < nrpl )) && pv=${prepldst[j]}
524 elif [[ $pp != ?(/) ]]; then
525 pv="<a href=\"$pp${sp_name[num]}_${pvdsc##+([0-9]):}.dsc\">$pv</a>"
527 [[ $pp != ?(/) ]] && pv="<a href=\"$pp\">[dir]</a> $pv"
528 y=${y:+"$y<br />"}$pv
531 print " <td rowspan=\"2\" class=\"srcpkgitem\">$y</td>"
533 print "</tr><tr class=\"srcpkgline\">"
534 print " <td class=\"srcpkgname\">${sp_name[num]}</td>"
537 while (( k < nbin )); do
538 (( (i = bp_sort[k++]) < 0 )) && continue
539 [[ ${bp_name[i]} = "${sp_name[num]}" && \
540 ${bp_dist[i]} = "${sp_dist[num]}" ]] || continue
542 #print "<!-- bp #$i for${bp_suites[i]} -->"
543 print "<!-- bp #$i -->"
544 print "<tr class=\"binpkgline\">"
545 print " <td class=\"binpkgname\">${bp_disp[i]}</td>"
546 print " <td class=\"binpkgdesc\">${bp_desc[i]}</td>"
547 for suitename in $allsuites; do
548 eval pv=\${bp_ver_${suitename}[i]}
549 if [[ -z $pv ]]; then
552 x=${suitename}/${sp_dist[num]}/${sp_name[num]}/%
554 while (( j < nrpl )); do
555 [[ ${preplsrc[j]} = "$x" ]] && break
558 (( j < nrpl )) && pv=${prepldst[j]}
561 print " <td class=\"binpkgitem\">$pv</td>"
568 for i in ${bp_sort[*]}; do
569 (( i < 0 )) && continue
571 print "\n<!-- sp ENOENT -->"
572 print "<tr class=\"srcpkgline\">"
573 print " <td class=\"srcpkgname\">~ENOENT~</td>"
574 print " <td class=\"srcpkgdesc\">binary" \
575 "packages without a matching source package</td>"
576 for suitename in $allsuites; do
577 print " <td class=\"srcpkgitem\">-</td>"
582 #print "<!-- bp #$i for${bp_suites[i]} -->"
583 print "<!-- bp #$i -->"
584 print "<tr class=\"binpkgline\">"
585 print " <td class=\"binpkgdist\">${bp_dist[i]}</td>"
586 print " <td rowspan=\"2\" class=\"binpkgdesc\">${bp_desc[i]}</td>"
587 for suitename in $allsuites; do
588 eval pv=\${bp_ver_${suitename}[i]}
589 if [[ -z $pv ]]; then
592 x=${suitename}/${bp_dist[num]}/${bp_disp[num]}/=
594 while (( j < nrpl )); do
595 [[ ${preplsrc[j]} = "$x" ]] && break
598 (( j < nrpl )) && pv=${prepldst[j]}
601 print " <td rowspan=\"2\" class=\"binpkgitem\">$pv</td>"
603 print "</tr><tr class=\"binpkgline\">"
604 print " <td class=\"binpkgname\">${bp_disp[i]}</td>"
612 <p>• <a href="http://validator.w3.org/check/referer">Valid XHTML/1.1!</a>
613 • <small>Generated on $(date -u +'%F %T') by <tt
614 style="white-space:pre;">$rcsid</tt></small> •</p>