cookutils view lighttpd/index.cgi @ rev 1090

Working with "i486", "x86_64" and "any" architecture; post-check with badges; new icons, tag cloud, and other improvements
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Nov 24 13:28:02 2018 +0200 (2018-11-24)
parents 01e5c3e760d7
children c0b06e1eb456
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI + Lighttpd web interface.
4 #
6 # Make request URI relative to the script name
7 base="$(dirname "$SCRIPT_NAME")"; [ "$base" == '/' ] && base=''
8 REQUEST_URI=$(echo "$REQUEST_URI" | sed "s|^$base/*|/|; s|\?.*||")
10 # Split the URI request to /pkg/cmd/arg
11 export pkg=$(echo "$REQUEST_URI" | cut -d/ -f2)
12 export cmd=$(echo "$REQUEST_URI" | cut -d/ -f3)
13 export arg=$(echo "$REQUEST_URI" | sed 's|^/[^/]*/[^/]*/||')
16 . /usr/lib/slitaz/httphelper.sh
18 case $QUERY_STRING in
19 *debug*)
20 debug='yes'
21 QUERY_STRING="$(echo "$QUERY_STRING" | sed 's|debug||; s|^&||; s|&&|\&|; s|&$||')"
22 ;;
23 esac
25 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
26 [ -f "./cook.conf" ] && . ./cook.conf
27 wok="$WOK"
28 title=${title:-SliTaz Cooker}
29 # Cooker DB files.
30 activity="$CACHE/activity"
31 commits="$CACHE/commits"
32 cooklist="$CACHE/cooklist"
33 cookorder="$CACHE/cookorder"
34 command="$CACHE/command"; touch $command
35 blocked="$CACHE/blocked"
36 broken="$CACHE/broken"
37 cooknotes="$CACHE/cooknotes"
38 cooktime="$CACHE/cooktime"
39 wokrev="$CACHE/wokrev"
40 webstat="$CACHE/webstat" # note, file should be previously created with write permissions for www
41 splitdb="$CACHE/split.db"
42 maintdb="$CACHE/maint.db"
43 repologydb="$CACHE/repology.db" # note, file should be previously created with write permissions for www
45 # Path to markdown to html convertor
46 cmark_opts='--smart -e table -e strikethrough -e autolink -e tagfilter'
47 if [ -n "$(which cmark 2>/dev/null)" ]; then
48 md2html="$(which cmark) $cmark_opts"
49 elif [ -x "./cmark" ]; then
50 md2html="./cmark $cmark_opts"
51 elif [ -n "$(which sundown 2>/dev/null)" ]; then
52 md2html=$(which sundown)
53 elif [ -x "./sundown" ]; then
54 md2html="./sundown"
55 fi
60 # Search form redirection
61 if [ -n "$(GET search)" ]; then
62 echo -e "HTTP/1.1 301 Moved Permanently\nLocation: $base/$(GET q)\n\n"
63 exit 0
64 fi
67 # Show the running command and its progression
69 running_command() {
70 state="$(cat $command)"
71 local pct=''
72 if [ -n "$state" ];then
73 echo -n "$state</td></tr><tr><td>Completion</td>"
74 set -- $(grep "^$state" $cooktime)
75 [ -n "$1" -a $2 -ne 0 ] && pct=$((($(date +%s)-$3)*100/$2))
76 [ -n "$pct" ] && max="max='100'"
77 echo -n "<td><progress id='gauge' $max value='$pct' title='Click to stop updating' onclick='stopUpdating()'>"
78 echo -n "</progress> <span id='pct'>${pct:-?}%</span>"
79 [ "$2" -gt 60 ] &&
80 echo -n "</td></tr><tr><td>Estimated end time</td><td>$(date +%H:%M -ud @$(($2+$3)))"
81 else
82 echo 'not running'
83 fi
84 }
87 # HTML page header
89 page_header() {
90 local theme t='' css pretitle='' command
91 theme=$(COOKIE theme)
92 [ "$theme" == 'default' ] && theme=''
93 [ -n "$theme" ] && theme="-$theme"
94 css="cooker$theme.css"
96 if [ -n "$pkg" ]; then
97 case "$pkg" in
98 ~) if [ -z "$cmd" ]; then pretitle="Tag cloud - "; else pretitle="Tag \"$cmd\" - "; fi;;
99 %) if [ -z "$cmd" ]; then pretitle="Badges - "; else pretitle="Badge \"$cmd\" - "; fi;;
100 *) pretitle="$pkg - ";;
101 esac
102 else
103 command="$(cat $command)"
104 [ -n "$command" ] && pretitle="$command - "
105 fi
106 [ -z "$favicon" ] && favicon='/slitaz-cooker.png'
108 echo -e 'Content-Type: text/html; charset=UTF-8\n'
110 cat <<EOT
111 <!DOCTYPE html>
112 <html lang="en">
113 <head>
114 <title>$pretitle$title</title>
115 <link rel="stylesheet" href="/$css">
116 <link rel="icon" type="image/png" href="$favicon">
117 <link rel="search" href="$base/os.xml" title="$title" type="application/opensearchdescription+xml">
118 <!-- mobile -->
119 <meta name="viewport" content="width=device-width, initial-scale=1.0">
120 <meta name="theme-color" content="#222">
121 <!-- rss -->
122 <link rel="alternate" type="application/rss+xml" title="$title Feed" href="?rss">
123 <script>
124 // Get part of the main page
125 function getPart(part) {
126 var partRequest = new XMLHttpRequest();
127 partRequest.onreadystatechange = function() {
128 if (this.readyState == 4 && this.status == 200) {
129 response = this.responseText;
130 var partElement = document.getElementById(part);
131 if (response !== null) partElement.innerHTML = response;
132 }
133 };
134 partRequest.open('GET', '?part=' + part, true);
135 partRequest.responseType = '';
136 partRequest.send();
137 }
138 </script>
139 </head>
140 <body>
141 <div id="container">
142 <header>
143 <h1><a href="$base/">$title</a></h1>
144 <div class="network">
145 <a href="http://www.slitaz.org/">Home</a>
146 <a href="http://bugs.slitaz.org/">Bugs</a>
147 <a href="http://hg.slitaz.org/wok-next/">Hg</a>
148 <a href="http://roadmap.slitaz.org/">Roadmap</a>
149 <a href="http://pizza.slitaz.me/">Pizza</a>
150 <a href="http://tank.slitaz.org/">Tank</a>
151 |
152 <a href="/cross/">Cross</a>
153 <a href="/i486.cgi">i486</a>
154 <a href="$base/cookiso.cgi">ISO</a>
155 <select onChange="window.location.href=this.value" style="display: none">
156 <option value=".">Go to…</option>
157 <option value="http://www.slitaz.org/">Home</option>
158 <option value="http://bugs.slitaz.org/">Bug tracker</option>
159 <option value="http://hg.slitaz.org/wok/">Hg wok</option>
160 <option value="http://roadmap.slitaz.org/">Roadmap</option>
161 <option value="http://pizza.slitaz.me/">Pizza</option>
162 <option value="http://tank.slitaz.org/">Tank</option>
163 <option disabled>---------</option>
164 <option value="cross/">Cross</option>
165 <option value="i486.cgi">i486</option>
166 <option value="cookiso.cgi">ISO</option>
167 </select>
168 </div>
169 </header>
171 <main>
172 EOT
174 [ -n "$debug" ] && echo "<pre><code class='language-ini'>$(env | sort)</code></pre>"
175 }
178 # HTML page footer
180 page_footer() {
181 date_now=$(date +%s)
182 sec_now=$(date +%S); sec_now=${sec_now#0} # remove one leading zero
183 wait_sec=$(( 60 - $sec_now ))
184 cat <<-EOT
185 </main>
187 <footer>
188 <a href="http://www.slitaz.org/">SliTaz Website</a>
189 <a href="http://tank.slitaz.org/graphs.php">Server status</a>
190 <a href="$base/doc/cookutils/cookutils.html">Documentation</a>
191 <a href="$base/?theme">Theme</a>
192 </footer>
193 </div>
194 <script src="/cooker.js"></script>
195 <script>refreshDate(${wait_sec}000, ${date_now}000)</script>
196 </body>
197 </html>
198 EOT
199 }
202 show_note() {
203 echo "<div class='bigicon-$1'>$2</div>"
204 }
207 not_found() {
208 local file="${1#$PKGS/}"; file="${file#$LOGS/}"; file="${file#$WOK/}"
209 echo "HTTP/1.1 404 Not Found"
210 page_header
211 echo "<h2>Not Found</h2>"
212 case $2 in
213 pkg)
214 show_note e "The requested package “$(basename "$(dirname "$file")")” was not found." ;;
215 *)
216 show_note e "The requested file “$file” was not found." ;;
217 esac
218 page_footer
219 }
222 manage_modified() {
223 local file="$1" option="$2" nul day mon year time hh mm ss date_s
224 if [ ! -f "$file" ]; then
225 if [ "$option" == 'silently-absent' ]; then
226 echo "HTTP/1.1 404 Not Found"
227 return
228 else
229 not_found "$file" "$2"
230 exit
231 fi
232 fi
233 [ "$option" == 'no-last-modified' ] && return
234 if [ -n "$HTTP_IF_MODIFIED_SINCE" ]; then
235 echo "$HTTP_IF_MODIFIED_SINCE" | \
236 while read nul day mon year time nul; do
237 case $mon in
238 Jan) mon='01';; Feb) mon='02';; Mar) mon='03';; Apr) mon='04';;
239 May) mon='05';; Jun) mon='06';; Jul) mon='07';; Aug) mon='08';;
240 Sep) mon='09';; Oct) mon='10';; Nov) mon='11';; Dec) mon='12';;
241 esac
242 hh=$(echo $time | cut -d: -f1)
243 mm=$(echo $time | cut -d: -f2)
244 ss=$(echo $time | cut -d: -f3)
245 date_s=$(date -ud "$year$mon$day$hh$mm.$ss" +%s)
246 # if [ "$date_s" -ge "$(date -ur "$file" +%s)" ]; then
247 # echo -e 'HTTP/1.1 304 Not Modified\n'
248 # exit
249 # fi
250 # TODO: improve caching control
251 done
252 fi
253 echo "Last-Modified: $(date -Rur "$file" | sed 's|UTC|GMT|')"
254 echo "Cache-Control: public, max-age=3600"
255 }
258 # Proxy to the Repology
259 # Problems:
260 # 1. Function "latest packaged version" widely used here and it has no JSON API, but only SVG badge.
261 # 2. So, all version comparisons can be only visual and not automated.
262 # 3. If the thousands of badges present on the web page, many of them are broken (maybe server
263 # drops requests), while our server displays status icons well.
264 # 4. Default badges are wide and not customizable.
265 # Solution:
266 # 1. Make local cache. Update it on demand, but no more than once a day (Repology caches info
267 # on a hourly basis). Use cached values when they are not expired.
268 # 2. Extract and save version(s) from the SVG badges. Values can be compared in the scripts as well
269 # as custom badges that may also be provided.
271 repology_get() {
272 local found versions day=$(date +%j) # %j is the number of the day in the year
273 found=$(awk -F$'\t' -vpkg="$1" -vday="$day" '{
274 if ($1 == pkg && $2 == day) { print $3; exit; }
275 }' $repologydb)
276 if [ -n "$found" ]; then
277 echo "$found"
278 else
279 # set HOST_WGET in cook.conf
280 versions=$($HOST_WGET -q -T 20 -O- https://repology.org/badge/latest-versions/$1.svg \
281 | sed '/<text /!d; /fill/d; /latest/d; s|.*>\(.*\)<.*|\1|; s|, | |g') # space separated list
282 if [ -n "$versions" ]; then
283 sed -i "/^$1 /d" $repologydb
284 echo -e "$1\t$day\t$versions" >> $repologydb
285 echo $versions
286 fi
287 fi
288 }
291 # Query '?pct=<package>': update percentage
293 if [ -n "$(GET pct)" ]; then
294 pkg="$(GET pct)"
295 state="$(cat $command)"
296 if [ "$state" == "cook:$pkg" ]; then
297 set -- $(grep "^$state" $cooktime)
298 [ -n "$1" ] && pct=$(( ($(date +%s) - $3) * 100 / $2 ))
299 echo "${pct:-?}"
300 else
301 echo 'reload'
302 fi
303 exit 0
304 fi
307 # Query '?poke': poke cooker
309 if [ -n "$(GET poke)" ]; then
310 touch $CACHE/cooker-request
311 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
312 exit
313 fi
316 # Query '?recook=<package>': query to recook package
318 if [ -n "$(GET recook)" ]; then
319 pkg="$(GET recook)"
320 case "$HTTP_USER_AGENT" in
321 *SliTaz*)
322 grep -qs "^$pkg$" $CACHE/recook-packages ||
323 echo "$pkg" >> $CACHE/recook-packages
324 esac
325 echo -e "Location: ${HTTP_REFERER:-${REQUEST_URI%\?*}}\n"
326 exit
327 fi
330 # Query '/i/<log>/<pkg>': show indicator icon
331 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
333 if [ "$pkg" == 'i' ]; then
334 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
335 if [ $LOGS/$cmd -nt $PKGS/$arg.tazpkg ]; then
336 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
337 else
338 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
339 fi
340 exit
341 fi
344 # Query '/s/<pkg>': show status indicator icon
345 # Can't use ?query - not able to change '+' to '%2B' in the sed rules (see log handler)
347 if [ "$pkg" == 's' ]; then
348 # argument <pkg> is in $cmd variable
349 echo -en "Content-Type: image/svg+xml\n\n<svg xmlns='http://www.w3.org/2000/svg' height='12' width='8'><path d='"
350 # packages.info updates with each new package, so we'll find actual info here
351 if grep -q "^$cmd"$'\t' $PKGS/packages-$ARCH.info; then
352 echo "m1 2-1 1v8l1 1h6l1-1v-8l-1-1z' fill='#090'/></svg>"
353 else
354 echo "m0 3v8l1 1h6l1-1v-8l-1-1h-6zm3 0h2v5h-2zm0 6h2v2h-2z' fill='#d00'/></svg>"
355 fi
356 exit
357 fi
360 # Query '?theme[=<theme>]': change UI theme
362 if [ -n "$(GET theme)" ]; then
363 theme="$(GET theme)"
364 ref="$(echo "$HTTP_REFERER" | sed 's|:|%3A|g; s|/|%2F|g; s|\?|%3F|g; s|\+|%2B|g;')"
365 case $theme in
366 theme)
367 current=$(COOKIE theme)
368 page_header
369 cat <<-EOT
370 <section>
371 <h2>Change theme</h2>
372 <p>Current theme: “${current:-default}”. Select other:</p>
373 <ul>$(
374 for i in default emerald sky goldenrod midnight like2016 terminal; do
375 [ "$i" == "${current:-default}" ] || echo "<li><a href=\"$base/?theme=$i&amp;ref=$ref\">$i</a></li>"
376 done
377 )</ul>
378 </section>
379 EOT
380 page_footer
381 exit 0
382 ;;
383 default|emerald|sky|goldenrod|midnight|like2016|terminal)
384 ref="$(GET ref)"
385 [ -n "$ref" ] || ref="$base/"
386 # Expires in a year
387 expires=$(date -uRd @$(($(date +%s)+31536000)) | sed 's|UTC|GMT|')
388 echo -e "HTTP/1.1 302 Found\nLocation: $ref\nCache-Control: no-cache\nSet-Cookie: theme=$theme; expires=$expires\n\n"
389 exit 0
390 ;;
391 esac
392 fi
395 #case "$QUERY_STRING" in
396 # stuff*)
397 # file="$wok/$(GET stuff)"
398 # manage_modified "$file"
399 # ;;
400 #
401 # pkg=*|receipt=*|description=*|files=*|log=*|man=*|doc=*|info=*)
402 # type=${QUERY_STRING%%=*}
403 # pkg=$(GET $type)
404 # case "$type" in
405 # description)
406 # manage_modified "$wok/$pkg/receipt" 'no-last-modified'
407 # manage_modified "$wok/$pkg/description.txt" 'silently-absent'
408 # ;;
409 # log)
410 # manage_modified "$wok/${pkg%%.log*}/receipt" 'no-last-modified'
411 # manage_modified "$LOGS/$pkg"
412 # ;;
413 # *)
414 # manage_modified "$wok/$pkg/receipt" pkg
415 # ;;
416 # esac
417 # ;;
418 #esac
421 # RSS feed generator
422 # URI: ?rss[&limit={1..100}]
424 if [ -n "$(GET rss)" ]; then
425 limit=$(GET limit); limit="${limit:-12}"; [ "$limit" -gt 100 ] && limit='100'
426 pubdate=$(date -Rur$(ls -t $FEEDS/*.xml | head -n1) | sed 's|UTC|GMT|')
427 cooker_url="http://$HTTP_HOST$base/"
428 cat <<-EOT
429 Content-Type: application/rss+xml
431 <?xml version="1.0" encoding="utf-8" ?>
432 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
433 <channel>
434 <title>$title</title>
435 <description>The SliTaz packages cooker feed</description>
436 <link>$cooker_url</link>
437 <lastBuildDate>$pubdate</lastBuildDate>
438 <pubDate>$pubdate</pubDate>
439 <atom:link href="$cooker_url?rss" rel="self" type="application/rss+xml" />
440 EOT
441 for rss in $(ls -t $FEEDS/*.xml | head -n$limit); do
442 sed -e "/\?pkg=/s|http[^=]*=|$cooker_url|;" \
443 -e "s|\([0-9]\)</pubDate>|\1 GMT</pubDate>|" $rss
444 done
445 cat <<-EOT
446 </channel>
447 </rss>
448 EOT
449 exit 0
450 fi
453 ### OpenSearch ###
455 # Query '/os.xml': get OpenSearch Description
457 if [ "$pkg" == 'os.xml' ]; then
458 cat <<-EOT
459 Content-Type: application/xml; charset=UTF-8
461 <?xml version="1.0" encoding="UTF-8"?>
462 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
463 <ShortName>$title</ShortName>
464 <Description>SliTaz packages search</Description>
465 <Image width="16" height="16" type="image/png">http://$HTTP_HOST/images/logo.png</Image>
466 <Url type="text/html" method="GET" template="http://$HTTP_HOST$base/{searchTerms}"/>
467 <Url type="application/x-suggestions+json" method="GET" template="http://$HTTP_HOST$base/">
468 <Param name="oss" value="{searchTerms}"/>
469 </Url>
470 <SearchForm>http://$HTTP_HOST$base/</SearchForm>
471 <InputEncoding>UTF-8</InputEncoding>
472 </OpenSearchDescription>
473 EOT
474 exit 0
475 fi
477 # Query '?oss[=<term>]': OpenSearch suggestions
479 if [ -n "$(GET oss)" ]; then
480 term="$(GET oss | tr -cd '[:alnum:]+-')"
481 echo -e 'Content-Type: application/x-suggestions+json; charset=UTF-8\n'
482 cd $wok
483 ls | fgrep "$term" | head -n10 | awk -vterm="$term" '
484 BEGIN{printf("[\"%s\",[", term)}
485 {printf("%s\"%s\"", NR != 1 ? "," : "", $0)}
486 END {printf("]]")}
487 '
488 exit 0
489 fi
494 #
495 # Functions
496 #
499 # Unpack to stdout
501 docat() {
502 case "$1" in
503 *gz) zcat ;;
504 *bz2) bzcat ;;
505 *xz) xzcat ;;
506 *) cat
507 esac < $1
508 }
511 # Tiny texinfo converter
513 info2html() {
514 sed \
515 -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;' \
516 -e "s|\`\([^']*\)'|<b>\1</b>|g" \
517 -e 's|"\([A-Za-z0-9]\)|“\1|g; s|"|”|g' \
518 -e 's|^\* \(.*\)::|* <a href="#\1">\1</a> |' \
519 -e 's|\*note \(.*\)::|<a href="#\1">\1</a>|' \
520 -e '/^File: / s|(dir)|Top|g' \
521 -e '/^File: / s|Next: \([^,]*\)|<a class="button icon next" href="#\1">Next: \1</a>|' \
522 -e '/^File: / s|Prev: \([^,]*\)|<a class="button icon prev" href="#\1">Prev: \1</a>|' \
523 -e '/^File: / s|Up: \([^,]*\)|<a class="button icon up" href="#\1">Up: \1</a>|' \
524 -e '/^File: / s|^.* Node: \([^,]*\), *\(.*\)$|<pre id="\1">\2|' \
525 -e '/^<pre id=/ s|^\([^>]*>\)\(<a[^>]*>Next: [^,]*\), *\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1<div class="buttonbar">\3 \4 \2</div>|' \
526 -e '/^<pre id=/ s|^\([^>]*>\)*\(<a[^>]*>Prev: [^,]*\), *\(<a[^>]*>Up: .*\)|\1<div class="buttonbar">\2 \3 <a class="button icon next" href="#">Next</a></div>|' \
527 -e '/^Tag Table:$/,/^End Tag Table$/d' \
528 -e '/INFO-DIR/,/^END-INFO-DIR/d' \
529 -e "s|https*://[^>),'\"\`’ ]*|<a href=\"&\">&</a>|g" \
530 -e "s|ftp://[^>),\"\` ]*|<a href=\"&\">&</a>|g" \
531 -e 's|^\* Menu:|<b>Menu:</b>|' \
532 -e "s|^|</pre>|"
533 }
536 # Put some colors into log and DB files.
538 syntax_highlighter() {
539 case $1 in
540 log)
541 # If variables not defined - define them with some rare values
542 : ${_src=#_#_#}
543 : ${_install=#_#_#}
544 : ${_fs=#_#_#}
545 : ${_stuff=#_#_#}
546 # Use one-letter html tags to save some bytes :)
547 # <b>is error (red)</b> <u>is warning (orange)</u> <i>is informative (green)</i>
548 sed \
549 -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' \
550 -e 's#OK$#<i>OK</i>#' \
551 -e 's#\([Dd]one\)$#<i>\1</i>#' \
552 -e 's#Success$#<i>Success</i>#' \
553 -e 's#\([^a-z]\)ok$#\1<i>ok</i>#' \
554 -e 's#\([^a-z]\)yes$#\1<i>yes</i>#' \
555 -e 's#: \(YES.*\)#: <i>\1</i>#' \
556 -e 's#\([^a-z]\)ON$#\1<i>ON</i>#' \
557 -e 's#\(enabled\)$#<i>\1</i>#' \
558 -e 's#\([^a-z]\)no$#\1<u>no</u>#' \
559 -e 's#: \(NO.*\)#: <u>\1</u>#' \
560 -e 's#\([^a-z]\)none$#\1<u>none</u>#' \
561 -e 's#\([^a-z]\)false$#\1<u>false</u>#' \
562 -e 's#\([^a-z]\)OFF$#\1<u>OFF</u>#' \
563 -e 's#\(disabled\)$#<u>\1</u>#' \
564 -e 's#\(^checking .*\.\.\. \)\(.*\)$#\1<i>\2</i>#' \
565 \
566 -e 's#\( \[Y[nm/]\?\] n\)$# <u>\1</u>#' \
567 -e 's#\( \[N[ym/]\?\] y\)$# <i>\1</i>#' \
568 -e 's# y$# <i>y</i>#' \
569 -e 's# n$# <u>n</u>#' \
570 -e 's#(NEW) *$#<b>(NEW)</b>#' \
571 \
572 -e 's#.*(pkg/local).*#<i>\0</i>#' \
573 -e 's#.*(web/cache).*#<u>\0</u>#' \
574 \
575 -e 's#\([^a-zA-Z]\)\([Ee]rror\)$#\1<b>\2</b>#' \
576 -e 's#ERROR:#<b>ERROR:</b>#g' \
577 \
578 -e 's#^.*multiple definition of.*#<b>\0</b>#' \
579 -e 's#^.*[Ff][Aa][Ii][Ll][Ee][Dd].*#<b>\0</b>#' \
580 -e 's#^.*[^A-Za-z:/-][Ff]atal.*#<b>\0</b>#' \
581 -e '/non-fatal/ s|</*b>||g' \
582 -e 's#^.*[Nn]ot found.*#<b>\0</b>#' \
583 -e 's#^.*[Nn]o such file.*#<b>\0</b>#' \
584 -e 's#^.*No package .* found.*#<b>\0</b>#' \
585 -e 's#^.*Unable to find.*#<b>\0</b>#' \
586 -e 's#[^a-zA-Z-][Ii]nvalid.*#<b>\0</b>#' \
587 -e 's#Segmentation fault#<b>\1</b>#' \
588 -e 's#\([Nn][Oo][Tt] found\.*\)$#<b>\1</b>#' \
589 -e 's#\(found\.*\)$#<i>\1</i>#' \
590 \
591 -e 's#^.*WARNING:.*#<u>\0</u>#' \
592 -e 's#^.*warning:.*#<u>\0</u>#' \
593 -e 's#^.* [Ee]rror:* .*#<b>\0</b>#' \
594 -e 's#^.*terminated.*#<b>\0</b>#' \
595 -e 's#\(missing\)#<b>\1</b>#g' \
596 -e 's#^.*[Cc]annot find.*#<b>\0</b>#' \
597 -e 's#^.*unrecognized option.*#<u>\0</u>#' \
598 -e 's#^.*does not.*#<u>\0</u>#' \
599 -e 's#^.*[Ii]gnoring.*#<u>\0</u>#' \
600 -e 's#^.*note:.*#<u>\0</u>#' \
601 \
602 -e 's#^.* will not .*#<u>\0</u>#' \
603 -e 's!^Hunk .* succeeded at .*!<u>\0</u>!' \
604 -e 's#^.* Warning: .*#<u>\0</u>#' \
605 \
606 -e "s#^Executing:\([^']*\).#<em>\0</em>#" \
607 -e "s#^Making.*#<em>\0</em>#" \
608 -e "s#^Scanning dependencies of target .*#<em>\0</em>#" \
609 -e "s#^====\([^']*\).#<span class='span-line'>\0</span>#g" \
610 -e "s#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#g" \
611 -e "s#[fh]tt*ps*://[^ '\"]*#<a href='\0'>\0</a>#g" \
612 -e 's|^Switching to the .*|<span class="switch">‣‣‣ \0</span>|' \
613 \
614 -e 's|^<u>\(.*libtool: warning: relinking.*\)</u>|\1|' \
615 -e 's|^<u>\(.*libtool: warning: .* has not been installed in .*\)</u>|\1|' \
616 -e 's|^<u>\(.*checking for a sed.*\)</u>|\1|' \
617 -e 's|^<u><b>\(.*inlining failed.*\)</b></u>|<u>\1</u>|' \
618 \
619 -e "s|$_src|<var>\${src}</var>|g;
620 s|$_install|<var>\${install}</var>|g;
621 s|$_fs|<var>\${fs}</var>|g;
622 s|$_stuff|<var>\${stuff}</var>|g" \
623 \
624 -e "s|\[\([01]\)m\[3\([1-7]\)m|<span class='c\2\1'>|g;
625 s|\[\([01]\);3\([1-7]\)m|<span class='c\2\1'>|g;
626 s|\[3\([1-7]\)m|<span class='c\10'>|g;
627 s|\[\([01]\);0m|<span class='c0\1'>|g;
628 s|\[0m|</span>|g;
629 s|\[m|</span>|g;
630 s|\[0;10m|</span>|g;
631 s|\[K||g;" \
632 \
633 -e "s|\[9\([1-6]\)m|<span class='c\10'>|;
634 s|\[39m|</span>|;
635 #s|\[1m|<span class='c01'>|g;
636 s|\[1m|<span style='font-weight:bold'>|g; s|(B|</span>|g;
637 s|\[m||g;" \
638 \
639 -e "s!^|\(+.*\)!|<span class='c20'>\1</span>!;
640 s!^|\(-.*\)!|<span class='c10'>\1</span>!;
641 s!^|\(@@.*@@\)\$!|<span class='c30'>\1</span>!;" \
642 \
643 -e "s|^Successfully installed [^ ][^ ]*$|<i>\0</i>|;
644 s|^Successfully installed .*$|<b>\0</b>|;
645 s|^\(Requirement already satisfied: .*\) in|<i>\1</i> in|;
646 s|^Collecting .* (from .*$|<b>\0</b>|;
647 s|^ Could not find.*|<b>\0</b>|;
648 s|^No matching distribution found for.*|<b>\0</b>|;"
650 ;;
652 files)
653 # Highlight the Busybox's `ls` output
654 awk '{
655 part1 = substr($0, 0, 16);
656 part2 = substr($0, 17, 9);
657 part3 = substr($0, 26, 9);
658 part4 = substr($0, 35);
659 if (part2 != "root ") part2 = "<span class=\"c11\">" part2 "</span>";
660 if (part3 != "root ") part3 = "<span class=\"c11\">" part3 "</span>";
661 print part1 part2 part3 part4;
662 }' | \
663 sed "s|\[0m/|/\[0m|g;
664 s|\[\([01]\);3\([1-7]\)m|<a class='c\2\1'>|g;
665 s|\[\([01]\);0m|<a class='c0\1'>|g;
666 s|\[0m|</a>|g;
667 s|^\(lrwxrwxrwx\)|<span class='c61'>\1</span>|;
668 s|^\(-rwxr-xr-x\)|<span class='c21'>\1</span>|;
669 s|^\(-rw-r--r--\)|<span class='c31'>\1</span>|;
670 s|^\(drwxr-xr-x\)|<span class='c41'>\1</span>|;
671 s|^\(-rwsr-xr-x\)|<span class='c51'>\1</span>|;
672 s|^\([lrwxs-][lrwxs-]*\)|<span class='c11'>\1</span>|;
673 "
674 ;;
675 esac
676 }
679 show_code() {
680 echo -n "<pre><code class=\"language-$1\">"
681 sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g'
682 echo '</code></pre>'
683 }
686 datalist() {
687 cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | sort -u | awk '
688 BEGIN{printf("<datalist id=\"packages\">")}
689 {printf("<option>%s",$1)}
690 END {printf("</datalist>")}
691 '
692 }
695 mklog() {
696 awk '
697 BEGIN { printf("<pre class=\"log dog\">\n") }
698 { print }
699 END { print "</pre>" }'
700 }
703 summary() {
704 log="$1"
705 pkg="$(basename ${log%%.log*})"
707 if [ -f "$log" ]; then
708 if grep -q "cook:$pkg$" $command; then
709 show_note i "The Cooker is currently building $pkg" \
710 | sed 's|>|&<progress id="gauge" class="meter-small" max="100" value="0"></progress> |'
711 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
712 elif fgrep -q "Summary for:" $log; then
713 sed '/^Summary for:/,$!d' $log | awk '
714 BEGIN { print "<section>" }
715 function row(line) {
716 split(line, s, " : ");
717 printf("\t<tr><td>%s</td><td>%s</td></tr>\n", s[1], s[2]);
718 }
719 function row2(line, rowNum) {
720 split(line, s, " : ");
721 if (rowNum == 1) {
722 print "<thead>";
723 printf("\t<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", s[1], s[2], s[3], s[4], s[5]);
724 print "</thead><tbody>";
725 }
726 else
727 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n", s[1], s[2], s[3], s[4], s[5]);
728 }
729 {
730 if (NR==1) { printf("<h3>%s</h3>\n<table>\n", $0); next }
731 if ($0 ~ "===") { seen++; if (seen == 1) next; else exit; }
732 if ($0 ~ "---") {
733 seen2++;
734 if (seen2 == 1) print "</table>\n\n<table class=\"pkgslist\">"
735 next
736 }
737 if (seen2) row2($0, seen2); else row($0);
738 }
739 END { print "</tbody></table></section>" }
740 '
741 elif fgrep -q "Debug information" $log; then
742 # second line of log is "Cook: <package> <version>"
743 echo -e "<section>\n<h3>Debug information for $(sed '2!d; s|.*: ||' $log)</h3>"
744 sed -e '/^Debug information/,$!d; /^===/d; /^$/d' $log | sed -n '1!p' | \
745 if [ -n "$2" ]; then
746 syntax_highlighter log | sed 's|\([^0-9 ]\)\([0-9][0-9]*\):|\1<a href="#l\2">\2</a>:|'
747 else
748 sed 's|^[0-9][0-9]*:||' | syntax_highlighter log
749 fi | mklog
750 echo '</section>'
751 fi
752 else
753 [ -n "$pkg" -a -d "$wok/$pkg" ] && show_note e "No log for $pkg"
754 fi
755 }
758 active() {
759 [ "$cmd" == "$1" -o "$cmd" == "${2:-$1}" ] && echo -n ' active'
760 }
763 pkg_info() {
764 local log active bpkg short_desc=''
765 log="$LOGS/$pkg.log"
767 echo -n "<div id=\"hdr\"><a href=\"$base/${requested_pkg:-$pkg}\">"
768 if [ -e $wok/$pkg/.icon.png ]; then
769 echo -n "<img src=\"$base/$pkg/browse/.icon.png\" alt=\"$pkg icon\"/>"
770 else
771 echo -n "<img src=\"/tazpkg.png\" alt=\"package icon\"/>"
772 fi
773 echo -n "</a>"
774 echo -n "<h2><a href=\"$base/${requested_pkg:-$pkg}\">${requested_pkg:-$pkg}</a>"
775 # Get short description for existing packages
776 [ -f $PKGS/packages.info ] &&
777 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages.info)"
778 # If package does not exist (not created yet or broken), get short description
779 # (but only for "main" package) from receipt
780 [ -n "$short_desc" ] || short_desc="$(. $wok/$pkg/receipt; echo "$SHORT_DESC")"
781 echo "<br/>$short_desc</h2></div>"
782 echo '<div id="info">'
783 echo "<a class='button icon receipt$(active receipt stuff)' href='$base/$pkg/receipt'>receipt &amp; stuff</a>"
785 # In the receipts $EXTRAVERSION is defined using $kvers, get it here [copy from 'cook' set_paths()]
786 if [ -f "$wok/linux/receipt" ]; then
787 kvers=$(. $wok/linux/receipt; echo $VERSION)
788 kbasevers=$(echo $kvers | cut -d. -f1,2)
789 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
790 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
791 kbasevers=$(echo $kvers | cut -d. -f1,2)
792 fi
794 unset WEB_SITE WANTED
795 . $wok/$pkg/receipt
797 [ -n "$WEB_SITE" ] &&
798 echo "<a class='button icon website' href='$WEB_SITE' target='_blank' rel='noopener noreferrer'>web site</a>"
800 [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION$EXTRAVERSION/receipt" ] &&
801 echo "<a class='button icon files$(active files)' href='$base/$pkg/files'>files</a>"
803 [ -n "$(ls $wok/$pkg/description*.txt)" ] &&
804 echo "<a class='button icon desc$(active description)' href='$base/$pkg/description'>description</a>"
806 [ -n "$TARBALL" -a -s "$SRC/$TARBALL" -o -d "$wok/$pkg/taz" ] &&
807 echo "<a class='button icon download' href='$base/$pkg/download'>downloads</a>"
809 echo "<a class='button icon browse' href='$base/$pkg/browse/'>browse</a>"
811 [ -x ./man2html.bin -a -d "$wok/$pkg/install/usr/share/man" ] &&
812 echo "<a class='button icon doc$(active man)' href='$base/$pkg/man/'>man</a>"
814 [ -d "$wok/$pkg/install/usr/share/doc" -o -d "$wok/$pkg/install/usr/share/gtk-doc" ] &&
815 echo "<a class='button icon doc$(active doc)' href='$base/$pkg/doc/'>doc</a>"
817 [ -d "$wok/$pkg/install/usr/share/info" ] &&
818 echo "<a class='button icon doc$(active info)' href='$base/$pkg/info/#Top'>info</a>"
820 if [ -n "$LFS" ]; then
821 printf "<a class='button icon lfs' href='%s' target='_blank' rel='noopener noreferrer'>" "$LFS"
822 [ "${LFS/blfs/}" != "$LFS" ] && printf "B"
823 printf "LFS</a>\n"
824 fi
826 ls $log* >/dev/null 2>&1 &&
827 echo "<a class='button icon log$(active log)' href='$base/$pkg/log/'>logs</a>"
829 echo '</div>'
830 }
833 mktable() {
834 sed 's# : #|#' | awk -vc="$1" '
835 BEGIN { printf("<table class=\"%s\">\n", c); FS="|" }
836 { printf("<tr><td>%s</td>", $1);
837 if (NF == 2) printf("<td>%s</td>", $2);
838 printf("</tr>\n", $2) }
839 END { print "</table>" }'
840 }
843 section() {
844 local i=$(basename "$1")
845 echo -e '\n\n<section>'
846 [ $(wc -l < $1) -gt $2 ] && echo "<a class='button icon more r' href='?$i'>${3#*|}</a>"
847 echo "<h2>${3%|*}</h2>"
848 mktable "$i"
849 echo '</section>'
850 }
853 show_desc() {
854 echo "<section><h3>Description of “$1”</h3>"
855 if [ -n "$md2html" ]; then
856 $md2html $2
857 else
858 show_code markdown < $2
859 fi
860 echo "</section>"
861 }
864 # Return all the names of packages bundled in this receipt
866 all_names() {
867 # Get package names from $SPLIT variable
868 local split=$(echo $SPLIT \
869 | awk '
870 BEGIN { RS = " "; FS = ":"; }
871 { print $1; }' \
872 | tr '\n' ' ')
873 local split_space=" $split "
874 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
875 # For receipts v1: $SPLIT may present in the $WANTED package,
876 # but split packages have their own receipts
877 echo $PACKAGE
878 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
879 # $PACKAGE included somewhere in $SPLIT (probably in the end).
880 # We should build packages in the order defined in the $SPLIT.
881 echo $split
882 else
883 # We'll build the $PACKAGE, then all defined in the $SPLIT.
884 echo $PACKAGE $split
885 fi
886 }
889 toolchain_version() {
890 echo "<tr><td><a href='$base/$1'>$1</a></td>"
891 awk -F$'\t' -vpkg="$1" '
892 BEGIN { version = description = "---"; }
893 {
894 if ($1 == pkg) { version = $2; description = $4; }
895 }
896 END { printf("<td>%s</td><td>%s</td></tr>", version, description); }
897 ' $PKGS/packages.info
898 }
901 files_header() {
902 echo '<section><h3>Available downloads:</h3>'
903 echo '<table><thead><tr><th>File</th><th>Size</th><th>Description</th></tr></thead><tbody>'
904 }
907 # Update statistics used in web interface.
908 # There is no need to recalculate the statistics every time the page is displayed.
909 # Note, $webstat file must be owned by www, otherwise this function will not be able to do the job.
911 update_webstat() {
912 # for receipts:
913 rtotal=$(ls $WOK/*/arch.$ARCH | wc -l)
914 rcooked=$(ls -d $WOK/*/taz | wc -l)
915 runbuilt=$(($rtotal - $rcooked))
916 rblocked=$(wc -l < $blocked)
917 rbroken=$(wc -l < $broken)
919 # for packages:
920 ptotal=$(cut -d$'\t' -f2 $CACHE/split.db | tr ' ' '\n' | sort -u | wc -l)
921 pcooked=$(ls $PKGS/*.tazpkg | wc -l)
922 punbuilt=$(($ptotal - $pcooked))
923 pblocked=$(
924 while read i; do
925 sed "/^$i\t/!d" $CACHE/split.db
926 done < $blocked | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
927 pbroken=$(
928 while read i; do
929 sed "/^$i\t/!d" $CACHE/split.db
930 done < $broken | cut -d$'\t' -f2 | tr ' ' '\n' | wc -l)
932 cat > $webstat <<-EOT
933 rtotal="$rtotal"; rcooked="$rcooked"; runbuilt="$runbuilt"; rblocked="$rblocked"; rbroken="$rbroken"
934 ptotal="$ptotal"; pcooked="$pcooked"; punbuilt="$punbuilt"; pblocked="$pblocked"; pbroken="$pbroken"
935 EOT
936 }
939 # Show badges for specified package
941 show_badges() {
942 local t p s # title problem solution
944 case $layout in
945 table)
946 echo "<section><h2>Badges</h2><table class=\"badges\"><thead><tr><th></th><th>Problem</th><th>Solution</th></tr></thead><tbody>"
947 ;;
948 list)
949 echo "<section><h2>Badges list</h2><p>Click on badge to get list of packages</p><table class=\"badges\"><thead><tr><th></th><th>Problem</th></tr></thead><tbody>"
950 ;;
951 esac
953 for badge in $@; do
954 case $badge in
955 bdbroken)
956 t="Broken bdeps"
957 p="This package cannot be built because its creation depends on broken packages"
958 s="Fix broken build dependencies"
959 ;;
960 broken)
961 t="Broken package"
962 p="Package is broken"
963 s="Fix package build: analyze <a href=\"log/\">logs</a>, upgrade the version, search for patches"
964 ;;
965 any)
966 t="“Any” arch"
967 p="This package contains only architecture-less <a href=\"files\">files</a>, it does not make sense to make it several times in each build environment"
968 s="Add the line <code>HOST_ARCH=\"any\"</code> to <a href=\"receipt\">receipt</a>"
969 ;;
970 noany)
971 t="No “any” arch"
972 p="This package contains architecture dependent <a href=\"files\">files</a>"
973 s="Remove the line <code>HOST_ARCH=\"any\"</code> from <a href=\"receipt\">receipt</a>"
974 ;;
975 libtool)
976 t="Libtool isn't fixed"
977 p="This package use <code>libtool</code> that likes to add unnecessary dependencies to programs and libraries"
978 s="Add the <code>fix libtool</code> command to the <a href=\"receipt\">receipt</a> between the <code>configure</code> and <code>make</code> commands invocation"
979 ;;
980 nolibtool)
981 t="Libtool is absent"
982 p="This package does not use <code>libtool</code>, nothing to fix"
983 s="Remove the command <code>fix libtool</code> from <a href=\"receipt\">receipt</a>"
984 ;;
985 own)
986 t="Ownership problems"
987 p="Some files of this package have <a href=\"files\">ownership problems</a>"
988 s="Correct the ownership or add problem files to the “<a href=\"stuff/overrides\">overrides</a>” list if you believe it is OK"
989 ;;
990 ownover)
991 t="Ownership overridden"
992 p="This package contains files with <a href=\"files\">ownership problems</a> that have been overridden"
993 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"stuff/overrides\">the list</a>"
994 ;;
995 perm)
996 t="Permissions problems"
997 p="Some files of this package have <a href=\"files\">unusual permissions</a>"
998 s="Correct the permissions or add problem files to the “<a href=\"stuff/overrides\">overrides</a>” list if you believe it is OK"
999 ;;
1000 permover)
1001 t="Permissions overridden"
1002 p="This package contains files with <a href=\"files\">unusual permissions</a> that have been recorded"
1003 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"stuff/overrides\">the list</a>"
1004 ;;
1005 symlink)
1006 t="Broken symlink"
1007 p="This package contains one or more <a href=\"files\">broken symlinks</a>"
1008 s="Fix the symlinks destination; you may use <code>fix symlinks</code> when symlinks have absolute path"
1009 ;;
1010 ss)
1011 t="Site script"
1012 p="This autotools-based building system use site script; most of paths (like <var>prefix</var>, <var>sysconfdir</var> and <var>mandir</var>) are defined there with correct default values"
1013 s="You may remove your paths from <code>configure</code> invocation"
1014 ;;
1015 fadd)
1016 t="Files have been added"
1017 p="Some files absent in <var>\$install</var> was <a href=\"files#outoftree\">directly added</a> to <var>\$fs</var>"
1018 s="Rework your <code>compile_rules()</code> to add all the required files to <var>\$install</var> there"
1019 ;;
1020 frem)
1021 t="Files have been removed"
1022 p="Some files existing in <var>\$install</var> <a href=\"files#orphans\">not belong to any package</a>"
1023 s="Revise <code>genpkg_rules()</code> or add files to “<a href=\"stuff/overrides\">overrides</a>” list"
1024 ;;
1025 fdup)
1026 t="Files are duplicated"
1027 p="Some files existing in <var>\$install</var> was added to <a href=\"files#repeats\">more than one</a> package"
1028 s="Check your copy rules in <code>genpkg_rules()</code>"
1029 ;;
1030 old)
1031 t="Oldie"
1032 p="According to Repology, this package may be <a href=\"https://repology.org/metapackage/${REPOLOGY:-$pkg}\" target=\"_blank\" rel=\"noopener noreferrer\">outdated</a>"
1033 s="Update the package"
1034 ;;
1035 win)
1036 t="Winner"
1037 p="This package has no problems"
1038 s="Well done, keep it up!"
1039 ;;
1040 orphan)
1041 t="Orphaned package"
1042 p="It seems that no other package depends on this one"
1043 s="See if anyone needs it"
1044 ;;
1045 patch)
1046 t="Patch"
1047 p="Patch has been applied"
1048 s="<abbr title=\"For your information\">FYI</abbr> only, you may want to revise <a href=\"$base/$PACKAGE/stuff/patches/series\">the list of patches</a>"
1049 ;;
1050 esac
1051 case $layout in
1052 table)
1053 echo "<tr><td><span class=\"badge $badge\" title=\"$t\"/></td><td>$p</td><td>$s</td></tr>"
1054 ;;
1055 list)
1056 p=$(echo $p | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g')
1057 s=$(echo $s | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g|')
1058 echo "<tr><td><a href=\"$badge\"><span class=\"badge $badge\" title=\"$t\"/></a></td><td>$p</td></tr>"
1059 ;;
1060 *)
1061 echo -n "<span class=\"badge $badge\" title=\"$t\"/>"
1062 ;;
1063 esac
1064 done
1066 case $layout in
1067 table|list)
1068 echo "</tbody></table></section>"
1069 ;;
1070 esac
1074 # Generate part of the main page
1076 part() {
1077 echo -n "<div id='$1'>"
1079 case $1 in
1080 summary)
1081 echo '<h2>Summary</h2>'
1083 mktable <<EOT
1084 Cooker state : $(running_command)
1085 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
1086 Commits to cook : $(wc -l < $commits)
1087 Current cooklist : $(wc -l < $cooklist)
1088 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
1089 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
1090 EOT
1092 # If command is "cook:*", update gauge and percentage periodically.
1093 # If different package is cooking, reload the page (with new settings)
1094 cmd="$(cat $command)"
1095 case "$cmd" in
1096 cook:*)
1097 pkg=${cmd#*:}
1098 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
1099 ;;
1100 esac
1101 ;;
1102 webstat)
1103 # Do we need to update the statistics?
1104 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
1105 . $webstat
1107 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
1109 cat <<-EOT
1110 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
1112 <table class="webstat">
1113 <thead>
1114 <tr>
1115 <th> </th>
1116 <th>Total </th>
1117 <th>Cooked </th>
1118 <th>Unbuilt </th>
1119 <th>Blocked </th>
1120 <th>Broken </th>
1121 </tr>
1122 </thead>
1123 <tbody>
1124 <tr>
1125 <td>Receipts</td>
1126 <td>$rtotal</td>
1127 <td>$rcooked</td>
1128 <td>$runbuilt</td>
1129 <td>$rblocked</td>
1130 <td>$rbroken</td>
1131 </tr>
1132 <tr>
1133 <td>Packages</td>
1134 <td>$ptotal</td>
1135 <td>$pcooked</td>
1136 <td>$punbuilt</td>
1137 <td>$pblocked</td>
1138 <td>$pbroken</td>
1139 </tr>
1140 </tbody>
1141 </table>
1142 EOT
1143 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
1144 ;;
1145 activity)
1146 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1147 s|\[ Done|<span class="r c20">Done|;
1148 s|\[ Failed|<span class="r c10">Failed|;
1149 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1150 s| \]|</span>|;
1151 s|%2B|\+|g' \
1152 | while read line; do
1153 case "$line" in
1154 *data-badges=*)
1155 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1156 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1157 ;;
1158 *)
1159 echo "$line"
1160 ;;
1161 esac
1162 done | section $activity 12 "Activity|More activity" \
1163 ;;
1164 cooknotes)
1165 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1166 section $cooknotes 12 "Cooknotes|More notes"
1167 ;;
1168 commits)
1169 [ -s "$commits" ] && head -n20 $commits | \
1170 section $commits 20 "Commits|More commits"
1171 ;;
1172 cooklist)
1173 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1174 section $cooklist 20 "Cooklist|Full cooklist"
1175 ;;
1176 broken)
1177 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1178 section $broken 20 "Broken|All broken packages"
1179 ;;
1180 blocked)
1181 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1182 section $blocked 12 "Blocked|All blocked packages"
1183 ;;
1184 pkgs)
1185 cd $PKGS
1186 # About BusyBox's `ls`
1187 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1188 # It supported the option `-e`, output with `-let` options like this:
1189 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1190 # 1 2 3 4 5 6 7 8 9 10 11
1191 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1192 # configure it or return the option back. It supported the long option
1193 # `--full-time` instead, but output is different:
1194 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1195 # 1 2 3 4 5 6 7 8 9
1196 if ls -let >/dev/null 2>&1; then
1197 ls -let *.tazpkg \
1198 | awk '
1199 (NR<=20){
1200 sub(/:[0-9][0-9]$/, "", $9);
1201 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1202 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1203 }' \
1204 | section $activity 1000 "Latest cook"
1205 else
1206 ls -lt --full-time *.tazpkg \
1207 | awk '
1208 (NR<=20){
1209 sub(/:[0-9][0-9]$/, "", $7);
1210 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1211 }' \
1212 | section $activity 1000 "Latest cook"
1213 fi
1214 ;;
1215 esac
1216 echo "</div>"
1220 # Query '?part=<part>': get part of the main page
1222 if [ -n "$(GET part)" ]; then
1223 part="$(GET part)"
1224 case $part in
1225 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1226 nojs='yes'
1227 part $part
1228 ;;
1229 esac
1230 exit 0
1231 fi
1237 # Load requested page
1240 if [ -z "$pkg" ]; then
1242 page_header
1243 if [ -n "$QUERY_STRING" ]; then
1245 [ "$QUERY_STRING" != 'commits.log' ] &&
1246 for list in activity cooknotes cooklist commits; do
1247 [ -n "$(GET $list)" ] || continue
1248 case $list in
1249 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1250 commits) nb="- Packages: $(wc -l < $commits)";;
1251 esac
1252 echo '<section id="content2">'
1253 echo "<h2>DB: $list $nb</h2>"
1255 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1256 s|\[ Done|<span class="r c20">Done|;
1257 s|\[ Failed|<span class="r c10">Failed|;
1258 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1259 s| \]|</span>|;
1260 s|%2B|\+|g' \
1261 | while read line; do
1262 case "$line" in
1263 *data-badges=*)
1264 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1265 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1266 ;;
1267 *)
1268 echo "$line"
1269 ;;
1270 esac
1271 done \
1272 | mktable $list
1274 echo '</section>'
1275 done
1277 if [ -n "$(GET broken)" ]; then
1278 echo '<section id="content2">'
1279 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1280 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1281 echo '</section>'
1282 fi
1284 case "$QUERY_STRING" in
1285 *.log)
1286 log=$LOGS/$QUERY_STRING
1287 name=$(basename $log)
1288 if [ -f "$log" ]; then
1289 echo "<h2>Log for: ${name%.log}</h2>"
1290 if fgrep -q "Summary" $log; then
1291 echo '<pre class="log">'
1292 grep -A 20 'Summary' $log | syntax_highlighter log
1293 echo '</pre>'
1294 fi
1295 echo '<pre class="log">'
1296 syntax_highlighter log < $log
1297 echo '</pre>'
1298 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1299 # Display button only for SliTaz web browser
1300 case "$HTTP_USER_AGENT" in
1301 *SliTaz*)
1302 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1303 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1304 show_note i "The package database has been requested for re-creation"
1305 else
1306 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1307 fi
1308 fi
1309 ;;
1310 esac
1311 fi
1312 else
1313 show_note e "No log file: $log"
1314 fi
1315 ;;
1316 toolchain)
1317 cat <<-EOT
1318 <div id="content2">
1319 <section>
1320 <h2>SliTaz GNU/Linux toolchain</h2>
1322 <table>
1323 <tr>
1324 <td>Build date</td>
1325 <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1326 </tr>
1327 <tr>
1328 <td>Build duration</td>
1329 <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1330 </tr>
1331 <tr>
1332 <td>Architecture</td>
1333 <td colspan="2">$ARCH</td>
1334 </tr>
1335 <tr>
1336 <td>Host system</td>
1337 <td colspan="2">$BUILD_SYSTEM</td>
1338 </tr>
1339 <tr>
1340 <td>Target system</td>
1341 <td colspan="2">$HOST_SYSTEM</td>
1342 </tr>
1343 <tr>
1344 <th>Package</th>
1345 <th>Version</th>
1346 <th>Description</th>
1347 </tr>
1348 $(toolchain_version slitaz-toolchain)
1349 $(toolchain_version binutils)
1350 $(toolchain_version linux-api-headers)
1351 $(toolchain_version gcc)
1352 $(toolchain_version glibc)
1353 </table>
1355 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1356 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1357 </p>
1359 </section>
1360 </div>
1361 EOT
1362 ;;
1363 maintainer*)
1364 maintainer=$(GET maintainer); maintainer=${maintainer/maintainer/}
1365 regexp=$(GET regexp); regexp=${regexp/regexp/}
1366 [ -n "$regexp" ] && maintainer=''
1367 cat <<-EOT
1368 <section>
1369 <h2>For maintainers</h2>
1370 <p>Here you can <a href="%/">explore the badges</a>.</p>
1371 <p>Or see some <a href="?maintainer&amp;stats">repository statistics</a>.</p>
1372 <p>Or check packages version either for specified maintainer or using regular expression:</p>
1373 <form>
1374 <select name="maintainer">
1375 <option value=''>--- select maintainer ---
1376 EOT
1377 cut -d$'\t' -f1 $maintdb | sort -u \
1378 | awk -vm=$maintainer '{
1379 selected=$0==m?"selected":""
1380 printf("<option %s value=\"%s\">%s\n", selected, $0, $0)
1381 }'
1382 cat <<-EOT
1383 </select>
1384 or
1385 <input type="text" name="regexp" value="$regexp"/>
1386 <button type="submit">Go</button>
1387 </form>
1388 EOT
1389 if [ -n "$maintainer" -o -n "$regexp" ]; then
1390 tmp_status=$(mktemp)
1391 cat <<-EOT
1392 <table class="maint">
1393 <thead><tr><th>Package</th><th>Version</th><th>Repology</th></tr></thead>
1394 EOT
1396 if [ -n "$maintainer" ]; then
1397 awk -vm=$maintainer '{if ($1 == m) print $2}' $maintdb
1398 fi
1399 if [ -n "$regexp" ]; then
1400 cd $wok; ls | grep "$regexp"
1401 fi
1402 } | while read pkg; do
1403 unset VERSION; REPOLOGY=$pkg
1404 . $wok/$pkg/receipt
1405 ver=$(awk -F$'\t' -vpkg="$pkg" '{if ($1 == pkg) {print $2; exit}}' $PKGS/packages.info)
1406 if [ "$REPOLOGY" == '-' ]; then
1407 unset repo_info1 repo_info2
1408 echo '-' >>$tmp_status
1409 else
1410 repo_ver=$(repology_get $REPOLOGY)
1411 if [ "$repo_ver" == '-' ]; then
1412 echo '-' >>$tmp_status
1413 icon='more'
1414 else
1415 if echo " $repo_ver " | fgrep -q " ${ver:-$VERSION} "; then
1416 icon='actual'
1417 else
1418 icon='update'
1419 fi
1420 echo $icon >>$tmp_status
1421 fi
1422 repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
1423 repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
1424 fi
1425 cat <<-EOT
1426 <tr>
1427 <td><img src="$base/s/$pkg" alt="$pkg"> <a href="$pkg">$pkg</a></td>
1428 <td>${ver:-$VERSION}</td>
1429 <td>$repo_info1 $repo_info2</td>
1430 </tr>
1431 EOT
1432 done
1434 pkg_total=$( wc -l < $tmp_status)
1435 pkg_actual=$( fgrep actual $tmp_status | wc -l)
1436 pkg_outdated=$(fgrep update $tmp_status | wc -l)
1437 pkg_unknown=$( fgrep '-' $tmp_status | wc -l)
1439 pct_actual=$(( $pkg_actual * 100 / $pkg_total ))
1440 pct_outdated=$(( $pkg_outdated * 100 / $pkg_total ))
1441 pct_unknown=$(( $pkg_unknown * 100 / $pkg_total ))
1443 [ "$pkg_actual" -eq 0 ] && pkg_actual=''
1444 [ "$pkg_outdated" -eq 0 ] && pkg_outdated=''
1445 [ "$pkg_unknown" -eq 0 ] && pkg_unknown=''
1447 cat <<-EOT
1448 </table>
1450 <div class="meter" style="width:100%;text-align:center"><div
1451 style="display:inline-block;background-color:#090;width:$pct_actual%">$pkg_actual</div><div
1452 style="display:inline-block;background-color:#f90;width:$pct_outdated%">$pkg_outdated</div><div
1453 style="display:inline-block;background-color:#ccc;width:$pct_unknown%">$pkg_unknown</div></div>
1454 EOT
1455 rm $tmp_status
1456 fi
1457 cat <<-EOT
1458 </section>
1459 EOT
1460 ;;
1461 esac
1462 page_footer
1463 exit 0
1464 fi
1467 # We may have a toolchain.cgi script for cross cooker's
1468 if [ -f "toolchain.cgi" ]; then
1469 toolchain="toolchain.cgi"
1470 else
1471 toolchain="?toolchain"
1472 fi
1474 # Main page with summary. Count only packages included in ARCH,
1475 # use 'cooker arch-db' to manually create arch.$ARCH files.
1477 cat <<-EOT
1478 <div id="content2">
1480 <section>
1481 <form method="get" action="" class="search r">
1482 <input type="hidden" name="search" value="pkg"/>
1483 <button type="submit" title="Search">Search</button>
1484 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1485 </form>
1486 EOT
1488 unset nojs
1489 part summary
1490 part webstat
1492 cat <<-EOT
1493 <p>
1494 Service logs:
1495 <a href="?cookorder.log">cookorder</a> ·
1496 <a href="?commits.log">commits</a> ·
1497 <a href="?pkgdb.log">pkgdb</a>
1498 </p>
1499 EOT
1501 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1502 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1503 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1504 else
1505 show_note i 'Cooker will be launched in the next 5 minutes.'
1506 fi
1507 fi
1509 cat <<-EOT
1510 <a class="button icon maintainers" href="?maintainer">For maintainers</a>
1511 <a class="button icon tag" href="~/">Tags</a>
1512 </section>
1513 EOT
1515 part activity
1516 part cooknotes
1517 part commits
1518 part cooklist
1519 part broken
1520 part blocked
1521 part pkgs
1523 echo '</div>'
1524 datalist
1525 page_footer
1526 exit 0
1527 fi
1530 # show tag
1532 if [ "$pkg" == '~' ]; then
1533 page_header
1534 echo '<div id="content2"><section>'
1536 if [ -n "$cmd" ]; then
1537 tag="$cmd"
1538 cat <<-EOT
1539 <h2>Tag “$tag”</h2>
1541 <table>
1542 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1543 <tbody>
1544 EOT
1545 sort $PKGS/packages-$ARCH.info \
1546 | awk -F$'\t' -vtag=" $tag " -vbase="$base/" '{
1547 if (index(" " $6 " ", tag)) {
1548 url = base $1 "/";
1549 gsub("+", "%2B", url);
1550 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1551 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1553 }'
1554 echo '</tbody></table>'
1555 else
1556 # Fast and nice tag cloud
1557 echo '<h2>Tag cloud</h2><p class="tags">'
1558 # Some magic in tag sizes :-) It's because of non-linear distribution
1559 # of tags. Currently 1x198 (each of 198 tags marks one package);
1560 # 2x79 (each of 79 other tags marks two packages); 3x28 (and so on);
1561 # 4x23; 5x14; 6x5; 7x9; 8x11; 9x4; 10x3; 11x5; 12x6; 13x3; 14x1; 15x1;
1562 # 16x2; 18x1; 20x3; 22x3; 23, 24, 27, 33, 39, 42, 45, 57, 59, 65, 90x1.
1563 awk -F$'\t' -vbase="$base/~/" '
1565 split($6, tags, " ");
1566 for (i in tags) { tag[tags[i]]++; if (tag[tags[i]] > max) max = tag[tags[i]]; }
1568 END {
1569 for (i in tag) {
1570 j = tag[i];
1571 size = (j == 1) ? 0 : (j == 2) ? 1 : (j < 5) ? 2 : (j < 9) ? 3 : (j < 18) ? 4 : 5;
1572 printf("<a href=\"%s\" class=\"tag%s\">%s<sup>%s</sup></a>\n", base i, size, i, tag[i]);
1575 ' $PKGS/packages-$ARCH.info | sort -f # sort alphabetically case insensitive
1576 fi
1577 echo '</p></section></div>'
1578 page_footer
1579 exit 0
1580 fi
1583 # show badges
1585 if [ "$pkg" == '%' ]; then
1586 page_header
1587 echo '<div id="content2">'
1589 if [ -n "$cmd" ]; then
1590 badge="$cmd"
1591 cat <<-EOT
1592 <section>
1593 <h2 class="badge $badge"> Badge “$badge”</h2>
1595 <table>
1596 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1597 <tbody>
1598 EOT
1599 ls $WOK \
1600 | while read pkg; do
1601 [ -e $WOK/$pkg/.badges ] || continue
1602 grep -q "^${badge}$" $WOK/$pkg/.badges &&
1603 awk -F$'\t' -vpkg="$pkg" -vbase="$base/" '{
1604 if ($1 == pkg) {
1605 url = base $1 "/";
1606 gsub("+", "%2B", url);
1607 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1608 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1610 }' $PKGS/packages-$ARCH.info
1611 done
1612 echo '</tbody></table></section>'
1613 else
1614 layout='list' show_badges bdbroken broken any noany libtool nolibtool own ownover perm permover symlink ss fadd frem fdup old orphan patch win
1615 fi
1616 echo '</div>'
1617 page_footer
1618 exit 0
1619 fi
1622 case "$cmd" in
1623 '')
1624 page_header
1626 requested_pkg="$pkg"
1627 # Package info.
1628 if [ ! -f "$wok/$pkg/receipt" ]; then
1629 # Let's look at the cases when the package was not found
1631 # Maybe query is the exact name of split package? -> proceed to main package
1632 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1633 if (index(" " $2 " ", pkg)) {print $1; exit}
1634 }' $splitdb)
1636 # No, so let's find any matches among packages names (both main and split)
1637 if [ -z "$mainpkg" ]; then
1638 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1639 # Nothing matched
1640 if [ -z "$pkgs" ]; then
1641 echo "<h2>Not Found</h2>"
1642 show_note e "The requested package <b>$pkg</b> was not found on this server."
1643 page_footer; exit 0
1644 fi
1645 # Search results page
1646 echo "<section><h2>Package names matching “$pkg”</h2>"
1647 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1648 query="$pkg"
1649 for pkg in $pkgs; do
1650 # Find main package
1651 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1652 if (index(" " $2 " ", pkg)) {print $1; exit}
1653 }' $splitdb)
1654 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1656 unset SHORT_DESC CATEGORY
1657 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1658 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1660 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1661 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1662 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1663 done
1664 echo '</tbody></table></section>'
1665 page_footer; exit 0
1666 fi
1667 pkg="$mainpkg"
1668 fi
1670 log=$LOGS/$pkg.log
1671 pkg_info
1673 # Check for a log file and display summary if it exists.
1674 summary "$log"
1677 # Show Cooker badges
1678 if [ -s $wok/$pkg/.badges ]; then
1679 layout='table' show_badges $(cat $wok/$pkg/.badges)
1680 fi
1683 # Repology badge
1684 [ "$REPOLOGY" == '-' ] || cat <<-EOT
1685 <section>
1686 <h3>Repology</h3>
1687 <a href="https://repology.org/metapackage/${REPOLOGY:-$pkg}" target='_blank'
1688 rel='noopener noreferrer' title="latest packaged version(s) by Repology">
1689 <img src="https://repology.org/badge/latest-versions/${REPOLOGY:-$pkg}.svg" alt="latest packaged version(s)">
1690 <img src="https://repology.org/badge/tiny-repos/${REPOLOGY:-$pkg}.svg" alt="Packaging status">
1691 </a>
1692 </section>
1693 EOT
1696 # Show tag list
1697 taglist=$(
1698 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1699 [ -s "$PKGS/packages.info" ] &&
1700 awk -F$'\t' -vpkg="$i" '{
1701 if ($1 == pkg) { print $6; exit; }
1702 }' "$PKGS/packages.info"
1703 done \
1704 | tr ' ' '\n' \
1705 | sort -u
1707 if [ -n "$taglist" ]; then
1708 echo -n '<section><h3>Tags</h3><p>'
1709 lasttag=$(echo "$taglist" | tail -n1)
1710 for tag in $taglist; do
1711 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1712 [ "$tag" != "$lasttag" ] && echo -n " · "
1713 done
1714 echo '</p></section>'
1715 fi
1718 # Informational table with dependencies
1719 pkg="$requested_pkg"
1720 inf="$(mktemp -d)"
1722 # 1/3: Build dependencies (from receipt and pkgdb)
1723 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1724 echo "$i" >> $inf/a
1725 done
1727 # 2/3: Runtime dependencies (from pkgdb)
1729 [ -s "$PKGS/packages.info" ] &&
1730 awk -F$'\t' -vp="$pkg" '{
1731 if ($1 == p) print $8
1732 }' "$PKGS/packages.info"
1733 } | tr ' ' '\n' | sort -u > $inf/b
1735 # 3/3: Required by (from pkgdb)
1737 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1738 [ -s "$PKGS/packages.info" ] &&
1739 awk -F$'\t' -vp=" $i " '{
1740 if (index(" " $8 " ", p)) print $1
1741 }' "$PKGS/packages.info"
1743 [ -s "$PKGS/bdeps.txt" ] &&
1744 awk -F$'\t' -vp=" $i " '{
1745 if (index(" " $2 " ", p)) print $1
1746 }' $PKGS/bdeps.txt
1747 done
1748 } | sort -u > $inf/c
1750 cat <<-EOT
1751 <section>
1752 <h3>Related packages</h3>
1753 <table class="third">
1754 <thead>
1755 <tr>
1756 <th>Build dependencies</th>
1757 <th>Runtime dependencies</th>
1758 <th>Required by</th>
1759 </tr>
1760 </thead>
1761 <tbody>
1762 EOT
1764 awk -vinf="$inf" -vbase="$base" '
1765 function linki(i) {
1766 if (i) return sprintf("<img src=\"%s/s/%s\" alt=\"%s\"> <a href=\"%s/%s\">%s</a>", base, i, i, base, i, i);
1768 BEGIN{
1769 do {
1770 a = b = c = "";
1771 getline a < inf "/a";
1772 getline b < inf "/b";
1773 getline c < inf "/c";
1774 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1775 } while ( a b c )
1776 }'
1777 cat <<-EOT
1778 </tbody>
1779 </table>
1780 </section>
1781 EOT
1782 # Clean
1783 rm -r $inf
1788 # Display <Recook> button only for SliTaz web browser
1789 case "$HTTP_USER_AGENT" in
1790 *SliTaz*)
1791 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1792 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1793 show_note i "The package “$pkg” has been requested for recook"
1794 else
1795 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1796 fi
1797 fi
1798 ;;
1799 esac
1800 ;;
1802 receipt)
1803 page_header
1804 pkg_info
1805 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1806 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1807 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1809 show_code bash < $wok/$pkg/receipt
1810 ;;
1812 stuff)
1813 page_header
1814 pkg_info
1815 file="$pkg/stuff/$arg"
1816 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1817 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1818 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1819 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1820 }'
1822 if [ -f "$wok/$file" ]; then
1823 case $file in
1824 *.desktop|*.theme) class="ini" ;;
1825 *.patch|*.diff|*.u) class="diff" ;;
1826 */patches/series) class="bash";;
1827 *.sh) class="bash" ;;
1828 *.conf*|*.ini)
1829 class="bash"
1830 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1831 ;;
1832 *.pl) class="perl" ;;
1833 *.c|*.h|*.awk) class="clike" ;;
1834 *.svg) class="svg" ;;
1835 *Makefile*) class="makefile" ;;
1836 *.po|*.pot) class="bash" ;;
1837 *.css) class="css" ;;
1838 *.htm|*.html) class="html" ;;
1839 *.js) class="js" ;;
1840 *.txt) class="asciidoc" ;;
1841 *)
1842 case $(head -n1 $wok/$file) in
1843 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1844 esac
1845 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1846 class="bash"
1847 fi
1848 if [ -z "$class" ]; then
1849 # Follow Busybox restrictions. Search for non-printable chars
1850 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1851 raw="true"
1852 fi
1853 fi
1854 ;;
1855 esac
1857 # Display image
1858 case $file in
1859 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1860 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto' alt=''/>"
1861 ;;
1862 esac
1864 # Display colored listing for all text-based documents (also for *.svg)
1865 case $file in
1866 *.png|*.jpg|*.jpeg|*.ico) ;;
1867 *)
1868 if [ -z "$raw" ]; then
1869 cat $wok/$file | show_code $class
1870 fi
1871 ;;
1872 esac
1874 # Display hex dump for binary files
1875 if [ -n "$raw" ]; then
1876 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1877 fi
1878 else
1879 show_note e "File “$file” absent!"
1880 fi
1881 ;;
1883 files)
1884 page_header
1885 pkg_info
1887 # find main package
1888 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1889 main=${wanted:-$pkg}
1890 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1892 splitsets=$(echo $SPLIT" " \
1893 | awk '
1894 BEGIN { RS = " "; FS = ":"; }
1895 { print $2; }' \
1896 | sort -u \
1897 | tr '\n' ' ' \
1898 | sed 's|^ *||; s| *$||')
1900 splitpkgs=$(echo $SPLIT" " \
1901 | awk '
1902 BEGIN { RS = " "; FS = ":"; }
1903 { print $1; }' \
1904 | tr '\n' ' ' \
1905 | sed 's|^ *||; s| *$||')
1907 # we need the version
1908 if [ -f "$WOK/linux/receipt" ]; then
1909 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1910 kbasevers=$(echo $kvers | cut -d. -f1,2)
1911 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1912 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1913 kbasevers=$(echo $kvers | cut -d. -f1,2)
1914 fi
1915 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1917 echo "<section><h3>Quick jump:</h3>"
1920 for part in head body; do
1922 for set in '' $splitsets; do
1923 pkgsofset=$(echo $SPLIT" " \
1924 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1925 BEGIN {
1926 RS = " "; FS = ":";
1927 if (!set) print main;
1928 if (!set && dev) print dev;
1931 if ($2 == set) print $1;
1932 }' \
1933 | sort -u)
1935 set_description=''
1936 [ -n "$splitsets" ] &&
1937 case "$set" in
1938 '')
1939 set_description=' (default set)'
1940 set_title='Default set'
1941 ;;
1942 *)
1943 set_description=" (set “$set”)"
1944 set_title="Set “$set”"
1945 ;;
1946 esac
1948 install="$wok/$main/install"
1949 [ -n "$set" ] && install="$install-$set"
1951 case $part in
1952 head)
1953 [ -n "$splitsets" ] &&
1954 case "$set" in
1955 '') echo "<ul><li>Default set:";;
1956 *) echo "<li>Set “$set”:";;
1957 esac
1958 echo -e '\t<ul>'
1959 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1960 cat <<-EOT
1961 <li id='li-repeats$set' style='display:none'>
1962 <a href='#repeats$set'>repeatedly packaged files</a></li>
1963 <li id='li-empty$set' style='display:none'>
1964 <a href='#empty$set'>unpackaged empty folders</a></li>
1965 <li id='li-outoftree$set' style='display:none'>
1966 <a href='#outoftree$set'>out-of-tree files</a></li>
1967 <li id='li-orphans$set' style='display:none'>
1968 <a href='#orphans$set'>unpackaged files</a>
1969 <span id='orphansTypes$set'></span></li>
1970 EOT
1971 echo -e '\t</ul>'
1972 [ -n "$splitsets" ] && echo "</li>"
1973 ;;
1974 body)
1975 all_files=$(mktemp)
1976 cd $install; find ! -type d | sed 's|\.||' > $all_files
1978 # ------------------------------------------------------
1979 # Packages content
1980 # ------------------------------------------------------
1981 packaged=$(mktemp)
1982 for p in $pkgsofset; do
1983 namever="$(awk -F$'\t' -vp="$p" '{
1984 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
1985 }' $PKGS/packages-$ARCH.info)"
1986 if [ -d "$wok/$p/taz/$p-$ver" ]; then
1987 indir=$p
1988 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
1989 indir=$main
1990 fi
1991 dir="$wok/$indir/taz/$p-$ver/fs"
1993 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
1995 echo
1996 echo "<section id='$p'>"
1997 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
1998 echo ' <pre class="files">'
1999 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
2000 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2001 cd $dir
2002 find . -print0 \
2003 | sort -z \
2004 | xargs -0 ls -ldp --color=always \
2005 | syntax_highlighter files \
2006 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
2007 | awk 'BEGIN { FS="\""; }
2008 { gsub("+", "%2B", $2); print; }'
2009 else
2010 echo 'No files'
2011 fi
2012 echo '</pre>'
2013 echo '</section>'
2015 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
2016 done
2017 # ------------------------------------------------------
2018 # /Packages content
2019 # ------------------------------------------------------
2021 # ------------------------------------------------------
2022 # Repeatedly packaged files
2023 # ------------------------------------------------------
2024 repeats=$(mktemp)
2025 sort $packaged | uniq -d > $repeats
2026 if [ -s "$repeats" ]; then
2027 cat <<-EOT
2029 <script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>
2030 <section id='repeats$set'>
2031 <h3>Repeatedly packaged files$set_description:</h3>
2032 EOT
2033 cd $install
2035 IFS=$'\n'
2036 echo -n ' <pre class="files">'
2037 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2038 while read i; do
2039 find .$i -exec ls -ldp --color=always '{}' \; \
2040 | syntax_highlighter files \
2041 | sed 's|>\./|>/|'
2042 done < $repeats
2043 cat <<-EOT
2044 </pre>
2045 </section>
2046 EOT
2047 unset IFS
2048 fi
2049 rm $repeats
2050 # ------------------------------------------------------
2051 # /Repeatedly packaged files
2052 # ------------------------------------------------------
2054 # ------------------------------------------------------
2055 # Unpackaged empty folders
2056 # ------------------------------------------------------
2057 emptydirs=$(mktemp)
2058 cd $install
2059 IFS=$'\n'
2060 find -type d \
2061 | sed 's|\.||' \
2062 | while read d; do
2063 [ -z "$(ls "$install$d")" ] || continue
2064 # empty dir determined by empty `ls`
2065 echo $d
2066 done \
2067 | while read d; do
2068 notfound='yes'
2069 for p in $(cd $wok/$main/taz; ls); do
2070 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
2071 notfound=''
2072 break
2073 fi
2074 done
2075 [ -n "$notfound" ] &&
2076 ls -ldp --color=always .$d \
2077 | syntax_highlighter files \
2078 | sed 's|>\./|>/|'
2079 done > $emptydirs
2080 unset IFS
2081 if [ -s "$emptydirs" ]; then
2082 cat <<-EOT
2084 <script>document.getElementById('li-empty$set').style.display = 'list-item'</script>
2085 <section id='empty$set'>
2086 <h3>Unpackaged empty folders$set_description:</h3>
2087 EOT
2088 echo -n ' <pre class="files">'
2089 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2090 cat $emptydirs
2091 cat <<-EOT
2092 </pre>
2093 </section>
2094 EOT
2095 fi
2096 rm $emptydirs
2097 # ------------------------------------------------------
2098 # /Unpackaged empty folders
2099 # ------------------------------------------------------
2101 # ------------------------------------------------------
2102 # Out-of-tree files
2103 # ------------------------------------------------------
2104 outoftree=$(mktemp)
2105 awk -F$'\n' -vall="$all_files" '
2107 if (FILENAME == all) files_all[$1] = "1";
2108 else files_pkg[$1] = "1";
2110 END {
2111 for (i in files_pkg) {
2112 if (! files_all[i]) print i;
2115 ' "$all_files" "$packaged" > $outoftree
2117 if [ -d "$install" -a -s "$outoftree" ]; then
2118 echo
2119 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
2120 echo "<section id='outoftree$set'>"
2121 echo " <h3>Out-of-tree files$set_description:</h3>"
2122 echo -n ' <pre class="files">'
2123 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2124 IFS=$'\n'
2125 while read outoftree_line; do
2126 # Find the package out-of-tree file belongs to
2127 for i in $pkgsofset; do
2128 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
2129 cd $wok/$main/taz/$i-$ver/fs
2130 ls -ldp --color=always ".$outoftree_line" \
2131 | syntax_highlighter files \
2132 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
2133 | awk 'BEGIN { FS="\""; }
2134 { gsub("+", "%2B", $2); print; }'
2135 fi
2136 done
2137 done < $outoftree
2138 unset IFS
2139 echo '</pre>'
2140 echo '</section>'
2141 fi
2142 rm $outoftree
2143 # ------------------------------------------------------
2144 # /Out-of-tree files
2145 # ------------------------------------------------------
2147 # ------------------------------------------------------
2148 # Unpackaged files
2149 # ------------------------------------------------------
2150 orphans=$(mktemp)
2151 awk -F$'\n' -vall="$all_files" '
2153 if (FILENAME == all) files_all[$1] = "1";
2154 else files_pkg[$1] = "1";
2156 END {
2157 for (i in files_all) {
2158 if (! files_pkg[i]) print i;
2161 ' "$all_files" "$packaged" | sort > $orphans
2162 if [ -d "$install" -a -s "$orphans" ]; then
2163 echo
2164 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
2165 echo "<section id='orphans$set'>"
2166 echo " <h3>Unpackaged files$set_description:</h3>"
2167 table=$(mktemp)
2168 awk '
2169 function tag(text, color) {
2170 printf("<span class=\"c%s1\">%s</span> ", color, text);
2171 printf("%s\n", $0);
2173 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
2174 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
2175 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
2176 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ ||
2177 /\/cache\/.*\.gem$/ {
2178 tag("---", 0); next }
2179 /\.pod$/ { tag("pod", 5); next }
2180 /\/share\/man\// { tag("man", 5); next }
2181 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
2182 /\/share\/devhelp\// { tag("doc", 5); next }
2183 /\/share\/icons\// { tag("ico", 2); next }
2184 /\/share\/locale\// { tag("loc", 4); next }
2185 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
2186 /\/Makefile.*$/ { tag("dev", 3); next }
2187 /\/share\/help\// || /\/share\/appdata\// ||
2188 /\/share\/metainfo\// || /\/share\/application-registry\// ||
2189 /\/share\/mime-info\// || /\/share\/gnome\/help\// || /\/share\/omf\// {
2190 tag("gnm", 6); next }
2191 { tag("???", 1) }
2192 ' "$orphans" > $table
2194 # Summary table
2195 orphans_types='()'
2196 for i in head body; do
2197 case $i in
2198 head) echo -n '<table class="summary"><tr>';;
2199 body) echo -n '<th> </th></tr><tr>';;
2200 esac
2201 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
2202 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
2203 case $i in
2204 head) echo -n "<th class='$class'>$tag</th>";;
2205 body)
2206 tagscount="$(grep ">$tag<" $table | wc -l)"
2207 printf '<td>%s</td>' "$tagscount"
2208 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
2209 ;;
2210 esac
2211 done
2212 done
2213 echo '<td> </td></tr></table>'
2214 orphans_types="${orphans_types/( /(}"
2215 [ "$orphans_types" != '()' ] &&
2216 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
2218 suffix=''; [ -n "$set" ] && suffix="-$set"
2219 echo -n ' <pre class="files">'
2220 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2221 IFS=$'\n'
2222 while read orphan_line; do
2223 echo -n "${orphan_line/span> */span>} "
2224 cd $install
2225 ls -ldp --color=always ".${orphan_line#*</span> }" \
2226 | syntax_highlighter files \
2227 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
2228 | awk 'BEGIN { FS="\""; }
2229 { gsub("+", "%2B", $2); print; }'
2230 done < $table
2231 unset IFS
2232 echo '</pre>'
2233 echo '</section>'
2234 rm $table
2235 fi
2236 rm $orphans
2237 # ------------------------------------------------------
2238 # /Unpackaged files
2239 # ------------------------------------------------------
2241 rm $all_files $packaged
2242 ;;
2243 esac
2244 done # /set
2246 case "$part" in
2247 head)
2248 [ -n "$splitsets" ] && echo "</ul>"
2249 echo "</section>"
2250 ;;
2251 esac
2252 done # /part
2254 ;;
2256 description)
2257 page_header
2258 pkg_info
2259 descs="$(ls $WOK/$pkg/description*.txt)"
2260 if [ -n "$descs" ]; then
2261 echo '<div id="content2">'
2262 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
2263 for i in $descs; do
2264 case $i in
2265 */description.txt) continue ;;
2266 *) package=$(echo $i | cut -d. -f2) ;;
2267 esac
2268 show_desc "$package" "$i"
2269 done
2270 echo '</div>'
2271 else
2272 show_note w "No description of $pkg"
2273 fi
2274 ;;
2276 log)
2277 page_header
2278 pkg_info
2279 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
2281 echo '<div class="btnList">'
2282 acc='l' # access key for the latest log is 'L'
2283 while read log; do
2284 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
2285 timestamp=$(stat -c %Y $log)
2286 class=''
2287 if [ "$arg" == "$timestamp" ]; then
2288 class=' log'
2289 logfile="$log"
2290 fi
2291 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
2292 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
2293 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
2294 case $acc in
2295 l) acc=0;;
2296 *) acc=$((acc+1));;
2297 esac
2298 done <<EOT
2299 $(find $LOGS -name "$pkg.log*" | sort)
2300 $(find $LOGS -name "$pkg-pack.log")
2301 EOT
2302 echo '</div>'
2304 if [ -z "$logfile" ]; then
2305 show_note e "Requested log is absent"
2306 page_footer
2307 exit 0
2308 fi
2310 # Define cook variables for syntax highlighter
2311 if [ -s "$WOK/$pkg/receipt" ]; then
2312 . "$WOK/$pkg/receipt"
2313 _wok='/home/slitaz/wok'
2314 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
2315 _install="$_wok/$pkg/install"
2316 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
2317 _stuff="$_wok/$pkg/stuff"
2318 fi
2320 # if [ ! -f "gzlog/$pkg.$arg" ]; then
2321 # {
2322 # summary "$logfile" links
2324 # syntax_highlighter log < $logfile | awk '
2325 # BEGIN { print "<pre class=\"log\">"; }
2326 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
2327 # END { print "</pre>"; }
2328 # '
2330 # page_footer
2331 # } | gzip > gzlog/$pkg.$arg
2332 # fi
2334 blog=$(basename $logfile)
2335 summary "$logfile" links
2337 # disable next `sed` for the 'like2016' theme
2338 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
2339 cat $logfile | syntax_highlighter log | \
2340 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1' alt=''> \1|" | \
2341 awk '
2342 BEGIN { print "<pre class=\"log\">"; }
2343 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
2344 END { print "</pre>"; }
2346 ;;
2349 man|doc|info)
2350 page_header
2351 pkg_info
2352 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
2354 dir="wok/$pkg/install/usr/share/$cmd/"; dir2=''
2355 if [ "$cmd" == 'doc' ]; then
2356 dir2="wok/$pkg/install/usr/share/gtk-doc/"
2357 subdirs="$(ls -p $dir | sed '/\/$/!d')"
2358 [ $(echo "$subdirs" | wc -l) -eq 1 ] && dir="$dir$subdirs"
2359 if [ -z "$arg" ]; then
2360 try=$(for i in $dir $dir2; do find $i -name 'index.htm*'; done | sed q)
2361 [ -n "$try" ] && arg="$try"
2362 fi
2363 fi
2365 while read i; do
2366 [ -s "$i" ] || continue
2367 case "$i" in
2368 *.jp*g|*.png|*.gif|*.svg|*.css) continue
2369 esac
2370 i=${i#$dir}; i=${i#$dir2}
2371 [ -n "$arg" ] || arg="$i"
2372 class=''; [ "$arg" == "$i" ] && class=" doc"
2373 case "$cmd" in
2374 man)
2375 case $i in
2376 man*) lang='';;
2377 *) lang="${i%%/*}: ";;
2378 esac
2379 man=$(basename $i .gz)
2380 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
2381 ;;
2382 doc)
2383 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$i</a>"
2384 ;;
2385 info)
2386 info=$(basename $i)
2387 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
2388 ;;
2389 esac
2390 done <<EOT
2391 $(for i in $dir $dir2; do find $i -type f; done | sort)
2392 EOT
2393 echo '</div>'
2395 [ -f "$arg" ] || arg="$dir/$arg"
2396 if [ -f "$arg" ]; then
2397 tmp="$(mktemp)"
2398 docat "$arg" > $tmp
2399 [ -s "$tmp" ] &&
2400 case "$cmd" in
2401 info)
2402 echo '<div id="content2" class="texinfo"><pre class="first">'
2403 info2html < "$tmp"
2404 echo '</pre></div>'
2405 ;;
2406 doc)
2407 case "$arg" in
2408 *.sgml|*.devhelp2) class='xml';;
2409 *.py) class='python';; # pycurl package
2410 *.css) class='css';;
2411 *.sh) class='bash';;
2412 *.rb|*/Rakefile*|*/Gemfile*) class='ruby';;
2413 *.rdoc) class='asciidoc';;
2414 *)
2415 first=$(head -n1 "$tmp")
2416 if [ "${first:0:1}" == '#' ]; then
2417 class='bash' # first line begins with '#'
2418 else
2419 class='asciidoc'
2420 fi;;
2421 esac
2422 case "$arg" in
2423 *.htm*)
2424 case $arg in
2425 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2426 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2427 esac
2428 # make the iframe height so long to contain its contents without scrollbar
2429 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
2430 ;;
2431 *.pdf)
2432 case $arg in
2433 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2434 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2435 esac
2436 cat <<-EOT
2437 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
2438 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
2439 </object>
2440 EOT
2441 ;;
2442 *.md|*.markdown)
2443 echo '<section class="markdown">'
2444 $md2html "$tmp" | sed 's|class="|class="language-|g'
2445 echo '</section>'
2446 ;;
2447 *)
2448 show_code $class < "$tmp"
2449 ;;
2450 esac
2451 ;;
2452 man)
2453 #export TEXTDOMAIN='man2html'
2454 echo "<div id='content2'>"
2456 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2457 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2458 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2460 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2461 # Process the pre-formatted man-cat page
2462 # (for example see sudo package without groff in build dependencies)
2463 sed -i '
2464 s|M-bM-^@M-^S|—|g;
2465 s|M-bM-^@M-^\\|<b>|g;
2466 s|M-bM-^@M-^]|</b>|g
2467 s|M-bM-^@M-^X|<u>|g;
2468 s|M-bM-^@M-^Y|</u>|g;
2469 s|M-BM-||g;
2470 s|++oo|•|g;
2471 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2472 ' "$tmp"
2473 for i in a b c d e f g h i j k l m n o p q r s t u v w x y z \
2474 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
2475 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2476 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2477 done
2478 echo '<pre class="catman">'
2479 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2480 echo '</pre>'
2481 else
2482 echo "$html"
2483 fi
2484 echo "</div>"
2485 ;;
2486 esac
2487 rm -f $tmp
2488 else
2489 show_note e "File “$arg” does not exist!"
2490 fi
2491 ;;
2493 download)
2494 page_header
2495 pkg_info
2496 show=0
2498 . $wok/$pkg/receipt
2500 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2501 files_header
2502 echo "<tr><td><a href='$base/src/$TARBALL' class='icon tarball'>$TARBALL</a></td>"
2503 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2504 echo "<td>Sources for building the package “$pkg”</td></tr>"
2505 show=1
2506 fi
2508 if [ -d "$wok/$pkg/taz" ]; then
2509 [ "$show" -eq 1 ] || files_header
2511 common_version=$VERSION
2512 for i in $(all_names | tr ' ' '\n' | sort); do
2513 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2514 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2516 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-any.tazpkg"; do
2517 [ -f "$PKGS/$filename" ] || continue
2519 case $filename in
2520 *-x86_64.tazpkg) class='pkg64';;
2521 *-any.tazpkg) class='pkgany';;
2522 *) class='pkg32';;
2523 esac
2524 cat <<-EOT
2525 <tr>
2526 <td><a href="$base/get/$filename" class='icon $class'>$filename</a></td>
2527 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2528 <td>$SHORT_DESC</td>
2529 </tr>
2530 EOT
2531 done
2532 done
2533 show=1
2534 fi
2536 if [ "$show" -eq 1 ]; then
2537 echo '</tbody></table></section>'
2538 else
2539 show_note w "Sorry, there's nothing to download…"
2540 fi
2541 ;;
2543 esac
2546 page_footer
2547 exit 0