cookutils view lighttpd/index.cgi @ rev 1144

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