cookutils view lighttpd/index.cgi @ rev 1106

Typos (again)
author Paul Issott <paul@slitaz.org>
date Sat Dec 01 10:48:06 2018 +0000 (2018-12-01)
parents 5dcdc6015a2d
children 7fdea1dfb4e2
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. Of 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-$ARCH.info ] &&
777 short_desc="$(awk -F$'\t' -vp="${requested_pkg:-$pkg}" '{if ($1 == p) { printf("%s", $4); exit; }}' $PKGS/packages-$ARCH.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-$ARCH.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=$(wc -l < $PKGS/packages-$ARCH.info)
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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/receipt\">receipt</a>"
969 ;;
970 noany)
971 t="No “any” arch"
972 p="This package contains architecture dependent <a href=\"$base/$PACKAGE/files\">files</a>"
973 s="Remove the line <code>HOST_ARCH=\"any\"</code> from <a href=\"$base/$PACKAGE/receipt\">receipt</a>"
974 ;;
975 libtool)
976 t="Libtool isn't fixed"
977 p="This package uses <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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/receipt\">receipt</a>"
984 ;;
985 own)
986 t="Ownership problems"
987 p="Some files of this package have <a href=\"$base/$PACKAGE/files\">ownership problems</a>"
988 s="Correct the ownership or add problem files to the “<a href=\"$base/$PACKAGE/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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/stuff/overrides\">the list</a>"
994 ;;
995 perm)
996 t="Permissions problems"
997 p="Some files of this package have <a href=\"$base/$PACKAGE/files\">unusual permissions</a>"
998 s="Correct the permissions or add problem files to the “<a href=\"$base/$PACKAGE/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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/stuff/overrides\">the list</a>"
1004 ;;
1005 symlink)
1006 t="Broken symlink"
1007 p="This package contains one or more <a href=\"$base/$PACKAGE/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 uses site script; most of the 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=\"$base/$PACKAGE/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=\"$base/$PACKAGE/files#orphans\">not belonging to any package</a>"
1023 s="Revise <code>genpkg_rules()</code> or add files to “<a href=\"$base/$PACKAGE/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=\"$base/$PACKAGE/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 no-badge)
1051 t="No badge"
1052 p="Packages without badges"
1053 s=""
1054 ;;
1055 esac
1056 case $layout in
1057 table)
1058 echo "<tr><td><span class=\"badge $badge\" title=\"$t\"/></td><td>$p</td><td>$s</td></tr>"
1059 ;;
1060 list)
1061 p=$(echo $p | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g')
1062 s=$(echo $s | sed 's|<a [^>]*>\([^<]*\)</a>|\1|g|')
1063 echo "<tr><td><a href=\"$badge\"><span class=\"badge $badge\" title=\"$t\"/></a></td><td>$p</td></tr>"
1064 ;;
1065 *)
1066 echo -n "<span class=\"badge $badge\" title=\"$t\"/>"
1067 ;;
1068 esac
1069 done
1071 case $layout in
1072 table|list)
1073 echo "</tbody></table></section>"
1074 ;;
1075 esac
1079 # Generate part of the main page
1081 part() {
1082 echo -n "<div id='$1'>"
1084 case $1 in
1085 summary)
1086 echo '<h2>Summary</h2>'
1088 mktable <<EOT
1089 Cooker state : $(running_command)
1090 Wok revision : <a href='$WOK_URL' target='_blank' rel='noopener noreferrer'>$(cat $wokrev)</a>
1091 Commits to cook : $(wc -l < $commits)
1092 Current cooklist : $(wc -l < $cooklist)
1093 Architecture : $ARCH, <a href="$toolchain">toolchain</a>
1094 Server date : <span id='date'>$(date -u '+%F %R %Z')</span>
1095 EOT
1097 # If command is "cook:*", update gauge and percentage periodically.
1098 # If different package is cooking, reload the page (with new settings)
1099 cmd="$(cat $command)"
1100 case "$cmd" in
1101 cook:*)
1102 pkg=${cmd#*:}
1103 echo "<script>updatePkg = '${pkg//+/%2B}';</script>"
1104 ;;
1105 esac
1106 ;;
1107 webstat)
1108 # Do we need to update the statistics?
1109 if [ -n "$nojs" -a "$activity" -nt "$webstat" ]; then update_webstat; fi
1110 . $webstat
1112 pct=0; [ "$rtotal" -gt 0 ] && pct=$(( ($rcooked * 100) / $rtotal ))
1114 cat <<-EOT
1115 <div class="meter"><progress max="100" value="$pct">${pct}%</progress><span>${pct}%</span></div>
1117 <table class="webstat">
1118 <thead>
1119 <tr>
1120 <th> </th>
1121 <th>Total </th>
1122 <th>Cooked </th>
1123 <th>Unbuilt </th>
1124 <th>Blocked </th>
1125 <th>Broken </th>
1126 </tr>
1127 </thead>
1128 <tbody>
1129 <tr>
1130 <td>Receipts</td>
1131 <td>$rtotal</td>
1132 <td>$rcooked</td>
1133 <td>$runbuilt</td>
1134 <td>$rblocked</td>
1135 <td>$rbroken</td>
1136 </tr>
1137 <tr>
1138 <td>Packages</td>
1139 <td>$ptotal</td>
1140 <td>$pcooked</td>
1141 <td>$punbuilt</td>
1142 <td>$pblocked</td>
1143 <td>$pbroken</td>
1144 </tr>
1145 </tbody>
1146 </table>
1147 EOT
1148 if [ -z "$nojs" ]; then echo "<script>getPart('$1')</script>"; fi
1149 ;;
1150 activity)
1151 tac $activity | head -n12 | sed 's|cooker.cgi?pkg=||;
1152 s|\[ Done|<span class="r c20">Done|;
1153 s|\[ Failed|<span class="r c10">Failed|;
1154 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1155 s| \]|</span>|;
1156 s|%2B|\+|g' \
1157 | while read line; do
1158 case "$line" in
1159 *data-badges=*)
1160 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1161 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1162 ;;
1163 *)
1164 echo "$line"
1165 ;;
1166 esac
1167 done | section $activity 12 "Activity|More activity" \
1168 ;;
1169 cooknotes)
1170 [ -s "$cooknotes" ] && tac $cooknotes | head -n12 | \
1171 section $cooknotes 12 "Cooknotes|More notes"
1172 ;;
1173 commits)
1174 [ -s "$commits" ] && head -n20 $commits | \
1175 section $commits 20 "Commits|More commits"
1176 ;;
1177 cooklist)
1178 [ -s "$cooklist" ] && head -n 20 $cooklist | \
1179 section $cooklist 20 "Cooklist|Full cooklist"
1180 ;;
1181 broken)
1182 [ -s "$broken" ] && head -n20 $broken | sed "s|^[^']*|<a href='\0'>\0</a>|g" | \
1183 section $broken 20 "Broken|All broken packages"
1184 ;;
1185 blocked)
1186 [ -s "$blocked" ] && sed "s|^[^']*|<a href='\0'>\0</a>|g" $blocked | \
1187 section $blocked 12 "Blocked|All blocked packages"
1188 ;;
1189 pkgs)
1190 cd $PKGS
1191 # About BusyBox's `ls`
1192 # On the Tank server: BusyBox v1.18.4 (2012-03-14 03:32:25 CET) multi-call binary.
1193 # It supported the option `-e`, output with `-let` options like this:
1194 # -rw-r--r-- 1 user group 100000 Fri Nov 3 10:00:00 2017 filename
1195 # 1 2 3 4 5 6 7 8 9 10 11
1196 # Newer BusyBox v1.27.2 doesn't support option `-e` and has no configs to
1197 # configure it or return the option back. It supported the long option
1198 # `--full-time` instead, but output is different:
1199 # -rw-r--r-- 1 user group 100000 2017-11-03 10:00:00 +0200 filename
1200 # 1 2 3 4 5 6 7 8 9
1201 if ls -let >/dev/null 2>&1; then
1202 ls -let *.tazpkg \
1203 | awk '
1204 (NR<=20){
1205 sub(/:[0-9][0-9]$/, "", $9);
1206 mon = index(" JanFebMarAprMayJunJulAugSepOctNovDec", $7) / 3;
1207 printf("%d-%02d-%02d %s : <a href=\"get/%s\">%s</a>\n", $10, mon, $8, $9, $11, $11);
1208 }' \
1209 | section $activity 1000 "Latest cook"
1210 else
1211 ls -lt --full-time *.tazpkg \
1212 | awk '
1213 (NR<=20){
1214 sub(/:[0-9][0-9]$/, "", $7);
1215 printf("%s %s : <a href=\"get/%s\">%s</a>\n", $6, $7, $9, $9);
1216 }' \
1217 | section $activity 1000 "Latest cook"
1218 fi
1219 ;;
1220 esac
1221 echo "</div>"
1225 # Query '?part=<part>': get part of the main page
1227 if [ -n "$(GET part)" ]; then
1228 part="$(GET part)"
1229 case $part in
1230 summary|webstat|activity|cooknotes|commits|cooklist|broken|blocked|pkgs)
1231 nojs='yes'
1232 part $part
1233 ;;
1234 esac
1235 exit 0
1236 fi
1242 # Load requested page
1245 if [ -z "$pkg" ]; then
1247 page_header
1248 if [ -n "$QUERY_STRING" ]; then
1250 [ "$QUERY_STRING" != 'commits.log' ] &&
1251 for list in activity cooknotes cooklist commits; do
1252 [ -n "$(GET $list)" ] || continue
1253 case $list in
1254 cooklist) nb="- Packages: $(wc -l < $cooklist)";;
1255 commits) nb="- Packages: $(wc -l < $commits)";;
1256 esac
1257 echo '<section id="content2">'
1258 echo "<h2>DB: $list $nb</h2>"
1260 tac $CACHE/$list | sed 's|cooker.cgi?pkg=||; s|%2B|+|g;
1261 s|\[ Done|<span class="r c20">Done|;
1262 s|\[ Failed|<span class="r c10">Failed|;
1263 s|\[ -Failed|<span class="r c10"><del>Failed</del>|;
1264 s| \]|</span>|;
1265 s|%2B|\+|g' \
1266 | while read line; do
1267 case "$line" in
1268 *data-badges=*)
1269 badges="$(echo "$line" | sed "s|.*data-badges='\([^']*\)'.*|\1|")"
1270 echo "$line" | sed "s|</a>|</a> $(show_badges "$badges")|"
1271 ;;
1272 *)
1273 echo "$line"
1274 ;;
1275 esac
1276 done \
1277 | mktable $list
1279 echo '</section>'
1280 done
1282 if [ -n "$(GET broken)" ]; then
1283 echo '<section id="content2">'
1284 echo "<h2>DB: broken - Packages: $(wc -l < $broken)</h2>"
1285 sort $CACHE/broken | sed "s|^[^']*|<a href='$base/\0'>\0</a>|g" | mktable
1286 echo '</section>'
1287 fi
1289 case "$QUERY_STRING" in
1290 *.log)
1291 log=$LOGS/$QUERY_STRING
1292 name=$(basename $log)
1293 if [ -f "$log" ]; then
1294 echo "<h2>Log for: ${name%.log}</h2>"
1295 if fgrep -q "Summary" $log; then
1296 echo '<pre class="log">'
1297 grep -A 20 'Summary' $log | syntax_highlighter log
1298 echo '</pre>'
1299 fi
1300 echo '<pre class="log">'
1301 syntax_highlighter log < $log
1302 echo '</pre>'
1303 if [ "$QUERY_STRING" == 'pkgdb.log' ]; then
1304 # Display button only for SliTaz web browser
1305 case "$HTTP_USER_AGENT" in
1306 *SliTaz*)
1307 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1308 if grep -qs '^pkgdb$' $CACHE/recook-packages; then
1309 show_note i "The package database has been requested for re-creation"
1310 else
1311 echo "<a class='button' href='$base/?recook=pkgdb'>Re-create the DB</a>"
1312 fi
1313 fi
1314 ;;
1315 esac
1316 fi
1317 else
1318 show_note e "No log file: $log"
1319 fi
1320 ;;
1321 toolchain)
1322 cat <<-EOT
1323 <div id="content2">
1324 <section>
1325 <h2>SliTaz GNU/Linux toolchain</h2>
1327 <table>
1328 <tr>
1329 <td>Build date</td>
1330 <td colspan="2">$(sed -n '/^Cook date/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1331 </tr>
1332 <tr>
1333 <td>Build duration</td>
1334 <td colspan="2">$(sed -n '/^Cook time/s|[^:]*: \(.*\)|\1|p' $LOGS/slitaz-toolchain.log)</td>
1335 </tr>
1336 <tr>
1337 <td>Architecture</td>
1338 <td colspan="2">$ARCH</td>
1339 </tr>
1340 <tr>
1341 <td>Host system</td>
1342 <td colspan="2">$BUILD_SYSTEM</td>
1343 </tr>
1344 <tr>
1345 <td>Target system</td>
1346 <td colspan="2">$HOST_SYSTEM</td>
1347 </tr>
1348 <tr>
1349 <th>Package</th>
1350 <th>Version</th>
1351 <th>Description</th>
1352 </tr>
1353 $(toolchain_version slitaz-toolchain)
1354 $(toolchain_version binutils)
1355 $(toolchain_version linux-api-headers)
1356 $(toolchain_version gcc)
1357 $(toolchain_version glibc)
1358 </table>
1360 <p>Toolchain documentation: <a target="_blank" rel="noopener noreferrer"
1361 href="http://doc.slitaz.org/en:cookbook:toolchain">http://doc.slitaz.org/en:cookbook:toolchain</a>
1362 </p>
1364 </section>
1365 </div>
1366 EOT
1367 ;;
1368 maintainer*)
1369 maintainer=$(GET maintainer); maintainer=${maintainer/maintainer/}
1370 regexp=$(GET regexp); regexp=${regexp/regexp/}
1371 [ -n "$regexp" ] && maintainer=''
1372 cat <<-EOT
1373 <section>
1374 <h2>For maintainers</h2>
1375 <p>Here you can <a href="=/">explore the badges</a>.</p>
1376 <p>Or see some <a href="?maintainer&amp;stats">repository statistics</a>.</p>
1377 <p>Or check packages version either for specified maintainer or using regular expressions:</p>
1378 <form>
1379 <select name="maintainer">
1380 <option value=''>--- select maintainer ---
1381 EOT
1382 cut -d$'\t' -f1 $maintdb | sort -u \
1383 | awk -vm=$maintainer '{
1384 selected=$0==m?"selected":""
1385 printf("<option %s value=\"%s\">%s\n", selected, $0, $0)
1386 }'
1387 cat <<-EOT
1388 </select>
1389 or
1390 <input type="text" name="regexp" value="$regexp"/>
1391 <button type="submit">Go</button>
1392 </form>
1393 EOT
1394 if [ -n "$maintainer" -o -n "$regexp" ]; then
1395 tmp_status=$(mktemp)
1396 cat <<-EOT
1397 <table class="maint">
1398 <thead><tr><th>Package</th><th>Version</th><th>Repology</th></tr></thead>
1399 EOT
1401 if [ -n "$maintainer" ]; then
1402 awk -vm=$maintainer '{if ($1 == m) print $2}' $maintdb
1403 fi
1404 if [ -n "$regexp" ]; then
1405 cd $wok; ls | grep "$regexp"
1406 fi
1407 } | while read pkg; do
1408 unset VERSION; REPOLOGY=$pkg
1409 . $wok/$pkg/receipt
1410 ver=$(awk -F$'\t' -vpkg="$pkg" '{if ($1 == pkg) {print $2; exit}}' $PKGS/packages-$ARCH.info)
1411 if [ "$REPOLOGY" == '-' ]; then
1412 unset repo_info1 repo_info2
1413 echo '-' >>$tmp_status
1414 else
1415 repo_ver=$(repology_get $REPOLOGY)
1416 if [ "$repo_ver" == '-' ]; then
1417 echo '-' >>$tmp_status
1418 icon='more'
1419 else
1420 if echo " $repo_ver " | fgrep -q " ${ver:-$VERSION} "; then
1421 icon='actual'
1422 else
1423 icon='update'
1424 fi
1425 echo $icon >>$tmp_status
1426 fi
1427 repo_info1="<a class='icon $icon' href='https://repology.org/metapackage/$REPOLOGY' target='_blank'"
1428 repo_info2="rel='noopener noreferrer' title='latest packaged version(s)'>${repo_ver// /, }</a>"
1429 fi
1430 cat <<-EOT
1431 <tr>
1432 <td><img src="$base/s/$pkg" alt="$pkg"> <a href="$pkg">$pkg</a></td>
1433 <td>${ver:-$VERSION}</td>
1434 <td>$repo_info1 $repo_info2</td>
1435 </tr>
1436 EOT
1437 done
1439 pkg_total=$( wc -l < $tmp_status)
1440 pkg_actual=$( fgrep actual $tmp_status | wc -l)
1441 pkg_outdated=$(fgrep update $tmp_status | wc -l)
1442 pkg_unknown=$( fgrep '-' $tmp_status | wc -l)
1444 pct_actual=$(( $pkg_actual * 100 / $pkg_total ))
1445 pct_outdated=$(( $pkg_outdated * 100 / $pkg_total ))
1446 pct_unknown=$(( $pkg_unknown * 100 / $pkg_total ))
1448 [ "$pkg_actual" -eq 0 ] && pkg_actual=''
1449 [ "$pkg_outdated" -eq 0 ] && pkg_outdated=''
1450 [ "$pkg_unknown" -eq 0 ] && pkg_unknown=''
1452 cat <<-EOT
1453 </table>
1455 <div class="meter" style="width:100%;text-align:center"><div
1456 style="display:inline-block;background-color:#090;width:$pct_actual%">$pkg_actual</div><div
1457 style="display:inline-block;background-color:#f90;width:$pct_outdated%">$pkg_outdated</div><div
1458 style="display:inline-block;background-color:#ccc;width:$pct_unknown%">$pkg_unknown</div></div>
1459 EOT
1460 rm $tmp_status
1461 fi
1462 cat <<-EOT
1463 </section>
1464 EOT
1465 ;;
1466 esac
1467 page_footer
1468 exit 0
1469 fi
1472 # We may have a toolchain.cgi script for cross cooker's
1473 if [ -f "toolchain.cgi" ]; then
1474 toolchain="toolchain.cgi"
1475 else
1476 toolchain="?toolchain"
1477 fi
1479 # Main page with summary. Count only packages included in ARCH,
1480 # use 'cooker arch-db' to manually create arch.$ARCH files.
1482 cat <<-EOT
1483 <div id="content2">
1485 <section>
1486 <form method="get" action="" class="search r">
1487 <input type="hidden" name="search" value="pkg"/>
1488 <button type="submit" title="Search">Search</button>
1489 <input type="search" name="q" placeholder="Package" list="packages" autocorrect="off" autocapitalize="off"/>
1490 </form>
1491 EOT
1493 unset nojs
1494 part summary
1495 part webstat
1497 cat <<-EOT
1498 <p>
1499 Service logs:
1500 <a href="?cookorder.log">cookorder</a> ·
1501 <a href="?commits.log">commits</a> ·
1502 <a href="?pkgdb.log">pkgdb</a>
1503 </p>
1504 EOT
1506 if [ -e "$CACHE/cooker-request" -a ! -s $command ]; then
1507 if [ "$activity" -nt "$CACHE/cooker-request" ]; then
1508 echo '<a class="button icon bell r" href="?poke">Wake up</a>'
1509 else
1510 show_note i 'Cooker will be launched in the next 5 minutes.'
1511 fi
1512 fi
1514 cat <<-EOT
1515 <a class="button icon maintainers" href="?maintainer">For maintainers</a>
1516 <a class="button icon tag" href="~/">Tags</a>
1517 </section>
1518 EOT
1520 part activity
1521 part cooknotes
1522 part commits
1523 part cooklist
1524 part broken
1525 part blocked
1526 part pkgs
1528 echo '</div>'
1529 datalist
1530 page_footer
1531 exit 0
1532 fi
1535 # show tag
1537 if [ "$pkg" == '~' ]; then
1538 page_header
1539 echo '<div id="content2"><section>'
1541 if [ -n "$cmd" ]; then
1542 tag="$cmd"
1543 cat <<-EOT
1544 <h2>Tag “$tag”</h2>
1546 <table>
1547 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1548 <tbody>
1549 EOT
1550 sort $PKGS/packages-$ARCH.info \
1551 | awk -F$'\t' -vtag=" $tag " -vbase="$base/" '{
1552 if (index(" " $6 " ", tag)) {
1553 url = base $1 "/";
1554 gsub("+", "%2B", url);
1555 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1556 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1558 }'
1559 echo '</tbody></table>'
1560 else
1561 # Fast and nice tag cloud
1562 echo '<h2>Tag cloud</h2><p class="tags">'
1563 # Some magic in tag sizes :-) It's because of non-linear distribution
1564 # of tags. Currently 1x198 (each of 198 tags marks one package);
1565 # 2x79 (each of 79 other tags marks two packages); 3x28 (and so on);
1566 # 4x23; 5x14; 6x5; 7x9; 8x11; 9x4; 10x3; 11x5; 12x6; 13x3; 14x1; 15x1;
1567 # 16x2; 18x1; 20x3; 22x3; 23, 24, 27, 33, 39, 42, 45, 57, 59, 65, 90x1.
1568 awk -F$'\t' -vbase="$base/~/" '
1570 split($6, tags, " ");
1571 for (i in tags) { tag[tags[i]]++; if (tag[tags[i]] > max) max = tag[tags[i]]; }
1573 END {
1574 for (i in tag) {
1575 j = tag[i];
1576 size = (j == 1) ? 0 : (j == 2) ? 1 : (j < 5) ? 2 : (j < 9) ? 3 : (j < 18) ? 4 : 5;
1577 printf("<a href=\"%s\" class=\"tag%s\">%s<sup>%s</sup></a>\n", base i, size, i, tag[i]);
1580 ' $PKGS/packages-$ARCH.info | sort -f # sort alphabetically case insensitive
1581 fi
1582 echo '</p></section></div>'
1583 page_footer
1584 exit 0
1585 fi
1588 # show badges
1590 if [ "$pkg" == '=' ]; then
1591 page_header
1592 echo '<div id="content2">'
1594 if [ -n "$cmd" ]; then
1595 badge="$cmd"
1596 case "$badge" in
1597 no-badge)
1598 cat <<-EOT
1599 <section>
1600 <h2 class="badge $badge"> Packages without badges</h2>
1602 <table>
1603 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1604 <tbody>
1605 EOT
1607 ls $WOK \
1608 | while read pkg; do
1609 [ -s $WOK/$pkg/.badges ] && continue
1610 awk -F$'\t' -vpkg="$pkg" -vbase="$base/" '{
1611 if ($1 == pkg) {
1612 url = base $1 "/";
1613 gsub("+", "%2B", url);
1614 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1615 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1617 }' $PKGS/packages-$ARCH.info
1618 done
1619 ;;
1620 *)
1621 cat <<-EOT
1622 <section>
1623 <h2 class="badge $badge"> Badge “$badge”</h2>
1625 <table>
1626 <thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead>
1627 <tbody>
1628 EOT
1630 ls $WOK \
1631 | while read pkg; do
1632 [ -e $WOK/$pkg/.badges ] || continue
1633 grep -q "^${badge}$" $WOK/$pkg/.badges &&
1634 awk -F$'\t' -vpkg="$pkg" -vbase="$base/" '{
1635 if ($1 == pkg) {
1636 url = base $1 "/";
1637 gsub("+", "%2B", url);
1638 printf("<tr><td><img src=\"%ss/%s\" alt=\"%s\"> ", base, $1, $1);
1639 printf("<a href=\"%s\">%s</a></td><td>%s</td><td>%s</td></tr>\n", url, $1, $4, $3);
1641 }' $PKGS/packages-$ARCH.info
1642 done
1643 ;;
1644 esac
1645 echo '</tbody></table></section>'
1646 else
1647 layout='list' show_badges bdbroken broken any noany libtool nolibtool own ownover perm permover symlink ss fadd frem fdup old orphan patch win no-badge
1648 fi
1649 echo '</div>'
1650 page_footer
1651 exit 0
1652 fi
1655 case "$cmd" in
1656 '')
1657 page_header
1659 requested_pkg="$pkg"
1660 # Package info.
1661 if [ ! -f "$wok/$pkg/receipt" ]; then
1662 # Let's look at the cases when the package was not found
1664 # Maybe query is the exact name of split package? -> proceed to main package
1665 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1666 if (index(" " $2 " ", pkg)) {print $1; exit}
1667 }' $splitdb)
1669 # No, so let's find any matches among packages names (both main and split)
1670 if [ -z "$mainpkg" ]; then
1671 pkgs=$(cut -d$'\t' -f2 $splitdb | tr ' ' '\n' | fgrep "$pkg")
1672 # Nothing matched
1673 if [ -z "$pkgs" ]; then
1674 echo "<h2>Not Found</h2>"
1675 show_note e "The requested package <b>$pkg</b> was not found on this server."
1676 page_footer; exit 0
1677 fi
1678 # Search results page
1679 echo "<section><h2>Package names matching “$pkg”</h2>"
1680 echo "<table><thead><tr><th>Name</th><th>Description</th><th>Category</th></tr></thead><tbody>"
1681 query="$pkg"
1682 for pkg in $pkgs; do
1683 # Find main package
1684 mainpkg=$(awk -F$'\t' -vpkg=" $pkg " '{
1685 if (index(" " $2 " ", pkg)) {print $1; exit}
1686 }' $splitdb)
1687 unset SHORT_DESC CATEGORY; . $wok/$mainpkg/receipt
1689 unset SHORT_DESC CATEGORY
1690 [ -e "$wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt" ] &&
1691 . $wok/$mainpkg/taz/$PACKAGE-$VERSION/receipt
1693 echo -n "<tr><td><a href="$base/$pkg">${pkg//$query/<mark>$query</mark>}</a>"
1694 [ "$pkg" == "$mainpkg" ] || echo -n " (${mainpkg//$query/<mark>$query</mark>})"
1695 echo -n "</td><td>$SHORT_DESC</td><td>$CATEGORY</td></tr>"
1696 done
1697 echo '</tbody></table></section>'
1698 page_footer; exit 0
1699 fi
1700 pkg="$mainpkg"
1701 fi
1703 log=$LOGS/$pkg.log
1704 pkg_info
1706 # Check for a log file and display summary if it exists.
1707 summary "$log"
1710 # Show Cooker badges
1711 if [ -s $wok/$pkg/.badges ]; then
1712 layout='table' show_badges $(cat $wok/$pkg/.badges)
1713 fi
1716 # Repology badge
1717 [ "$REPOLOGY" == '-' ] || cat <<-EOT
1718 <section>
1719 <h3>Repology</h3>
1720 <a href="https://repology.org/metapackage/${REPOLOGY:-$pkg}" target='_blank'
1721 rel='noopener noreferrer' title="latest packaged version(s) by Repology">
1722 <img src="https://repology.org/badge/latest-versions/${REPOLOGY:-$pkg}.svg" alt="latest packaged version(s)">
1723 <img src="https://repology.org/badge/tiny-repos/${REPOLOGY:-$pkg}.svg" alt="Packaging status">
1724 </a>
1725 </section>
1726 EOT
1729 # Show tag list
1730 taglist=$(
1731 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1732 [ -s "$PKGS/packages-$ARCH.info" ] &&
1733 awk -F$'\t' -vpkg="$i" '{
1734 if ($1 == pkg) { print $6; exit; }
1735 }' "$PKGS/packages-$ARCH.info"
1736 done \
1737 | tr ' ' '\n' \
1738 | sort -u
1740 if [ -n "$taglist" ]; then
1741 echo -n '<section><h3>Tags</h3><p>'
1742 lasttag=$(echo "$taglist" | tail -n1)
1743 for tag in $taglist; do
1744 echo -n "<a href=\"$base/~/${tag//+/%2B}\">$tag</a>"
1745 [ "$tag" != "$lasttag" ] && echo -n " · "
1746 done
1747 echo '</p></section>'
1748 fi
1751 # Informational table with dependencies
1752 pkg="$requested_pkg"
1753 inf="$(mktemp -d)"
1755 # 1/3: Build dependencies (from receipt and pkgdb)
1756 for i in $WANTED $BUILD_DEPENDS $(awk -F$'\t' -vp=" $pkg " '{if (index(" " $2 " ", p) && (" " $1 " " != p)) print $1}' $splitdb); do
1757 echo "$i" >> $inf/a
1758 done
1760 # 2/3: Runtime dependencies (from pkgdb)
1762 [ -s "$PKGS/packages-$ARCH.info" ] &&
1763 awk -F$'\t' -vp="$pkg" '{
1764 if ($1 == p) print $8
1765 }' "$PKGS/packages-$ARCH.info"
1766 } | tr ' ' '\n' | sort -u > $inf/b
1768 # 3/3: Required by (from pkgdb)
1770 for i in $pkg $(awk -F$'\t' -vp="$pkg" '{if ($1 == p) print $2}' $splitdb); do
1771 [ -s "$PKGS/packages-$ARCH.info" ] &&
1772 awk -F$'\t' -vp=" $i " '{
1773 if (index(" " $8 " ", p)) print $1
1774 }' "$PKGS/packages-$ARCH.info"
1776 [ -s "$PKGS/bdeps.txt" ] &&
1777 awk -F$'\t' -vp=" $i " '{
1778 if (index(" " $2 " ", p)) print $1
1779 }' $PKGS/bdeps.txt
1780 done
1781 } | sort -u > $inf/c
1783 cat <<-EOT
1784 <section>
1785 <h3>Related packages</h3>
1786 <table class="third">
1787 <thead>
1788 <tr>
1789 <th>Build dependencies</th>
1790 <th>Runtime dependencies</th>
1791 <th>Required by</th>
1792 </tr>
1793 </thead>
1794 <tbody>
1795 EOT
1797 awk -vinf="$inf" -vbase="$base" '
1798 function linki(i) {
1799 if (i) return sprintf("<img src=\"%s/s/%s\" alt=\"%s\"> <a href=\"%s/%s\">%s</a>", base, i, i, base, i, i);
1801 BEGIN{
1802 do {
1803 a = b = c = "";
1804 getline a < inf "/a";
1805 getline b < inf "/b";
1806 getline c < inf "/c";
1807 printf("<tr><td>%s </td><td>%s </td><td>%s </td></tr>", linki(a), linki(b), linki(c));
1808 } while ( a b c )
1809 }'
1810 cat <<-EOT
1811 </tbody>
1812 </table>
1813 </section>
1814 EOT
1815 # Clean
1816 rm -r $inf
1821 # Display <Recook> button only for SliTaz web browser
1822 case "$HTTP_USER_AGENT" in
1823 *SliTaz*)
1824 if [ -f $CACHE/cooker-request -a -n "$HTTP_REFERER" ]; then
1825 if grep -qs "^$pkg$" $CACHE/recook-packages; then
1826 show_note i "The package “$pkg” has been requested for recook"
1827 else
1828 echo "<a class='button' href='$base/?recook=${pkg//+/%2B}'>Recook $pkg</a>"
1829 fi
1830 fi
1831 ;;
1832 esac
1833 ;;
1835 receipt)
1836 page_header
1837 pkg_info
1838 echo "<a class='button receipt' href='$base/$pkg/receipt'>receipt</a>"
1839 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1840 awk -vb="$base/$pkg" '{printf("<a class=\"button\" href=\"%s/%s\">%s</a>\n", b, $0, $0)}'
1842 show_code bash < $wok/$pkg/receipt
1843 ;;
1845 stuff)
1846 page_header
1847 pkg_info
1848 file="$pkg/stuff/$arg"
1849 echo "<a class='button' href='$base/$pkg/receipt'>receipt</a>"
1850 ( cd $wok/$pkg; find stuff -type f 2>/dev/null ) | sort | \
1851 awk -vb="$base/$pkg" -va="stuff/$arg" '{
1852 printf("<a class=\"button%s\" href=\"%s/%s\">%s</a>\n", a==$0 ? " receipt" : "", b, $0, $0)
1853 }'
1855 if [ -f "$wok/$file" ]; then
1856 case $file in
1857 *.desktop|*.theme) class="ini" ;;
1858 *.patch|*.diff|*.u) class="diff" ;;
1859 */patches/series) class="bash";;
1860 *.sh) class="bash" ;;
1861 *.conf*|*.ini)
1862 class="bash"
1863 [ -n "$(cut -c1 < $wok/$file | fgrep '[')" ] && class="ini"
1864 ;;
1865 *.pl) class="perl" ;;
1866 *.c|*.h|*.awk) class="clike" ;;
1867 *.svg) class="svg" ;;
1868 *Makefile*) class="makefile" ;;
1869 *.po|*.pot) class="bash" ;;
1870 *.css) class="css" ;;
1871 *.htm|*.html) class="html" ;;
1872 *.js) class="js" ;;
1873 *.txt) class="asciidoc" ;;
1874 *)
1875 case $(head -n1 $wok/$file) in
1876 *!/bin/sh*|*!/bin/bash*) class="bash" ;;
1877 esac
1878 if [ -z "$class" -a "$(head -n1 $wok/$file | cut -b1)" == '#' ]; then
1879 class="bash"
1880 fi
1881 if [ -z "$class" ]; then
1882 # Follow Busybox restrictions. Search for non-printable chars
1883 if [ $(tr -d '[:alnum:][:punct:][:blank:][:cntrl:]' < "$wok/$file" | wc -c) -gt 0 ]; then
1884 raw="true"
1885 fi
1886 fi
1887 ;;
1888 esac
1890 # Display image
1891 case $file in
1892 *.png|*.svg|*.jpg|*.jpeg|*.ico)
1893 echo "<img src='$base/$pkg/browse/stuff/$arg' style='display: block; max-width: 100%; margin: auto' alt=''/>"
1894 ;;
1895 esac
1897 # Display colored listing for all text-based documents (also for *.svg)
1898 case $file in
1899 *.png|*.jpg|*.jpeg|*.ico) ;;
1900 *)
1901 if [ -z "$raw" ]; then
1902 cat $wok/$file | show_code $class
1903 fi
1904 ;;
1905 esac
1907 # Display hex dump for binary files
1908 if [ -n "$raw" ]; then
1909 hexdump -C $wok/$file | show_code #| sed 's|^\([0-9a-f][0-9a-f]*\)|<span class="c2">\1</span>|'
1910 fi
1911 else
1912 show_note e "File “$file” absent!"
1913 fi
1914 ;;
1916 files)
1917 page_header
1918 pkg_info
1920 # find main package
1921 wanted=$(. $wok/$pkg/receipt; echo $WANTED)
1922 main=${wanted:-$pkg}
1923 devpkg=''; [ -d "$wok/$main-dev" ] && devpkg="$main-dev"
1925 splitsets=$(echo $SPLIT" " \
1926 | awk '
1927 BEGIN { RS = " "; FS = ":"; }
1928 { print $2; }' \
1929 | sort -u \
1930 | tr '\n' ' ' \
1931 | sed 's|^ *||; s| *$||')
1933 splitpkgs=$(echo $SPLIT" " \
1934 | awk '
1935 BEGIN { RS = " "; FS = ":"; }
1936 { print $1; }' \
1937 | tr '\n' ' ' \
1938 | sed 's|^ *||; s| *$||')
1940 # we need the version
1941 if [ -f "$WOK/linux/receipt" ]; then
1942 kvers=$(. $WOK/linux/receipt; echo $VERSION)
1943 kbasevers=$(echo $kvers | cut -d. -f1,2)
1944 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
1945 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
1946 kbasevers=$(echo $kvers | cut -d. -f1,2)
1947 fi
1948 ver=$(. $wok/$main/receipt; echo $VERSION$EXTRAVERSION)
1950 echo "<section><h3>Quick jump:</h3>"
1953 for part in head body; do
1955 for set in '' $splitsets; do
1956 pkgsofset=$(echo $SPLIT" " \
1957 | awk -vset="$set" -vmain="$main" -vdev="$devpkg" '
1958 BEGIN {
1959 RS = " "; FS = ":";
1960 if (!set) print main;
1961 if (!set && dev) print dev;
1964 if ($2 == set) print $1;
1965 }' \
1966 | sort -u)
1968 set_description=''
1969 [ -n "$splitsets" ] &&
1970 case "$set" in
1971 '')
1972 set_description=' (default set)'
1973 set_title='Default set'
1974 ;;
1975 *)
1976 set_description=" (set “$set”)"
1977 set_title="Set “$set”"
1978 ;;
1979 esac
1981 install="$wok/$main/install"
1982 [ -n "$set" ] && install="$install-$set"
1984 case $part in
1985 head)
1986 [ -n "$splitsets" ] &&
1987 case "$set" in
1988 '') echo "<ul><li>Default set:";;
1989 *) echo "<li>Set “$set”:";;
1990 esac
1991 echo -e '\t<ul>'
1992 echo "$pkgsofset" | sed 'p' | xargs printf "\t\t<li><a href='#%s'>%s</a></li>\n"
1993 cat <<-EOT
1994 <li id='li-repeats$set' style='display:none'>
1995 <a href='#repeats$set'>repeatedly packaged files</a></li>
1996 <li id='li-empty$set' style='display:none'>
1997 <a href='#empty$set'>unpackaged empty folders</a></li>
1998 <li id='li-outoftree$set' style='display:none'>
1999 <a href='#outoftree$set'>out-of-tree files</a></li>
2000 <li id='li-orphans$set' style='display:none'>
2001 <a href='#orphans$set'>unpackaged files</a>
2002 <span id='orphansTypes$set'></span></li>
2003 EOT
2004 echo -e '\t</ul>'
2005 [ -n "$splitsets" ] && echo "</li>"
2006 ;;
2007 body)
2008 all_files=$(mktemp)
2009 cd $install; find ! -type d | sed 's|\.||' > $all_files
2011 # ------------------------------------------------------
2012 # Packages content
2013 # ------------------------------------------------------
2014 packaged=$(mktemp)
2015 for p in $pkgsofset; do
2016 namever="$(awk -F$'\t' -vp="$p" '{
2017 if ($1==p) {printf("%s-%s\n", $1, $2); exit}
2018 }' $PKGS/packages-$ARCH.info)"
2019 if [ -d "$wok/$p/taz/$p-$ver" ]; then
2020 indir=$p
2021 elif [ -d "$wok/$main/taz/$p-$ver" ]; then
2022 indir=$main
2023 fi
2024 dir="$wok/$indir/taz/$p-$ver/fs"
2026 size=$(du -hs $dir | awk '{ sub(/\.0/, ""); print $1 }')
2028 echo
2029 echo "<section id='$p'>"
2030 echo " <h3>Contents of package “$namever” (${size:-empty}):</h3>"
2031 echo ' <pre class="files">'
2032 if [ -s "$wok/$indir/taz/$p-$ver/files.list" ]; then
2033 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2034 cd $dir
2035 find . -print0 \
2036 | sort -z \
2037 | xargs -0 ls -ldp --color=always \
2038 | syntax_highlighter files \
2039 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$indir/browse/taz/$p-$ver/fs\2'>\2\3|;" \
2040 | awk 'BEGIN { FS="\""; }
2041 { gsub("+", "%2B", $2); print; }'
2042 else
2043 echo 'No files'
2044 fi
2045 echo '</pre>'
2046 echo '</section>'
2048 cat $wok/$indir/taz/$p-$ver/files.list >> $packaged
2049 done
2050 # ------------------------------------------------------
2051 # /Packages content
2052 # ------------------------------------------------------
2054 # ------------------------------------------------------
2055 # Repeatedly packaged files
2056 # ------------------------------------------------------
2057 repeats=$(mktemp)
2058 sort $packaged | uniq -d > $repeats
2059 if [ -s "$repeats" ]; then
2060 cat <<-EOT
2062 <script>document.getElementById('li-repeats$set').style.display = 'list-item'</script>
2063 <section id='repeats$set'>
2064 <h3>Repeatedly packaged files$set_description:</h3>
2065 EOT
2066 cd $install
2068 IFS=$'\n'
2069 echo -n ' <pre class="files">'
2070 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2071 while read i; do
2072 find .$i -exec ls -ldp --color=always '{}' \; \
2073 | syntax_highlighter files \
2074 | sed 's|>\./|>/|'
2075 done < $repeats
2076 cat <<-EOT
2077 </pre>
2078 </section>
2079 EOT
2080 unset IFS
2081 fi
2082 rm $repeats
2083 # ------------------------------------------------------
2084 # /Repeatedly packaged files
2085 # ------------------------------------------------------
2087 # ------------------------------------------------------
2088 # Unpackaged empty folders
2089 # ------------------------------------------------------
2090 emptydirs=$(mktemp)
2091 cd $install
2092 IFS=$'\n'
2093 find -type d \
2094 | sed 's|\.||' \
2095 | while read d; do
2096 [ -z "$(ls "$install$d")" ] || continue
2097 # empty dir determined by empty `ls`
2098 echo $d
2099 done \
2100 | while read d; do
2101 notfound='yes'
2102 for p in $(cd $wok/$main/taz; ls); do
2103 if [ -d "$wok/$main/taz/$p/fs$d" ]; then
2104 notfound=''
2105 break
2106 fi
2107 done
2108 [ -n "$notfound" ] &&
2109 ls -ldp --color=always .$d \
2110 | syntax_highlighter files \
2111 | sed 's|>\./|>/|'
2112 done > $emptydirs
2113 unset IFS
2114 if [ -s "$emptydirs" ]; then
2115 cat <<-EOT
2117 <script>document.getElementById('li-empty$set').style.display = 'list-item'</script>
2118 <section id='empty$set'>
2119 <h3>Unpackaged empty folders$set_description:</h3>
2120 EOT
2121 echo -n ' <pre class="files">'
2122 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2123 cat $emptydirs
2124 cat <<-EOT
2125 </pre>
2126 </section>
2127 EOT
2128 fi
2129 rm $emptydirs
2130 # ------------------------------------------------------
2131 # /Unpackaged empty folders
2132 # ------------------------------------------------------
2134 # ------------------------------------------------------
2135 # Out-of-tree files
2136 # ------------------------------------------------------
2137 outoftree=$(mktemp)
2138 awk -F$'\n' -vall="$all_files" '
2140 if (FILENAME == all) files_all[$1] = "1";
2141 else files_pkg[$1] = "1";
2143 END {
2144 for (i in files_pkg) {
2145 if (! files_all[i]) print i;
2148 ' "$all_files" "$packaged" > $outoftree
2150 if [ -d "$install" -a -s "$outoftree" ]; then
2151 echo
2152 echo "<script>document.getElementById('li-outoftree$set').style.display = 'list-item'</script>"
2153 echo "<section id='outoftree$set'>"
2154 echo " <h3>Out-of-tree files$set_description:</h3>"
2155 echo -n ' <pre class="files">'
2156 echo -en '<span class="underline">permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2157 IFS=$'\n'
2158 while read outoftree_line; do
2159 # Find the package out-of-tree file belongs to
2160 for i in $pkgsofset; do
2161 if grep -q "^$outoftree_line$" $wok/$main/taz/$i-$ver/files.list; then
2162 cd $wok/$main/taz/$i-$ver/fs
2163 ls -ldp --color=always ".$outoftree_line" \
2164 | syntax_highlighter files \
2165 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/taz/$i-$ver/fs\2'>\2\3|;" \
2166 | awk 'BEGIN { FS="\""; }
2167 { gsub("+", "%2B", $2); print; }'
2168 fi
2169 done
2170 done < $outoftree
2171 unset IFS
2172 echo '</pre>'
2173 echo '</section>'
2174 fi
2175 rm $outoftree
2176 # ------------------------------------------------------
2177 # /Out-of-tree files
2178 # ------------------------------------------------------
2180 # ------------------------------------------------------
2181 # Unpackaged files
2182 # ------------------------------------------------------
2183 orphans=$(mktemp)
2184 awk -F$'\n' -vall="$all_files" '
2186 if (FILENAME == all) files_all[$1] = "1";
2187 else files_pkg[$1] = "1";
2189 END {
2190 for (i in files_all) {
2191 if (! files_pkg[i]) print i;
2194 ' "$all_files" "$packaged" | sort > $orphans
2195 if [ -d "$install" -a -s "$orphans" ]; then
2196 echo
2197 echo "<script>document.getElementById('li-orphans$set').style.display = 'list-item'</script>"
2198 echo "<section id='orphans$set'>"
2199 echo " <h3>Unpackaged files$set_description:</h3>"
2200 table=$(mktemp)
2201 awk '
2202 function tag(text, color) {
2203 printf("<span class=\"c%s1\">%s</span> ", color, text);
2204 printf("%s\n", $0);
2206 /\/perllocal\.pod$/ || /\/\.packlist$/ ||
2207 /\/share\/bash-completion\// || /\/etc\/bash_completion\.d\// ||
2208 /\/lib\/systemd\// || /\.pyc$/ || /\.pyo$/ ||
2209 /\/fonts\.scale$/ || /\/fonts\.dir$/ || /\.la$/ ||
2210 /\/cache\/.*\.gem$/ {
2211 tag("---", 0); next }
2212 /\.pod$/ { tag("pod", 5); next }
2213 /\/share\/man\// { tag("man", 5); next }
2214 /\/share\/doc\// || /\/share\/gtk-doc\// || /\/share\/info\// ||
2215 /\/share\/devhelp\// { tag("doc", 5); next }
2216 /\/share\/icons\// { tag("ico", 2); next }
2217 /\/share\/locale\// { tag("loc", 4); next }
2218 /\.h$/ || /\.a$/ || /\.pc$/ || /\/bin\/.*-config$/ ||
2219 /\/Makefile.*$/ { tag("dev", 3); next }
2220 /\/share\/help\// || /\/share\/appdata\// ||
2221 /\/share\/metainfo\// || /\/share\/application-registry\// ||
2222 /\/share\/mime-info\// || /\/share\/gnome\/help\// || /\/share\/omf\// {
2223 tag("gnm", 6); next }
2224 { tag("???", 1) }
2225 ' "$orphans" > $table
2227 # Summary table
2228 orphans_types='()'
2229 for i in head body; do
2230 case $i in
2231 head) echo -n '<table class="summary"><tr>';;
2232 body) echo -n '<th> </th></tr><tr>';;
2233 esac
2234 for j in '???1' dev3 loc4 ico2 doc5 man5 pod5 gnm6 '---0'; do
2235 tag=${j:0:3}; class="c${j:3:1}0"; [ "$class" == 'c00' ] && class='c01'
2236 case $i in
2237 head) echo -n "<th class='$class'>$tag</th>";;
2238 body)
2239 tagscount="$(grep ">$tag<" $table | wc -l)"
2240 printf '<td>%s</td>' "$tagscount"
2241 [ "$tagscount" -gt 0 ] && orphans_types="${orphans_types/)/ $tag)}"
2242 ;;
2243 esac
2244 done
2245 done
2246 echo '<td> </td></tr></table>'
2247 orphans_types="${orphans_types/( /(}"
2248 [ "$orphans_types" != '()' ] &&
2249 echo "<script>document.getElementById('orphansTypes$set').innerText = '${orphans_types// /, }';</script>"
2251 suffix=''; [ -n "$set" ] && suffix="-$set"
2252 echo -n ' <pre class="files">'
2253 echo -en '<span class="underline">tag·permissions·lnk·user ·group · size·date &amp; time ·name\n</span>'
2254 IFS=$'\n'
2255 while read orphan_line; do
2256 echo -n "${orphan_line/span> */span>} "
2257 cd $install
2258 ls -ldp --color=always ".${orphan_line#*</span> }" \
2259 | syntax_highlighter files \
2260 | sed "s|\([^>]*\)>\.\([^<]*\)\(<.*\)$|\1 href='$base/$main/browse/install$suffix\2'>\2\3|;" \
2261 | awk 'BEGIN { FS="\""; }
2262 { gsub("+", "%2B", $2); print; }'
2263 done < $table
2264 unset IFS
2265 echo '</pre>'
2266 echo '</section>'
2267 rm $table
2268 fi
2269 rm $orphans
2270 # ------------------------------------------------------
2271 # /Unpackaged files
2272 # ------------------------------------------------------
2274 rm $all_files $packaged
2275 ;;
2276 esac
2277 done # /set
2279 case "$part" in
2280 head)
2281 [ -n "$splitsets" ] && echo "</ul>"
2282 echo "</section>"
2283 ;;
2284 esac
2285 done # /part
2287 ;;
2289 description)
2290 page_header
2291 pkg_info
2292 descs="$(ls $WOK/$pkg/description*.txt)"
2293 if [ -n "$descs" ]; then
2294 echo '<div id="content2">'
2295 [ -f "$WOK/$pkg/description.txt" ] && show_desc "$pkg" "$WOK/$pkg/description.txt"
2296 for i in $descs; do
2297 case $i in
2298 */description.txt) continue ;;
2299 *) package=$(echo $i | cut -d. -f2) ;;
2300 esac
2301 show_desc "$package" "$i"
2302 done
2303 echo '</div>'
2304 else
2305 show_note w "No description of $pkg"
2306 fi
2307 ;;
2309 log)
2310 page_header
2311 pkg_info
2312 [ -z "$arg" ] && arg=$(stat -c %Y $LOGS/$pkg.log)
2314 echo '<div class="btnList">'
2315 acc='l' # access key for the latest log is 'L'
2316 while read log; do
2317 # for all $pkg.log, $pkg.log.0 .. $pkg.log.9, $pkg-pack.log (if any)
2318 timestamp=$(stat -c %Y $log)
2319 class=''
2320 if [ "$arg" == "$timestamp" ]; then
2321 class=' log'
2322 logfile="$log"
2323 fi
2324 case $log in *-pack.log) acc='p';; esac # access key for the packing log is 'P'
2325 echo -n "<a class='button$class' data-acc='$acc' accesskey='$acc' href='$base/$pkg/log/$timestamp'>"
2326 echo "$(stat -c %y $log | cut -d: -f1,2)</a>"
2327 case $acc in
2328 l) acc=0;;
2329 *) acc=$((acc+1));;
2330 esac
2331 done <<EOT
2332 $(find $LOGS -name "$pkg.log*" | sort)
2333 $(find $LOGS -name "$pkg-pack.log")
2334 EOT
2335 echo '</div>'
2337 if [ -z "$logfile" ]; then
2338 show_note e "Requested log is absent"
2339 page_footer
2340 exit 0
2341 fi
2343 # Define cook variables for syntax highlighter
2344 if [ -s "$WOK/$pkg/receipt" ]; then
2345 . "$WOK/$pkg/receipt"
2346 _wok='/home/slitaz/wok'
2347 _src="$_wok/$pkg/source/$PACKAGE-$VERSION"
2348 _install="$_wok/$pkg/install"
2349 _fs="$_wok/$pkg/taz/$PACKAGE-$VERSION/fs"
2350 _stuff="$_wok/$pkg/stuff"
2351 fi
2353 # if [ ! -f "gzlog/$pkg.$arg" ]; then
2354 # {
2355 # summary "$logfile" links
2357 # syntax_highlighter log < $logfile | awk '
2358 # BEGIN { print "<pre class=\"log\">"; }
2359 # { printf("<a name=\"l%d\" href=\"#l%d\">%5d</a> %s\n", NR, NR, NR, $0); }
2360 # END { print "</pre>"; }
2361 # '
2363 # page_footer
2364 # } | gzip > gzlog/$pkg.$arg
2365 # fi
2367 blog=$(basename $logfile)
2368 summary "$logfile" links
2370 # disable next `sed` for the 'like2016' theme
2371 theme=$(COOKIE theme); theme=${theme:-default}; [ "$theme" != 'like2016' ] && theme=''
2372 cat $logfile | syntax_highlighter log | \
2373 sed -e "/(pkg\/local$theme):/ s|: \([^<]*\)|<img src='$base/i/$blog/\1' alt=''> \1|" | \
2374 awk '
2375 BEGIN { print "<pre class=\"log\">"; }
2376 { printf("<span id=\"l%d\">%s</span><a href=\"#l%d\"></a>\n", NR, $0, NR); }
2377 END { print "</pre>"; }
2379 ;;
2382 man|doc|info)
2383 page_header
2384 pkg_info
2385 echo '<div style="max-height: 6.4em; overflow: auto; padding: 0 4px">'
2387 dir="wok/$pkg/install/usr/share/$cmd/"; dir2=''
2388 if [ "$cmd" == 'doc' ]; then
2389 dir2="wok/$pkg/install/usr/share/gtk-doc/"
2390 subdirs="$(ls -p $dir | sed '/\/$/!d')"
2391 [ $(echo "$subdirs" | wc -l) -eq 1 ] && dir="$dir$subdirs"
2392 if [ -z "$arg" ]; then
2393 try=$(for i in $dir $dir2; do find $i -name 'index.htm*'; done | sed q)
2394 [ -n "$try" ] && arg="$try"
2395 fi
2396 fi
2398 while read i; do
2399 [ -s "$i" ] || continue
2400 case "$i" in
2401 *.jp*g|*.png|*.gif|*.svg|*.css) continue
2402 esac
2403 i=${i#$dir}; i=${i#$dir2}
2404 [ -n "$arg" ] || arg="$i"
2405 class=''; [ "$arg" == "$i" ] && class=" doc"
2406 case "$cmd" in
2407 man)
2408 case $i in
2409 man*) lang='';;
2410 *) lang="${i%%/*}: ";;
2411 esac
2412 man=$(basename $i .gz)
2413 echo "<a class='button$class' href='$base/$pkg/man/$i'>$lang${man%.*} (${man##*.})</a>"
2414 ;;
2415 doc)
2416 echo "<a class='button$class' href='$base/$pkg/doc/$i'>$i</a>"
2417 ;;
2418 info)
2419 info=$(basename $i)
2420 echo "<a class='button$class' href='$base/$pkg/info/$i#Top'>${info/.info/}</a>"
2421 ;;
2422 esac
2423 done <<EOT
2424 $(for i in $dir $dir2; do find $i -type f; done | sort)
2425 EOT
2426 echo '</div>'
2428 [ -f "$arg" ] || arg="$dir/$arg"
2429 if [ -f "$arg" ]; then
2430 tmp="$(mktemp)"
2431 docat "$arg" > $tmp
2432 [ -s "$tmp" ] &&
2433 case "$cmd" in
2434 info)
2435 echo '<div id="content2" class="texinfo"><pre class="first">'
2436 info2html < "$tmp"
2437 echo '</pre></div>'
2438 ;;
2439 doc)
2440 case "$arg" in
2441 *.sgml|*.devhelp2) class='xml';;
2442 *.py) class='python';; # pycurl package
2443 *.css) class='css';;
2444 *.sh) class='bash';;
2445 *.rb|*/Rakefile*|*/Gemfile*) class='ruby';;
2446 *.rdoc) class='asciidoc';;
2447 *)
2448 first=$(head -n1 "$tmp")
2449 if [ "${first:0:1}" == '#' ]; then
2450 class='bash' # first line begins with '#'
2451 else
2452 class='asciidoc'
2453 fi;;
2454 esac
2455 case "$arg" in
2456 *.htm*)
2457 case $arg in
2458 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2459 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2460 esac
2461 # make the iframe height so long to contain its contents without scrollbar
2462 echo "<iframe id='idoc' src='$page' width='100%' onload='resizeIframe(this)'></iframe>"
2463 ;;
2464 *.pdf)
2465 case $arg in
2466 wok/*) page="${arg#wok/}"; page="$base/$pkg/browse/${page#*/}";;
2467 *) page="$base/$pkg/browse/install/usr/share/$cmd/$arg";;
2468 esac
2469 cat <<-EOT
2470 <object id="idoc" data="$page" width="100%" height="100%" type="application/pdf" style="min-height: 600px">
2471 $(show_note w "Missing PDF plugin.<br/>Get the file <a href="$page">$(basename "$page")</a>.")
2472 </object>
2473 EOT
2474 ;;
2475 *.md|*.markdown)
2476 echo '<section class="markdown">'
2477 $md2html "$tmp" | sed 's|class="|class="language-|g'
2478 echo '</section>'
2479 ;;
2480 *)
2481 show_code $class < "$tmp"
2482 ;;
2483 esac
2484 ;;
2485 man)
2486 #export TEXTDOMAIN='man2html'
2487 echo "<div id='content2'>"
2489 html=$(./man2html.bin "$tmp" | sed -e '1,/<header>/d' -e '/<footer>/,$d' \
2490 -e 's|<a href="file:///[^>]*>\([^<]*\)</a>|\1|g' \
2491 -e 's|<a href="?[1-9]\+[^>]*>\([^<]*\)</a>|\1|g')
2493 if [ -n "$(echo "$html" | fgrep 'The requested file /tmp/tmp.')" ]; then
2494 # Process the pre-formatted man-cat page
2495 # (for example see sudo package without groff in build dependencies)
2496 sed -i '
2497 s|M-bM-^@M-^S|—|g;
2498 s|M-bM-^@M-^\\|<b>|g;
2499 s|M-bM-^@M-^]|</b>|g
2500 s|M-bM-^@M-^X|<u>|g;
2501 s|M-bM-^@M-^Y|</u>|g;
2502 s|M-BM-||g;
2503 s|++oo|•|g;
2504 s|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g;
2505 ' "$tmp"
2506 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 \
2507 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 \
2508 0 1 2 3 4 5 6 7 8 9 _ - '\\+' '\.' /; do
2509 sed -i "s|$i$i|<b>$i</b>|g; s|_$i|<u>$i</u>|g" "$tmp"
2510 done
2511 echo '<pre class="catman">'
2512 sed 's|</b><b>||g; s|</u><u>||g; s|</u><b>_</b><u>|_|g; s|</b> <b>| |g;' "$tmp"
2513 echo '</pre>'
2514 else
2515 echo "$html"
2516 fi
2517 echo "</div>"
2518 ;;
2519 esac
2520 rm -f $tmp
2521 else
2522 show_note e "File “$arg” does not exist!"
2523 fi
2524 ;;
2526 download)
2527 page_header
2528 pkg_info
2529 show=0
2531 . $wok/$pkg/receipt
2533 if [ -n "$TARBALL" -a -s "$SRC/$TARBALL" ]; then
2534 files_header
2535 echo "<tr><td><a href='$base/src/$TARBALL' class='icon tarball'>$TARBALL</a></td>"
2536 ls -lh "$SRC/$TARBALL" | awk '{printf("<td>%sB</td>", $5)}'
2537 echo "<td>Sources for building the package “$pkg”</td></tr>"
2538 show=1
2539 fi
2541 if [ -d "$wok/$pkg/taz" ]; then
2542 [ "$show" -eq 1 ] || files_header
2544 common_version=$VERSION
2545 for i in $(all_names | tr ' ' '\n' | sort); do
2546 [ -e "$wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt" ] || continue
2547 . $wok/$pkg/taz/$i-$common_version$EXTRAVERSION/receipt
2549 for filename in "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" "$PACKAGE-$VERSION$EXTRAVERSION-any.tazpkg"; do
2550 [ -f "$PKGS/$filename" ] || continue
2552 case $filename in
2553 *-x86_64.tazpkg) class='pkg64';;
2554 *-any.tazpkg) class='pkgany';;
2555 *) class='pkg32';;
2556 esac
2557 cat <<-EOT
2558 <tr>
2559 <td><a href="$base/get/$filename" class='icon $class'>$filename</a></td>
2560 <td>$(ls -lh ./packages/$filename | awk '{printf("%sB", $5)}')</td>
2561 <td>$SHORT_DESC</td>
2562 </tr>
2563 EOT
2564 done
2565 done
2566 show=1
2567 fi
2569 if [ "$show" -eq 1 ]; then
2570 echo '</tbody></table></section>'
2571 else
2572 show_note w "Sorry, there's nothing to download…"
2573 fi
2574 ;;
2576 esac
2579 page_footer
2580 exit 0